Tonne of debugging - getting ready for the production builds
This commit is contained in:
3
api/dist/modules/auth/auth.routes.d.ts
vendored
Normal file
3
api/dist/modules/auth/auth.routes.d.ts
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
declare const router: import("express-serve-static-core").Router;
|
||||
export { router as authRouter };
|
||||
//# sourceMappingURL=auth.routes.d.ts.map
|
||||
1
api/dist/modules/auth/auth.routes.d.ts.map
vendored
Normal file
1
api/dist/modules/auth/auth.routes.d.ts.map
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"auth.routes.d.ts","sourceRoot":"","sources":["../../../src/modules/auth/auth.routes.ts"],"names":[],"mappings":"AAOA,QAAA,MAAM,MAAM,4CAAW,CAAC;AAmGxB,OAAO,EAAE,MAAM,IAAI,UAAU,EAAE,CAAC"}
|
||||
116
api/dist/modules/auth/auth.routes.js
vendored
Normal file
116
api/dist/modules/auth/auth.routes.js
vendored
Normal file
@@ -0,0 +1,116 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
var desc = Object.getOwnPropertyDescriptor(m, k);
|
||||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
||||
desc = { enumerable: true, get: function() { return m[k]; } };
|
||||
}
|
||||
Object.defineProperty(o, k2, desc);
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||
}) : function(o, v) {
|
||||
o["default"] = v;
|
||||
});
|
||||
var __importStar = (this && this.__importStar) || (function () {
|
||||
var ownKeys = function(o) {
|
||||
ownKeys = Object.getOwnPropertyNames || function (o) {
|
||||
var ar = [];
|
||||
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
||||
return ar;
|
||||
};
|
||||
return ownKeys(o);
|
||||
};
|
||||
return function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
})();
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.authRouter = void 0;
|
||||
const express_1 = require("express");
|
||||
const auth_service_1 = require("./auth.service");
|
||||
const auth_schemas_1 = require("./auth.schemas");
|
||||
const validate_1 = require("../../middleware/validate");
|
||||
const auth_middleware_1 = require("../../middleware/auth.middleware");
|
||||
const rate_limit_1 = require("../../middleware/rate-limit");
|
||||
const router = (0, express_1.Router)();
|
||||
exports.authRouter = router;
|
||||
// POST /api/auth/login
|
||||
router.post('/login', rate_limit_1.authRateLimit, (0, validate_1.validate)(auth_schemas_1.loginSchema), async (req, res, next) => {
|
||||
try {
|
||||
const result = await auth_service_1.authService.login(req.body.email, req.body.password);
|
||||
res.json(result);
|
||||
}
|
||||
catch (err) {
|
||||
next(err);
|
||||
}
|
||||
});
|
||||
// POST /api/auth/register
|
||||
router.post('/register', rate_limit_1.authRateLimit, (0, validate_1.validate)(auth_schemas_1.registerSchema), async (req, res, next) => {
|
||||
try {
|
||||
const result = await auth_service_1.authService.register(req.body);
|
||||
res.status(201).json(result);
|
||||
}
|
||||
catch (err) {
|
||||
next(err);
|
||||
}
|
||||
});
|
||||
// POST /api/auth/refresh
|
||||
router.post('/refresh', rate_limit_1.authRateLimit, (0, validate_1.validate)(auth_schemas_1.refreshSchema), async (req, res, next) => {
|
||||
try {
|
||||
const result = await auth_service_1.authService.refreshTokens(req.body.refreshToken);
|
||||
res.json(result);
|
||||
}
|
||||
catch (err) {
|
||||
next(err);
|
||||
}
|
||||
});
|
||||
// POST /api/auth/logout
|
||||
router.post('/logout', rate_limit_1.authRateLimit, (0, validate_1.validate)(auth_schemas_1.refreshSchema), async (req, res, next) => {
|
||||
try {
|
||||
await auth_service_1.authService.logout(req.body.refreshToken);
|
||||
res.json({ message: 'Logged out' });
|
||||
}
|
||||
catch (err) {
|
||||
next(err);
|
||||
}
|
||||
});
|
||||
// GET /api/auth/me
|
||||
router.get('/me', auth_middleware_1.authenticate, async (req, res, next) => {
|
||||
try {
|
||||
const { prisma } = await Promise.resolve().then(() => __importStar(require('../../config/database')));
|
||||
const user = await prisma.user.findUnique({
|
||||
where: { id: req.user.id },
|
||||
select: {
|
||||
id: true,
|
||||
email: true,
|
||||
name: true,
|
||||
phone: true,
|
||||
role: true,
|
||||
status: true,
|
||||
permissions: true,
|
||||
createdVia: true,
|
||||
emailVerified: true,
|
||||
lastLoginAt: true,
|
||||
createdAt: true,
|
||||
updatedAt: true,
|
||||
},
|
||||
});
|
||||
if (!user) {
|
||||
res.status(401).json({ error: { message: 'Invalid token', code: 'INVALID_TOKEN' } });
|
||||
return;
|
||||
}
|
||||
res.json(user);
|
||||
}
|
||||
catch (err) {
|
||||
next(err);
|
||||
}
|
||||
});
|
||||
//# sourceMappingURL=auth.routes.js.map
|
||||
1
api/dist/modules/auth/auth.routes.js.map
vendored
Normal file
1
api/dist/modules/auth/auth.routes.js.map
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"auth.routes.js","sourceRoot":"","sources":["../../../src/modules/auth/auth.routes.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,qCAAkE;AAClE,iDAA6C;AAC7C,iDAA4E;AAC5E,wDAAqD;AACrD,sEAAgE;AAChE,4DAA4D;AAE5D,MAAM,MAAM,GAAG,IAAA,gBAAM,GAAE,CAAC;AAmGL,4BAAU;AAjG7B,uBAAuB;AACvB,MAAM,CAAC,IAAI,CACT,QAAQ,EACR,0BAAa,EACb,IAAA,mBAAQ,EAAC,0BAAW,CAAC,EACrB,KAAK,EAAE,GAAY,EAAE,GAAa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E,OAAO,EAAE,eAAe,EAAE,IAAI,EAAE,eAAe,EAAE,EAAE,CAAC,CAAC;YACrF,OAAO;QACT,CAAC;QAED,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACjB,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,IAAI,CAAC,GAAG,CAAC,CAAC;IACZ,CAAC;AACH,CAAC,CACF,CAAC"}
|
||||
38
api/dist/modules/auth/auth.schemas.d.ts
vendored
Normal file
38
api/dist/modules/auth/auth.schemas.d.ts
vendored
Normal file
@@ -0,0 +1,38 @@
|
||||
import { z } from 'zod';
|
||||
export declare const loginSchema: z.ZodObject<{
|
||||
email: z.ZodString;
|
||||
password: z.ZodString;
|
||||
}, "strip", z.ZodTypeAny, {
|
||||
email: string;
|
||||
password: string;
|
||||
}, {
|
||||
email: string;
|
||||
password: string;
|
||||
}>;
|
||||
export declare const registerSchema: z.ZodObject<{
|
||||
email: z.ZodString;
|
||||
password: z.ZodString;
|
||||
name: z.ZodOptional<z.ZodString>;
|
||||
phone: z.ZodOptional<z.ZodString>;
|
||||
}, "strip", z.ZodTypeAny, {
|
||||
email: string;
|
||||
password: string;
|
||||
name?: string | undefined;
|
||||
phone?: string | undefined;
|
||||
}, {
|
||||
email: string;
|
||||
password: string;
|
||||
name?: string | undefined;
|
||||
phone?: string | undefined;
|
||||
}>;
|
||||
export declare const refreshSchema: z.ZodObject<{
|
||||
refreshToken: z.ZodString;
|
||||
}, "strip", z.ZodTypeAny, {
|
||||
refreshToken: string;
|
||||
}, {
|
||||
refreshToken: string;
|
||||
}>;
|
||||
export type LoginInput = z.infer<typeof loginSchema>;
|
||||
export type RegisterInput = z.infer<typeof registerSchema>;
|
||||
export type RefreshInput = z.infer<typeof refreshSchema>;
|
||||
//# sourceMappingURL=auth.schemas.d.ts.map
|
||||
1
api/dist/modules/auth/auth.schemas.d.ts.map
vendored
Normal file
1
api/dist/modules/auth/auth.schemas.d.ts.map
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"auth.schemas.d.ts","sourceRoot":"","sources":["../../../src/modules/auth/auth.schemas.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB,eAAO,MAAM,WAAW;;;;;;;;;EAGtB,CAAC;AAEH,eAAO,MAAM,cAAc;;;;;;;;;;;;;;;EAUzB,CAAC;AAEH,eAAO,MAAM,aAAa;;;;;;EAExB,CAAC;AAEH,MAAM,MAAM,UAAU,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,WAAW,CAAC,CAAC;AACrD,MAAM,MAAM,aAAa,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,cAAc,CAAC,CAAC;AAC3D,MAAM,MAAM,YAAY,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,aAAa,CAAC,CAAC"}
|
||||
23
api/dist/modules/auth/auth.schemas.js
vendored
Normal file
23
api/dist/modules/auth/auth.schemas.js
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.refreshSchema = exports.registerSchema = exports.loginSchema = void 0;
|
||||
const zod_1 = require("zod");
|
||||
exports.loginSchema = zod_1.z.object({
|
||||
email: zod_1.z.string().email(),
|
||||
password: zod_1.z.string().min(1, 'Password is required'),
|
||||
});
|
||||
exports.registerSchema = zod_1.z.object({
|
||||
email: zod_1.z.string().email(),
|
||||
password: zod_1.z.string()
|
||||
.min(12, 'Password must be at least 12 characters')
|
||||
.regex(/[A-Z]/, 'Password must contain at least one uppercase letter')
|
||||
.regex(/[a-z]/, 'Password must contain at least one lowercase letter')
|
||||
.regex(/[0-9]/, 'Password must contain at least one digit'),
|
||||
name: zod_1.z.string().optional(),
|
||||
phone: zod_1.z.string().optional(),
|
||||
// Role removed from public registration - must be set server-side only
|
||||
});
|
||||
exports.refreshSchema = zod_1.z.object({
|
||||
refreshToken: zod_1.z.string().min(1, 'Refresh token is required'),
|
||||
});
|
||||
//# sourceMappingURL=auth.schemas.js.map
|
||||
1
api/dist/modules/auth/auth.schemas.js.map
vendored
Normal file
1
api/dist/modules/auth/auth.schemas.js.map
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"auth.schemas.js","sourceRoot":"","sources":["../../../src/modules/auth/auth.schemas.ts"],"names":[],"mappings":";;;AAAA,6BAAwB;AAGX,QAAA,WAAW,GAAG,OAAC,CAAC,MAAM,CAAC;IAClC,KAAK,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,KAAK,EAAE;IACzB,QAAQ,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,EAAE,sBAAsB,CAAC;CACpD,CAAC,CAAC;AAEU,QAAA,cAAc,GAAG,OAAC,CAAC,MAAM,CAAC;IACrC,KAAK,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,KAAK,EAAE;IACzB,QAAQ,EAAE,OAAC,CAAC,MAAM,EAAE;SACjB,GAAG,CAAC,EAAE,EAAE,yCAAyC,CAAC;SAClD,KAAK,CAAC,OAAO,EAAE,qDAAqD,CAAC;SACrE,KAAK,CAAC,OAAO,EAAE,qDAAqD,CAAC;SACrE,KAAK,CAAC,OAAO,EAAE,0CAA0C,CAAC;IAC7D,IAAI,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAC3B,KAAK,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAC5B,uEAAuE;CACxE,CAAC,CAAC;AAEU,QAAA,aAAa,GAAG,OAAC,CAAC,MAAM,CAAC;IACpC,YAAY,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,EAAE,2BAA2B,CAAC;CAC7D,CAAC,CAAC"}
|
||||
86
api/dist/modules/auth/auth.service.d.ts
vendored
Normal file
86
api/dist/modules/auth/auth.service.d.ts
vendored
Normal file
@@ -0,0 +1,86 @@
|
||||
import { UserRole } from '@prisma/client';
|
||||
import type { RegisterInput } from './auth.schemas';
|
||||
interface TokenPair {
|
||||
accessToken: string;
|
||||
refreshToken: string;
|
||||
}
|
||||
export declare const authService: {
|
||||
login(email: string, password: string): Promise<{
|
||||
accessToken: string;
|
||||
refreshToken: string;
|
||||
user: {
|
||||
status: import(".prisma/client").$Enums.UserStatus;
|
||||
id: string;
|
||||
email: string;
|
||||
name: string | null;
|
||||
phone: string | null;
|
||||
role: import(".prisma/client").$Enums.UserRole;
|
||||
permissions: import("@prisma/client/runtime/library").JsonValue | null;
|
||||
createdVia: import(".prisma/client").$Enums.UserCreatedVia;
|
||||
expiresAt: Date | null;
|
||||
expireDays: number | null;
|
||||
lastLoginAt: Date | null;
|
||||
emailVerified: boolean;
|
||||
createdAt: Date;
|
||||
updatedAt: Date;
|
||||
};
|
||||
}>;
|
||||
register(data: RegisterInput): Promise<{
|
||||
accessToken: string;
|
||||
refreshToken: string;
|
||||
user: {
|
||||
status: import(".prisma/client").$Enums.UserStatus;
|
||||
id: string;
|
||||
email: string;
|
||||
name: string | null;
|
||||
phone: string | null;
|
||||
role: import(".prisma/client").$Enums.UserRole;
|
||||
permissions: import("@prisma/client/runtime/library").JsonValue | null;
|
||||
createdVia: import(".prisma/client").$Enums.UserCreatedVia;
|
||||
expiresAt: Date | null;
|
||||
expireDays: number | null;
|
||||
lastLoginAt: Date | null;
|
||||
emailVerified: boolean;
|
||||
createdAt: Date;
|
||||
updatedAt: Date;
|
||||
};
|
||||
}>;
|
||||
refreshTokens(refreshToken: string): Promise<{
|
||||
accessToken: string;
|
||||
refreshToken: string;
|
||||
user: {
|
||||
status: import(".prisma/client").$Enums.UserStatus;
|
||||
id: string;
|
||||
email: string;
|
||||
name: string | null;
|
||||
phone: string | null;
|
||||
role: import(".prisma/client").$Enums.UserRole;
|
||||
permissions: import("@prisma/client/runtime/library").JsonValue | null;
|
||||
createdVia: import(".prisma/client").$Enums.UserCreatedVia;
|
||||
expiresAt: Date | null;
|
||||
expireDays: number | null;
|
||||
lastLoginAt: Date | null;
|
||||
emailVerified: boolean;
|
||||
createdAt: Date;
|
||||
updatedAt: Date;
|
||||
};
|
||||
}>;
|
||||
logout(refreshToken: string): Promise<void>;
|
||||
generateAccessToken(user: {
|
||||
id: string;
|
||||
email: string;
|
||||
role: UserRole;
|
||||
}): string;
|
||||
generateRefreshToken(user: {
|
||||
id: string;
|
||||
email: string;
|
||||
role: UserRole;
|
||||
}): Promise<string>;
|
||||
generateTokenPair(user: {
|
||||
id: string;
|
||||
email: string;
|
||||
role: UserRole;
|
||||
}): Promise<TokenPair>;
|
||||
};
|
||||
export {};
|
||||
//# sourceMappingURL=auth.service.d.ts.map
|
||||
1
api/dist/modules/auth/auth.service.d.ts.map
vendored
Normal file
1
api/dist/modules/auth/auth.service.d.ts.map
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"auth.service.d.ts","sourceRoot":"","sources":["../../../src/modules/auth/auth.service.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAc,MAAM,gBAAgB,CAAC;AAKtD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAQpD,UAAU,SAAS;IACjB,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,MAAM,CAAC;CACtB;AAED,eAAO,MAAM,WAAW;iBACH,MAAM,YAAY,MAAM;qBAL9B,MAAM;sBACL,MAAM;;;;;;;;;;;;;;;;;;mBAwCC,aAAa;qBAzCrB,MAAM;sBACL,MAAM;;;;;;;;;;;;;;;;;;gCAgEc,MAAM;;;;;;;;;;;;;;;;;;;;yBAwDb,MAAM;8BAIP;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,QAAQ,CAAA;KAAE,GAAG,MAAM;+BAO/C;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,QAAQ,CAAA;KAAE,GAAG,OAAO,CAAC,MAAM,CAAC;4BAqBlE;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,QAAQ,CAAA;KAAE,GAAG,OAAO,CAAC,SAAS,CAAC;CAKjG,CAAC"}
|
||||
140
api/dist/modules/auth/auth.service.js
vendored
Normal file
140
api/dist/modules/auth/auth.service.js
vendored
Normal file
@@ -0,0 +1,140 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.authService = void 0;
|
||||
const bcryptjs_1 = __importDefault(require("bcryptjs"));
|
||||
const jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
|
||||
const client_1 = require("@prisma/client");
|
||||
const database_1 = require("../../config/database");
|
||||
const env_1 = require("../../config/env");
|
||||
const error_handler_1 = require("../../middleware/error-handler");
|
||||
const metrics_1 = require("../../utils/metrics");
|
||||
exports.authService = {
|
||||
async login(email, password) {
|
||||
const user = await database_1.prisma.user.findUnique({ where: { email } });
|
||||
if (!user) {
|
||||
(0, metrics_1.recordLoginAttempt)('failure');
|
||||
throw new error_handler_1.AppError(401, 'Invalid email or password', 'INVALID_CREDENTIALS');
|
||||
}
|
||||
const valid = await bcryptjs_1.default.compare(password, user.password);
|
||||
if (!valid) {
|
||||
(0, metrics_1.recordLoginAttempt)('failure');
|
||||
throw new error_handler_1.AppError(401, 'Invalid email or password', 'INVALID_CREDENTIALS');
|
||||
}
|
||||
if (user.status !== client_1.UserStatus.ACTIVE) {
|
||||
(0, metrics_1.recordLoginAttempt)('failure');
|
||||
throw new error_handler_1.AppError(403, `Account is ${user.status.toLowerCase()}`, 'ACCOUNT_INACTIVE');
|
||||
}
|
||||
if (user.expiresAt && user.expiresAt < new Date()) {
|
||||
(0, metrics_1.recordLoginAttempt)('failure');
|
||||
throw new error_handler_1.AppError(403, 'Account has expired', 'ACCOUNT_EXPIRED');
|
||||
}
|
||||
(0, metrics_1.recordLoginAttempt)('success');
|
||||
await database_1.prisma.user.update({
|
||||
where: { id: user.id },
|
||||
data: { lastLoginAt: new Date() },
|
||||
});
|
||||
const tokens = await this.generateTokenPair(user);
|
||||
const { password: _, ...userWithoutPassword } = user;
|
||||
return { user: userWithoutPassword, ...tokens };
|
||||
},
|
||||
async register(data) {
|
||||
const existing = await database_1.prisma.user.findUnique({ where: { email: data.email } });
|
||||
if (existing) {
|
||||
throw new error_handler_1.AppError(409, 'Email already registered', 'EMAIL_EXISTS');
|
||||
}
|
||||
const hashedPassword = await bcryptjs_1.default.hash(data.password, 12);
|
||||
const user = await database_1.prisma.user.create({
|
||||
data: {
|
||||
email: data.email,
|
||||
password: hashedPassword,
|
||||
name: data.name,
|
||||
phone: data.phone,
|
||||
role: client_1.UserRole.USER, // Always USER for public registration
|
||||
},
|
||||
});
|
||||
const tokens = await this.generateTokenPair(user);
|
||||
const { password: _, ...userWithoutPassword } = user;
|
||||
return { user: userWithoutPassword, ...tokens };
|
||||
},
|
||||
async refreshTokens(refreshToken) {
|
||||
let payload;
|
||||
try {
|
||||
payload = jsonwebtoken_1.default.verify(refreshToken, env_1.env.JWT_REFRESH_SECRET);
|
||||
}
|
||||
catch {
|
||||
throw new error_handler_1.AppError(401, 'Invalid refresh token', 'INVALID_REFRESH_TOKEN');
|
||||
}
|
||||
const stored = await database_1.prisma.refreshToken.findUnique({
|
||||
where: { token: refreshToken },
|
||||
include: { user: true },
|
||||
});
|
||||
if (!stored) {
|
||||
throw new error_handler_1.AppError(401, 'Refresh token not found', 'INVALID_REFRESH_TOKEN');
|
||||
}
|
||||
if (stored.expiresAt < new Date()) {
|
||||
await database_1.prisma.refreshToken.delete({ where: { id: stored.id } });
|
||||
throw new error_handler_1.AppError(401, 'Refresh token expired', 'REFRESH_TOKEN_EXPIRED');
|
||||
}
|
||||
// Rotate: delete old and create new atomically
|
||||
const tokens = await database_1.prisma.$transaction(async (tx) => {
|
||||
await tx.refreshToken.delete({ where: { id: stored.id } });
|
||||
// Generate new token pair
|
||||
const accessToken = this.generateAccessToken(stored.user);
|
||||
const refreshPayload = {
|
||||
id: stored.user.id,
|
||||
email: stored.user.email,
|
||||
role: stored.user.role
|
||||
};
|
||||
const refreshToken = jsonwebtoken_1.default.sign(refreshPayload, env_1.env.JWT_REFRESH_SECRET, {
|
||||
expiresIn: env_1.env.JWT_REFRESH_EXPIRY,
|
||||
});
|
||||
const decoded = jsonwebtoken_1.default.decode(refreshToken);
|
||||
const expiresAt = new Date(decoded.exp * 1000);
|
||||
await tx.refreshToken.create({
|
||||
data: {
|
||||
token: refreshToken,
|
||||
userId: stored.user.id,
|
||||
expiresAt,
|
||||
},
|
||||
});
|
||||
return { accessToken, refreshToken };
|
||||
});
|
||||
const { password: _, ...userWithoutPassword } = stored.user;
|
||||
return { user: userWithoutPassword, ...tokens };
|
||||
},
|
||||
async logout(refreshToken) {
|
||||
await database_1.prisma.refreshToken.deleteMany({ where: { token: refreshToken } });
|
||||
},
|
||||
generateAccessToken(user) {
|
||||
const payload = { id: user.id, email: user.email, role: user.role };
|
||||
return jsonwebtoken_1.default.sign(payload, env_1.env.JWT_ACCESS_SECRET, {
|
||||
expiresIn: env_1.env.JWT_ACCESS_EXPIRY,
|
||||
});
|
||||
},
|
||||
async generateRefreshToken(user) {
|
||||
const payload = { id: user.id, email: user.email, role: user.role };
|
||||
const token = jsonwebtoken_1.default.sign(payload, env_1.env.JWT_REFRESH_SECRET, {
|
||||
expiresIn: env_1.env.JWT_REFRESH_EXPIRY,
|
||||
});
|
||||
// Parse expiry to get a Date
|
||||
const decoded = jsonwebtoken_1.default.decode(token);
|
||||
const expiresAt = new Date(decoded.exp * 1000);
|
||||
await database_1.prisma.refreshToken.create({
|
||||
data: {
|
||||
token,
|
||||
userId: user.id,
|
||||
expiresAt,
|
||||
},
|
||||
});
|
||||
return token;
|
||||
},
|
||||
async generateTokenPair(user) {
|
||||
const accessToken = this.generateAccessToken(user);
|
||||
const refreshToken = await this.generateRefreshToken(user);
|
||||
return { accessToken, refreshToken };
|
||||
},
|
||||
};
|
||||
//# sourceMappingURL=auth.service.js.map
|
||||
1
api/dist/modules/auth/auth.service.js.map
vendored
Normal file
1
api/dist/modules/auth/auth.service.js.map
vendored
Normal file
File diff suppressed because one or more lines are too long
40
api/dist/modules/docs/docs-files.service.d.ts
vendored
Normal file
40
api/dist/modules/docs/docs-files.service.d.ts
vendored
Normal file
@@ -0,0 +1,40 @@
|
||||
export interface FileNode {
|
||||
name: string;
|
||||
path: string;
|
||||
isDirectory: boolean;
|
||||
children?: FileNode[];
|
||||
}
|
||||
/**
|
||||
* Resolve and validate a relative path within MKDOCS_DOCS_PATH.
|
||||
* Throws if the resolved path escapes the docs root.
|
||||
*/
|
||||
declare function safeResolve(relativePath: string): string;
|
||||
export declare class PathTraversalError extends Error {
|
||||
constructor();
|
||||
}
|
||||
export declare class FileNotFoundError extends Error {
|
||||
constructor(filePath: string);
|
||||
}
|
||||
/**
|
||||
* Recursively list the file tree under MKDOCS_DOCS_PATH.
|
||||
* Cached in Redis with 1-hour TTL for root calls.
|
||||
*/
|
||||
declare function listTree(dir?: string, relBase?: string): Promise<FileNode[]>;
|
||||
declare function readFileContent(relativePath: string): Promise<string>;
|
||||
declare function writeFileContent(relativePath: string, content: string): Promise<void>;
|
||||
declare function createFile(relativePath: string, content?: string, isDirectory?: boolean): Promise<void>;
|
||||
declare function deleteFile(relativePath: string): Promise<void>;
|
||||
declare function renameFile(fromPath: string, toPath: string): Promise<void>;
|
||||
declare function isEditableFile(relativePath: string): boolean;
|
||||
export declare const docsFilesService: {
|
||||
listTree: typeof listTree;
|
||||
readFileContent: typeof readFileContent;
|
||||
writeFileContent: typeof writeFileContent;
|
||||
createFile: typeof createFile;
|
||||
deleteFile: typeof deleteFile;
|
||||
renameFile: typeof renameFile;
|
||||
safeResolve: typeof safeResolve;
|
||||
isEditableFile: typeof isEditableFile;
|
||||
};
|
||||
export {};
|
||||
//# sourceMappingURL=docs-files.service.d.ts.map
|
||||
1
api/dist/modules/docs/docs-files.service.d.ts.map
vendored
Normal file
1
api/dist/modules/docs/docs-files.service.d.ts.map
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"docs-files.service.d.ts","sourceRoot":"","sources":["../../../src/modules/docs/docs-files.service.ts"],"names":[],"mappings":"AAQA,MAAM,WAAW,QAAQ;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,OAAO,CAAC;IACrB,QAAQ,CAAC,EAAE,QAAQ,EAAE,CAAC;CACvB;AAaD;;;GAGG;AACH,iBAAS,WAAW,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM,CAOjD;AAED,qBAAa,kBAAmB,SAAQ,KAAK;;CAK5C;AAED,qBAAa,iBAAkB,SAAQ,KAAK;gBAC9B,QAAQ,EAAE,MAAM;CAI7B;AAED;;;GAGG;AACH,iBAAe,QAAQ,CAAC,GAAG,GAAE,MAAkB,EAAE,OAAO,GAAE,MAAW,GAAG,OAAO,CAAC,QAAQ,EAAE,CAAC,CAiD1F;AAED,iBAAe,eAAe,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAmCpE;AAED,iBAAe,gBAAgB,CAAC,YAAY,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAYpF;AAED,iBAAe,UAAU,CAAC,YAAY,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CA0BtG;AAED,iBAAe,UAAU,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CA8B7D;AAED,iBAAe,UAAU,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAyBzE;AAED,iBAAS,cAAc,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAGrD;AAED,eAAO,MAAM,gBAAgB;;;;;;;;;CAS5B,CAAC"}
|
||||
248
api/dist/modules/docs/docs-files.service.js
vendored
Normal file
248
api/dist/modules/docs/docs-files.service.js
vendored
Normal file
@@ -0,0 +1,248 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.docsFilesService = exports.FileNotFoundError = exports.PathTraversalError = void 0;
|
||||
const promises_1 = require("fs/promises");
|
||||
const path_1 = require("path");
|
||||
const crypto_1 = __importDefault(require("crypto"));
|
||||
const env_1 = require("../../config/env");
|
||||
const redis_1 = require("../../config/redis");
|
||||
const logger_1 = require("../../utils/logger");
|
||||
const metrics_1 = require("../../utils/metrics");
|
||||
const DOCS_ROOT = (0, path_1.resolve)(env_1.env.MKDOCS_DOCS_PATH);
|
||||
// Redis cache configuration
|
||||
const CACHE_KEY_PREFIX = 'DOCS_CACHE:';
|
||||
const TREE_CACHE_KEY = `${CACHE_KEY_PREFIX}tree`;
|
||||
const FILE_CACHE_TTL = 60 * 60; // 1 hour
|
||||
function hashFilePath(path) {
|
||||
return crypto_1.default.createHash('sha256').update(path).digest('hex').substring(0, 16);
|
||||
}
|
||||
/**
|
||||
* Resolve and validate a relative path within MKDOCS_DOCS_PATH.
|
||||
* Throws if the resolved path escapes the docs root.
|
||||
*/
|
||||
function safeResolve(relativePath) {
|
||||
const normalized = (0, path_1.normalize)(relativePath).replace(/^(\.\.(\/|\\|$))+/, '');
|
||||
const resolved = (0, path_1.resolve)(DOCS_ROOT, normalized);
|
||||
if (!resolved.startsWith(DOCS_ROOT)) {
|
||||
throw new PathTraversalError();
|
||||
}
|
||||
return resolved;
|
||||
}
|
||||
class PathTraversalError extends Error {
|
||||
constructor() {
|
||||
super('Path traversal not allowed');
|
||||
this.name = 'PathTraversalError';
|
||||
}
|
||||
}
|
||||
exports.PathTraversalError = PathTraversalError;
|
||||
class FileNotFoundError extends Error {
|
||||
constructor(filePath) {
|
||||
super(`File not found: ${filePath}`);
|
||||
this.name = 'FileNotFoundError';
|
||||
}
|
||||
}
|
||||
exports.FileNotFoundError = FileNotFoundError;
|
||||
/**
|
||||
* Recursively list the file tree under MKDOCS_DOCS_PATH.
|
||||
* Cached in Redis with 1-hour TTL for root calls.
|
||||
*/
|
||||
async function listTree(dir = DOCS_ROOT, relBase = '') {
|
||||
// Try cache for root call only
|
||||
if (dir === DOCS_ROOT && !relBase) {
|
||||
try {
|
||||
const cached = await redis_1.redis.get(TREE_CACHE_KEY);
|
||||
if (cached) {
|
||||
metrics_1.cm_docs_cache_hits.inc({ type: 'tree' });
|
||||
return JSON.parse(cached);
|
||||
}
|
||||
metrics_1.cm_docs_cache_misses.inc({ type: 'tree' });
|
||||
}
|
||||
catch (err) {
|
||||
logger_1.logger.warn('Failed to get cached docs tree:', err);
|
||||
metrics_1.cm_docs_cache_misses.inc({ type: 'tree' });
|
||||
}
|
||||
}
|
||||
const entries = await (0, promises_1.readdir)(dir, { withFileTypes: true });
|
||||
const sorted = entries
|
||||
.filter(e => !e.name.startsWith('.'))
|
||||
.sort((a, b) => {
|
||||
if (a.isDirectory() && !b.isDirectory())
|
||||
return -1;
|
||||
if (!a.isDirectory() && b.isDirectory())
|
||||
return 1;
|
||||
return a.name.localeCompare(b.name);
|
||||
});
|
||||
// Parallel I/O instead of sequential for better performance
|
||||
const nodes = await Promise.all(sorted.map(async (entry) => {
|
||||
const relPath = relBase ? `${relBase}/${entry.name}` : entry.name;
|
||||
if (entry.isDirectory()) {
|
||||
const children = await listTree((0, path_1.join)(dir, entry.name), relPath);
|
||||
return { name: entry.name, path: relPath, isDirectory: true, children };
|
||||
}
|
||||
else {
|
||||
return { name: entry.name, path: relPath, isDirectory: false };
|
||||
}
|
||||
}));
|
||||
// Cache root result
|
||||
if (dir === DOCS_ROOT && !relBase) {
|
||||
try {
|
||||
await redis_1.redis.setex(TREE_CACHE_KEY, FILE_CACHE_TTL, JSON.stringify(nodes));
|
||||
}
|
||||
catch (err) {
|
||||
logger_1.logger.warn('Failed to cache docs tree:', err);
|
||||
}
|
||||
}
|
||||
return nodes;
|
||||
}
|
||||
async function readFileContent(relativePath) {
|
||||
const cacheKey = `${CACHE_KEY_PREFIX}file:${hashFilePath(relativePath)}`;
|
||||
// Try cache first
|
||||
try {
|
||||
const cached = await redis_1.redis.get(cacheKey);
|
||||
if (cached) {
|
||||
metrics_1.cm_docs_cache_hits.inc({ type: 'file' });
|
||||
return cached;
|
||||
}
|
||||
metrics_1.cm_docs_cache_misses.inc({ type: 'file' });
|
||||
}
|
||||
catch (err) {
|
||||
logger_1.logger.warn('Failed to get cached file content:', err);
|
||||
metrics_1.cm_docs_cache_misses.inc({ type: 'file' });
|
||||
}
|
||||
// Read from disk
|
||||
const fullPath = safeResolve(relativePath);
|
||||
try {
|
||||
const content = await (0, promises_1.readFile)(fullPath, 'utf-8');
|
||||
// Cache the result
|
||||
try {
|
||||
await redis_1.redis.setex(cacheKey, FILE_CACHE_TTL, content);
|
||||
}
|
||||
catch (err) {
|
||||
logger_1.logger.warn('Failed to cache file content:', err);
|
||||
}
|
||||
return content;
|
||||
}
|
||||
catch (err) {
|
||||
if (err.code === 'ENOENT') {
|
||||
throw new FileNotFoundError(relativePath);
|
||||
}
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
async function writeFileContent(relativePath, content) {
|
||||
const fullPath = safeResolve(relativePath);
|
||||
await (0, promises_1.mkdir)((0, path_1.dirname)(fullPath), { recursive: true });
|
||||
await (0, promises_1.writeFile)(fullPath, content, 'utf-8');
|
||||
// Invalidate file cache (content changed, structure unchanged)
|
||||
const cacheKey = `${CACHE_KEY_PREFIX}file:${hashFilePath(relativePath)}`;
|
||||
try {
|
||||
await redis_1.redis.del(cacheKey);
|
||||
}
|
||||
catch (err) {
|
||||
logger_1.logger.warn('Failed to invalidate file cache:', err);
|
||||
}
|
||||
}
|
||||
async function createFile(relativePath, content, isDirectory) {
|
||||
const fullPath = safeResolve(relativePath);
|
||||
try {
|
||||
await (0, promises_1.stat)(fullPath);
|
||||
throw new Error(`Already exists: ${relativePath}`);
|
||||
}
|
||||
catch (err) {
|
||||
if (err.code !== 'ENOENT') {
|
||||
if (err.message?.startsWith('Already exists'))
|
||||
throw err;
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
if (isDirectory) {
|
||||
await (0, promises_1.mkdir)(fullPath, { recursive: true });
|
||||
}
|
||||
else {
|
||||
await (0, promises_1.mkdir)((0, path_1.dirname)(fullPath), { recursive: true });
|
||||
await (0, promises_1.writeFile)(fullPath, content || '', 'utf-8');
|
||||
}
|
||||
// Invalidate tree cache (structure changed)
|
||||
try {
|
||||
await redis_1.redis.del(TREE_CACHE_KEY);
|
||||
}
|
||||
catch (err) {
|
||||
logger_1.logger.warn('Failed to invalidate tree cache:', err);
|
||||
}
|
||||
}
|
||||
async function deleteFile(relativePath) {
|
||||
const fullPath = safeResolve(relativePath);
|
||||
try {
|
||||
const info = await (0, promises_1.stat)(fullPath);
|
||||
if (info.isDirectory()) {
|
||||
const entries = await (0, promises_1.readdir)(fullPath);
|
||||
if (entries.length > 0) {
|
||||
throw new Error('Directory is not empty');
|
||||
}
|
||||
await (0, promises_1.rm)(fullPath, { recursive: false });
|
||||
}
|
||||
else {
|
||||
await (0, promises_1.rm)(fullPath);
|
||||
}
|
||||
}
|
||||
catch (err) {
|
||||
if (err.code === 'ENOENT') {
|
||||
throw new FileNotFoundError(relativePath);
|
||||
}
|
||||
throw err;
|
||||
}
|
||||
// Invalidate both tree and file cache
|
||||
const fileCacheKey = `${CACHE_KEY_PREFIX}file:${hashFilePath(relativePath)}`;
|
||||
try {
|
||||
await Promise.all([
|
||||
redis_1.redis.del(TREE_CACHE_KEY),
|
||||
redis_1.redis.del(fileCacheKey),
|
||||
]);
|
||||
}
|
||||
catch (err) {
|
||||
logger_1.logger.warn('Failed to invalidate caches on delete:', err);
|
||||
}
|
||||
}
|
||||
async function renameFile(fromPath, toPath) {
|
||||
const fullFrom = safeResolve(fromPath);
|
||||
const fullTo = safeResolve(toPath);
|
||||
try {
|
||||
await (0, promises_1.stat)(fullFrom);
|
||||
}
|
||||
catch {
|
||||
throw new FileNotFoundError(fromPath);
|
||||
}
|
||||
await (0, promises_1.mkdir)((0, path_1.dirname)(fullTo), { recursive: true });
|
||||
await (0, promises_1.rename)(fullFrom, fullTo);
|
||||
// Invalidate tree and both file paths
|
||||
const fromCacheKey = `${CACHE_KEY_PREFIX}file:${hashFilePath(fromPath)}`;
|
||||
const toCacheKey = `${CACHE_KEY_PREFIX}file:${hashFilePath(toPath)}`;
|
||||
try {
|
||||
await Promise.all([
|
||||
redis_1.redis.del(TREE_CACHE_KEY),
|
||||
redis_1.redis.del(fromCacheKey),
|
||||
redis_1.redis.del(toCacheKey),
|
||||
]);
|
||||
}
|
||||
catch (err) {
|
||||
logger_1.logger.warn('Failed to invalidate caches on rename:', err);
|
||||
}
|
||||
}
|
||||
function isEditableFile(relativePath) {
|
||||
const ext = (0, path_1.extname)(relativePath).toLowerCase();
|
||||
return ['.md', '.txt', '.yml', '.yaml', '.json', '.css', '.html', '.js'].includes(ext);
|
||||
}
|
||||
exports.docsFilesService = {
|
||||
listTree,
|
||||
readFileContent,
|
||||
writeFileContent,
|
||||
createFile,
|
||||
deleteFile,
|
||||
renameFile,
|
||||
safeResolve,
|
||||
isEditableFile,
|
||||
};
|
||||
//# sourceMappingURL=docs-files.service.js.map
|
||||
1
api/dist/modules/docs/docs-files.service.js.map
vendored
Normal file
1
api/dist/modules/docs/docs-files.service.js.map
vendored
Normal file
File diff suppressed because one or more lines are too long
2
api/dist/modules/docs/docs.routes.d.ts
vendored
Normal file
2
api/dist/modules/docs/docs.routes.d.ts
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
export declare const docsRouter: import("express-serve-static-core").Router;
|
||||
//# sourceMappingURL=docs.routes.d.ts.map
|
||||
1
api/dist/modules/docs/docs.routes.d.ts.map
vendored
Normal file
1
api/dist/modules/docs/docs.routes.d.ts.map
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"docs.routes.d.ts","sourceRoot":"","sources":["../../../src/modules/docs/docs.routes.ts"],"names":[],"mappings":"AAiQA,eAAO,MAAM,UAAU,4CAAS,CAAC"}
|
||||
219
api/dist/modules/docs/docs.routes.js
vendored
Normal file
219
api/dist/modules/docs/docs.routes.js
vendored
Normal file
@@ -0,0 +1,219 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.docsRouter = void 0;
|
||||
const express_1 = require("express");
|
||||
const auth_middleware_1 = require("../../middleware/auth.middleware");
|
||||
const rbac_middleware_1 = require("../../middleware/rbac.middleware");
|
||||
const env_1 = require("../../config/env");
|
||||
const logger_1 = require("../../utils/logger");
|
||||
const health_check_1 = require("../../utils/health-check");
|
||||
const metrics_1 = require("../../utils/metrics");
|
||||
const docs_files_service_1 = require("./docs-files.service");
|
||||
const mkdocs_config_service_1 = require("./mkdocs-config.service");
|
||||
const router = (0, express_1.Router)();
|
||||
router.use(auth_middleware_1.authenticate);
|
||||
router.use(rbac_middleware_1.requireNonTemp);
|
||||
// Removed duplicated isServiceOnline - now using shared utility from utils/health-check.ts
|
||||
// GET /api/docs/status — check MkDocs and Code Server availability
|
||||
router.get('/status', async (_req, res, next) => {
|
||||
try {
|
||||
const [mkdocsOnline, codeServerOnline, siteServerOnline] = await Promise.all([
|
||||
(0, health_check_1.isServiceOnline)(env_1.env.MKDOCS_PREVIEW_URL),
|
||||
(0, health_check_1.isServiceOnline)(env_1.env.CODE_SERVER_URL),
|
||||
(0, health_check_1.isServiceOnline)(env_1.env.MKDOCS_SITE_SERVER_URL),
|
||||
]);
|
||||
res.json({
|
||||
mkdocs: { online: mkdocsOnline, url: env_1.env.MKDOCS_PREVIEW_URL },
|
||||
codeServer: { online: codeServerOnline, url: env_1.env.CODE_SERVER_URL },
|
||||
siteServer: { online: siteServerOnline, url: env_1.env.MKDOCS_SITE_SERVER_URL },
|
||||
});
|
||||
}
|
||||
catch (err) {
|
||||
logger_1.logger.error('Failed to check docs status', err);
|
||||
next(err);
|
||||
}
|
||||
});
|
||||
// GET /api/docs/config — return public-facing port numbers for iframe URLs
|
||||
router.get('/config', async (_req, res, _next) => {
|
||||
res.json({
|
||||
codeServerPort: env_1.env.CODE_SERVER_PORT,
|
||||
mkdocsPort: env_1.env.MKDOCS_PORT,
|
||||
mkdocsSitePort: env_1.env.MKDOCS_SITE_SERVER_PORT,
|
||||
});
|
||||
});
|
||||
// --- MkDocs Config Endpoints ---
|
||||
// GET /api/docs/mkdocs-config — read raw mkdocs.yml content
|
||||
router.get('/mkdocs-config', async (_req, res, next) => {
|
||||
try {
|
||||
const content = await mkdocs_config_service_1.mkdocsConfigService.readConfig();
|
||||
res.json({ content });
|
||||
}
|
||||
catch (err) {
|
||||
logger_1.logger.error('Failed to read mkdocs config', err);
|
||||
next(err);
|
||||
}
|
||||
});
|
||||
// PUT /api/docs/mkdocs-config — validate + write mkdocs.yml (SUPER_ADMIN only)
|
||||
router.put('/mkdocs-config', (0, rbac_middleware_1.requireRole)('SUPER_ADMIN'), async (req, res, next) => {
|
||||
try {
|
||||
const { content } = req.body;
|
||||
if (typeof content !== 'string') {
|
||||
res.status(400).json({ error: { message: 'Content string required', code: 'VALIDATION_ERROR' } });
|
||||
return;
|
||||
}
|
||||
await mkdocs_config_service_1.mkdocsConfigService.writeConfig(content);
|
||||
res.json({ success: true });
|
||||
}
|
||||
catch (err) {
|
||||
if (err.message?.startsWith('Invalid YAML')) {
|
||||
res.status(400).json({ error: { message: err.message, code: 'VALIDATION_ERROR' } });
|
||||
return;
|
||||
}
|
||||
logger_1.logger.error('Failed to write mkdocs config', err);
|
||||
next(err);
|
||||
}
|
||||
});
|
||||
// POST /api/docs/build — trigger mkdocs build in container (SUPER_ADMIN only)
|
||||
router.post('/build', (0, rbac_middleware_1.requireRole)('SUPER_ADMIN'), async (_req, res, next) => {
|
||||
try {
|
||||
const result = await mkdocs_config_service_1.mkdocsConfigService.triggerBuild();
|
||||
res.json(result);
|
||||
}
|
||||
catch (err) {
|
||||
logger_1.logger.error('MkDocs build failed', err);
|
||||
next(err);
|
||||
}
|
||||
});
|
||||
// --- File Management Endpoints ---
|
||||
// GET /api/docs/files — list file tree
|
||||
router.get('/files', async (_req, res, next) => {
|
||||
try {
|
||||
metrics_1.cm_docs_operations.inc({ operation: 'list' });
|
||||
const tree = await docs_files_service_1.docsFilesService.listTree();
|
||||
res.json(tree);
|
||||
}
|
||||
catch (err) {
|
||||
logger_1.logger.error('Failed to list docs files', err);
|
||||
next(err);
|
||||
}
|
||||
});
|
||||
// POST /api/docs/files/rename — rename/move file
|
||||
router.post('/files/rename', async (req, res, next) => {
|
||||
try {
|
||||
metrics_1.cm_docs_operations.inc({ operation: 'rename' });
|
||||
const { from, to } = req.body;
|
||||
if (!from || !to) {
|
||||
res.status(400).json({ error: { message: 'Both "from" and "to" paths are required', code: 'VALIDATION_ERROR' } });
|
||||
return;
|
||||
}
|
||||
await docs_files_service_1.docsFilesService.renameFile(from, to);
|
||||
res.json({ success: true });
|
||||
}
|
||||
catch (err) {
|
||||
handleFileError(err, res, next);
|
||||
}
|
||||
});
|
||||
// GET /api/docs/files/* — read file content
|
||||
router.get('/files/*', async (req, res, next) => {
|
||||
try {
|
||||
metrics_1.cm_docs_operations.inc({ operation: 'read' });
|
||||
const filePath = extractWildcardPath(req);
|
||||
if (!filePath) {
|
||||
res.status(400).json({ error: { message: 'File path required', code: 'VALIDATION_ERROR' } });
|
||||
return;
|
||||
}
|
||||
const content = await docs_files_service_1.docsFilesService.readFileContent(filePath);
|
||||
res.json({ path: filePath, content });
|
||||
}
|
||||
catch (err) {
|
||||
handleFileError(err, res, next);
|
||||
}
|
||||
});
|
||||
// PUT /api/docs/files/* — write/update file content
|
||||
router.put('/files/*', async (req, res, next) => {
|
||||
try {
|
||||
metrics_1.cm_docs_operations.inc({ operation: 'write' });
|
||||
const filePath = extractWildcardPath(req);
|
||||
if (!filePath) {
|
||||
res.status(400).json({ error: { message: 'File path required', code: 'VALIDATION_ERROR' } });
|
||||
return;
|
||||
}
|
||||
const { content } = req.body;
|
||||
if (typeof content !== 'string') {
|
||||
res.status(400).json({ error: { message: 'Content string required', code: 'VALIDATION_ERROR' } });
|
||||
return;
|
||||
}
|
||||
await docs_files_service_1.docsFilesService.writeFileContent(filePath, content);
|
||||
res.json({ success: true, path: filePath });
|
||||
}
|
||||
catch (err) {
|
||||
handleFileError(err, res, next);
|
||||
}
|
||||
});
|
||||
// POST /api/docs/files/* — create new file or folder
|
||||
router.post('/files/*', async (req, res, next) => {
|
||||
try {
|
||||
metrics_1.cm_docs_operations.inc({ operation: 'create' });
|
||||
const filePath = extractWildcardPath(req);
|
||||
if (!filePath) {
|
||||
res.status(400).json({ error: { message: 'File path required', code: 'VALIDATION_ERROR' } });
|
||||
return;
|
||||
}
|
||||
const { content, isDirectory } = req.body;
|
||||
await docs_files_service_1.docsFilesService.createFile(filePath, content, isDirectory);
|
||||
res.status(201).json({ success: true, path: filePath });
|
||||
}
|
||||
catch (err) {
|
||||
handleFileError(err, res, next);
|
||||
}
|
||||
});
|
||||
// DELETE /api/docs/files/* — delete file or empty folder
|
||||
router.delete('/files/*', async (req, res, next) => {
|
||||
try {
|
||||
metrics_1.cm_docs_operations.inc({ operation: 'delete' });
|
||||
const filePath = extractWildcardPath(req);
|
||||
if (!filePath) {
|
||||
res.status(400).json({ error: { message: 'File path required', code: 'VALIDATION_ERROR' } });
|
||||
return;
|
||||
}
|
||||
await docs_files_service_1.docsFilesService.deleteFile(filePath);
|
||||
res.json({ success: true });
|
||||
}
|
||||
catch (err) {
|
||||
handleFileError(err, res, next);
|
||||
}
|
||||
});
|
||||
/**
|
||||
* Extract the wildcard path from Express 5 req.params.
|
||||
* Express 5 uses params[0] for * routes.
|
||||
*/
|
||||
function extractWildcardPath(req) {
|
||||
// Express 5: req.params is array-like for * routes
|
||||
const params = req.params;
|
||||
const wildcardParam = params[0] || params['0'];
|
||||
if (Array.isArray(wildcardParam))
|
||||
return wildcardParam.join('/');
|
||||
return wildcardParam || '';
|
||||
}
|
||||
function handleFileError(err, res, next) {
|
||||
if (err instanceof docs_files_service_1.PathTraversalError) {
|
||||
res.status(403).json({ error: { message: 'Path traversal not allowed', code: 'FORBIDDEN' } });
|
||||
return;
|
||||
}
|
||||
if (err instanceof docs_files_service_1.FileNotFoundError) {
|
||||
res.status(404).json({ error: { message: err.message, code: 'NOT_FOUND' } });
|
||||
return;
|
||||
}
|
||||
if (err.message?.startsWith('Already exists')) {
|
||||
res.status(409).json({ error: { message: err.message, code: 'CONFLICT' } });
|
||||
return;
|
||||
}
|
||||
if (err.message === 'Directory is not empty') {
|
||||
res.status(400).json({ error: { message: 'Directory is not empty', code: 'VALIDATION_ERROR' } });
|
||||
return;
|
||||
}
|
||||
logger_1.logger.error('Docs file operation failed', err);
|
||||
next(err);
|
||||
}
|
||||
exports.docsRouter = router;
|
||||
//# sourceMappingURL=docs.routes.js.map
|
||||
1
api/dist/modules/docs/docs.routes.js.map
vendored
Normal file
1
api/dist/modules/docs/docs.routes.js.map
vendored
Normal file
File diff suppressed because one or more lines are too long
30
api/dist/modules/docs/mkdocs-config.service.d.ts
vendored
Normal file
30
api/dist/modules/docs/mkdocs-config.service.d.ts
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
import { Document } from 'yaml';
|
||||
/**
|
||||
* Parse mkdocs.yml content with support for !!python/name: tags.
|
||||
* Returns a yaml Document that preserves comments and formatting.
|
||||
*/
|
||||
declare function parseConfig(content: string): Document;
|
||||
/**
|
||||
* Validate that a string is valid YAML (with python tags support).
|
||||
* Returns null if valid, error message if invalid.
|
||||
*/
|
||||
declare function validateYaml(content: string): string | null;
|
||||
declare function readConfig(): Promise<string>;
|
||||
declare function writeConfig(content: string): Promise<void>;
|
||||
/**
|
||||
* Execute `mkdocs build` inside the running MkDocs container via Docker Engine API.
|
||||
*/
|
||||
declare function triggerBuild(): Promise<{
|
||||
success: boolean;
|
||||
output: string;
|
||||
duration: number;
|
||||
}>;
|
||||
export declare const mkdocsConfigService: {
|
||||
readConfig: typeof readConfig;
|
||||
writeConfig: typeof writeConfig;
|
||||
validateYaml: typeof validateYaml;
|
||||
parseConfig: typeof parseConfig;
|
||||
triggerBuild: typeof triggerBuild;
|
||||
};
|
||||
export {};
|
||||
//# sourceMappingURL=mkdocs-config.service.d.ts.map
|
||||
1
api/dist/modules/docs/mkdocs-config.service.d.ts.map
vendored
Normal file
1
api/dist/modules/docs/mkdocs-config.service.d.ts.map
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"mkdocs-config.service.d.ts","sourceRoot":"","sources":["../../../src/modules/docs/mkdocs-config.service.ts"],"names":[],"mappings":"AAIA,OAAO,EAAiB,QAAQ,EAAE,MAAM,MAAM,CAAC;AAuB/C;;;GAGG;AACH,iBAAS,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,QAAQ,CAS9C;AAED;;;GAGG;AACH,iBAAS,YAAY,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAWpD;AAED,iBAAe,UAAU,IAAI,OAAO,CAAC,MAAM,CAAC,CAE3C;AAED,iBAAe,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAezD;AA8DD;;GAEG;AACH,iBAAe,YAAY,IAAI,OAAO,CAAC;IAAE,OAAO,EAAE,OAAO,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,CAAC,CAgE7F;AAED,eAAO,MAAM,mBAAmB;;;;;;CAM/B,CAAC"}
|
||||
190
api/dist/modules/docs/mkdocs-config.service.js
vendored
Normal file
190
api/dist/modules/docs/mkdocs-config.service.js
vendored
Normal file
@@ -0,0 +1,190 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.mkdocsConfigService = void 0;
|
||||
const promises_1 = require("fs/promises");
|
||||
const http_1 = require("http");
|
||||
const env_1 = require("../../config/env");
|
||||
const logger_1 = require("../../utils/logger");
|
||||
const yaml_1 = require("yaml");
|
||||
const DOCKER_SOCKET = '/var/run/docker.sock';
|
||||
/**
|
||||
* Custom YAML tag schema to preserve !!python/name: and !!python/object: tags.
|
||||
* Without this, the yaml library would reject these custom tags.
|
||||
*/
|
||||
const pythonNameTag = {
|
||||
identify: () => false,
|
||||
tag: '!python/name',
|
||||
collection: undefined,
|
||||
resolve: (str) => str,
|
||||
};
|
||||
const pythonObjectTag = {
|
||||
identify: () => false,
|
||||
tag: '!python/object',
|
||||
collection: undefined,
|
||||
resolve: (str) => str,
|
||||
};
|
||||
/**
|
||||
* Parse mkdocs.yml content with support for !!python/name: tags.
|
||||
* Returns a yaml Document that preserves comments and formatting.
|
||||
*/
|
||||
function parseConfig(content) {
|
||||
return (0, yaml_1.parseDocument)(content, {
|
||||
customTags: (tags) => [
|
||||
...tags,
|
||||
pythonNameTag,
|
||||
pythonObjectTag,
|
||||
],
|
||||
keepSourceTokens: true,
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Validate that a string is valid YAML (with python tags support).
|
||||
* Returns null if valid, error message if invalid.
|
||||
*/
|
||||
function validateYaml(content) {
|
||||
try {
|
||||
const doc = parseConfig(content);
|
||||
const errors = doc.errors;
|
||||
if (errors.length > 0) {
|
||||
return errors.map(e => e.message).join('; ');
|
||||
}
|
||||
return null;
|
||||
}
|
||||
catch (err) {
|
||||
return err.message;
|
||||
}
|
||||
}
|
||||
async function readConfig() {
|
||||
return (0, promises_1.readFile)(env_1.env.MKDOCS_CONFIG_PATH, 'utf-8');
|
||||
}
|
||||
async function writeConfig(content) {
|
||||
// Validate YAML first
|
||||
const error = validateYaml(content);
|
||||
if (error) {
|
||||
throw new Error(`Invalid YAML: ${error}`);
|
||||
}
|
||||
// Create backup
|
||||
try {
|
||||
await (0, promises_1.copyFile)(env_1.env.MKDOCS_CONFIG_PATH, `${env_1.env.MKDOCS_CONFIG_PATH}.bak`);
|
||||
}
|
||||
catch {
|
||||
logger_1.logger.warn('Could not create backup of mkdocs.yml');
|
||||
}
|
||||
await (0, promises_1.writeFile)(env_1.env.MKDOCS_CONFIG_PATH, content, 'utf-8');
|
||||
}
|
||||
/**
|
||||
* Make a request to the Docker Engine API over Unix socket.
|
||||
*/
|
||||
function dockerRequest(method, path, body) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const options = {
|
||||
socketPath: DOCKER_SOCKET,
|
||||
path,
|
||||
method,
|
||||
headers: body
|
||||
? { 'Content-Type': 'application/json' }
|
||||
: undefined,
|
||||
};
|
||||
const req = (0, http_1.request)(options, (res) => {
|
||||
const chunks = [];
|
||||
res.on('data', (chunk) => chunks.push(chunk));
|
||||
res.on('end', () => {
|
||||
resolve({
|
||||
statusCode: res.statusCode || 0,
|
||||
body: Buffer.concat(chunks).toString(),
|
||||
});
|
||||
});
|
||||
});
|
||||
req.on('error', reject);
|
||||
if (body) {
|
||||
req.write(JSON.stringify(body));
|
||||
}
|
||||
req.end();
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Read raw output from a Docker exec start stream.
|
||||
* Docker multiplexes stdout/stderr with 8-byte headers.
|
||||
*/
|
||||
function demuxDockerStream(raw) {
|
||||
const lines = [];
|
||||
let offset = 0;
|
||||
while (offset < raw.length) {
|
||||
if (offset + 8 > raw.length)
|
||||
break;
|
||||
// byte 0: stream type (1=stdout, 2=stderr)
|
||||
const size = raw.readUInt32BE(offset + 4);
|
||||
offset += 8;
|
||||
if (offset + size > raw.length) {
|
||||
lines.push(raw.subarray(offset).toString('utf-8'));
|
||||
break;
|
||||
}
|
||||
lines.push(raw.subarray(offset, offset + size).toString('utf-8'));
|
||||
offset += size;
|
||||
}
|
||||
return lines.join('');
|
||||
}
|
||||
/**
|
||||
* Execute `mkdocs build` inside the running MkDocs container via Docker Engine API.
|
||||
*/
|
||||
async function triggerBuild() {
|
||||
const containerName = env_1.env.MKDOCS_CONTAINER_NAME;
|
||||
const startTime = Date.now();
|
||||
try {
|
||||
// 1. Create exec instance
|
||||
const execCreate = await dockerRequest('POST', `/containers/${containerName}/exec`, {
|
||||
AttachStdout: true,
|
||||
AttachStderr: true,
|
||||
Cmd: ['mkdocs', 'build', '--clean'],
|
||||
});
|
||||
if (execCreate.statusCode !== 201) {
|
||||
throw new Error(`Failed to create exec: ${execCreate.body}`);
|
||||
}
|
||||
const { Id: execId } = JSON.parse(execCreate.body);
|
||||
// 2. Start exec and collect output
|
||||
const execOutput = await new Promise((resolve, reject) => {
|
||||
const options = {
|
||||
socketPath: DOCKER_SOCKET,
|
||||
path: `/exec/${execId}/start`,
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
};
|
||||
const req = (0, http_1.request)(options, (res) => {
|
||||
const chunks = [];
|
||||
res.on('data', (chunk) => chunks.push(chunk));
|
||||
res.on('end', () => resolve(Buffer.concat(chunks)));
|
||||
});
|
||||
req.on('error', reject);
|
||||
req.write(JSON.stringify({ Detach: false, Tty: false }));
|
||||
req.end();
|
||||
});
|
||||
const output = demuxDockerStream(execOutput);
|
||||
// 3. Check exit code
|
||||
const execInspect = await dockerRequest('GET', `/exec/${execId}/json`);
|
||||
const inspectData = JSON.parse(execInspect.body);
|
||||
const exitCode = inspectData.ExitCode ?? -1;
|
||||
const duration = Date.now() - startTime;
|
||||
return {
|
||||
success: exitCode === 0,
|
||||
output: output || '(no output)',
|
||||
duration,
|
||||
};
|
||||
}
|
||||
catch (err) {
|
||||
const duration = Date.now() - startTime;
|
||||
logger_1.logger.error('MkDocs build failed', err);
|
||||
return {
|
||||
success: false,
|
||||
output: `Build error: ${err.message}`,
|
||||
duration,
|
||||
};
|
||||
}
|
||||
}
|
||||
exports.mkdocsConfigService = {
|
||||
readConfig,
|
||||
writeConfig,
|
||||
validateYaml,
|
||||
parseConfig,
|
||||
triggerBuild,
|
||||
};
|
||||
//# sourceMappingURL=mkdocs-config.service.js.map
|
||||
1
api/dist/modules/docs/mkdocs-config.service.js.map
vendored
Normal file
1
api/dist/modules/docs/mkdocs-config.service.js.map
vendored
Normal file
File diff suppressed because one or more lines are too long
3
api/dist/modules/email-templates/email-templates-admin.routes.d.ts
vendored
Normal file
3
api/dist/modules/email-templates/email-templates-admin.routes.d.ts
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
declare const router: import("express-serve-static-core").Router;
|
||||
export default router;
|
||||
//# sourceMappingURL=email-templates-admin.routes.d.ts.map
|
||||
1
api/dist/modules/email-templates/email-templates-admin.routes.d.ts.map
vendored
Normal file
1
api/dist/modules/email-templates/email-templates-admin.routes.d.ts.map
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"email-templates-admin.routes.d.ts","sourceRoot":"","sources":["../../../src/modules/email-templates/email-templates-admin.routes.ts"],"names":[],"mappings":"AAqBA,QAAA,MAAM,MAAM,4CAAW,CAAC;AA8UxB,eAAe,MAAM,CAAC"}
|
||||
277
api/dist/modules/email-templates/email-templates-admin.routes.js
vendored
Normal file
277
api/dist/modules/email-templates/email-templates-admin.routes.js
vendored
Normal file
@@ -0,0 +1,277 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const express_1 = require("express");
|
||||
const email_templates_service_1 = require("./email-templates.service");
|
||||
const email_service_1 = require("../../services/email.service");
|
||||
const validate_1 = require("../../middleware/validate");
|
||||
const email_templates_schemas_1 = require("./email-templates.schemas");
|
||||
const logger_1 = require("../../utils/logger");
|
||||
const auth_middleware_1 = require("../../middleware/auth.middleware");
|
||||
const rbac_middleware_1 = require("../../middleware/rbac.middleware");
|
||||
const client_1 = require("@prisma/client");
|
||||
const express_rate_limit_1 = __importDefault(require("express-rate-limit"));
|
||||
const rate_limit_redis_1 = __importDefault(require("rate-limit-redis"));
|
||||
const redis_1 = require("../../config/redis");
|
||||
const router = (0, express_1.Router)();
|
||||
// All email template routes require authentication
|
||||
router.use(auth_middleware_1.authenticate);
|
||||
// All routes require admin role (SUPER_ADMIN, INFLUENCE_ADMIN, or MAP_ADMIN)
|
||||
const requireAdminRole = (0, rbac_middleware_1.requireRole)(client_1.UserRole.SUPER_ADMIN, client_1.UserRole.INFLUENCE_ADMIN, client_1.UserRole.MAP_ADMIN);
|
||||
/**
|
||||
* List email templates
|
||||
* GET /email-templates
|
||||
*/
|
||||
router.get('/', requireAdminRole, (0, validate_1.validate)(email_templates_schemas_1.listEmailTemplatesSchema, 'query'), async (req, res) => {
|
||||
try {
|
||||
const result = await email_templates_service_1.emailTemplatesService.list(req.query);
|
||||
res.json(result);
|
||||
}
|
||||
catch (error) {
|
||||
logger_1.logger.error('Error listing email templates:', error);
|
||||
res.status(500).json({ error: 'Failed to list email templates' });
|
||||
}
|
||||
});
|
||||
/**
|
||||
* Get single email template
|
||||
* GET /email-templates/:id
|
||||
*/
|
||||
router.get('/:id', requireAdminRole, async (req, res) => {
|
||||
try {
|
||||
const template = await email_templates_service_1.emailTemplatesService.getById(req.params.id);
|
||||
res.json(template);
|
||||
}
|
||||
catch (error) {
|
||||
if (error instanceof Error && error.message === 'Template not found') {
|
||||
res.status(404).json({ error: 'Template not found' });
|
||||
return;
|
||||
}
|
||||
logger_1.logger.error('Error getting email template:', error);
|
||||
res.status(500).json({ error: 'Failed to get email template' });
|
||||
}
|
||||
});
|
||||
/**
|
||||
* Create email template
|
||||
* POST /email-templates
|
||||
*/
|
||||
router.post('/', requireAdminRole, (0, validate_1.validate)(email_templates_schemas_1.createEmailTemplateSchema), async (req, res) => {
|
||||
try {
|
||||
const template = await email_templates_service_1.emailTemplatesService.create(req.body, req.user.id);
|
||||
res.status(201).json(template);
|
||||
}
|
||||
catch (error) {
|
||||
if (error instanceof Error && error.message.includes('already exists')) {
|
||||
res.status(409).json({ error: error.message });
|
||||
return;
|
||||
}
|
||||
if (error instanceof Error && error.message.includes('validation failed')) {
|
||||
res.status(400).json({ error: error.message });
|
||||
return;
|
||||
}
|
||||
logger_1.logger.error('Error creating email template:', error);
|
||||
res.status(500).json({ error: 'Failed to create email template' });
|
||||
}
|
||||
});
|
||||
/**
|
||||
* Update email template
|
||||
* PUT /email-templates/:id
|
||||
*/
|
||||
router.put('/:id', requireAdminRole, (0, validate_1.validate)(email_templates_schemas_1.updateEmailTemplateSchema), async (req, res) => {
|
||||
try {
|
||||
const template = await email_templates_service_1.emailTemplatesService.update(req.params.id, req.body, req.user.id);
|
||||
// Clear cache so changes take effect immediately
|
||||
email_service_1.emailService.clearDatabaseCache(template.key);
|
||||
logger_1.logger.info(`Cleared template cache for: ${template.key}`);
|
||||
res.json(template);
|
||||
}
|
||||
catch (error) {
|
||||
if (error instanceof Error && error.message === 'Template not found') {
|
||||
res.status(404).json({ error: 'Template not found' });
|
||||
return;
|
||||
}
|
||||
if (error instanceof Error && error.message.includes('validation failed')) {
|
||||
res.status(400).json({ error: error.message });
|
||||
return;
|
||||
}
|
||||
logger_1.logger.error('Error updating email template:', error);
|
||||
res.status(500).json({ error: 'Failed to update email template' });
|
||||
}
|
||||
});
|
||||
/**
|
||||
* Delete email template
|
||||
* DELETE /email-templates/:id
|
||||
*/
|
||||
router.delete('/:id', requireAdminRole, async (req, res) => {
|
||||
try {
|
||||
// Fetch template before deleting to get the key
|
||||
const template = await email_templates_service_1.emailTemplatesService.getById(req.params.id);
|
||||
await email_templates_service_1.emailTemplatesService.delete(req.params.id);
|
||||
// Clear cache for deleted template
|
||||
email_service_1.emailService.clearDatabaseCache(template.key);
|
||||
logger_1.logger.info(`Cleared template cache for deleted template: ${template.key}`);
|
||||
res.status(204).send();
|
||||
}
|
||||
catch (error) {
|
||||
if (error instanceof Error && error.message === 'Template not found') {
|
||||
res.status(404).json({ error: 'Template not found' });
|
||||
return;
|
||||
}
|
||||
if (error instanceof Error && error.message.includes('Cannot delete system templates')) {
|
||||
res.status(403).json({ error: error.message });
|
||||
return;
|
||||
}
|
||||
logger_1.logger.error('Error deleting email template:', error);
|
||||
res.status(500).json({ error: 'Failed to delete email template' });
|
||||
}
|
||||
});
|
||||
/**
|
||||
* Get version history
|
||||
* GET /email-templates/:id/versions
|
||||
*/
|
||||
router.get('/:id/versions', requireAdminRole, async (req, res) => {
|
||||
try {
|
||||
const versions = await email_templates_service_1.emailTemplatesService.getVersions(req.params.id);
|
||||
res.json(versions);
|
||||
}
|
||||
catch (error) {
|
||||
logger_1.logger.error('Error getting template versions:', error);
|
||||
res.status(500).json({ error: 'Failed to get template versions' });
|
||||
}
|
||||
});
|
||||
/**
|
||||
* Get specific version
|
||||
* GET /email-templates/:id/versions/:versionNumber
|
||||
*/
|
||||
router.get('/:id/versions/:versionNumber', requireAdminRole, async (req, res) => {
|
||||
try {
|
||||
const version = await email_templates_service_1.emailTemplatesService.getVersion(req.params.id, parseInt(req.params.versionNumber, 10));
|
||||
res.json(version);
|
||||
}
|
||||
catch (error) {
|
||||
if (error instanceof Error && error.message === 'Version not found') {
|
||||
res.status(404).json({ error: 'Version not found' });
|
||||
return;
|
||||
}
|
||||
logger_1.logger.error('Error getting template version:', error);
|
||||
res.status(500).json({ error: 'Failed to get template version' });
|
||||
}
|
||||
});
|
||||
/**
|
||||
* Rollback to previous version
|
||||
* POST /email-templates/:id/rollback
|
||||
*/
|
||||
router.post('/:id/rollback', requireAdminRole, (0, validate_1.validate)(email_templates_schemas_1.rollbackToVersionSchema), async (req, res) => {
|
||||
try {
|
||||
const template = await email_templates_service_1.emailTemplatesService.rollbackToVersion(req.params.id, req.body, req.user.id);
|
||||
res.json(template);
|
||||
}
|
||||
catch (error) {
|
||||
if (error instanceof Error && (error.message === 'Template not found' || error.message === 'Version not found')) {
|
||||
res.status(404).json({ error: error.message });
|
||||
return;
|
||||
}
|
||||
logger_1.logger.error('Error rolling back template:', error);
|
||||
res.status(500).json({ error: 'Failed to rollback template' });
|
||||
}
|
||||
});
|
||||
/**
|
||||
* Validate template syntax
|
||||
* POST /email-templates/validate
|
||||
*/
|
||||
router.post('/validate', requireAdminRole, (0, validate_1.validate)(email_templates_schemas_1.validateTemplateSchema), async (req, res) => {
|
||||
try {
|
||||
const result = email_templates_service_1.emailTemplatesService.validateTemplate(req.body);
|
||||
res.json(result);
|
||||
}
|
||||
catch (error) {
|
||||
logger_1.logger.error('Error validating template:', error);
|
||||
res.status(500).json({ error: 'Failed to validate template' });
|
||||
}
|
||||
});
|
||||
/**
|
||||
* Send test email
|
||||
* POST /email-templates/:id/test
|
||||
* Rate limited to 10 per 15 minutes per user
|
||||
*/
|
||||
router.post('/:id/test', requireAdminRole, (0, express_rate_limit_1.default)({
|
||||
windowMs: 15 * 60 * 1000, // 15 minutes
|
||||
max: 10,
|
||||
standardHeaders: true,
|
||||
legacyHeaders: false,
|
||||
store: new rate_limit_redis_1.default({
|
||||
sendCommand: (command, ...args) => redis_1.redis.call(command, ...args),
|
||||
prefix: 'rl:email-template-test:',
|
||||
}),
|
||||
keyGenerator: (req) => req.user.id,
|
||||
}), (0, validate_1.validate)(email_templates_schemas_1.sendTestEmailSchema), async (req, res) => {
|
||||
try {
|
||||
const result = await email_templates_service_1.emailTemplatesService.sendTestEmail(req.params.id, req.body, req.user.id);
|
||||
res.json(result);
|
||||
}
|
||||
catch (error) {
|
||||
if (error instanceof Error && error.message === 'Template not found') {
|
||||
res.status(404).json({ error: 'Template not found' });
|
||||
return;
|
||||
}
|
||||
logger_1.logger.error('Error sending test email:', error);
|
||||
res.status(500).json({ error: 'Failed to send test email' });
|
||||
}
|
||||
});
|
||||
/**
|
||||
* Get test logs for template
|
||||
* GET /email-templates/:id/test-logs
|
||||
*/
|
||||
router.get('/:id/test-logs', requireAdminRole, async (req, res) => {
|
||||
try {
|
||||
const limit = req.query.limit ? parseInt(req.query.limit, 10) : 10;
|
||||
const logs = await email_templates_service_1.emailTemplatesService.getTestLogs(req.params.id, limit);
|
||||
res.json(logs);
|
||||
}
|
||||
catch (error) {
|
||||
logger_1.logger.error('Error getting test logs:', error);
|
||||
res.status(500).json({ error: 'Failed to get test logs' });
|
||||
}
|
||||
});
|
||||
/**
|
||||
* Seed templates from filesystem (SUPER_ADMIN only)
|
||||
* POST /email-templates/seed
|
||||
*/
|
||||
router.post('/seed', (0, rbac_middleware_1.requireRole)(client_1.UserRole.SUPER_ADMIN), async (req, res) => {
|
||||
try {
|
||||
// This is a placeholder - the actual seeding is done via the script
|
||||
// But we keep this endpoint for manual triggering if needed
|
||||
const { exec } = require('child_process');
|
||||
const { promisify } = require('util');
|
||||
const execAsync = promisify(exec);
|
||||
const result = await execAsync('npx tsx src/scripts/seed-email-templates.ts', {
|
||||
cwd: '/app',
|
||||
});
|
||||
logger_1.logger.info('Email templates seeded via API');
|
||||
res.json({ success: true, output: result.stdout });
|
||||
}
|
||||
catch (error) {
|
||||
logger_1.logger.error('Error seeding templates:', error);
|
||||
res.status(500).json({ error: 'Failed to seed templates' });
|
||||
}
|
||||
});
|
||||
/**
|
||||
* Clear template cache (SUPER_ADMIN only)
|
||||
* POST /email-templates/clear-cache
|
||||
* Body: { key?: string } - Optional template key to clear. If not provided, clears all.
|
||||
*/
|
||||
router.post('/clear-cache', (0, rbac_middleware_1.requireRole)(client_1.UserRole.SUPER_ADMIN), async (req, res) => {
|
||||
try {
|
||||
const { key } = req.body;
|
||||
email_service_1.emailService.clearDatabaseCache(key);
|
||||
logger_1.logger.info(`Template cache cleared${key ? ` for: ${key}` : ' (all)'}`);
|
||||
res.json({ success: true, cleared: key || 'all' });
|
||||
}
|
||||
catch (error) {
|
||||
logger_1.logger.error('Error clearing template cache:', error);
|
||||
res.status(500).json({ error: 'Failed to clear template cache' });
|
||||
}
|
||||
});
|
||||
exports.default = router;
|
||||
//# sourceMappingURL=email-templates-admin.routes.js.map
|
||||
1
api/dist/modules/email-templates/email-templates-admin.routes.js.map
vendored
Normal file
1
api/dist/modules/email-templates/email-templates-admin.routes.js.map
vendored
Normal file
File diff suppressed because one or more lines are too long
324
api/dist/modules/email-templates/email-templates.schemas.d.ts
vendored
Normal file
324
api/dist/modules/email-templates/email-templates.schemas.d.ts
vendored
Normal file
@@ -0,0 +1,324 @@
|
||||
import { z } from 'zod';
|
||||
export declare const EmailTemplateVariableTypeSchema: z.ZodEnum<["TEXT", "VIDEO"]>;
|
||||
export type EmailTemplateVariableTypeType = z.infer<typeof EmailTemplateVariableTypeSchema>;
|
||||
export declare const emailTemplateVariableSchema: z.ZodEffects<z.ZodObject<{
|
||||
key: z.ZodString;
|
||||
label: z.ZodString;
|
||||
description: z.ZodOptional<z.ZodString>;
|
||||
type: z.ZodDefault<z.ZodEnum<["TEXT", "VIDEO"]>>;
|
||||
videoId: z.ZodOptional<z.ZodNumber>;
|
||||
isRequired: z.ZodDefault<z.ZodBoolean>;
|
||||
isConditional: z.ZodDefault<z.ZodBoolean>;
|
||||
sampleValue: z.ZodOptional<z.ZodString>;
|
||||
sortOrder: z.ZodDefault<z.ZodNumber>;
|
||||
}, "strip", z.ZodTypeAny, {
|
||||
type: "VIDEO" | "TEXT";
|
||||
key: string;
|
||||
label: string;
|
||||
sortOrder: number;
|
||||
isRequired: boolean;
|
||||
isConditional: boolean;
|
||||
videoId?: number | undefined;
|
||||
description?: string | undefined;
|
||||
sampleValue?: string | undefined;
|
||||
}, {
|
||||
key: string;
|
||||
label: string;
|
||||
type?: "VIDEO" | "TEXT" | undefined;
|
||||
videoId?: number | undefined;
|
||||
description?: string | undefined;
|
||||
sortOrder?: number | undefined;
|
||||
isRequired?: boolean | undefined;
|
||||
isConditional?: boolean | undefined;
|
||||
sampleValue?: string | undefined;
|
||||
}>, {
|
||||
type: "VIDEO" | "TEXT";
|
||||
key: string;
|
||||
label: string;
|
||||
sortOrder: number;
|
||||
isRequired: boolean;
|
||||
isConditional: boolean;
|
||||
videoId?: number | undefined;
|
||||
description?: string | undefined;
|
||||
sampleValue?: string | undefined;
|
||||
}, {
|
||||
key: string;
|
||||
label: string;
|
||||
type?: "VIDEO" | "TEXT" | undefined;
|
||||
videoId?: number | undefined;
|
||||
description?: string | undefined;
|
||||
sortOrder?: number | undefined;
|
||||
isRequired?: boolean | undefined;
|
||||
isConditional?: boolean | undefined;
|
||||
sampleValue?: string | undefined;
|
||||
}>;
|
||||
export declare const listEmailTemplatesSchema: z.ZodObject<{
|
||||
page: z.ZodDefault<z.ZodNumber>;
|
||||
limit: z.ZodDefault<z.ZodNumber>;
|
||||
search: z.ZodOptional<z.ZodString>;
|
||||
category: z.ZodOptional<z.ZodNativeEnum<{
|
||||
INFLUENCE: "INFLUENCE";
|
||||
MAP: "MAP";
|
||||
SYSTEM: "SYSTEM";
|
||||
}>>;
|
||||
isActive: z.ZodOptional<z.ZodBoolean>;
|
||||
}, "strip", z.ZodTypeAny, {
|
||||
limit: number;
|
||||
page: number;
|
||||
search?: string | undefined;
|
||||
category?: "INFLUENCE" | "MAP" | "SYSTEM" | undefined;
|
||||
isActive?: boolean | undefined;
|
||||
}, {
|
||||
search?: string | undefined;
|
||||
limit?: number | undefined;
|
||||
category?: "INFLUENCE" | "MAP" | "SYSTEM" | undefined;
|
||||
page?: number | undefined;
|
||||
isActive?: boolean | undefined;
|
||||
}>;
|
||||
export type ListEmailTemplatesDto = z.infer<typeof listEmailTemplatesSchema>;
|
||||
export declare const createEmailTemplateSchema: z.ZodObject<{
|
||||
key: z.ZodString;
|
||||
name: z.ZodString;
|
||||
description: z.ZodOptional<z.ZodString>;
|
||||
category: z.ZodNativeEnum<{
|
||||
INFLUENCE: "INFLUENCE";
|
||||
MAP: "MAP";
|
||||
SYSTEM: "SYSTEM";
|
||||
}>;
|
||||
subjectLine: z.ZodString;
|
||||
htmlContent: z.ZodString;
|
||||
textContent: z.ZodString;
|
||||
isActive: z.ZodDefault<z.ZodBoolean>;
|
||||
variables: z.ZodOptional<z.ZodArray<z.ZodEffects<z.ZodObject<{
|
||||
key: z.ZodString;
|
||||
label: z.ZodString;
|
||||
description: z.ZodOptional<z.ZodString>;
|
||||
type: z.ZodDefault<z.ZodEnum<["TEXT", "VIDEO"]>>;
|
||||
videoId: z.ZodOptional<z.ZodNumber>;
|
||||
isRequired: z.ZodDefault<z.ZodBoolean>;
|
||||
isConditional: z.ZodDefault<z.ZodBoolean>;
|
||||
sampleValue: z.ZodOptional<z.ZodString>;
|
||||
sortOrder: z.ZodDefault<z.ZodNumber>;
|
||||
}, "strip", z.ZodTypeAny, {
|
||||
type: "VIDEO" | "TEXT";
|
||||
key: string;
|
||||
label: string;
|
||||
sortOrder: number;
|
||||
isRequired: boolean;
|
||||
isConditional: boolean;
|
||||
videoId?: number | undefined;
|
||||
description?: string | undefined;
|
||||
sampleValue?: string | undefined;
|
||||
}, {
|
||||
key: string;
|
||||
label: string;
|
||||
type?: "VIDEO" | "TEXT" | undefined;
|
||||
videoId?: number | undefined;
|
||||
description?: string | undefined;
|
||||
sortOrder?: number | undefined;
|
||||
isRequired?: boolean | undefined;
|
||||
isConditional?: boolean | undefined;
|
||||
sampleValue?: string | undefined;
|
||||
}>, {
|
||||
type: "VIDEO" | "TEXT";
|
||||
key: string;
|
||||
label: string;
|
||||
sortOrder: number;
|
||||
isRequired: boolean;
|
||||
isConditional: boolean;
|
||||
videoId?: number | undefined;
|
||||
description?: string | undefined;
|
||||
sampleValue?: string | undefined;
|
||||
}, {
|
||||
key: string;
|
||||
label: string;
|
||||
type?: "VIDEO" | "TEXT" | undefined;
|
||||
videoId?: number | undefined;
|
||||
description?: string | undefined;
|
||||
sortOrder?: number | undefined;
|
||||
isRequired?: boolean | undefined;
|
||||
isConditional?: boolean | undefined;
|
||||
sampleValue?: string | undefined;
|
||||
}>, "many">>;
|
||||
}, "strip", z.ZodTypeAny, {
|
||||
name: string;
|
||||
category: "INFLUENCE" | "MAP" | "SYSTEM";
|
||||
isActive: boolean;
|
||||
key: string;
|
||||
subjectLine: string;
|
||||
htmlContent: string;
|
||||
textContent: string;
|
||||
description?: string | undefined;
|
||||
variables?: {
|
||||
type: "VIDEO" | "TEXT";
|
||||
key: string;
|
||||
label: string;
|
||||
sortOrder: number;
|
||||
isRequired: boolean;
|
||||
isConditional: boolean;
|
||||
videoId?: number | undefined;
|
||||
description?: string | undefined;
|
||||
sampleValue?: string | undefined;
|
||||
}[] | undefined;
|
||||
}, {
|
||||
name: string;
|
||||
category: "INFLUENCE" | "MAP" | "SYSTEM";
|
||||
key: string;
|
||||
subjectLine: string;
|
||||
htmlContent: string;
|
||||
textContent: string;
|
||||
description?: string | undefined;
|
||||
isActive?: boolean | undefined;
|
||||
variables?: {
|
||||
key: string;
|
||||
label: string;
|
||||
type?: "VIDEO" | "TEXT" | undefined;
|
||||
videoId?: number | undefined;
|
||||
description?: string | undefined;
|
||||
sortOrder?: number | undefined;
|
||||
isRequired?: boolean | undefined;
|
||||
isConditional?: boolean | undefined;
|
||||
sampleValue?: string | undefined;
|
||||
}[] | undefined;
|
||||
}>;
|
||||
export type CreateEmailTemplateDto = z.infer<typeof createEmailTemplateSchema>;
|
||||
export declare const updateEmailTemplateSchema: z.ZodObject<{
|
||||
name: z.ZodOptional<z.ZodString>;
|
||||
description: z.ZodNullable<z.ZodOptional<z.ZodString>>;
|
||||
category: z.ZodOptional<z.ZodNativeEnum<{
|
||||
INFLUENCE: "INFLUENCE";
|
||||
MAP: "MAP";
|
||||
SYSTEM: "SYSTEM";
|
||||
}>>;
|
||||
subjectLine: z.ZodOptional<z.ZodString>;
|
||||
htmlContent: z.ZodOptional<z.ZodString>;
|
||||
textContent: z.ZodOptional<z.ZodString>;
|
||||
isActive: z.ZodOptional<z.ZodBoolean>;
|
||||
variables: z.ZodOptional<z.ZodArray<z.ZodEffects<z.ZodObject<{
|
||||
key: z.ZodString;
|
||||
label: z.ZodString;
|
||||
description: z.ZodOptional<z.ZodString>;
|
||||
type: z.ZodDefault<z.ZodEnum<["TEXT", "VIDEO"]>>;
|
||||
videoId: z.ZodOptional<z.ZodNumber>;
|
||||
isRequired: z.ZodDefault<z.ZodBoolean>;
|
||||
isConditional: z.ZodDefault<z.ZodBoolean>;
|
||||
sampleValue: z.ZodOptional<z.ZodString>;
|
||||
sortOrder: z.ZodDefault<z.ZodNumber>;
|
||||
}, "strip", z.ZodTypeAny, {
|
||||
type: "VIDEO" | "TEXT";
|
||||
key: string;
|
||||
label: string;
|
||||
sortOrder: number;
|
||||
isRequired: boolean;
|
||||
isConditional: boolean;
|
||||
videoId?: number | undefined;
|
||||
description?: string | undefined;
|
||||
sampleValue?: string | undefined;
|
||||
}, {
|
||||
key: string;
|
||||
label: string;
|
||||
type?: "VIDEO" | "TEXT" | undefined;
|
||||
videoId?: number | undefined;
|
||||
description?: string | undefined;
|
||||
sortOrder?: number | undefined;
|
||||
isRequired?: boolean | undefined;
|
||||
isConditional?: boolean | undefined;
|
||||
sampleValue?: string | undefined;
|
||||
}>, {
|
||||
type: "VIDEO" | "TEXT";
|
||||
key: string;
|
||||
label: string;
|
||||
sortOrder: number;
|
||||
isRequired: boolean;
|
||||
isConditional: boolean;
|
||||
videoId?: number | undefined;
|
||||
description?: string | undefined;
|
||||
sampleValue?: string | undefined;
|
||||
}, {
|
||||
key: string;
|
||||
label: string;
|
||||
type?: "VIDEO" | "TEXT" | undefined;
|
||||
videoId?: number | undefined;
|
||||
description?: string | undefined;
|
||||
sortOrder?: number | undefined;
|
||||
isRequired?: boolean | undefined;
|
||||
isConditional?: boolean | undefined;
|
||||
sampleValue?: string | undefined;
|
||||
}>, "many">>;
|
||||
}, "strip", z.ZodTypeAny, {
|
||||
name?: string | undefined;
|
||||
category?: "INFLUENCE" | "MAP" | "SYSTEM" | undefined;
|
||||
description?: string | null | undefined;
|
||||
isActive?: boolean | undefined;
|
||||
subjectLine?: string | undefined;
|
||||
htmlContent?: string | undefined;
|
||||
textContent?: string | undefined;
|
||||
variables?: {
|
||||
type: "VIDEO" | "TEXT";
|
||||
key: string;
|
||||
label: string;
|
||||
sortOrder: number;
|
||||
isRequired: boolean;
|
||||
isConditional: boolean;
|
||||
videoId?: number | undefined;
|
||||
description?: string | undefined;
|
||||
sampleValue?: string | undefined;
|
||||
}[] | undefined;
|
||||
}, {
|
||||
name?: string | undefined;
|
||||
category?: "INFLUENCE" | "MAP" | "SYSTEM" | undefined;
|
||||
description?: string | null | undefined;
|
||||
isActive?: boolean | undefined;
|
||||
subjectLine?: string | undefined;
|
||||
htmlContent?: string | undefined;
|
||||
textContent?: string | undefined;
|
||||
variables?: {
|
||||
key: string;
|
||||
label: string;
|
||||
type?: "VIDEO" | "TEXT" | undefined;
|
||||
videoId?: number | undefined;
|
||||
description?: string | undefined;
|
||||
sortOrder?: number | undefined;
|
||||
isRequired?: boolean | undefined;
|
||||
isConditional?: boolean | undefined;
|
||||
sampleValue?: string | undefined;
|
||||
}[] | undefined;
|
||||
}>;
|
||||
export type UpdateEmailTemplateDto = z.infer<typeof updateEmailTemplateSchema>;
|
||||
export declare const rollbackToVersionSchema: z.ZodObject<{
|
||||
versionNumber: z.ZodNumber;
|
||||
changeNotes: z.ZodOptional<z.ZodString>;
|
||||
}, "strip", z.ZodTypeAny, {
|
||||
versionNumber: number;
|
||||
changeNotes?: string | undefined;
|
||||
}, {
|
||||
versionNumber: number;
|
||||
changeNotes?: string | undefined;
|
||||
}>;
|
||||
export type RollbackToVersionDto = z.infer<typeof rollbackToVersionSchema>;
|
||||
export declare const validateTemplateSchema: z.ZodObject<{
|
||||
htmlContent: z.ZodString;
|
||||
textContent: z.ZodString;
|
||||
subjectLine: z.ZodOptional<z.ZodString>;
|
||||
}, "strip", z.ZodTypeAny, {
|
||||
htmlContent: string;
|
||||
textContent: string;
|
||||
subjectLine?: string | undefined;
|
||||
}, {
|
||||
htmlContent: string;
|
||||
textContent: string;
|
||||
subjectLine?: string | undefined;
|
||||
}>;
|
||||
export type ValidateTemplateDto = z.infer<typeof validateTemplateSchema>;
|
||||
export declare const sendTestEmailSchema: z.ZodObject<{
|
||||
recipientEmail: z.ZodString;
|
||||
testData: z.ZodRecord<z.ZodString, z.ZodString>;
|
||||
}, "strip", z.ZodTypeAny, {
|
||||
recipientEmail: string;
|
||||
testData: Record<string, string>;
|
||||
}, {
|
||||
recipientEmail: string;
|
||||
testData: Record<string, string>;
|
||||
}>;
|
||||
export type SendTestEmailDto = z.infer<typeof sendTestEmailSchema>;
|
||||
//# sourceMappingURL=email-templates.schemas.d.ts.map
|
||||
1
api/dist/modules/email-templates/email-templates.schemas.d.ts.map
vendored
Normal file
1
api/dist/modules/email-templates/email-templates.schemas.d.ts.map
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"email-templates.schemas.d.ts","sourceRoot":"","sources":["../../../src/modules/email-templates/email-templates.schemas.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAIxB,eAAO,MAAM,+BAA+B,8BAA4B,CAAC;AACzE,MAAM,MAAM,6BAA6B,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,+BAA+B,CAAC,CAAC;AAG5F,eAAO,MAAM,2BAA2B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAmBvC,CAAC;AAGF,eAAO,MAAM,wBAAwB;;;;;;;;;;;;;;;;;;;;;;EAMnC,CAAC;AAEH,MAAM,MAAM,qBAAqB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,wBAAwB,CAAC,CAAC;AAG7E,eAAO,MAAM,yBAAyB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAUpC,CAAC;AAEH,MAAM,MAAM,sBAAsB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,yBAAyB,CAAC,CAAC;AAG/E,eAAO,MAAM,yBAAyB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EASpC,CAAC;AAEH,MAAM,MAAM,sBAAsB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,yBAAyB,CAAC,CAAC;AAG/E,eAAO,MAAM,uBAAuB;;;;;;;;;EAGlC,CAAC;AAEH,MAAM,MAAM,oBAAoB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,uBAAuB,CAAC,CAAC;AAG3E,eAAO,MAAM,sBAAsB;;;;;;;;;;;;EAIjC,CAAC;AAEH,MAAM,MAAM,mBAAmB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,sBAAsB,CAAC,CAAC;AAGzE,eAAO,MAAM,mBAAmB;;;;;;;;;EAG9B,CAAC;AAEH,MAAM,MAAM,gBAAgB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,mBAAmB,CAAC,CAAC"}
|
||||
73
api/dist/modules/email-templates/email-templates.schemas.js
vendored
Normal file
73
api/dist/modules/email-templates/email-templates.schemas.js
vendored
Normal file
@@ -0,0 +1,73 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.sendTestEmailSchema = exports.validateTemplateSchema = exports.rollbackToVersionSchema = exports.updateEmailTemplateSchema = exports.createEmailTemplateSchema = exports.listEmailTemplatesSchema = exports.emailTemplateVariableSchema = exports.EmailTemplateVariableTypeSchema = void 0;
|
||||
const zod_1 = require("zod");
|
||||
const client_1 = require("@prisma/client");
|
||||
// Variable type enum
|
||||
exports.EmailTemplateVariableTypeSchema = zod_1.z.enum(['TEXT', 'VIDEO']);
|
||||
// Variable schema
|
||||
exports.emailTemplateVariableSchema = zod_1.z.object({
|
||||
key: zod_1.z.string().regex(/^[A-Z_]+$/, 'Variable key must be uppercase letters and underscores'),
|
||||
label: zod_1.z.string().min(1).max(100),
|
||||
description: zod_1.z.string().max(500).optional(),
|
||||
type: exports.EmailTemplateVariableTypeSchema.default('TEXT'),
|
||||
videoId: zod_1.z.number().int().positive().optional(),
|
||||
isRequired: zod_1.z.boolean().default(true),
|
||||
isConditional: zod_1.z.boolean().default(false),
|
||||
sampleValue: zod_1.z.string().max(1000).optional(),
|
||||
sortOrder: zod_1.z.number().int().min(0).default(0),
|
||||
}).refine((data) => {
|
||||
// VIDEO type must have videoId
|
||||
if (data.type === 'VIDEO' && !data.videoId) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}, { message: 'VIDEO variables must have a videoId', path: ['videoId'] });
|
||||
// List templates
|
||||
exports.listEmailTemplatesSchema = zod_1.z.object({
|
||||
page: zod_1.z.coerce.number().int().min(1).default(1),
|
||||
limit: zod_1.z.coerce.number().int().min(1).max(100).default(20),
|
||||
search: zod_1.z.string().max(200).optional(),
|
||||
category: zod_1.z.nativeEnum(client_1.EmailTemplateCategory).optional(),
|
||||
isActive: zod_1.z.coerce.boolean().optional(),
|
||||
});
|
||||
// Create template
|
||||
exports.createEmailTemplateSchema = zod_1.z.object({
|
||||
key: zod_1.z.string().regex(/^[a-z0-9-]+$/, 'Template key must be lowercase alphanumeric with hyphens').min(1).max(100),
|
||||
name: zod_1.z.string().min(1).max(200),
|
||||
description: zod_1.z.string().max(1000).optional(),
|
||||
category: zod_1.z.nativeEnum(client_1.EmailTemplateCategory),
|
||||
subjectLine: zod_1.z.string().min(1).max(500),
|
||||
htmlContent: zod_1.z.string().min(1).max(100000, 'HTML content exceeds 100KB limit'),
|
||||
textContent: zod_1.z.string().min(1).max(50000, 'Text content exceeds 50KB limit'),
|
||||
isActive: zod_1.z.boolean().default(true),
|
||||
variables: zod_1.z.array(exports.emailTemplateVariableSchema).optional(),
|
||||
});
|
||||
// Update template
|
||||
exports.updateEmailTemplateSchema = zod_1.z.object({
|
||||
name: zod_1.z.string().min(1).max(200).optional(),
|
||||
description: zod_1.z.string().max(1000).optional().nullable(),
|
||||
category: zod_1.z.nativeEnum(client_1.EmailTemplateCategory).optional(),
|
||||
subjectLine: zod_1.z.string().min(1).max(500).optional(),
|
||||
htmlContent: zod_1.z.string().min(1).max(100000, 'HTML content exceeds 100KB limit').optional(),
|
||||
textContent: zod_1.z.string().min(1).max(50000, 'Text content exceeds 50KB limit').optional(),
|
||||
isActive: zod_1.z.boolean().optional(),
|
||||
variables: zod_1.z.array(exports.emailTemplateVariableSchema).optional(),
|
||||
});
|
||||
// Rollback to version
|
||||
exports.rollbackToVersionSchema = zod_1.z.object({
|
||||
versionNumber: zod_1.z.number().int().min(1),
|
||||
changeNotes: zod_1.z.string().max(500).optional(),
|
||||
});
|
||||
// Validate template
|
||||
exports.validateTemplateSchema = zod_1.z.object({
|
||||
htmlContent: zod_1.z.string().min(1).max(100000),
|
||||
textContent: zod_1.z.string().min(1).max(50000),
|
||||
subjectLine: zod_1.z.string().min(1).max(500).optional(),
|
||||
});
|
||||
// Send test email
|
||||
exports.sendTestEmailSchema = zod_1.z.object({
|
||||
recipientEmail: zod_1.z.string().email('Invalid email address').max(255),
|
||||
testData: zod_1.z.record(zod_1.z.string(), zod_1.z.string()),
|
||||
});
|
||||
//# sourceMappingURL=email-templates.schemas.js.map
|
||||
1
api/dist/modules/email-templates/email-templates.schemas.js.map
vendored
Normal file
1
api/dist/modules/email-templates/email-templates.schemas.js.map
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"email-templates.schemas.js","sourceRoot":"","sources":["../../../src/modules/email-templates/email-templates.schemas.ts"],"names":[],"mappings":";;;AAAA,6BAAwB;AACxB,2CAAuD;AAEvD,qBAAqB;AACR,QAAA,+BAA+B,GAAG,OAAC,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;AAGzE,kBAAkB;AACL,QAAA,2BAA2B,GAAG,OAAC,CAAC,MAAM,CAAC;IAClD,GAAG,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,WAAW,EAAE,wDAAwD,CAAC;IAC5F,KAAK,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC;IACjC,WAAW,EAAE,O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AACP,QAAA,sBAAsB,GAAG,OAAC,CAAC,MAAM,CAAC;IAC7C,WAAW,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC;IAC1C,WAAW,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC;IACzC,WAAW,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE;CACnD,CAAC,CAAC;AAIH,kBAAkB;AACL,QAAA,mBAAmB,GAAG,OAAC,CAAC,MAAM,CAAC;IAC1C,cAAc,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,uBAAuB,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC;IAClE,QAAQ,EAAE,OAAC,CAAC,MAAM,CAAC,OAAC,CAAC,MAAM,EAAE,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC;CAC3C,CAAC,CAAC"}
|
||||
266
api/dist/modules/email-templates/email-templates.service.d.ts
vendored
Normal file
266
api/dist/modules/email-templates/email-templates.service.d.ts
vendored
Normal file
@@ -0,0 +1,266 @@
|
||||
import { Prisma } from '@prisma/client';
|
||||
import type { ListEmailTemplatesDto, CreateEmailTemplateDto, UpdateEmailTemplateDto, RollbackToVersionDto, ValidateTemplateDto, SendTestEmailDto } from './email-templates.schemas';
|
||||
interface EmailTemplatesListResponse {
|
||||
templates: any[];
|
||||
pagination: {
|
||||
page: number;
|
||||
limit: number;
|
||||
total: number;
|
||||
totalPages: number;
|
||||
};
|
||||
}
|
||||
interface ValidationResult {
|
||||
valid: boolean;
|
||||
errors: string[];
|
||||
warnings?: string[];
|
||||
extractedVariables?: string[];
|
||||
}
|
||||
export declare class EmailTemplatesService {
|
||||
/**
|
||||
* List email templates with pagination, search, and filters
|
||||
*/
|
||||
list(params: ListEmailTemplatesDto): Promise<EmailTemplatesListResponse>;
|
||||
/**
|
||||
* Get a single email template by ID
|
||||
*/
|
||||
getById(id: string): Promise<{
|
||||
_count: {
|
||||
versions: number;
|
||||
testLogs: number;
|
||||
};
|
||||
variables: {
|
||||
type: import(".prisma/client").$Enums.EmailTemplateVariableType;
|
||||
id: string;
|
||||
videoId: number | null;
|
||||
description: string | null;
|
||||
key: string;
|
||||
templateId: string;
|
||||
label: string;
|
||||
sortOrder: number;
|
||||
isRequired: boolean;
|
||||
isConditional: boolean;
|
||||
sampleValue: string | null;
|
||||
}[];
|
||||
updatedBy: {
|
||||
id: string;
|
||||
email: string;
|
||||
name: string | null;
|
||||
} | null;
|
||||
createdBy: {
|
||||
id: string;
|
||||
email: string;
|
||||
name: string | null;
|
||||
};
|
||||
} & {
|
||||
id: string;
|
||||
name: string;
|
||||
createdAt: Date;
|
||||
updatedAt: Date;
|
||||
category: import(".prisma/client").$Enums.EmailTemplateCategory;
|
||||
description: string | null;
|
||||
isActive: boolean;
|
||||
key: string;
|
||||
createdByUserId: string;
|
||||
updatedByUserId: string | null;
|
||||
subjectLine: string;
|
||||
htmlContent: string;
|
||||
textContent: string;
|
||||
isSystem: boolean;
|
||||
}>;
|
||||
/**
|
||||
* Get template by key
|
||||
*/
|
||||
getByKey(key: string): Promise<({
|
||||
variables: {
|
||||
type: import(".prisma/client").$Enums.EmailTemplateVariableType;
|
||||
id: string;
|
||||
videoId: number | null;
|
||||
description: string | null;
|
||||
key: string;
|
||||
templateId: string;
|
||||
label: string;
|
||||
sortOrder: number;
|
||||
isRequired: boolean;
|
||||
isConditional: boolean;
|
||||
sampleValue: string | null;
|
||||
}[];
|
||||
} & {
|
||||
id: string;
|
||||
name: string;
|
||||
createdAt: Date;
|
||||
updatedAt: Date;
|
||||
category: import(".prisma/client").$Enums.EmailTemplateCategory;
|
||||
description: string | null;
|
||||
isActive: boolean;
|
||||
key: string;
|
||||
createdByUserId: string;
|
||||
updatedByUserId: string | null;
|
||||
subjectLine: string;
|
||||
htmlContent: string;
|
||||
textContent: string;
|
||||
isSystem: boolean;
|
||||
}) | null>;
|
||||
/**
|
||||
* Create a new email template
|
||||
*/
|
||||
create(data: CreateEmailTemplateDto, userId: string): Promise<{
|
||||
variables: {
|
||||
type: import(".prisma/client").$Enums.EmailTemplateVariableType;
|
||||
id: string;
|
||||
videoId: number | null;
|
||||
description: string | null;
|
||||
key: string;
|
||||
templateId: string;
|
||||
label: string;
|
||||
sortOrder: number;
|
||||
isRequired: boolean;
|
||||
isConditional: boolean;
|
||||
sampleValue: string | null;
|
||||
}[];
|
||||
} & {
|
||||
id: string;
|
||||
name: string;
|
||||
createdAt: Date;
|
||||
updatedAt: Date;
|
||||
category: import(".prisma/client").$Enums.EmailTemplateCategory;
|
||||
description: string | null;
|
||||
isActive: boolean;
|
||||
key: string;
|
||||
createdByUserId: string;
|
||||
updatedByUserId: string | null;
|
||||
subjectLine: string;
|
||||
htmlContent: string;
|
||||
textContent: string;
|
||||
isSystem: boolean;
|
||||
}>;
|
||||
/**
|
||||
* Update an email template
|
||||
*/
|
||||
update(id: string, data: UpdateEmailTemplateDto, userId: string): Promise<{
|
||||
variables: {
|
||||
type: import(".prisma/client").$Enums.EmailTemplateVariableType;
|
||||
id: string;
|
||||
videoId: number | null;
|
||||
description: string | null;
|
||||
key: string;
|
||||
templateId: string;
|
||||
label: string;
|
||||
sortOrder: number;
|
||||
isRequired: boolean;
|
||||
isConditional: boolean;
|
||||
sampleValue: string | null;
|
||||
}[];
|
||||
} & {
|
||||
id: string;
|
||||
name: string;
|
||||
createdAt: Date;
|
||||
updatedAt: Date;
|
||||
category: import(".prisma/client").$Enums.EmailTemplateCategory;
|
||||
description: string | null;
|
||||
isActive: boolean;
|
||||
key: string;
|
||||
createdByUserId: string;
|
||||
updatedByUserId: string | null;
|
||||
subjectLine: string;
|
||||
htmlContent: string;
|
||||
textContent: string;
|
||||
isSystem: boolean;
|
||||
}>;
|
||||
/**
|
||||
* Delete an email template
|
||||
*/
|
||||
delete(id: string): Promise<void>;
|
||||
/**
|
||||
* Get version history for a template
|
||||
*/
|
||||
getVersions(templateId: string): Promise<({
|
||||
createdBy: {
|
||||
id: string;
|
||||
email: string;
|
||||
name: string | null;
|
||||
};
|
||||
} & {
|
||||
id: string;
|
||||
createdAt: Date;
|
||||
createdByUserId: string;
|
||||
subjectLine: string;
|
||||
htmlContent: string;
|
||||
textContent: string;
|
||||
versionNumber: number;
|
||||
changeNotes: string | null;
|
||||
templateId: string;
|
||||
})[]>;
|
||||
/**
|
||||
* Get a specific version
|
||||
*/
|
||||
getVersion(templateId: string, versionNumber: number): Promise<{
|
||||
createdBy: {
|
||||
id: string;
|
||||
email: string;
|
||||
name: string | null;
|
||||
};
|
||||
} & {
|
||||
id: string;
|
||||
createdAt: Date;
|
||||
createdByUserId: string;
|
||||
subjectLine: string;
|
||||
htmlContent: string;
|
||||
textContent: string;
|
||||
versionNumber: number;
|
||||
changeNotes: string | null;
|
||||
templateId: string;
|
||||
}>;
|
||||
/**
|
||||
* Rollback to a previous version
|
||||
*/
|
||||
rollbackToVersion(templateId: string, data: RollbackToVersionDto, userId: string): Promise<{
|
||||
id: string;
|
||||
name: string;
|
||||
createdAt: Date;
|
||||
updatedAt: Date;
|
||||
category: import(".prisma/client").$Enums.EmailTemplateCategory;
|
||||
description: string | null;
|
||||
isActive: boolean;
|
||||
key: string;
|
||||
createdByUserId: string;
|
||||
updatedByUserId: string | null;
|
||||
subjectLine: string;
|
||||
htmlContent: string;
|
||||
textContent: string;
|
||||
isSystem: boolean;
|
||||
}>;
|
||||
/**
|
||||
* Validate template syntax
|
||||
*/
|
||||
validateTemplate(data: ValidateTemplateDto): ValidationResult;
|
||||
/**
|
||||
* Send test email
|
||||
*/
|
||||
sendTestEmail(templateId: string, data: SendTestEmailDto, userId: string): Promise<{
|
||||
success: boolean;
|
||||
messageId: string | undefined;
|
||||
}>;
|
||||
/**
|
||||
* Get test logs for a template
|
||||
*/
|
||||
getTestLogs(templateId: string, limit?: number): Promise<({
|
||||
sentBy: {
|
||||
id: string;
|
||||
email: string;
|
||||
name: string | null;
|
||||
};
|
||||
} & {
|
||||
id: string;
|
||||
success: boolean;
|
||||
recipientEmail: string;
|
||||
sentAt: Date;
|
||||
templateId: string;
|
||||
testData: Prisma.JsonValue;
|
||||
errorMessage: string | null;
|
||||
messageId: string | null;
|
||||
sentByUserId: string;
|
||||
})[]>;
|
||||
}
|
||||
export declare const emailTemplatesService: EmailTemplatesService;
|
||||
export {};
|
||||
//# sourceMappingURL=email-templates.service.d.ts.map
|
||||
1
api/dist/modules/email-templates/email-templates.service.d.ts.map
vendored
Normal file
1
api/dist/modules/email-templates/email-templates.service.d.ts.map
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"email-templates.service.d.ts","sourceRoot":"","sources":["../../../src/modules/email-templates/email-templates.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,MAAM,EAAE,MAAM,gBAAgB,CAAC;AACtD,OAAO,KAAK,EACV,qBAAqB,EACrB,sBAAsB,EACtB,sBAAsB,EACtB,oBAAoB,EACpB,mBAAmB,EACnB,gBAAgB,EACjB,MAAM,2BAA2B,CAAC;AAMnC,UAAU,0BAA0B;IAClC,SAAS,EAAE,GAAG,EAAE,CAAC;IACjB,UAAU,EAAE;QACV,IAAI,EAAE,MAAM,CAAC;QACb,KAAK,EAAE,MAAM,CAAC;QACd,KAAK,EAAE,MAAM,CAAC;QACd,UAAU,EAAE,MAAM,CAAC;KACpB,CAAC;CACH;AAED,UAAU,gBAAgB;IACxB,KAAK,EAAE,OAAO,CAAC;IACf,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IACpB,kBAAkB,CAAC,EAAE,MAAM,EAAE,CAAC;CAC/B;AAED,qBAAa,qBAAqB;IAChC;;OAEG;IACG,IAAI,CAAC,MAAM,EAAE,qBAAqB,GAAG,OAAO,CAAC,0BAA0B,CAAC;IAuD9E;;OAEG;IACG,OAAO,CAAC,EAAE,EAAE,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IA6BxB;;OAEG;IACG,QAAQ,CAAC,GAAG,EAAE,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAa1B;;OAEG;IACG,MAAM,CAAC,IAAI,EAAE,sBAAsB,EAAE,MAAM,EAAE,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAsEzD;;OAEG;IACG,MAAM,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,sBAAsB,EAAE,MAAM,EAAE,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IA8ErE;;OAEG;IACG,MAAM,CAAC,EAAE,EAAE,MAAM;IAiBvB;;OAEG;IACG,WAAW,CAAC,UAAU,EAAE,MAAM;;;;;;;;;;;;;;;;;IAcpC;;OAEG;IACG,UAAU,CAAC,UAAU,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM;;;;;;;;;;;;;;;;;IAsB1D;;OAEG;IACG,iBAAiB,CAAC,UAAU,EAAE,MAAM,EAAE,IAAI,EAAE,oBAAoB,EAAE,MAAM,EAAE,MAAM;;;;;;;;;;;;;;;;IAgDtF;;OAEG;IACH,gBAAgB,CAAC,IAAI,EAAE,mBAAmB,GAAG,gBAAgB;IA2D7D;;OAEG;IACG,aAAa,CAAC,UAAU,EAAE,MAAM,EAAE,IAAI,EAAE,gBAAgB,EAAE,MAAM,EAAE,MAAM;;;;IAmE9E;;OAEG;IACG,WAAW,CAAC,UAAU,EAAE,MAAM,EAAE,KAAK,SAAK;;;;;;;;;;;;;;;;;CAcjD;AAED,eAAO,MAAM,qBAAqB,uBAA8B,CAAC"}
|
||||
467
api/dist/modules/email-templates/email-templates.service.js
vendored
Normal file
467
api/dist/modules/email-templates/email-templates.service.js
vendored
Normal file
@@ -0,0 +1,467 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.emailTemplatesService = exports.EmailTemplatesService = void 0;
|
||||
const client_1 = require("@prisma/client");
|
||||
const logger_1 = require("../../utils/logger");
|
||||
const email_service_1 = require("../../services/email.service");
|
||||
const prisma = new client_1.PrismaClient();
|
||||
class EmailTemplatesService {
|
||||
/**
|
||||
* List email templates with pagination, search, and filters
|
||||
*/
|
||||
async list(params) {
|
||||
const { page, limit, search, category, isActive } = params;
|
||||
const skip = (page - 1) * limit;
|
||||
// Build where clause
|
||||
const where = {
|
||||
...(search && {
|
||||
OR: [
|
||||
{ key: { contains: search, mode: 'insensitive' } },
|
||||
{ name: { contains: search, mode: 'insensitive' } },
|
||||
{ description: { contains: search, mode: 'insensitive' } },
|
||||
],
|
||||
}),
|
||||
...(category && { category }),
|
||||
...(isActive !== undefined && { isActive }),
|
||||
};
|
||||
const [data, total] = await Promise.all([
|
||||
prisma.emailTemplate.findMany({
|
||||
where,
|
||||
skip,
|
||||
take: limit,
|
||||
orderBy: [{ isSystem: 'desc' }, { category: 'asc' }, { name: 'asc' }],
|
||||
include: {
|
||||
variables: {
|
||||
orderBy: { sortOrder: 'asc' },
|
||||
},
|
||||
_count: {
|
||||
select: {
|
||||
versions: true,
|
||||
testLogs: true,
|
||||
},
|
||||
},
|
||||
createdBy: {
|
||||
select: { id: true, name: true, email: true },
|
||||
},
|
||||
updatedBy: {
|
||||
select: { id: true, name: true, email: true },
|
||||
},
|
||||
},
|
||||
}),
|
||||
prisma.emailTemplate.count({ where }),
|
||||
]);
|
||||
return {
|
||||
templates: data,
|
||||
pagination: {
|
||||
page,
|
||||
limit,
|
||||
total,
|
||||
totalPages: Math.ceil(total / limit),
|
||||
},
|
||||
};
|
||||
}
|
||||
/**
|
||||
* Get a single email template by ID
|
||||
*/
|
||||
async getById(id) {
|
||||
const template = await prisma.emailTemplate.findUnique({
|
||||
where: { id },
|
||||
include: {
|
||||
variables: {
|
||||
orderBy: { sortOrder: 'asc' },
|
||||
},
|
||||
_count: {
|
||||
select: {
|
||||
versions: true,
|
||||
testLogs: true,
|
||||
},
|
||||
},
|
||||
createdBy: {
|
||||
select: { id: true, name: true, email: true },
|
||||
},
|
||||
updatedBy: {
|
||||
select: { id: true, name: true, email: true },
|
||||
},
|
||||
},
|
||||
});
|
||||
if (!template) {
|
||||
throw new Error('Template not found');
|
||||
}
|
||||
return template;
|
||||
}
|
||||
/**
|
||||
* Get template by key
|
||||
*/
|
||||
async getByKey(key) {
|
||||
const template = await prisma.emailTemplate.findUnique({
|
||||
where: { key },
|
||||
include: {
|
||||
variables: {
|
||||
orderBy: { sortOrder: 'asc' },
|
||||
},
|
||||
},
|
||||
});
|
||||
return template;
|
||||
}
|
||||
/**
|
||||
* Create a new email template
|
||||
*/
|
||||
async create(data, userId) {
|
||||
// Check for duplicate key
|
||||
const existing = await prisma.emailTemplate.findUnique({
|
||||
where: { key: data.key },
|
||||
});
|
||||
if (existing) {
|
||||
throw new Error(`Template with key "${data.key}" already exists`);
|
||||
}
|
||||
// Validate template content
|
||||
const validation = this.validateTemplate({
|
||||
htmlContent: data.htmlContent,
|
||||
textContent: data.textContent,
|
||||
subjectLine: data.subjectLine,
|
||||
});
|
||||
if (!validation.valid) {
|
||||
throw new Error(`Template validation failed: ${validation.errors.join(', ')}`);
|
||||
}
|
||||
// Create template with variables and initial version in transaction
|
||||
const template = await prisma.$transaction(async (tx) => {
|
||||
const newTemplate = await tx.emailTemplate.create({
|
||||
data: {
|
||||
key: data.key,
|
||||
name: data.name,
|
||||
description: data.description,
|
||||
category: data.category,
|
||||
subjectLine: data.subjectLine,
|
||||
htmlContent: data.htmlContent,
|
||||
textContent: data.textContent,
|
||||
isSystem: false, // User-created templates are never system templates
|
||||
isActive: data.isActive ?? true,
|
||||
createdByUserId: userId,
|
||||
variables: data.variables
|
||||
? {
|
||||
create: data.variables,
|
||||
}
|
||||
: undefined,
|
||||
},
|
||||
include: {
|
||||
variables: true,
|
||||
},
|
||||
});
|
||||
// Create initial version
|
||||
await tx.emailTemplateVersion.create({
|
||||
data: {
|
||||
templateId: newTemplate.id,
|
||||
versionNumber: 1,
|
||||
subjectLine: data.subjectLine,
|
||||
htmlContent: data.htmlContent,
|
||||
textContent: data.textContent,
|
||||
changeNotes: 'Initial version',
|
||||
createdByUserId: userId,
|
||||
},
|
||||
});
|
||||
return newTemplate;
|
||||
});
|
||||
logger_1.logger.info(`Email template created: ${template.key} by user ${userId}`);
|
||||
// Clear email service cache for this template
|
||||
email_service_1.emailService.clearDatabaseCache(template.key);
|
||||
return template;
|
||||
}
|
||||
/**
|
||||
* Update an email template
|
||||
*/
|
||||
async update(id, data, userId) {
|
||||
const existing = await this.getById(id);
|
||||
// Validate template content if provided
|
||||
if (data.htmlContent || data.textContent) {
|
||||
const validation = this.validateTemplate({
|
||||
htmlContent: data.htmlContent ?? existing.htmlContent,
|
||||
textContent: data.textContent ?? existing.textContent,
|
||||
subjectLine: data.subjectLine ?? existing.subjectLine,
|
||||
});
|
||||
if (!validation.valid) {
|
||||
throw new Error(`Template validation failed: ${validation.errors.join(', ')}`);
|
||||
}
|
||||
}
|
||||
// Update template and create new version if content changed
|
||||
const template = await prisma.$transaction(async (tx) => {
|
||||
// Update template
|
||||
const updated = await tx.emailTemplate.update({
|
||||
where: { id },
|
||||
data: {
|
||||
...(data.name && { name: data.name }),
|
||||
...(data.description !== undefined && { description: data.description }),
|
||||
...(data.category && { category: data.category }),
|
||||
...(data.subjectLine && { subjectLine: data.subjectLine }),
|
||||
...(data.htmlContent && { htmlContent: data.htmlContent }),
|
||||
...(data.textContent && { textContent: data.textContent }),
|
||||
...(data.isActive !== undefined && { isActive: data.isActive }),
|
||||
updatedByUserId: userId,
|
||||
// Handle variables update
|
||||
...(data.variables && {
|
||||
variables: {
|
||||
deleteMany: {},
|
||||
create: data.variables,
|
||||
},
|
||||
}),
|
||||
},
|
||||
include: {
|
||||
variables: true,
|
||||
},
|
||||
});
|
||||
// Create new version if content changed
|
||||
if (data.subjectLine || data.htmlContent || data.textContent) {
|
||||
const latestVersion = await tx.emailTemplateVersion.findFirst({
|
||||
where: { templateId: id },
|
||||
orderBy: { versionNumber: 'desc' },
|
||||
});
|
||||
const nextVersionNumber = (latestVersion?.versionNumber ?? 0) + 1;
|
||||
await tx.emailTemplateVersion.create({
|
||||
data: {
|
||||
templateId: id,
|
||||
versionNumber: nextVersionNumber,
|
||||
subjectLine: data.subjectLine ?? existing.subjectLine,
|
||||
htmlContent: data.htmlContent ?? existing.htmlContent,
|
||||
textContent: data.textContent ?? existing.textContent,
|
||||
changeNotes: `Updated via admin interface`,
|
||||
createdByUserId: userId,
|
||||
},
|
||||
});
|
||||
logger_1.logger.info(`Created version ${nextVersionNumber} for template ${existing.key}`);
|
||||
}
|
||||
return updated;
|
||||
});
|
||||
logger_1.logger.info(`Email template updated: ${existing.key} by user ${userId}`);
|
||||
// Clear email service cache
|
||||
email_service_1.emailService.clearDatabaseCache(existing.key);
|
||||
return template;
|
||||
}
|
||||
/**
|
||||
* Delete an email template
|
||||
*/
|
||||
async delete(id) {
|
||||
const existing = await this.getById(id);
|
||||
if (existing.isSystem) {
|
||||
throw new Error('Cannot delete system templates');
|
||||
}
|
||||
await prisma.emailTemplate.delete({
|
||||
where: { id },
|
||||
});
|
||||
logger_1.logger.info(`Email template deleted: ${existing.key}`);
|
||||
// Clear email service cache
|
||||
email_service_1.emailService.clearDatabaseCache(existing.key);
|
||||
}
|
||||
/**
|
||||
* Get version history for a template
|
||||
*/
|
||||
async getVersions(templateId) {
|
||||
const versions = await prisma.emailTemplateVersion.findMany({
|
||||
where: { templateId },
|
||||
orderBy: { versionNumber: 'desc' },
|
||||
include: {
|
||||
createdBy: {
|
||||
select: { id: true, name: true, email: true },
|
||||
},
|
||||
},
|
||||
});
|
||||
return versions;
|
||||
}
|
||||
/**
|
||||
* Get a specific version
|
||||
*/
|
||||
async getVersion(templateId, versionNumber) {
|
||||
const version = await prisma.emailTemplateVersion.findUnique({
|
||||
where: {
|
||||
templateId_versionNumber: {
|
||||
templateId,
|
||||
versionNumber,
|
||||
},
|
||||
},
|
||||
include: {
|
||||
createdBy: {
|
||||
select: { id: true, name: true, email: true },
|
||||
},
|
||||
},
|
||||
});
|
||||
if (!version) {
|
||||
throw new Error('Version not found');
|
||||
}
|
||||
return version;
|
||||
}
|
||||
/**
|
||||
* Rollback to a previous version
|
||||
*/
|
||||
async rollbackToVersion(templateId, data, userId) {
|
||||
const template = await this.getById(templateId);
|
||||
const targetVersion = await this.getVersion(templateId, data.versionNumber);
|
||||
// Create new version with content from target version
|
||||
const result = await prisma.$transaction(async (tx) => {
|
||||
const latestVersion = await tx.emailTemplateVersion.findFirst({
|
||||
where: { templateId },
|
||||
orderBy: { versionNumber: 'desc' },
|
||||
});
|
||||
const nextVersionNumber = (latestVersion?.versionNumber ?? 0) + 1;
|
||||
// Update template to target version content
|
||||
const updated = await tx.emailTemplate.update({
|
||||
where: { id: templateId },
|
||||
data: {
|
||||
subjectLine: targetVersion.subjectLine,
|
||||
htmlContent: targetVersion.htmlContent,
|
||||
textContent: targetVersion.textContent,
|
||||
updatedByUserId: userId,
|
||||
},
|
||||
});
|
||||
// Create new version (rollback creates a new version, doesn't revert history)
|
||||
await tx.emailTemplateVersion.create({
|
||||
data: {
|
||||
templateId,
|
||||
versionNumber: nextVersionNumber,
|
||||
subjectLine: targetVersion.subjectLine,
|
||||
htmlContent: targetVersion.htmlContent,
|
||||
textContent: targetVersion.textContent,
|
||||
changeNotes: data.changeNotes ?? `Rolled back to version ${data.versionNumber}`,
|
||||
createdByUserId: userId,
|
||||
},
|
||||
});
|
||||
return updated;
|
||||
});
|
||||
logger_1.logger.info(`Template ${template.key} rolled back to version ${data.versionNumber} by user ${userId}`);
|
||||
// Clear email service cache
|
||||
email_service_1.emailService.clearDatabaseCache(template.key);
|
||||
return result;
|
||||
}
|
||||
/**
|
||||
* Validate template syntax
|
||||
*/
|
||||
validateTemplate(data) {
|
||||
const errors = [];
|
||||
const warnings = [];
|
||||
const variables = new Set();
|
||||
// Extract variables from content
|
||||
const variableRegex = /\{\{([A-Z_]+)\}\}/g;
|
||||
const conditionalRegex = /\{\{#if\s+([A-Z_]+)\}\}|\{\{\/if\}\}/g;
|
||||
// Check HTML content
|
||||
let match;
|
||||
while ((match = variableRegex.exec(data.htmlContent)) !== null) {
|
||||
variables.add(match[1]);
|
||||
}
|
||||
while ((match = conditionalRegex.exec(data.htmlContent)) !== null) {
|
||||
if (match[1])
|
||||
variables.add(match[1]);
|
||||
}
|
||||
// Check text content
|
||||
while ((match = variableRegex.exec(data.textContent)) !== null) {
|
||||
variables.add(match[1]);
|
||||
}
|
||||
while ((match = conditionalRegex.exec(data.textContent)) !== null) {
|
||||
if (match[1])
|
||||
variables.add(match[1]);
|
||||
}
|
||||
// Check subject line if provided
|
||||
if (data.subjectLine) {
|
||||
while ((match = variableRegex.exec(data.subjectLine)) !== null) {
|
||||
variables.add(match[1]);
|
||||
}
|
||||
}
|
||||
// Check for unmatched conditionals
|
||||
const ifCount = (data.htmlContent.match(/\{\{#if/g) || []).length;
|
||||
const endifCount = (data.htmlContent.match(/\{\{\/if\}\}/g) || []).length;
|
||||
if (ifCount !== endifCount) {
|
||||
errors.push('Unmatched {{#if}} conditional blocks in HTML content');
|
||||
}
|
||||
const ifCountText = (data.textContent.match(/\{\{#if/g) || []).length;
|
||||
const endifCountText = (data.textContent.match(/\{\{\/if\}\}/g) || []).length;
|
||||
if (ifCountText !== endifCountText) {
|
||||
errors.push('Unmatched {{#if}} conditional blocks in text content');
|
||||
}
|
||||
// Warn if no variables found
|
||||
if (variables.size === 0) {
|
||||
warnings.push('No template variables found');
|
||||
}
|
||||
return {
|
||||
valid: errors.length === 0,
|
||||
errors,
|
||||
warnings,
|
||||
extractedVariables: Array.from(variables),
|
||||
};
|
||||
}
|
||||
/**
|
||||
* Send test email
|
||||
*/
|
||||
async sendTestEmail(templateId, data, userId) {
|
||||
const template = await this.getById(templateId);
|
||||
try {
|
||||
// Process template with test data
|
||||
let htmlContent = template.htmlContent;
|
||||
let textContent = template.textContent;
|
||||
let subjectLine = template.subjectLine;
|
||||
// Replace variables
|
||||
for (const [key, value] of Object.entries(data.testData)) {
|
||||
const regex = new RegExp(`\\{\\{${key}\\}\\}`, 'g');
|
||||
htmlContent = htmlContent.replace(regex, value);
|
||||
textContent = textContent.replace(regex, value);
|
||||
subjectLine = subjectLine.replace(regex, value);
|
||||
}
|
||||
// Handle conditionals (simple implementation)
|
||||
for (const [key, value] of Object.entries(data.testData)) {
|
||||
const ifRegex = new RegExp(`\\{\\{#if\\s+${key}\\}\\}([\\s\\S]*?)\\{\\{\\/if\\}\\}`, 'g');
|
||||
const shouldShow = value && value !== 'false' && value !== '0';
|
||||
htmlContent = htmlContent.replace(ifRegex, shouldShow ? '$1' : '');
|
||||
textContent = textContent.replace(ifRegex, shouldShow ? '$1' : '');
|
||||
}
|
||||
// Send email via email service
|
||||
const result = await email_service_1.emailService.sendEmail({
|
||||
to: data.recipientEmail,
|
||||
subject: subjectLine,
|
||||
text: textContent,
|
||||
html: htmlContent,
|
||||
});
|
||||
// Log test email
|
||||
await prisma.emailTemplateTestLog.create({
|
||||
data: {
|
||||
templateId,
|
||||
recipientEmail: data.recipientEmail,
|
||||
testData: data.testData,
|
||||
success: true,
|
||||
messageId: result.messageId,
|
||||
sentByUserId: userId,
|
||||
},
|
||||
});
|
||||
logger_1.logger.info(`Test email sent for template ${template.key} to ${data.recipientEmail}`);
|
||||
return { success: true, messageId: result.messageId };
|
||||
}
|
||||
catch (error) {
|
||||
// Log failed test
|
||||
await prisma.emailTemplateTestLog.create({
|
||||
data: {
|
||||
templateId,
|
||||
recipientEmail: data.recipientEmail,
|
||||
testData: data.testData,
|
||||
success: false,
|
||||
errorMessage: error instanceof Error ? error.message : String(error),
|
||||
sentByUserId: userId,
|
||||
},
|
||||
});
|
||||
logger_1.logger.error(`Test email failed for template ${template.key}: ${error}`);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Get test logs for a template
|
||||
*/
|
||||
async getTestLogs(templateId, limit = 10) {
|
||||
const logs = await prisma.emailTemplateTestLog.findMany({
|
||||
where: { templateId },
|
||||
orderBy: { sentAt: 'desc' },
|
||||
take: limit,
|
||||
include: {
|
||||
sentBy: {
|
||||
select: { id: true, name: true, email: true },
|
||||
},
|
||||
},
|
||||
});
|
||||
return logs;
|
||||
}
|
||||
}
|
||||
exports.EmailTemplatesService = EmailTemplatesService;
|
||||
exports.emailTemplatesService = new EmailTemplatesService();
|
||||
//# sourceMappingURL=email-templates.service.js.map
|
||||
1
api/dist/modules/email-templates/email-templates.service.js.map
vendored
Normal file
1
api/dist/modules/email-templates/email-templates.service.js.map
vendored
Normal file
File diff suppressed because one or more lines are too long
4
api/dist/modules/influence/campaign-emails/campaign-emails.routes.d.ts
vendored
Normal file
4
api/dist/modules/influence/campaign-emails/campaign-emails.routes.d.ts
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
declare const publicRouter: import("express-serve-static-core").Router;
|
||||
declare const adminRouter: import("express-serve-static-core").Router;
|
||||
export { publicRouter as campaignEmailsPublicRouter, adminRouter as campaignEmailsAdminRouter };
|
||||
//# sourceMappingURL=campaign-emails.routes.d.ts.map
|
||||
1
api/dist/modules/influence/campaign-emails/campaign-emails.routes.d.ts.map
vendored
Normal file
1
api/dist/modules/influence/campaign-emails/campaign-emails.routes.d.ts.map
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"campaign-emails.routes.d.ts","sourceRoot":"","sources":["../../../../src/modules/influence/campaign-emails/campaign-emails.routes.ts"],"names":[],"mappings":"AAgBA,QAAA,MAAM,YAAY,4CAAW,CAAC;AAqC9B,QAAA,MAAM,WAAW,4CAAW,CAAC;AAiC7B,OAAO,EAAE,YAAY,IAAI,0BAA0B,EAAE,WAAW,IAAI,yBAAyB,EAAE,CAAC"}
|
||||
67
api/dist/modules/influence/campaign-emails/campaign-emails.routes.js
vendored
Normal file
67
api/dist/modules/influence/campaign-emails/campaign-emails.routes.js
vendored
Normal file
@@ -0,0 +1,67 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.campaignEmailsAdminRouter = exports.campaignEmailsPublicRouter = void 0;
|
||||
const express_1 = require("express");
|
||||
const client_1 = require("@prisma/client");
|
||||
const campaign_emails_service_1 = require("./campaign-emails.service");
|
||||
const campaign_emails_schemas_1 = require("./campaign-emails.schemas");
|
||||
const validate_1 = require("../../../middleware/validate");
|
||||
const auth_middleware_1 = require("../../../middleware/auth.middleware");
|
||||
const rbac_middleware_1 = require("../../../middleware/rbac.middleware");
|
||||
const rate_limit_1 = require("../../../middleware/rate-limit");
|
||||
const ADMIN_ROLES = [client_1.UserRole.SUPER_ADMIN, client_1.UserRole.INFLUENCE_ADMIN, client_1.UserRole.MAP_ADMIN];
|
||||
// --- Public Routes (no auth) ---
|
||||
const publicRouter = (0, express_1.Router)();
|
||||
exports.campaignEmailsPublicRouter = publicRouter;
|
||||
// POST /api/campaigns/:slug/send-email
|
||||
publicRouter.post('/:slug/send-email', rate_limit_1.emailRateLimit, (0, validate_1.validate)(campaign_emails_schemas_1.sendCampaignEmailSchema), async (req, res, next) => {
|
||||
try {
|
||||
const slug = req.params.slug;
|
||||
const senderIp = req.ip || req.socket.remoteAddress;
|
||||
const result = await campaign_emails_service_1.campaignEmailsService.sendEmail(slug, req.body, senderIp);
|
||||
res.status(201).json(result);
|
||||
}
|
||||
catch (err) {
|
||||
next(err);
|
||||
}
|
||||
});
|
||||
// POST /api/campaigns/:slug/track-mailto
|
||||
publicRouter.post('/:slug/track-mailto', rate_limit_1.emailRateLimit, (0, validate_1.validate)(campaign_emails_schemas_1.trackMailtoSchema), async (req, res, next) => {
|
||||
try {
|
||||
const slug = req.params.slug;
|
||||
const senderIp = req.ip || req.socket.remoteAddress;
|
||||
const result = await campaign_emails_service_1.campaignEmailsService.trackMailto(slug, req.body, senderIp);
|
||||
res.status(201).json(result);
|
||||
}
|
||||
catch (err) {
|
||||
next(err);
|
||||
}
|
||||
});
|
||||
// --- Admin Routes (auth required) ---
|
||||
const adminRouter = (0, express_1.Router)();
|
||||
exports.campaignEmailsAdminRouter = adminRouter;
|
||||
adminRouter.use(auth_middleware_1.authenticate);
|
||||
adminRouter.use((0, rbac_middleware_1.requireRole)(...ADMIN_ROLES));
|
||||
// GET /api/campaigns/:id/emails
|
||||
adminRouter.get('/:id/emails', (0, validate_1.validate)(campaign_emails_schemas_1.listCampaignEmailsSchema, 'query'), async (req, res, next) => {
|
||||
try {
|
||||
const id = req.params.id;
|
||||
const result = await campaign_emails_service_1.campaignEmailsService.listByCampaign(id, req.query);
|
||||
res.json(result);
|
||||
}
|
||||
catch (err) {
|
||||
next(err);
|
||||
}
|
||||
});
|
||||
// GET /api/campaigns/:id/email-stats
|
||||
adminRouter.get('/:id/email-stats', async (req, res, next) => {
|
||||
try {
|
||||
const id = req.params.id;
|
||||
const stats = await campaign_emails_service_1.campaignEmailsService.getStats(id);
|
||||
res.json(stats);
|
||||
}
|
||||
catch (err) {
|
||||
next(err);
|
||||
}
|
||||
});
|
||||
//# sourceMappingURL=campaign-emails.routes.js.map
|
||||
1
api/dist/modules/influence/campaign-emails/campaign-emails.routes.js.map
vendored
Normal file
1
api/dist/modules/influence/campaign-emails/campaign-emails.routes.js.map
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"campaign-emails.routes.js","sourceRoot":"","sources":["../../../../src/modules/influence/campaign-emails/campaign-emails.routes.ts"],"names":[],"mappings":";;;AAAA,qCAAkE;AAClE,2CAA0C;AAC1C,uEAAkE;AAClE,uEAImC;AACnC,2DAAwD;AACxD,yEAAmE;AACnE,yEAAkE;AAClE,+DAAgE;AAEhE,MAAM,WAAW,GAAe,CAAC,iBAAQ,CAAC,WAAW,EAAE,iBAAQ,CAAC,eAAe,EAAE,iBAAQ,CAAC,SAAS,CAAC,CAAC;AAErG,kCAAkC;AAClC,MAAM,YAAY,GAAG,IAAA,gBAAM,GAAE,CAAC;AAsEL,kDAA0B;AApEnD,uCAAuC;AAC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ign-emails/campaign-emails.schemas.d.ts
vendored
Normal file
@@ -0,0 +1,116 @@
|
||||
import { z } from 'zod';
|
||||
export declare const sendCampaignEmailSchema: z.ZodObject<{
|
||||
userEmail: z.ZodString;
|
||||
userName: z.ZodString;
|
||||
postalCode: z.ZodString;
|
||||
recipientEmail: z.ZodString;
|
||||
recipientName: z.ZodOptional<z.ZodString>;
|
||||
recipientTitle: z.ZodOptional<z.ZodString>;
|
||||
recipientLevel: z.ZodOptional<z.ZodNativeEnum<{
|
||||
FEDERAL: "FEDERAL";
|
||||
PROVINCIAL: "PROVINCIAL";
|
||||
MUNICIPAL: "MUNICIPAL";
|
||||
SCHOOL_BOARD: "SCHOOL_BOARD";
|
||||
}>>;
|
||||
emailMethod: z.ZodNativeEnum<{
|
||||
SMTP: "SMTP";
|
||||
MAILTO: "MAILTO";
|
||||
}>;
|
||||
customEmailSubject: z.ZodOptional<z.ZodString>;
|
||||
customEmailBody: z.ZodOptional<z.ZodString>;
|
||||
}, "strip", z.ZodTypeAny, {
|
||||
userEmail: string;
|
||||
userName: string;
|
||||
recipientEmail: string;
|
||||
emailMethod: "SMTP" | "MAILTO";
|
||||
postalCode: string;
|
||||
recipientName?: string | undefined;
|
||||
recipientTitle?: string | undefined;
|
||||
recipientLevel?: "FEDERAL" | "PROVINCIAL" | "MUNICIPAL" | "SCHOOL_BOARD" | undefined;
|
||||
customEmailSubject?: string | undefined;
|
||||
customEmailBody?: string | undefined;
|
||||
}, {
|
||||
userEmail: string;
|
||||
userName: string;
|
||||
recipientEmail: string;
|
||||
emailMethod: "SMTP" | "MAILTO";
|
||||
postalCode: string;
|
||||
recipientName?: string | undefined;
|
||||
recipientTitle?: string | undefined;
|
||||
recipientLevel?: "FEDERAL" | "PROVINCIAL" | "MUNICIPAL" | "SCHOOL_BOARD" | undefined;
|
||||
customEmailSubject?: string | undefined;
|
||||
customEmailBody?: string | undefined;
|
||||
}>;
|
||||
export declare const trackMailtoSchema: z.ZodObject<{
|
||||
recipientEmail: z.ZodString;
|
||||
recipientName: z.ZodOptional<z.ZodString>;
|
||||
recipientTitle: z.ZodOptional<z.ZodString>;
|
||||
recipientLevel: z.ZodOptional<z.ZodNativeEnum<{
|
||||
FEDERAL: "FEDERAL";
|
||||
PROVINCIAL: "PROVINCIAL";
|
||||
MUNICIPAL: "MUNICIPAL";
|
||||
SCHOOL_BOARD: "SCHOOL_BOARD";
|
||||
}>>;
|
||||
userEmail: z.ZodOptional<z.ZodString>;
|
||||
userName: z.ZodOptional<z.ZodString>;
|
||||
postalCode: z.ZodOptional<z.ZodString>;
|
||||
}, "strip", z.ZodTypeAny, {
|
||||
recipientEmail: string;
|
||||
userEmail?: string | undefined;
|
||||
userName?: string | undefined;
|
||||
recipientName?: string | undefined;
|
||||
recipientTitle?: string | undefined;
|
||||
recipientLevel?: "FEDERAL" | "PROVINCIAL" | "MUNICIPAL" | "SCHOOL_BOARD" | undefined;
|
||||
postalCode?: string | undefined;
|
||||
}, {
|
||||
recipientEmail: string;
|
||||
userEmail?: string | undefined;
|
||||
userName?: string | undefined;
|
||||
recipientName?: string | undefined;
|
||||
recipientTitle?: string | undefined;
|
||||
recipientLevel?: "FEDERAL" | "PROVINCIAL" | "MUNICIPAL" | "SCHOOL_BOARD" | undefined;
|
||||
postalCode?: string | undefined;
|
||||
}>;
|
||||
export declare const listCampaignEmailsSchema: z.ZodObject<{
|
||||
page: z.ZodDefault<z.ZodNumber>;
|
||||
limit: z.ZodDefault<z.ZodNumber>;
|
||||
status: z.ZodOptional<z.ZodNativeEnum<{
|
||||
QUEUED: "QUEUED";
|
||||
SENT: "SENT";
|
||||
FAILED: "FAILED";
|
||||
CLICKED: "CLICKED";
|
||||
USER_INFO_CAPTURED: "USER_INFO_CAPTURED";
|
||||
}>>;
|
||||
emailMethod: z.ZodOptional<z.ZodNativeEnum<{
|
||||
SMTP: "SMTP";
|
||||
MAILTO: "MAILTO";
|
||||
}>>;
|
||||
}, "strip", z.ZodTypeAny, {
|
||||
limit: number;
|
||||
page: number;
|
||||
status?: "QUEUED" | "SENT" | "FAILED" | "CLICKED" | "USER_INFO_CAPTURED" | undefined;
|
||||
emailMethod?: "SMTP" | "MAILTO" | undefined;
|
||||
}, {
|
||||
status?: "QUEUED" | "SENT" | "FAILED" | "CLICKED" | "USER_INFO_CAPTURED" | undefined;
|
||||
limit?: number | undefined;
|
||||
page?: number | undefined;
|
||||
emailMethod?: "SMTP" | "MAILTO" | undefined;
|
||||
}>;
|
||||
export declare const campaignSlugParamSchema: z.ZodObject<{
|
||||
slug: z.ZodString;
|
||||
}, "strip", z.ZodTypeAny, {
|
||||
slug: string;
|
||||
}, {
|
||||
slug: string;
|
||||
}>;
|
||||
export declare const campaignIdParamSchema: z.ZodObject<{
|
||||
id: z.ZodString;
|
||||
}, "strip", z.ZodTypeAny, {
|
||||
id: string;
|
||||
}, {
|
||||
id: string;
|
||||
}>;
|
||||
export type SendCampaignEmailInput = z.infer<typeof sendCampaignEmailSchema>;
|
||||
export type TrackMailtoInput = z.infer<typeof trackMailtoSchema>;
|
||||
export type ListCampaignEmailsInput = z.infer<typeof listCampaignEmailsSchema>;
|
||||
//# sourceMappingURL=campaign-emails.schemas.d.ts.map
|
||||
1
api/dist/modules/influence/campaign-emails/campaign-emails.schemas.d.ts.map
vendored
Normal file
1
api/dist/modules/influence/campaign-emails/campaign-emails.schemas.d.ts.map
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"campaign-emails.schemas.d.ts","sourceRoot":"","sources":["../../../../src/modules/influence/campaign-emails/campaign-emails.schemas.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB,eAAO,MAAM,uBAAuB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAWlC,CAAC;AAEH,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAQ5B,CAAC;AAEH,eAAO,MAAM,wBAAwB;;;;;;;;;;;;;;;;;;;;;;;;EAKnC,CAAC;AAEH,eAAO,MAAM,uBAAuB;;;;;;EAElC,CAAC;AAEH,eAAO,MAAM,qBAAqB;;;;;;EAEhC,CAAC;AAEH,MAAM,MAAM,sBAAsB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,uBAAuB,CAAC,CAAC;AAC7E,MAAM,MAAM,gBAAgB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,iBAAiB,CAAC,CAAC;AACjE,MAAM,MAAM,uBAAuB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,wBAAwB,CAAC,CAAC"}
|
||||
39
api/dist/modules/influence/campaign-emails/campaign-emails.schemas.js
vendored
Normal file
39
api/dist/modules/influence/campaign-emails/campaign-emails.schemas.js
vendored
Normal file
@@ -0,0 +1,39 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.campaignIdParamSchema = exports.campaignSlugParamSchema = exports.listCampaignEmailsSchema = exports.trackMailtoSchema = exports.sendCampaignEmailSchema = void 0;
|
||||
const zod_1 = require("zod");
|
||||
const client_1 = require("@prisma/client");
|
||||
exports.sendCampaignEmailSchema = zod_1.z.object({
|
||||
userEmail: zod_1.z.string().email('Valid email is required'),
|
||||
userName: zod_1.z.string().min(1, 'Name is required'),
|
||||
postalCode: zod_1.z.string().min(1, 'Postal code is required'),
|
||||
recipientEmail: zod_1.z.string().email('Valid recipient email is required'),
|
||||
recipientName: zod_1.z.string().optional(),
|
||||
recipientTitle: zod_1.z.string().optional(),
|
||||
recipientLevel: zod_1.z.nativeEnum(client_1.GovernmentLevel).optional(),
|
||||
emailMethod: zod_1.z.nativeEnum(client_1.EmailMethod),
|
||||
customEmailSubject: zod_1.z.string().optional(),
|
||||
customEmailBody: zod_1.z.string().optional(),
|
||||
});
|
||||
exports.trackMailtoSchema = zod_1.z.object({
|
||||
recipientEmail: zod_1.z.string().email('Valid recipient email is required'),
|
||||
recipientName: zod_1.z.string().optional(),
|
||||
recipientTitle: zod_1.z.string().optional(),
|
||||
recipientLevel: zod_1.z.nativeEnum(client_1.GovernmentLevel).optional(),
|
||||
userEmail: zod_1.z.string().email().optional(),
|
||||
userName: zod_1.z.string().optional(),
|
||||
postalCode: zod_1.z.string().optional(),
|
||||
});
|
||||
exports.listCampaignEmailsSchema = zod_1.z.object({
|
||||
page: zod_1.z.coerce.number().int().positive().default(1),
|
||||
limit: zod_1.z.coerce.number().int().positive().max(100).default(20),
|
||||
status: zod_1.z.nativeEnum(client_1.CampaignEmailStatus).optional(),
|
||||
emailMethod: zod_1.z.nativeEnum(client_1.EmailMethod).optional(),
|
||||
});
|
||||
exports.campaignSlugParamSchema = zod_1.z.object({
|
||||
slug: zod_1.z.string().min(1),
|
||||
});
|
||||
exports.campaignIdParamSchema = zod_1.z.object({
|
||||
id: zod_1.z.string().min(1),
|
||||
});
|
||||
//# sourceMappingURL=campaign-emails.schemas.js.map
|
||||
1
api/dist/modules/influence/campaign-emails/campaign-emails.schemas.js.map
vendored
Normal file
1
api/dist/modules/influence/campaign-emails/campaign-emails.schemas.js.map
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"campaign-emails.schemas.js","sourceRoot":"","sources":["../../../../src/modules/influence/campaign-emails/campaign-emails.schemas.ts"],"names":[],"mappings":";;;AAAA,6BAAwB;AACxB,2CAAmF;AAEtE,QAAA,uBAAuB,GAAG,OAAC,CAAC,MAAM,CAAC;IAC9C,SAAS,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,yBAAyB,CAAC;IACtD,QAAQ,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,EAAE,kBAAkB,CAAC;IAC/C,UAAU,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,EAAE,yBAAyB,CAAC;IACxD,cAAc,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,mCAAmC,CAAC;IACrE,aAAa,EAAE,OAAC,CAA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CAAC;IAC9D,MAAM,EAAE,OAAC,CAAC,UAAU,CAAC,4BAAmB,CAAC,CAAC,QAAQ,EAAE;IACpD,WAAW,EAAE,OAAC,CAAC,UAAU,CAAC,oBAAW,CAAC,CAAC,QAAQ,EAAE;CAClD,CAAC,CAAC;AAEU,QAAA,uBAAuB,GAAG,OAAC,CAAC,MAAM,CAAC;IAC9C,IAAI,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;CACxB,CAAC,CAAC;AAEU,QAAA,qBAAqB,GAAG,OAAC,CAAC,MAAM,CAAC;IAC5C,EAAE,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;CACtB,CAAC,CAAC"}
|
||||
36
api/dist/modules/influence/campaign-emails/campaign-emails.service.d.ts
vendored
Normal file
36
api/dist/modules/influence/campaign-emails/campaign-emails.service.d.ts
vendored
Normal file
@@ -0,0 +1,36 @@
|
||||
import type { SendCampaignEmailInput, TrackMailtoInput, ListCampaignEmailsInput } from './campaign-emails.schemas';
|
||||
export declare const campaignEmailsService: {
|
||||
sendEmail(slug: string, data: SendCampaignEmailInput, senderIp?: string): Promise<{
|
||||
id: string;
|
||||
status: import(".prisma/client").$Enums.CampaignEmailStatus;
|
||||
emailMethod: import(".prisma/client").$Enums.EmailMethod;
|
||||
}>;
|
||||
trackMailto(slug: string, data: TrackMailtoInput, senderIp?: string): Promise<{
|
||||
id: string;
|
||||
status: import(".prisma/client").$Enums.CampaignEmailStatus;
|
||||
emailMethod: import(".prisma/client").$Enums.EmailMethod;
|
||||
}>;
|
||||
listByCampaign(campaignId: string, filters: ListCampaignEmailsInput): Promise<{
|
||||
emails: {
|
||||
status: import(".prisma/client").$Enums.CampaignEmailStatus;
|
||||
id: string;
|
||||
userEmail: string | null;
|
||||
userName: string | null;
|
||||
userPostalCode: string | null;
|
||||
recipientEmail: string;
|
||||
recipientName: string | null;
|
||||
recipientLevel: import(".prisma/client").$Enums.GovernmentLevel | null;
|
||||
emailMethod: import(".prisma/client").$Enums.EmailMethod;
|
||||
subject: string;
|
||||
sentAt: Date;
|
||||
}[];
|
||||
pagination: {
|
||||
page: number;
|
||||
limit: number;
|
||||
total: number;
|
||||
totalPages: number;
|
||||
};
|
||||
}>;
|
||||
getStats(campaignId: string): Promise<Record<string, number>>;
|
||||
};
|
||||
//# sourceMappingURL=campaign-emails.service.d.ts.map
|
||||
1
api/dist/modules/influence/campaign-emails/campaign-emails.service.d.ts.map
vendored
Normal file
1
api/dist/modules/influence/campaign-emails/campaign-emails.service.d.ts.map
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"campaign-emails.service.d.ts","sourceRoot":"","sources":["../../../../src/modules/influence/campaign-emails/campaign-emails.service.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,sBAAsB,EAAE,gBAAgB,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAC;AAEnH,eAAO,MAAM,qBAAqB;oBACV,MAAM,QAAQ,sBAAsB,aAAa,MAAM;;;;;sBAwFrD,MAAM,QAAQ,gBAAgB,aAAa,MAAM;;;;;+BAgDxC,MAAM,WAAW,uBAAuB;;;;;;;;;;;;;;;;;;;;;yBA0C9C,MAAM;CAqClC,CAAC"}
|
||||
206
api/dist/modules/influence/campaign-emails/campaign-emails.service.js
vendored
Normal file
206
api/dist/modules/influence/campaign-emails/campaign-emails.service.js
vendored
Normal file
@@ -0,0 +1,206 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.campaignEmailsService = void 0;
|
||||
const client_1 = require("@prisma/client");
|
||||
const database_1 = require("../../../config/database");
|
||||
const error_handler_1 = require("../../../middleware/error-handler");
|
||||
const email_queue_service_1 = require("../../../services/email-queue.service");
|
||||
const metrics_1 = require("../../../utils/metrics");
|
||||
exports.campaignEmailsService = {
|
||||
async sendEmail(slug, data, senderIp) {
|
||||
const campaign = await database_1.prisma.campaign.findUnique({
|
||||
where: { slug },
|
||||
select: {
|
||||
id: true,
|
||||
slug: true,
|
||||
title: true,
|
||||
status: true,
|
||||
emailSubject: true,
|
||||
emailBody: true,
|
||||
allowSmtpEmail: true,
|
||||
allowMailtoLink: true,
|
||||
allowEmailEditing: true,
|
||||
},
|
||||
});
|
||||
if (!campaign) {
|
||||
throw new error_handler_1.AppError(404, 'Campaign not found', 'CAMPAIGN_NOT_FOUND');
|
||||
}
|
||||
if (campaign.status !== client_1.CampaignStatus.ACTIVE) {
|
||||
throw new error_handler_1.AppError(400, 'Campaign is not active', 'CAMPAIGN_NOT_ACTIVE');
|
||||
}
|
||||
if (data.emailMethod === client_1.EmailMethod.SMTP && !campaign.allowSmtpEmail) {
|
||||
throw new error_handler_1.AppError(400, 'SMTP email is not enabled for this campaign', 'SMTP_NOT_ALLOWED');
|
||||
}
|
||||
if (data.emailMethod === client_1.EmailMethod.MAILTO && !campaign.allowMailtoLink) {
|
||||
throw new error_handler_1.AppError(400, 'Mailto link is not enabled for this campaign', 'MAILTO_NOT_ALLOWED');
|
||||
}
|
||||
// Determine subject and body (custom only if campaign allows editing)
|
||||
const subject = (campaign.allowEmailEditing && data.customEmailSubject)
|
||||
? data.customEmailSubject
|
||||
: campaign.emailSubject;
|
||||
const message = (campaign.allowEmailEditing && data.customEmailBody)
|
||||
? data.customEmailBody
|
||||
: campaign.emailBody;
|
||||
const status = data.emailMethod === client_1.EmailMethod.SMTP
|
||||
? client_1.CampaignEmailStatus.QUEUED
|
||||
: client_1.CampaignEmailStatus.CLICKED;
|
||||
const campaignEmail = await database_1.prisma.campaignEmail.create({
|
||||
data: {
|
||||
campaignId: campaign.id,
|
||||
campaignSlug: campaign.slug,
|
||||
userEmail: data.userEmail,
|
||||
userName: data.userName,
|
||||
userPostalCode: data.postalCode,
|
||||
recipientEmail: data.recipientEmail,
|
||||
recipientName: data.recipientName,
|
||||
recipientTitle: data.recipientTitle,
|
||||
recipientLevel: data.recipientLevel,
|
||||
emailMethod: data.emailMethod,
|
||||
subject,
|
||||
message,
|
||||
status,
|
||||
senderIp,
|
||||
},
|
||||
});
|
||||
if (data.emailMethod === client_1.EmailMethod.SMTP) {
|
||||
await email_queue_service_1.emailQueueService.addCampaignEmail({
|
||||
campaignEmailId: campaignEmail.id,
|
||||
recipientEmail: data.recipientEmail,
|
||||
recipientName: data.recipientName,
|
||||
recipientLevel: data.recipientLevel,
|
||||
userEmail: data.userEmail,
|
||||
userName: data.userName,
|
||||
postalCode: data.postalCode,
|
||||
subject,
|
||||
message,
|
||||
campaignTitle: campaign.title,
|
||||
});
|
||||
}
|
||||
(0, metrics_1.recordCampaignEmail)(campaign.id);
|
||||
return {
|
||||
id: campaignEmail.id,
|
||||
status: campaignEmail.status,
|
||||
emailMethod: campaignEmail.emailMethod,
|
||||
};
|
||||
},
|
||||
async trackMailto(slug, data, senderIp) {
|
||||
const campaign = await database_1.prisma.campaign.findUnique({
|
||||
where: { slug },
|
||||
select: {
|
||||
id: true,
|
||||
slug: true,
|
||||
title: true,
|
||||
status: true,
|
||||
emailSubject: true,
|
||||
emailBody: true,
|
||||
allowMailtoLink: true,
|
||||
},
|
||||
});
|
||||
if (!campaign) {
|
||||
throw new error_handler_1.AppError(404, 'Campaign not found', 'CAMPAIGN_NOT_FOUND');
|
||||
}
|
||||
if (campaign.status !== client_1.CampaignStatus.ACTIVE) {
|
||||
throw new error_handler_1.AppError(400, 'Campaign is not active', 'CAMPAIGN_NOT_ACTIVE');
|
||||
}
|
||||
const campaignEmail = await database_1.prisma.campaignEmail.create({
|
||||
data: {
|
||||
campaignId: campaign.id,
|
||||
campaignSlug: campaign.slug,
|
||||
userEmail: data.userEmail,
|
||||
userName: data.userName,
|
||||
userPostalCode: data.postalCode,
|
||||
recipientEmail: data.recipientEmail,
|
||||
recipientName: data.recipientName,
|
||||
recipientTitle: data.recipientTitle,
|
||||
recipientLevel: data.recipientLevel,
|
||||
emailMethod: client_1.EmailMethod.MAILTO,
|
||||
subject: campaign.emailSubject,
|
||||
message: campaign.emailBody,
|
||||
status: client_1.CampaignEmailStatus.CLICKED,
|
||||
senderIp,
|
||||
},
|
||||
});
|
||||
return {
|
||||
id: campaignEmail.id,
|
||||
status: campaignEmail.status,
|
||||
emailMethod: campaignEmail.emailMethod,
|
||||
};
|
||||
},
|
||||
async listByCampaign(campaignId, filters) {
|
||||
const { page, limit, status, emailMethod } = filters;
|
||||
const skip = (page - 1) * limit;
|
||||
const where = { campaignId };
|
||||
if (status)
|
||||
where.status = status;
|
||||
if (emailMethod)
|
||||
where.emailMethod = emailMethod;
|
||||
const [emails, total] = await Promise.all([
|
||||
database_1.prisma.campaignEmail.findMany({
|
||||
where,
|
||||
skip,
|
||||
take: limit,
|
||||
orderBy: { sentAt: 'desc' },
|
||||
select: {
|
||||
id: true,
|
||||
userEmail: true,
|
||||
userName: true,
|
||||
userPostalCode: true,
|
||||
recipientEmail: true,
|
||||
recipientName: true,
|
||||
recipientLevel: true,
|
||||
emailMethod: true,
|
||||
subject: true,
|
||||
status: true,
|
||||
sentAt: true,
|
||||
},
|
||||
}),
|
||||
database_1.prisma.campaignEmail.count({ where }),
|
||||
]);
|
||||
return {
|
||||
emails,
|
||||
pagination: {
|
||||
page,
|
||||
limit,
|
||||
total,
|
||||
totalPages: Math.ceil(total / limit),
|
||||
},
|
||||
};
|
||||
},
|
||||
async getStats(campaignId) {
|
||||
const [totals, byMethod] = await Promise.all([
|
||||
database_1.prisma.campaignEmail.groupBy({
|
||||
by: ['status'],
|
||||
where: { campaignId },
|
||||
_count: true,
|
||||
}),
|
||||
database_1.prisma.campaignEmail.groupBy({
|
||||
by: ['emailMethod'],
|
||||
where: { campaignId },
|
||||
_count: true,
|
||||
}),
|
||||
]);
|
||||
const stats = {
|
||||
total: 0,
|
||||
queued: 0,
|
||||
sent: 0,
|
||||
failed: 0,
|
||||
clicked: 0,
|
||||
smtpCount: 0,
|
||||
mailtoCount: 0,
|
||||
};
|
||||
for (const row of totals) {
|
||||
stats.total += row._count;
|
||||
const key = row.status.toLowerCase();
|
||||
if (key in stats)
|
||||
stats[key] = row._count;
|
||||
}
|
||||
for (const row of byMethod) {
|
||||
if (row.emailMethod === client_1.EmailMethod.SMTP)
|
||||
stats.smtpCount = row._count;
|
||||
if (row.emailMethod === client_1.EmailMethod.MAILTO)
|
||||
stats.mailtoCount = row._count;
|
||||
}
|
||||
return stats;
|
||||
},
|
||||
};
|
||||
//# sourceMappingURL=campaign-emails.service.js.map
|
||||
1
api/dist/modules/influence/campaign-emails/campaign-emails.service.js.map
vendored
Normal file
1
api/dist/modules/influence/campaign-emails/campaign-emails.service.js.map
vendored
Normal file
File diff suppressed because one or more lines are too long
3
api/dist/modules/influence/campaigns/campaigns-public.routes.d.ts
vendored
Normal file
3
api/dist/modules/influence/campaigns/campaigns-public.routes.d.ts
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
declare const router: import("express-serve-static-core").Router;
|
||||
export { router as campaignPublicRouter };
|
||||
//# sourceMappingURL=campaigns-public.routes.d.ts.map
|
||||
1
api/dist/modules/influence/campaigns/campaigns-public.routes.d.ts.map
vendored
Normal file
1
api/dist/modules/influence/campaigns/campaigns-public.routes.d.ts.map
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"campaigns-public.routes.d.ts","sourceRoot":"","sources":["../../../../src/modules/influence/campaigns/campaigns-public.routes.ts"],"names":[],"mappings":"AAGA,QAAA,MAAM,MAAM,4CAAW,CAAC;AA6BxB,OAAO,EAAE,MAAM,IAAI,oBAAoB,EAAE,CAAC"}
|
||||
29
api/dist/modules/influence/campaigns/campaigns-public.routes.js
vendored
Normal file
29
api/dist/modules/influence/campaigns/campaigns-public.routes.js
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.campaignPublicRouter = void 0;
|
||||
const express_1 = require("express");
|
||||
const campaigns_service_1 = require("./campaigns.service");
|
||||
const router = (0, express_1.Router)();
|
||||
exports.campaignPublicRouter = router;
|
||||
// GET /api/campaigns/public — list all active campaigns (public)
|
||||
router.get('/public', async (_req, res, next) => {
|
||||
try {
|
||||
const campaigns = await campaigns_service_1.campaignsService.findActiveCampaigns();
|
||||
res.json(campaigns);
|
||||
}
|
||||
catch (err) {
|
||||
next(err);
|
||||
}
|
||||
});
|
||||
// GET /api/campaigns/:slug/details — public campaign data (ACTIVE only)
|
||||
router.get('/:slug/details', async (req, res, next) => {
|
||||
try {
|
||||
const slug = req.params.slug;
|
||||
const campaign = await campaigns_service_1.campaignsService.findBySlugPublic(slug);
|
||||
res.json(campaign);
|
||||
}
|
||||
catch (err) {
|
||||
next(err);
|
||||
}
|
||||
});
|
||||
//# sourceMappingURL=campaigns-public.routes.js.map
|
||||
1
api/dist/modules/influence/campaigns/campaigns-public.routes.js.map
vendored
Normal file
1
api/dist/modules/influence/campaigns/campaigns-public.routes.js.map
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"campaigns-public.routes.js","sourceRoot":"","sources":["../../../../src/modules/influence/campaigns/campaigns-public.routes.ts"],"names":[],"mappings":";;;AAAA,qCAAkE;AAClE,2DAAuD;AAEvD,MAAM,MAAM,GAAG,IAAA,gBAAM,GAAE,CAAC;AA6BL,sCAAoB;AA3BvC,iEAAiE;AACjE,MAAM,CAAC,GAAG,CACR,SAAS,EACT,KAAK,EAAE,IAAa,EAAE,GAAa,EAAE,IAAkB,EAAE,EAAE;IACzD,IAAI,CAAC;QACH,MAAM,SAAS,GAAG,MAAM,oCAAgB,CAAC,mBAAmB,EAAE,CAAC;QAC/D,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;IACtB,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,IAAI,CAAC,GAAG,CAAC,CAAC;IACZ,CAAC;AACH,CAAC,CACF,CAAC;AAEF,wEAAwE;AACxE,MAAM,CAAC,GAAG,CACR,gBAAgB,EAChB,KAAK,EAAE,GAAY,EAAE,GAAa,EAAE,IAAkB,EAAE,EAAE;IACxD,IAAI,CAAC;QACH,MAAM,IAAI,GAAG,GAAG,CAAC,MAAM,CAAC,IAAc,CAAC;QACvC,MAAM,QAAQ,GAAG,MAAM,oCAAgB,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAAC;QAC/D,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IACrB,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,IAAI,CAAC,GAAG,CAAC,CAAC;IACZ,CAAC;AACH,CAAC,CACF,CAAC"}
|
||||
3
api/dist/modules/influence/campaigns/campaigns.routes.d.ts
vendored
Normal file
3
api/dist/modules/influence/campaigns/campaigns.routes.d.ts
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
declare const router: import("express-serve-static-core").Router;
|
||||
export { router as campaignsRouter };
|
||||
//# sourceMappingURL=campaigns.routes.d.ts.map
|
||||
1
api/dist/modules/influence/campaigns/campaigns.routes.d.ts.map
vendored
Normal file
1
api/dist/modules/influence/campaigns/campaigns.routes.d.ts.map
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"campaigns.routes.d.ts","sourceRoot":"","sources":["../../../../src/modules/influence/campaigns/campaigns.routes.ts"],"names":[],"mappings":"AAUA,QAAA,MAAM,MAAM,4CAAW,CAAC;AA6ExB,OAAO,EAAE,MAAM,IAAI,eAAe,EAAE,CAAC"}
|
||||
70
api/dist/modules/influence/campaigns/campaigns.routes.js
vendored
Normal file
70
api/dist/modules/influence/campaigns/campaigns.routes.js
vendored
Normal file
@@ -0,0 +1,70 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.campaignsRouter = void 0;
|
||||
const express_1 = require("express");
|
||||
const client_1 = require("@prisma/client");
|
||||
const campaigns_service_1 = require("./campaigns.service");
|
||||
const campaigns_schemas_1 = require("./campaigns.schemas");
|
||||
const validate_1 = require("../../../middleware/validate");
|
||||
const auth_middleware_1 = require("../../../middleware/auth.middleware");
|
||||
const rbac_middleware_1 = require("../../../middleware/rbac.middleware");
|
||||
const ADMIN_ROLES = [client_1.UserRole.SUPER_ADMIN, client_1.UserRole.INFLUENCE_ADMIN, client_1.UserRole.MAP_ADMIN];
|
||||
const router = (0, express_1.Router)();
|
||||
exports.campaignsRouter = router;
|
||||
// All campaign admin routes require authentication + admin role
|
||||
router.use(auth_middleware_1.authenticate);
|
||||
router.use((0, rbac_middleware_1.requireRole)(...ADMIN_ROLES));
|
||||
// GET /api/campaigns — list campaigns with pagination/filters
|
||||
router.get('/', (0, validate_1.validate)(campaigns_schemas_1.listCampaignsSchema, 'query'), async (req, res, next) => {
|
||||
try {
|
||||
const result = await campaigns_service_1.campaignsService.findAll(req.query, req.user);
|
||||
res.json(result);
|
||||
}
|
||||
catch (err) {
|
||||
next(err);
|
||||
}
|
||||
});
|
||||
// GET /api/campaigns/:id — get single campaign
|
||||
router.get('/:id', async (req, res, next) => {
|
||||
try {
|
||||
const id = req.params.id;
|
||||
const campaign = await campaigns_service_1.campaignsService.findById(id);
|
||||
res.json(campaign);
|
||||
}
|
||||
catch (err) {
|
||||
next(err);
|
||||
}
|
||||
});
|
||||
// POST /api/campaigns — create campaign
|
||||
router.post('/', (0, validate_1.validate)(campaigns_schemas_1.createCampaignSchema), async (req, res, next) => {
|
||||
try {
|
||||
const campaign = await campaigns_service_1.campaignsService.create(req.body, req.user);
|
||||
res.status(201).json(campaign);
|
||||
}
|
||||
catch (err) {
|
||||
next(err);
|
||||
}
|
||||
});
|
||||
// PUT /api/campaigns/:id — update campaign
|
||||
router.put('/:id', (0, validate_1.validate)(campaigns_schemas_1.updateCampaignSchema), async (req, res, next) => {
|
||||
try {
|
||||
const id = req.params.id;
|
||||
const campaign = await campaigns_service_1.campaignsService.update(id, req.body);
|
||||
res.json(campaign);
|
||||
}
|
||||
catch (err) {
|
||||
next(err);
|
||||
}
|
||||
});
|
||||
// DELETE /api/campaigns/:id — delete campaign
|
||||
router.delete('/:id', async (req, res, next) => {
|
||||
try {
|
||||
const id = req.params.id;
|
||||
await campaigns_service_1.campaignsService.delete(id);
|
||||
res.status(204).send();
|
||||
}
|
||||
catch (err) {
|
||||
next(err);
|
||||
}
|
||||
});
|
||||
//# sourceMappingURL=campaigns.routes.js.map
|
||||
1
api/dist/modules/influence/campaigns/campaigns.routes.js.map
vendored
Normal file
1
api/dist/modules/influence/campaigns/campaigns.routes.js.map
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"campaigns.routes.js","sourceRoot":"","sources":["../../../../src/modules/influence/campaigns/campaigns.routes.ts"],"names":[],"mappings":";;;AAAA,qCAAkE;AAClE,2CAA0C;AAC1C,2DAAuD;AACvD,2DAAsG;AACtG,2DAAwD;AACxD,yEAAmE;AACnE,yEAAkE;AAElE,MAAM,WAAW,GAAe,CAAC,iBAAQ,CAAC,WAAW,EAAE,iBAAQ,CAAC,eAAe,EAAE,iBAAQ,CAAC,SAAS,CAAC,CAAC;AAErG,MAAM,MAAM,GAAG,IAAA,gBAAM,GAAE,CAAC;AA6EL,iCAAe;AA3ElC,gEAAgE;AAChE,MAAM,CAAC,GAAG,CAAC,8BAAY,CAAC,CAAC;AACzB,MAAM,CAAC,GAAG,CAAC,IAAA,6BAAW,EAAC,GAAG,WAAW,CAAC,CAAC,CAAC;AAExC,8DAA8D;AAC9D,MAAM,CAAC,GAAG,CACR,GAAG,EACH,IAAA,mBAAQ,EAAC,uCAAmB,EAAE,OAAO,CAAC,EACtC,KAAK,EAAE,GAAY,EAAE,GAAa,EAAE,IAAkB,EAAE,EAAE;IACxD,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,MAAM,oCAAgB,CAAC,OAAO,CAAC,GAAG,CAAC,KAAY,EAAE,GAAG,CAAC,IAAK,CAAC,CAAC;QAC3E,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IACnB,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,IAAI,CAAC,GAAG,CAAC,CAAC;IACZ,CAAC;AACH,CAAC,CACF,CAAC;AAEF,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CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IACrB,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,IAAI,CAAC,GAAG,CAAC,CAAC;IACZ,CAAC;AACH,CAAC,CACF,CAAC;AAEF,8CAA8C;AAC9C,MAAM,CAAC,MAAM,CACX,MAAM,EACN,KAAK,EAAE,GAAY,EAAE,GAAa,EAAE,IAAkB,EAAE,EAAE;IACxD,IAAI,CAAC;QACH,MAAM,EAAE,GAAG,GAAG,CAAC,MAAM,CAAC,EAAY,CAAC;QACnC,MAAM,oCAAgB,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;QAClC,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC;IACzB,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,IAAI,CAAC,GAAG,CAAC,CAAC;IACZ,CAAC;AACH,CAAC,CACF,CAAC"}
|
||||
163
api/dist/modules/influence/campaigns/campaigns.schemas.d.ts
vendored
Normal file
163
api/dist/modules/influence/campaigns/campaigns.schemas.d.ts
vendored
Normal file
@@ -0,0 +1,163 @@
|
||||
import { z } from 'zod';
|
||||
export declare const createCampaignSchema: z.ZodObject<{
|
||||
title: z.ZodString;
|
||||
description: z.ZodOptional<z.ZodString>;
|
||||
emailSubject: z.ZodString;
|
||||
emailBody: z.ZodString;
|
||||
callToAction: z.ZodOptional<z.ZodString>;
|
||||
status: z.ZodDefault<z.ZodOptional<z.ZodNativeEnum<{
|
||||
DRAFT: "DRAFT";
|
||||
ACTIVE: "ACTIVE";
|
||||
PAUSED: "PAUSED";
|
||||
ARCHIVED: "ARCHIVED";
|
||||
}>>>;
|
||||
targetGovernmentLevels: z.ZodDefault<z.ZodOptional<z.ZodArray<z.ZodNativeEnum<{
|
||||
FEDERAL: "FEDERAL";
|
||||
PROVINCIAL: "PROVINCIAL";
|
||||
MUNICIPAL: "MUNICIPAL";
|
||||
SCHOOL_BOARD: "SCHOOL_BOARD";
|
||||
}>, "many">>>;
|
||||
allowSmtpEmail: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
||||
allowMailtoLink: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
||||
collectUserInfo: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
||||
showEmailCount: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
||||
showCallCount: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
||||
allowEmailEditing: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
||||
allowCustomRecipients: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
||||
showResponseWall: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
||||
highlightCampaign: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
||||
coverPhoto: z.ZodOptional<z.ZodString>;
|
||||
}, "strip", z.ZodTypeAny, {
|
||||
status: "ACTIVE" | "DRAFT" | "PAUSED" | "ARCHIVED";
|
||||
title: string;
|
||||
emailSubject: string;
|
||||
emailBody: string;
|
||||
allowSmtpEmail: boolean;
|
||||
allowMailtoLink: boolean;
|
||||
collectUserInfo: boolean;
|
||||
showEmailCount: boolean;
|
||||
showCallCount: boolean;
|
||||
allowEmailEditing: boolean;
|
||||
allowCustomRecipients: boolean;
|
||||
showResponseWall: boolean;
|
||||
highlightCampaign: boolean;
|
||||
targetGovernmentLevels: ("FEDERAL" | "PROVINCIAL" | "MUNICIPAL" | "SCHOOL_BOARD")[];
|
||||
description?: string | undefined;
|
||||
callToAction?: string | undefined;
|
||||
coverPhoto?: string | undefined;
|
||||
}, {
|
||||
title: string;
|
||||
emailSubject: string;
|
||||
emailBody: string;
|
||||
status?: "ACTIVE" | "DRAFT" | "PAUSED" | "ARCHIVED" | undefined;
|
||||
description?: string | undefined;
|
||||
callToAction?: string | undefined;
|
||||
coverPhoto?: string | undefined;
|
||||
allowSmtpEmail?: boolean | undefined;
|
||||
allowMailtoLink?: boolean | undefined;
|
||||
collectUserInfo?: boolean | undefined;
|
||||
showEmailCount?: boolean | undefined;
|
||||
showCallCount?: boolean | undefined;
|
||||
allowEmailEditing?: boolean | undefined;
|
||||
allowCustomRecipients?: boolean | undefined;
|
||||
showResponseWall?: boolean | undefined;
|
||||
highlightCampaign?: boolean | undefined;
|
||||
targetGovernmentLevels?: ("FEDERAL" | "PROVINCIAL" | "MUNICIPAL" | "SCHOOL_BOARD")[] | undefined;
|
||||
}>;
|
||||
export declare const updateCampaignSchema: z.ZodObject<{
|
||||
title: z.ZodOptional<z.ZodString>;
|
||||
description: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
||||
emailSubject: z.ZodOptional<z.ZodString>;
|
||||
emailBody: z.ZodOptional<z.ZodString>;
|
||||
callToAction: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
||||
status: z.ZodOptional<z.ZodNativeEnum<{
|
||||
DRAFT: "DRAFT";
|
||||
ACTIVE: "ACTIVE";
|
||||
PAUSED: "PAUSED";
|
||||
ARCHIVED: "ARCHIVED";
|
||||
}>>;
|
||||
targetGovernmentLevels: z.ZodOptional<z.ZodArray<z.ZodNativeEnum<{
|
||||
FEDERAL: "FEDERAL";
|
||||
PROVINCIAL: "PROVINCIAL";
|
||||
MUNICIPAL: "MUNICIPAL";
|
||||
SCHOOL_BOARD: "SCHOOL_BOARD";
|
||||
}>, "many">>;
|
||||
allowSmtpEmail: z.ZodOptional<z.ZodBoolean>;
|
||||
allowMailtoLink: z.ZodOptional<z.ZodBoolean>;
|
||||
collectUserInfo: z.ZodOptional<z.ZodBoolean>;
|
||||
showEmailCount: z.ZodOptional<z.ZodBoolean>;
|
||||
showCallCount: z.ZodOptional<z.ZodBoolean>;
|
||||
allowEmailEditing: z.ZodOptional<z.ZodBoolean>;
|
||||
allowCustomRecipients: z.ZodOptional<z.ZodBoolean>;
|
||||
showResponseWall: z.ZodOptional<z.ZodBoolean>;
|
||||
highlightCampaign: z.ZodOptional<z.ZodBoolean>;
|
||||
coverPhoto: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
||||
}, "strip", z.ZodTypeAny, {
|
||||
status?: "ACTIVE" | "DRAFT" | "PAUSED" | "ARCHIVED" | undefined;
|
||||
title?: string | undefined;
|
||||
description?: string | null | undefined;
|
||||
emailSubject?: string | undefined;
|
||||
emailBody?: string | undefined;
|
||||
callToAction?: string | null | undefined;
|
||||
coverPhoto?: string | null | undefined;
|
||||
allowSmtpEmail?: boolean | undefined;
|
||||
allowMailtoLink?: boolean | undefined;
|
||||
collectUserInfo?: boolean | undefined;
|
||||
showEmailCount?: boolean | undefined;
|
||||
showCallCount?: boolean | undefined;
|
||||
allowEmailEditing?: boolean | undefined;
|
||||
allowCustomRecipients?: boolean | undefined;
|
||||
showResponseWall?: boolean | undefined;
|
||||
highlightCampaign?: boolean | undefined;
|
||||
targetGovernmentLevels?: ("FEDERAL" | "PROVINCIAL" | "MUNICIPAL" | "SCHOOL_BOARD")[] | undefined;
|
||||
}, {
|
||||
status?: "ACTIVE" | "DRAFT" | "PAUSED" | "ARCHIVED" | undefined;
|
||||
title?: string | undefined;
|
||||
description?: string | null | undefined;
|
||||
emailSubject?: string | undefined;
|
||||
emailBody?: string | undefined;
|
||||
callToAction?: string | null | undefined;
|
||||
coverPhoto?: string | null | undefined;
|
||||
allowSmtpEmail?: boolean | undefined;
|
||||
allowMailtoLink?: boolean | undefined;
|
||||
collectUserInfo?: boolean | undefined;
|
||||
showEmailCount?: boolean | undefined;
|
||||
showCallCount?: boolean | undefined;
|
||||
allowEmailEditing?: boolean | undefined;
|
||||
allowCustomRecipients?: boolean | undefined;
|
||||
showResponseWall?: boolean | undefined;
|
||||
highlightCampaign?: boolean | undefined;
|
||||
targetGovernmentLevels?: ("FEDERAL" | "PROVINCIAL" | "MUNICIPAL" | "SCHOOL_BOARD")[] | undefined;
|
||||
}>;
|
||||
export declare const listCampaignsSchema: z.ZodObject<{
|
||||
page: z.ZodDefault<z.ZodNumber>;
|
||||
limit: z.ZodDefault<z.ZodNumber>;
|
||||
search: z.ZodOptional<z.ZodString>;
|
||||
status: z.ZodOptional<z.ZodNativeEnum<{
|
||||
DRAFT: "DRAFT";
|
||||
ACTIVE: "ACTIVE";
|
||||
PAUSED: "PAUSED";
|
||||
ARCHIVED: "ARCHIVED";
|
||||
}>>;
|
||||
}, "strip", z.ZodTypeAny, {
|
||||
limit: number;
|
||||
page: number;
|
||||
status?: "ACTIVE" | "DRAFT" | "PAUSED" | "ARCHIVED" | undefined;
|
||||
search?: string | undefined;
|
||||
}, {
|
||||
status?: "ACTIVE" | "DRAFT" | "PAUSED" | "ARCHIVED" | undefined;
|
||||
search?: string | undefined;
|
||||
limit?: number | undefined;
|
||||
page?: number | undefined;
|
||||
}>;
|
||||
export declare const campaignIdSchema: z.ZodObject<{
|
||||
id: z.ZodString;
|
||||
}, "strip", z.ZodTypeAny, {
|
||||
id: string;
|
||||
}, {
|
||||
id: string;
|
||||
}>;
|
||||
export type CreateCampaignInput = z.infer<typeof createCampaignSchema>;
|
||||
export type UpdateCampaignInput = z.infer<typeof updateCampaignSchema>;
|
||||
export type ListCampaignsInput = z.infer<typeof listCampaignsSchema>;
|
||||
//# sourceMappingURL=campaigns.schemas.d.ts.map
|
||||
1
api/dist/modules/influence/campaigns/campaigns.schemas.d.ts.map
vendored
Normal file
1
api/dist/modules/influence/campaigns/campaigns.schemas.d.ts.map
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"campaigns.schemas.d.ts","sourceRoot":"","sources":["../../../../src/modules/influence/campaigns/campaigns.schemas.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB,eAAO,MAAM,oBAAoB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAkB/B,CAAC;AAEH,eAAO,MAAM,oBAAoB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAkB/B,CAAC;AAEH,eAAO,MAAM,mBAAmB;;;;;;;;;;;;;;;;;;;;EAK9B,CAAC;AAEH,eAAO,MAAM,gBAAgB;;;;;;EAE3B,CAAC;AAEH,MAAM,MAAM,mBAAmB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAC;AACvE,MAAM,MAAM,mBAAmB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAC;AACvE,MAAM,MAAM,kBAAkB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,mBAAmB,CAAC,CAAC"}
|
||||
53
api/dist/modules/influence/campaigns/campaigns.schemas.js
vendored
Normal file
53
api/dist/modules/influence/campaigns/campaigns.schemas.js
vendored
Normal file
@@ -0,0 +1,53 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.campaignIdSchema = exports.listCampaignsSchema = exports.updateCampaignSchema = exports.createCampaignSchema = void 0;
|
||||
const zod_1 = require("zod");
|
||||
const client_1 = require("@prisma/client");
|
||||
exports.createCampaignSchema = zod_1.z.object({
|
||||
title: zod_1.z.string().min(1, 'Title is required'),
|
||||
description: zod_1.z.string().optional(),
|
||||
emailSubject: zod_1.z.string().min(1, 'Email subject is required'),
|
||||
emailBody: zod_1.z.string().min(1, 'Email body is required'),
|
||||
callToAction: zod_1.z.string().optional(),
|
||||
status: zod_1.z.nativeEnum(client_1.CampaignStatus).optional().default(client_1.CampaignStatus.DRAFT),
|
||||
targetGovernmentLevels: zod_1.z.array(zod_1.z.nativeEnum(client_1.GovernmentLevel)).optional().default([]),
|
||||
allowSmtpEmail: zod_1.z.boolean().optional().default(true),
|
||||
allowMailtoLink: zod_1.z.boolean().optional().default(true),
|
||||
collectUserInfo: zod_1.z.boolean().optional().default(true),
|
||||
showEmailCount: zod_1.z.boolean().optional().default(true),
|
||||
showCallCount: zod_1.z.boolean().optional().default(true),
|
||||
allowEmailEditing: zod_1.z.boolean().optional().default(false),
|
||||
allowCustomRecipients: zod_1.z.boolean().optional().default(false),
|
||||
showResponseWall: zod_1.z.boolean().optional().default(false),
|
||||
highlightCampaign: zod_1.z.boolean().optional().default(false),
|
||||
coverPhoto: zod_1.z.string().optional(),
|
||||
});
|
||||
exports.updateCampaignSchema = zod_1.z.object({
|
||||
title: zod_1.z.string().min(1).optional(),
|
||||
description: zod_1.z.string().nullable().optional(),
|
||||
emailSubject: zod_1.z.string().min(1).optional(),
|
||||
emailBody: zod_1.z.string().min(1).optional(),
|
||||
callToAction: zod_1.z.string().nullable().optional(),
|
||||
status: zod_1.z.nativeEnum(client_1.CampaignStatus).optional(),
|
||||
targetGovernmentLevels: zod_1.z.array(zod_1.z.nativeEnum(client_1.GovernmentLevel)).optional(),
|
||||
allowSmtpEmail: zod_1.z.boolean().optional(),
|
||||
allowMailtoLink: zod_1.z.boolean().optional(),
|
||||
collectUserInfo: zod_1.z.boolean().optional(),
|
||||
showEmailCount: zod_1.z.boolean().optional(),
|
||||
showCallCount: zod_1.z.boolean().optional(),
|
||||
allowEmailEditing: zod_1.z.boolean().optional(),
|
||||
allowCustomRecipients: zod_1.z.boolean().optional(),
|
||||
showResponseWall: zod_1.z.boolean().optional(),
|
||||
highlightCampaign: zod_1.z.boolean().optional(),
|
||||
coverPhoto: zod_1.z.string().nullable().optional(),
|
||||
});
|
||||
exports.listCampaignsSchema = zod_1.z.object({
|
||||
page: zod_1.z.coerce.number().int().positive().default(1),
|
||||
limit: zod_1.z.coerce.number().int().positive().max(100).default(20),
|
||||
search: zod_1.z.string().optional(),
|
||||
status: zod_1.z.nativeEnum(client_1.CampaignStatus).optional(),
|
||||
});
|
||||
exports.campaignIdSchema = zod_1.z.object({
|
||||
id: zod_1.z.string().min(1),
|
||||
});
|
||||
//# sourceMappingURL=campaigns.schemas.js.map
|
||||
1
api/dist/modules/influence/campaigns/campaigns.schemas.js.map
vendored
Normal file
1
api/dist/modules/influence/campaigns/campaigns.schemas.js.map
vendored
Normal file
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B,CAAC,CAAC"}
|
||||
230
api/dist/modules/influence/campaigns/campaigns.service.d.ts
vendored
Normal file
230
api/dist/modules/influence/campaigns/campaigns.service.d.ts
vendored
Normal file
@@ -0,0 +1,230 @@
|
||||
import { UserRole } from '@prisma/client';
|
||||
import type { CreateCampaignInput, UpdateCampaignInput, ListCampaignsInput } from './campaigns.schemas';
|
||||
interface AuthUser {
|
||||
id: string;
|
||||
email: string;
|
||||
role: UserRole;
|
||||
}
|
||||
export declare const campaignsService: {
|
||||
findAll(filters: ListCampaignsInput, user?: AuthUser): Promise<{
|
||||
campaigns: {
|
||||
status: import(".prisma/client").$Enums.CampaignStatus;
|
||||
id: string;
|
||||
createdAt: Date;
|
||||
updatedAt: Date;
|
||||
_count: {
|
||||
responses: number;
|
||||
emails: number;
|
||||
};
|
||||
title: string;
|
||||
description: string | null;
|
||||
slug: string;
|
||||
emailSubject: string;
|
||||
emailBody: string;
|
||||
callToAction: string | null;
|
||||
coverPhoto: string | null;
|
||||
allowSmtpEmail: boolean;
|
||||
allowMailtoLink: boolean;
|
||||
collectUserInfo: boolean;
|
||||
showEmailCount: boolean;
|
||||
showCallCount: boolean;
|
||||
allowEmailEditing: boolean;
|
||||
allowCustomRecipients: boolean;
|
||||
showResponseWall: boolean;
|
||||
highlightCampaign: boolean;
|
||||
targetGovernmentLevels: import(".prisma/client").$Enums.GovernmentLevel[];
|
||||
createdByUserEmail: string | null;
|
||||
createdByUserName: string | null;
|
||||
createdByUserId: string | null;
|
||||
}[];
|
||||
pagination: {
|
||||
page: number;
|
||||
limit: number;
|
||||
total: number;
|
||||
totalPages: number;
|
||||
};
|
||||
}>;
|
||||
findById(id: string): Promise<{
|
||||
status: import(".prisma/client").$Enums.CampaignStatus;
|
||||
id: string;
|
||||
createdAt: Date;
|
||||
updatedAt: Date;
|
||||
_count: {
|
||||
responses: number;
|
||||
emails: number;
|
||||
};
|
||||
title: string;
|
||||
description: string | null;
|
||||
slug: string;
|
||||
emailSubject: string;
|
||||
emailBody: string;
|
||||
callToAction: string | null;
|
||||
coverPhoto: string | null;
|
||||
allowSmtpEmail: boolean;
|
||||
allowMailtoLink: boolean;
|
||||
collectUserInfo: boolean;
|
||||
showEmailCount: boolean;
|
||||
showCallCount: boolean;
|
||||
allowEmailEditing: boolean;
|
||||
allowCustomRecipients: boolean;
|
||||
showResponseWall: boolean;
|
||||
highlightCampaign: boolean;
|
||||
targetGovernmentLevels: import(".prisma/client").$Enums.GovernmentLevel[];
|
||||
createdByUserEmail: string | null;
|
||||
createdByUserName: string | null;
|
||||
createdByUserId: string | null;
|
||||
}>;
|
||||
findBySlug(slug: string): Promise<{
|
||||
status: import(".prisma/client").$Enums.CampaignStatus;
|
||||
id: string;
|
||||
createdAt: Date;
|
||||
updatedAt: Date;
|
||||
_count: {
|
||||
responses: number;
|
||||
emails: number;
|
||||
};
|
||||
title: string;
|
||||
description: string | null;
|
||||
slug: string;
|
||||
emailSubject: string;
|
||||
emailBody: string;
|
||||
callToAction: string | null;
|
||||
coverPhoto: string | null;
|
||||
allowSmtpEmail: boolean;
|
||||
allowMailtoLink: boolean;
|
||||
collectUserInfo: boolean;
|
||||
showEmailCount: boolean;
|
||||
showCallCount: boolean;
|
||||
allowEmailEditing: boolean;
|
||||
allowCustomRecipients: boolean;
|
||||
showResponseWall: boolean;
|
||||
highlightCampaign: boolean;
|
||||
targetGovernmentLevels: import(".prisma/client").$Enums.GovernmentLevel[];
|
||||
createdByUserEmail: string | null;
|
||||
createdByUserName: string | null;
|
||||
createdByUserId: string | null;
|
||||
}>;
|
||||
create(data: CreateCampaignInput, user: AuthUser): Promise<{
|
||||
status: import(".prisma/client").$Enums.CampaignStatus;
|
||||
id: string;
|
||||
createdAt: Date;
|
||||
updatedAt: Date;
|
||||
_count: {
|
||||
responses: number;
|
||||
emails: number;
|
||||
};
|
||||
title: string;
|
||||
description: string | null;
|
||||
slug: string;
|
||||
emailSubject: string;
|
||||
emailBody: string;
|
||||
callToAction: string | null;
|
||||
coverPhoto: string | null;
|
||||
allowSmtpEmail: boolean;
|
||||
allowMailtoLink: boolean;
|
||||
collectUserInfo: boolean;
|
||||
showEmailCount: boolean;
|
||||
showCallCount: boolean;
|
||||
allowEmailEditing: boolean;
|
||||
allowCustomRecipients: boolean;
|
||||
showResponseWall: boolean;
|
||||
highlightCampaign: boolean;
|
||||
targetGovernmentLevels: import(".prisma/client").$Enums.GovernmentLevel[];
|
||||
createdByUserEmail: string | null;
|
||||
createdByUserName: string | null;
|
||||
createdByUserId: string | null;
|
||||
}>;
|
||||
update(id: string, data: UpdateCampaignInput): Promise<{
|
||||
status: import(".prisma/client").$Enums.CampaignStatus;
|
||||
id: string;
|
||||
createdAt: Date;
|
||||
updatedAt: Date;
|
||||
_count: {
|
||||
responses: number;
|
||||
emails: number;
|
||||
};
|
||||
title: string;
|
||||
description: string | null;
|
||||
slug: string;
|
||||
emailSubject: string;
|
||||
emailBody: string;
|
||||
callToAction: string | null;
|
||||
coverPhoto: string | null;
|
||||
allowSmtpEmail: boolean;
|
||||
allowMailtoLink: boolean;
|
||||
collectUserInfo: boolean;
|
||||
showEmailCount: boolean;
|
||||
showCallCount: boolean;
|
||||
allowEmailEditing: boolean;
|
||||
allowCustomRecipients: boolean;
|
||||
showResponseWall: boolean;
|
||||
highlightCampaign: boolean;
|
||||
targetGovernmentLevels: import(".prisma/client").$Enums.GovernmentLevel[];
|
||||
createdByUserEmail: string | null;
|
||||
createdByUserName: string | null;
|
||||
createdByUserId: string | null;
|
||||
}>;
|
||||
findActiveCampaigns(): Promise<{
|
||||
status: import(".prisma/client").$Enums.CampaignStatus;
|
||||
id: string;
|
||||
createdAt: Date;
|
||||
updatedAt: Date;
|
||||
_count: {
|
||||
responses: number;
|
||||
emails: number;
|
||||
};
|
||||
title: string;
|
||||
description: string | null;
|
||||
slug: string;
|
||||
emailSubject: string;
|
||||
emailBody: string;
|
||||
callToAction: string | null;
|
||||
coverPhoto: string | null;
|
||||
allowSmtpEmail: boolean;
|
||||
allowMailtoLink: boolean;
|
||||
collectUserInfo: boolean;
|
||||
showEmailCount: boolean;
|
||||
showCallCount: boolean;
|
||||
allowEmailEditing: boolean;
|
||||
allowCustomRecipients: boolean;
|
||||
showResponseWall: boolean;
|
||||
highlightCampaign: boolean;
|
||||
targetGovernmentLevels: import(".prisma/client").$Enums.GovernmentLevel[];
|
||||
createdByUserEmail: string | null;
|
||||
createdByUserName: string | null;
|
||||
createdByUserId: string | null;
|
||||
}[]>;
|
||||
findBySlugPublic(slug: string): Promise<{
|
||||
status: import(".prisma/client").$Enums.CampaignStatus;
|
||||
id: string;
|
||||
createdAt: Date;
|
||||
updatedAt: Date;
|
||||
_count: {
|
||||
responses: number;
|
||||
emails: number;
|
||||
};
|
||||
title: string;
|
||||
description: string | null;
|
||||
slug: string;
|
||||
emailSubject: string;
|
||||
emailBody: string;
|
||||
callToAction: string | null;
|
||||
coverPhoto: string | null;
|
||||
allowSmtpEmail: boolean;
|
||||
allowMailtoLink: boolean;
|
||||
collectUserInfo: boolean;
|
||||
showEmailCount: boolean;
|
||||
showCallCount: boolean;
|
||||
allowEmailEditing: boolean;
|
||||
allowCustomRecipients: boolean;
|
||||
showResponseWall: boolean;
|
||||
highlightCampaign: boolean;
|
||||
targetGovernmentLevels: import(".prisma/client").$Enums.GovernmentLevel[];
|
||||
createdByUserEmail: string | null;
|
||||
createdByUserName: string | null;
|
||||
createdByUserId: string | null;
|
||||
}>;
|
||||
delete(id: string): Promise<void>;
|
||||
};
|
||||
export {};
|
||||
//# sourceMappingURL=campaigns.service.d.ts.map
|
||||
1
api/dist/modules/influence/campaigns/campaigns.service.d.ts.map
vendored
Normal file
1
api/dist/modules/influence/campaigns/campaigns.service.d.ts.map
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"campaigns.service.d.ts","sourceRoot":"","sources":["../../../../src/modules/influence/campaigns/campaigns.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAGlD,OAAO,KAAK,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AA8DxG,UAAU,QAAQ;IAChB,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,QAAQ,CAAC;CAChB;AAED,eAAO,MAAM,gBAAgB;qBACJ,kBAAkB,SAAS,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA2CvC,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;qBAaF,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAaV,mBAAmB,QAAQ,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;eAgCrC,MAAM,QAAQ,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;2BA0CrB,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;eAiBlB,MAAM;CAQxB,CAAC"}
|
||||
202
api/dist/modules/influence/campaigns/campaigns.service.js
vendored
Normal file
202
api/dist/modules/influence/campaigns/campaigns.service.js
vendored
Normal file
@@ -0,0 +1,202 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.campaignsService = void 0;
|
||||
const client_1 = require("@prisma/client");
|
||||
const database_1 = require("../../../config/database");
|
||||
const error_handler_1 = require("../../../middleware/error-handler");
|
||||
const campaignSelect = {
|
||||
id: true,
|
||||
slug: true,
|
||||
title: true,
|
||||
description: true,
|
||||
emailSubject: true,
|
||||
emailBody: true,
|
||||
callToAction: true,
|
||||
coverPhoto: true,
|
||||
status: true,
|
||||
allowSmtpEmail: true,
|
||||
allowMailtoLink: true,
|
||||
collectUserInfo: true,
|
||||
showEmailCount: true,
|
||||
showCallCount: true,
|
||||
allowEmailEditing: true,
|
||||
allowCustomRecipients: true,
|
||||
showResponseWall: true,
|
||||
highlightCampaign: true,
|
||||
targetGovernmentLevels: true,
|
||||
createdByUserId: true,
|
||||
createdByUserEmail: true,
|
||||
createdByUserName: true,
|
||||
createdAt: true,
|
||||
updatedAt: true,
|
||||
_count: {
|
||||
select: {
|
||||
emails: true,
|
||||
responses: true,
|
||||
},
|
||||
},
|
||||
};
|
||||
function generateSlug(title) {
|
||||
return title
|
||||
.toLowerCase()
|
||||
.replace(/[^a-z0-9]+/g, '-')
|
||||
.replace(/^-+|-+$/g, '')
|
||||
.slice(0, 80);
|
||||
}
|
||||
async function resolveSlugCollision(slug, excludeId) {
|
||||
let candidate = slug;
|
||||
let suffix = 2;
|
||||
while (true) {
|
||||
const existing = await database_1.prisma.campaign.findUnique({
|
||||
where: { slug: candidate },
|
||||
select: { id: true },
|
||||
});
|
||||
if (!existing || (excludeId && existing.id === excludeId)) {
|
||||
return candidate;
|
||||
}
|
||||
candidate = `${slug}-${suffix}`;
|
||||
suffix++;
|
||||
}
|
||||
}
|
||||
exports.campaignsService = {
|
||||
async findAll(filters, user) {
|
||||
const { page, limit, search, status } = filters;
|
||||
const skip = (page - 1) * limit;
|
||||
const where = {};
|
||||
if (search) {
|
||||
where.OR = [
|
||||
{ title: { contains: search, mode: 'insensitive' } },
|
||||
{ description: { contains: search, mode: 'insensitive' } },
|
||||
];
|
||||
}
|
||||
if (status)
|
||||
where.status = status;
|
||||
// Non-admin users only see their own campaigns
|
||||
const adminRoles = [client_1.UserRole.SUPER_ADMIN, client_1.UserRole.INFLUENCE_ADMIN, client_1.UserRole.MAP_ADMIN];
|
||||
if (user && !adminRoles.includes(user.role)) {
|
||||
where.createdByUserId = user.id;
|
||||
}
|
||||
const [campaigns, total] = await Promise.all([
|
||||
database_1.prisma.campaign.findMany({
|
||||
where,
|
||||
select: campaignSelect,
|
||||
skip,
|
||||
take: limit,
|
||||
orderBy: { createdAt: 'desc' },
|
||||
}),
|
||||
database_1.prisma.campaign.count({ where }),
|
||||
]);
|
||||
return {
|
||||
campaigns,
|
||||
pagination: {
|
||||
page,
|
||||
limit,
|
||||
total,
|
||||
totalPages: Math.ceil(total / limit),
|
||||
},
|
||||
};
|
||||
},
|
||||
async findById(id) {
|
||||
const campaign = await database_1.prisma.campaign.findUnique({
|
||||
where: { id },
|
||||
select: campaignSelect,
|
||||
});
|
||||
if (!campaign) {
|
||||
throw new error_handler_1.AppError(404, 'Campaign not found', 'CAMPAIGN_NOT_FOUND');
|
||||
}
|
||||
return campaign;
|
||||
},
|
||||
async findBySlug(slug) {
|
||||
const campaign = await database_1.prisma.campaign.findUnique({
|
||||
where: { slug },
|
||||
select: campaignSelect,
|
||||
});
|
||||
if (!campaign) {
|
||||
throw new error_handler_1.AppError(404, 'Campaign not found', 'CAMPAIGN_NOT_FOUND');
|
||||
}
|
||||
return campaign;
|
||||
},
|
||||
async create(data, user) {
|
||||
const baseSlug = generateSlug(data.title);
|
||||
const slug = await resolveSlugCollision(baseSlug);
|
||||
// Look up user name from DB
|
||||
const dbUser = await database_1.prisma.user.findUnique({
|
||||
where: { id: user.id },
|
||||
select: { name: true },
|
||||
});
|
||||
// If highlighting this campaign, unset any other highlighted campaign
|
||||
if (data.highlightCampaign) {
|
||||
await database_1.prisma.campaign.updateMany({
|
||||
where: { highlightCampaign: true },
|
||||
data: { highlightCampaign: false },
|
||||
});
|
||||
}
|
||||
const campaign = await database_1.prisma.campaign.create({
|
||||
data: {
|
||||
...data,
|
||||
slug,
|
||||
createdByUserId: user.id,
|
||||
createdByUserEmail: user.email,
|
||||
createdByUserName: dbUser?.name ?? null,
|
||||
},
|
||||
select: campaignSelect,
|
||||
});
|
||||
return campaign;
|
||||
},
|
||||
async update(id, data) {
|
||||
const existing = await database_1.prisma.campaign.findUnique({ where: { id } });
|
||||
if (!existing) {
|
||||
throw new error_handler_1.AppError(404, 'Campaign not found', 'CAMPAIGN_NOT_FOUND');
|
||||
}
|
||||
const updateData = { ...data };
|
||||
// Regenerate slug if title changes
|
||||
if (data.title && data.title !== existing.title) {
|
||||
const baseSlug = generateSlug(data.title);
|
||||
updateData.slug = await resolveSlugCollision(baseSlug, id);
|
||||
}
|
||||
// If highlighting this campaign, unset any other highlighted campaign
|
||||
if (data.highlightCampaign) {
|
||||
await database_1.prisma.campaign.updateMany({
|
||||
where: { highlightCampaign: true, id: { not: id } },
|
||||
data: { highlightCampaign: false },
|
||||
});
|
||||
}
|
||||
const campaign = await database_1.prisma.campaign.update({
|
||||
where: { id },
|
||||
data: updateData,
|
||||
select: campaignSelect,
|
||||
});
|
||||
return campaign;
|
||||
},
|
||||
async findActiveCampaigns() {
|
||||
return database_1.prisma.campaign.findMany({
|
||||
where: { status: 'ACTIVE' },
|
||||
select: campaignSelect,
|
||||
orderBy: [
|
||||
{ highlightCampaign: 'desc' },
|
||||
{ createdAt: 'desc' },
|
||||
],
|
||||
});
|
||||
},
|
||||
async findBySlugPublic(slug) {
|
||||
const campaign = await database_1.prisma.campaign.findUnique({
|
||||
where: { slug },
|
||||
select: campaignSelect,
|
||||
});
|
||||
if (!campaign) {
|
||||
throw new error_handler_1.AppError(404, 'Campaign not found', 'CAMPAIGN_NOT_FOUND');
|
||||
}
|
||||
if (campaign.status !== 'ACTIVE') {
|
||||
throw new error_handler_1.AppError(404, 'Campaign not found', 'CAMPAIGN_NOT_FOUND');
|
||||
}
|
||||
return campaign;
|
||||
},
|
||||
async delete(id) {
|
||||
const existing = await database_1.prisma.campaign.findUnique({ where: { id } });
|
||||
if (!existing) {
|
||||
throw new error_handler_1.AppError(404, 'Campaign not found', 'CAMPAIGN_NOT_FOUND');
|
||||
}
|
||||
await database_1.prisma.campaign.delete({ where: { id } });
|
||||
},
|
||||
};
|
||||
//# sourceMappingURL=campaigns.service.js.map
|
||||
1
api/dist/modules/influence/campaigns/campaigns.service.js.map
vendored
Normal file
1
api/dist/modules/influence/campaigns/campaigns.service.js.map
vendored
Normal file
File diff suppressed because one or more lines are too long
3
api/dist/modules/influence/email-queue/email-queue.routes.d.ts
vendored
Normal file
3
api/dist/modules/influence/email-queue/email-queue.routes.d.ts
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
declare const router: import("express-serve-static-core").Router;
|
||||
export { router as emailQueueRouter };
|
||||
//# sourceMappingURL=email-queue.routes.d.ts.map
|
||||
1
api/dist/modules/influence/email-queue/email-queue.routes.d.ts.map
vendored
Normal file
1
api/dist/modules/influence/email-queue/email-queue.routes.d.ts.map
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"email-queue.routes.d.ts","sourceRoot":"","sources":["../../../../src/modules/influence/email-queue/email-queue.routes.ts"],"names":[],"mappings":"AAQA,QAAA,MAAM,MAAM,4CAAW,CAAC;AAwDxB,OAAO,EAAE,MAAM,IAAI,gBAAgB,EAAE,CAAC"}
|
||||
54
api/dist/modules/influence/email-queue/email-queue.routes.js
vendored
Normal file
54
api/dist/modules/influence/email-queue/email-queue.routes.js
vendored
Normal file
@@ -0,0 +1,54 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.emailQueueRouter = void 0;
|
||||
const express_1 = require("express");
|
||||
const client_1 = require("@prisma/client");
|
||||
const auth_middleware_1 = require("../../../middleware/auth.middleware");
|
||||
const rbac_middleware_1 = require("../../../middleware/rbac.middleware");
|
||||
const email_queue_service_1 = require("../../../services/email-queue.service");
|
||||
const ADMIN_ROLES = [client_1.UserRole.SUPER_ADMIN, client_1.UserRole.INFLUENCE_ADMIN, client_1.UserRole.MAP_ADMIN];
|
||||
const router = (0, express_1.Router)();
|
||||
exports.emailQueueRouter = router;
|
||||
router.use(auth_middleware_1.authenticate);
|
||||
router.use((0, rbac_middleware_1.requireRole)(...ADMIN_ROLES));
|
||||
// GET /api/email-queue/stats
|
||||
router.get('/stats', async (_req, res, next) => {
|
||||
try {
|
||||
const stats = await email_queue_service_1.emailQueueService.getStats();
|
||||
res.json(stats);
|
||||
}
|
||||
catch (err) {
|
||||
next(err);
|
||||
}
|
||||
});
|
||||
// POST /api/email-queue/pause
|
||||
router.post('/pause', async (_req, res, next) => {
|
||||
try {
|
||||
await email_queue_service_1.emailQueueService.pause();
|
||||
res.json({ message: 'Queue paused' });
|
||||
}
|
||||
catch (err) {
|
||||
next(err);
|
||||
}
|
||||
});
|
||||
// POST /api/email-queue/resume
|
||||
router.post('/resume', async (_req, res, next) => {
|
||||
try {
|
||||
await email_queue_service_1.emailQueueService.resume();
|
||||
res.json({ message: 'Queue resumed' });
|
||||
}
|
||||
catch (err) {
|
||||
next(err);
|
||||
}
|
||||
});
|
||||
// POST /api/email-queue/clean
|
||||
router.post('/clean', async (_req, res, next) => {
|
||||
try {
|
||||
const cleaned = await email_queue_service_1.emailQueueService.clean();
|
||||
res.json({ message: `Cleaned ${cleaned} completed jobs`, cleaned });
|
||||
}
|
||||
catch (err) {
|
||||
next(err);
|
||||
}
|
||||
});
|
||||
//# sourceMappingURL=email-queue.routes.js.map
|
||||
1
api/dist/modules/influence/email-queue/email-queue.routes.js.map
vendored
Normal file
1
api/dist/modules/influence/email-queue/email-queue.routes.js.map
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"email-queue.routes.js","sourceRoot":"","sources":["../../../../src/modules/influence/email-queue/email-queue.routes.ts"],"names":[],"mappings":";;;AAAA,qCAAkE;AAClE,2CAA0C;AAC1C,yEAAmE;AACnE,yEAAkE;AAClE,+EAA0E;AAE1E,MAAM,WAAW,GAAe,CAAC,iBAAQ,CAAC,WAAW,EAAE,iBAAQ,CAAC,eAAe,EAAE,iBAAQ,CAAC,SAAS,CAAC,CAAC;AAErG,MAAM,MAAM,GAAG,IAAA,gBAAM,GAAE,CAAC;AAwDL,kCAAgB;AAvDnC,MAAM,CAAC,GAAG,CAAC,8BAAY,CAAC,CAAC;AACzB,MAAM,CAAC,GAAG,CAAC,IAAA,6BAAW,EAAC,GAAG,WAAW,CAAC,CAAC,CAAC;AAExC,6BAA6B;AAC7B,MAAM,CAAC,GAAG,CACR,QAAQ,EACR,KAAK,EAAE,IAAa,EAAE,GAAa,EAAE,IAAkB,EAAE,EAAE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AC,CAAC;IACtE,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,IAAI,CAAC,GAAG,CAAC,CAAC;IACZ,CAAC;AACH,CAAC,CACF,CAAC"}
|
||||
22
api/dist/modules/influence/postal-codes/postal-codes.schemas.d.ts
vendored
Normal file
22
api/dist/modules/influence/postal-codes/postal-codes.schemas.d.ts
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
import { z } from 'zod';
|
||||
/** Strip spaces, uppercase */
|
||||
export declare function normalizePostalCode(raw: string): string;
|
||||
/** Validate Canadian postal code (all provinces) */
|
||||
export declare function isValidCanadianPostalCode(code: string): boolean;
|
||||
export declare const postalCodeParamSchema: z.ZodObject<{
|
||||
postalCode: z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>;
|
||||
}, "strip", z.ZodTypeAny, {
|
||||
postalCode: string;
|
||||
}, {
|
||||
postalCode: string;
|
||||
}>;
|
||||
export declare const postalCodeQuerySchema: z.ZodObject<{
|
||||
refresh: z.ZodDefault<z.ZodOptional<z.ZodEnum<["true", "false"]>>>;
|
||||
}, "strip", z.ZodTypeAny, {
|
||||
refresh: "true" | "false";
|
||||
}, {
|
||||
refresh?: "true" | "false" | undefined;
|
||||
}>;
|
||||
export type PostalCodeParam = z.infer<typeof postalCodeParamSchema>;
|
||||
export type PostalCodeQuery = z.infer<typeof postalCodeQuerySchema>;
|
||||
//# sourceMappingURL=postal-codes.schemas.d.ts.map
|
||||
1
api/dist/modules/influence/postal-codes/postal-codes.schemas.d.ts.map
vendored
Normal file
1
api/dist/modules/influence/postal-codes/postal-codes.schemas.d.ts.map
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"postal-codes.schemas.d.ts","sourceRoot":"","sources":["../../../../src/modules/influence/postal-codes/postal-codes.schemas.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,8BAA8B;AAC9B,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAEvD;AAED,oDAAoD;AACpD,wBAAgB,yBAAyB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAE/D;AAED,eAAO,MAAM,qBAAqB;;;;;;EAKhC,CAAC;AAEH,eAAO,MAAM,qBAAqB;;;;;;EAEhC,CAAC;AAEH,MAAM,MAAM,eAAe,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,qBAAqB,CAAC,CAAC;AACpE,MAAM,MAAM,eAAe,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,qBAAqB,CAAC,CAAC"}
|
||||
24
api/dist/modules/influence/postal-codes/postal-codes.schemas.js
vendored
Normal file
24
api/dist/modules/influence/postal-codes/postal-codes.schemas.js
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.postalCodeQuerySchema = exports.postalCodeParamSchema = void 0;
|
||||
exports.normalizePostalCode = normalizePostalCode;
|
||||
exports.isValidCanadianPostalCode = isValidCanadianPostalCode;
|
||||
const zod_1 = require("zod");
|
||||
/** Strip spaces, uppercase */
|
||||
function normalizePostalCode(raw) {
|
||||
return raw.replace(/\s/g, '').toUpperCase();
|
||||
}
|
||||
/** Validate Canadian postal code (all provinces) */
|
||||
function isValidCanadianPostalCode(code) {
|
||||
return /^[ABCEGHJKLMNPRSTVXY]\d[ABCEGHJKLMNPRSTVWXYZ]\d[ABCEGHJKLMNPRSTVWXYZ]\d$/.test(code);
|
||||
}
|
||||
exports.postalCodeParamSchema = zod_1.z.object({
|
||||
postalCode: zod_1.z
|
||||
.string()
|
||||
.transform(normalizePostalCode)
|
||||
.refine(isValidCanadianPostalCode, { message: 'Invalid Canadian postal code' }),
|
||||
});
|
||||
exports.postalCodeQuerySchema = zod_1.z.object({
|
||||
refresh: zod_1.z.enum(['true', 'false']).optional().default('false'),
|
||||
});
|
||||
//# sourceMappingURL=postal-codes.schemas.js.map
|
||||
1
api/dist/modules/influence/postal-codes/postal-codes.schemas.js.map
vendored
Normal file
1
api/dist/modules/influence/postal-codes/postal-codes.schemas.js.map
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"postal-codes.schemas.js","sourceRoot":"","sources":["../../../../src/modules/influence/postal-codes/postal-codes.schemas.ts"],"names":[],"mappings":";;;AAGA,kDAEC;AAGD,8DAEC;AAVD,6BAAwB;AAExB,8BAA8B;AAC9B,SAAgB,mBAAmB,CAAC,GAAW;IAC7C,OAAO,GAAG,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,WAAW,EAAE,CAAC;AAC9C,CAAC;AAED,oDAAoD;AACpD,SAAgB,yBAAyB,CAAC,IAAY;IACpD,OAAO,0EAA0E,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC/F,CAAC;AAEY,QAAA,qBAAqB,GAAG,OAAC,CAAC,MAAM,CAAC;IAC5C,UAAU,EAAE,OAAC;SACV,MAAM,EAAE;SACR,SAAS,CAAC,mBAAmB,CAAC;SAC9B,MAAM,CAAC,yBAAyB,EAAE,EAAE,OAAO,EAAE,8BAA8B,EAAE,CAAC;CAClF,CAAC,CAAC;AAEU,QAAA,qBAAqB,GAAG,OAAC,CAAC,MAAM,CAAC;IAC5C,OAAO,EAAE,OAAC,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC;CAC/D,CAAC,CAAC"}
|
||||
60
api/dist/modules/influence/postal-codes/postal-codes.service.d.ts
vendored
Normal file
60
api/dist/modules/influence/postal-codes/postal-codes.service.d.ts
vendored
Normal file
@@ -0,0 +1,60 @@
|
||||
import { Prisma } from '@prisma/client';
|
||||
interface UpsertData {
|
||||
postalCode: string;
|
||||
city?: string | null;
|
||||
province?: string | null;
|
||||
centroidLat?: number | null;
|
||||
centroidLng?: number | null;
|
||||
}
|
||||
export declare const postalCodesService: {
|
||||
upsert(data: UpsertData): Promise<{
|
||||
id: string;
|
||||
city: string | null;
|
||||
postalCode: string;
|
||||
province: string | null;
|
||||
centroidLat: Prisma.Decimal | null;
|
||||
centroidLng: Prisma.Decimal | null;
|
||||
lastUpdated: Date;
|
||||
}>;
|
||||
findByPostalCode(code: string): Promise<{
|
||||
id: string;
|
||||
city: string | null;
|
||||
postalCode: string;
|
||||
province: string | null;
|
||||
centroidLat: Prisma.Decimal | null;
|
||||
centroidLng: Prisma.Decimal | null;
|
||||
lastUpdated: Date;
|
||||
} | null>;
|
||||
findAll(filters: {
|
||||
page: number;
|
||||
limit: number;
|
||||
search?: string;
|
||||
}): Promise<{
|
||||
postalCodes: {
|
||||
id: string;
|
||||
city: string | null;
|
||||
postalCode: string;
|
||||
province: string | null;
|
||||
centroidLat: Prisma.Decimal | null;
|
||||
centroidLng: Prisma.Decimal | null;
|
||||
lastUpdated: Date;
|
||||
}[];
|
||||
pagination: {
|
||||
page: number;
|
||||
limit: number;
|
||||
total: number;
|
||||
totalPages: number;
|
||||
};
|
||||
}>;
|
||||
delete(code: string): Promise<{
|
||||
id: string;
|
||||
city: string | null;
|
||||
postalCode: string;
|
||||
province: string | null;
|
||||
centroidLat: Prisma.Decimal | null;
|
||||
centroidLng: Prisma.Decimal | null;
|
||||
lastUpdated: Date;
|
||||
}>;
|
||||
};
|
||||
export {};
|
||||
//# sourceMappingURL=postal-codes.service.d.ts.map
|
||||
1
api/dist/modules/influence/postal-codes/postal-codes.service.d.ts.map
vendored
Normal file
1
api/dist/modules/influence/postal-codes/postal-codes.service.d.ts.map
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"postal-codes.service.d.ts","sourceRoot":"","sources":["../../../../src/modules/influence/postal-codes/postal-codes.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAGxC,UAAU,UAAU;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAC7B;AAED,eAAO,MAAM,kBAAkB;iBACV,UAAU;;;;;;;;;2BAoBA,MAAM;;;;;;;;;qBAMZ;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE;;;;;;;;;;;;;;;;;iBA6BpD,MAAM;;;;;;;;;CAK1B,CAAC"}
|
||||
61
api/dist/modules/influence/postal-codes/postal-codes.service.js
vendored
Normal file
61
api/dist/modules/influence/postal-codes/postal-codes.service.js
vendored
Normal file
@@ -0,0 +1,61 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.postalCodesService = void 0;
|
||||
const database_1 = require("../../../config/database");
|
||||
exports.postalCodesService = {
|
||||
async upsert(data) {
|
||||
return database_1.prisma.postalCodeCache.upsert({
|
||||
where: { postalCode: data.postalCode },
|
||||
update: {
|
||||
city: data.city ?? undefined,
|
||||
province: data.province ?? undefined,
|
||||
centroidLat: data.centroidLat ?? undefined,
|
||||
centroidLng: data.centroidLng ?? undefined,
|
||||
lastUpdated: new Date(),
|
||||
},
|
||||
create: {
|
||||
postalCode: data.postalCode,
|
||||
city: data.city ?? null,
|
||||
province: data.province ?? null,
|
||||
centroidLat: data.centroidLat ?? null,
|
||||
centroidLng: data.centroidLng ?? null,
|
||||
},
|
||||
});
|
||||
},
|
||||
async findByPostalCode(code) {
|
||||
return database_1.prisma.postalCodeCache.findUnique({
|
||||
where: { postalCode: code },
|
||||
});
|
||||
},
|
||||
async findAll(filters) {
|
||||
const { page, limit, search } = filters;
|
||||
const skip = (page - 1) * limit;
|
||||
const where = {};
|
||||
if (search) {
|
||||
where.OR = [
|
||||
{ postalCode: { contains: search, mode: 'insensitive' } },
|
||||
{ city: { contains: search, mode: 'insensitive' } },
|
||||
{ province: { contains: search, mode: 'insensitive' } },
|
||||
];
|
||||
}
|
||||
const [items, total] = await Promise.all([
|
||||
database_1.prisma.postalCodeCache.findMany({
|
||||
where,
|
||||
skip,
|
||||
take: limit,
|
||||
orderBy: { lastUpdated: 'desc' },
|
||||
}),
|
||||
database_1.prisma.postalCodeCache.count({ where }),
|
||||
]);
|
||||
return {
|
||||
postalCodes: items,
|
||||
pagination: { page, limit, total, totalPages: Math.ceil(total / limit) },
|
||||
};
|
||||
},
|
||||
async delete(code) {
|
||||
return database_1.prisma.postalCodeCache.delete({
|
||||
where: { postalCode: code },
|
||||
});
|
||||
},
|
||||
};
|
||||
//# sourceMappingURL=postal-codes.service.js.map
|
||||
1
api/dist/modules/influence/postal-codes/postal-codes.service.js.map
vendored
Normal file
1
api/dist/modules/influence/postal-codes/postal-codes.service.js.map
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"postal-codes.service.js","sourceRoot":"","sources":["../../../../src/modules/influence/postal-codes/postal-codes.service.ts"],"names":[],"mappings":";;;AACA,uDAAkD;AAUrC,QAAA,kBAAkB,GAAG;IAChC,KAAK,CAAC,MAAM,CAAC,IAAgB;QAC3B,OAAO,iBAAM,CAAC,eAAe,CAAC,MAAM,CAAC;YACnC,KAAK,EAAE,EAAE,UAAU,EAAE,IAAI,CAAC,UAAU,EAAE;YACtC,MAAM,EAAE;gBACN,IAAI,EAAE,IAAI,CAAC,IAAI,IAAI,SAAS;gBAC5B,QAAQ,EAAE,IAAI,CAAC,QAAQ,IAAI,SAAS;gBACpC,WAAW,EAAE,IAAI,CAAC,WAAW,IAAI,SAAS;gBAC1C,WAAW,EAAE,IAAI,CAAC,WAAW,IAAI,SAAS;gBAC1C,WAAW,EAAE,IAAI,IAAI,EAAE;aACxB;YACD,MAAM,EAAE;gBACN,UAAU,EAAE,IAAI,CAAC,UAAU;gBAC3B,IAAI,EAAE,IAAI,CAAC,IA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,CAAC,CAAC;QAEH,OAAO;YACL,WAAW,EAAE,KAAK;YAClB,UAAU,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,UAAU,EAAE,IAAI,CAAC,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC,EAAE;SACzE,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,IAAY;QACvB,OAAO,iBAAM,CAAC,eAAe,CAAC,MAAM,CAAC;YACnC,KAAK,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE;SAC5B,CAAC,CAAC;IACL,CAAC;CACF,CAAC"}
|
||||
39
api/dist/modules/influence/representatives/represent-api.client.d.ts
vendored
Normal file
39
api/dist/modules/influence/representatives/represent-api.client.d.ts
vendored
Normal file
@@ -0,0 +1,39 @@
|
||||
export interface RepresentOffice {
|
||||
type?: string;
|
||||
tel?: string;
|
||||
fax?: string;
|
||||
postal?: string;
|
||||
}
|
||||
export interface RepresentRepresentative {
|
||||
name: string;
|
||||
email: string | null;
|
||||
elected_office: string;
|
||||
district_name: string;
|
||||
party_name: string | null;
|
||||
representative_set_name: string;
|
||||
url: string;
|
||||
photo_url: string | null;
|
||||
offices: RepresentOffice[];
|
||||
}
|
||||
export interface RepresentPostalCodeResponse {
|
||||
city: string | null;
|
||||
province: string | null;
|
||||
centroid: {
|
||||
type: string;
|
||||
coordinates: [number, number];
|
||||
} | null;
|
||||
representatives_centroid: RepresentRepresentative[];
|
||||
representatives_concordance: RepresentRepresentative[];
|
||||
}
|
||||
declare class RepresentApiClient {
|
||||
private baseUrl;
|
||||
constructor();
|
||||
getByPostalCode(code: string): Promise<RepresentPostalCodeResponse>;
|
||||
testConnection(): Promise<{
|
||||
ok: boolean;
|
||||
message: string;
|
||||
}>;
|
||||
}
|
||||
export declare const representApiClient: RepresentApiClient;
|
||||
export {};
|
||||
//# sourceMappingURL=represent-api.client.d.ts.map
|
||||
1
api/dist/modules/influence/representatives/represent-api.client.d.ts.map
vendored
Normal file
1
api/dist/modules/influence/representatives/represent-api.client.d.ts.map
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"represent-api.client.d.ts","sourceRoot":"","sources":["../../../../src/modules/influence/representatives/represent-api.client.ts"],"names":[],"mappings":"AAKA,MAAM,WAAW,eAAe;IAC9B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,uBAAuB;IACtC,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,cAAc,EAAE,MAAM,CAAC;IACvB,aAAa,EAAE,MAAM,CAAC;IACtB,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,uBAAuB,EAAE,MAAM,CAAC;IAChC,GAAG,EAAE,MAAM,CAAC;IACZ,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,OAAO,EAAE,eAAe,EAAE,CAAC;CAC5B;AAED,MAAM,WAAW,2BAA2B;IAC1C,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,QAAQ,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,WAAW,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;KAAE,GAAG,IAAI,CAAC;IACjE,wBAAwB,EAAE,uBAAuB,EAAE,CAAC;IACpD,2BAA2B,EAAE,uBAAuB,EAAE,CAAC;CACxD;AAuBD,cAAM,kBAAkB;IACtB,OAAO,CAAC,OAAO,CAAS;;IAMlB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,2BAA2B,CAAC;IA6BnE,cAAc,IAAI,OAAO,CAAC;QAAE,EAAE,EAAE,OAAO,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC;CAyBlE;AAED,eAAO,MAAM,kBAAkB,oBAA2B,CAAC"}
|
||||
77
api/dist/modules/influence/representatives/represent-api.client.js
vendored
Normal file
77
api/dist/modules/influence/representatives/represent-api.client.js
vendored
Normal file
@@ -0,0 +1,77 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.representApiClient = void 0;
|
||||
const env_1 = require("../../../config/env");
|
||||
const logger_1 = require("../../../utils/logger");
|
||||
// --- In-memory sliding window rate limiter (55/min, under 60/min API limit) ---
|
||||
const RATE_LIMIT = 55;
|
||||
const RATE_WINDOW_MS = 60_000;
|
||||
const requestTimestamps = [];
|
||||
function checkRateLimit() {
|
||||
const now = Date.now();
|
||||
// Remove timestamps outside the window
|
||||
while (requestTimestamps.length > 0 && requestTimestamps[0] < now - RATE_WINDOW_MS) {
|
||||
requestTimestamps.shift();
|
||||
}
|
||||
return requestTimestamps.length < RATE_LIMIT;
|
||||
}
|
||||
function recordRequest() {
|
||||
requestTimestamps.push(Date.now());
|
||||
}
|
||||
// --- API Client ---
|
||||
class RepresentApiClient {
|
||||
baseUrl;
|
||||
constructor() {
|
||||
this.baseUrl = env_1.env.REPRESENT_API_URL;
|
||||
}
|
||||
async getByPostalCode(code) {
|
||||
if (!checkRateLimit()) {
|
||||
throw new Error('Represent API rate limit reached. Please try again in a minute.');
|
||||
}
|
||||
const url = `${this.baseUrl}/postcodes/${code}/`;
|
||||
logger_1.logger.debug(`Represent API request: ${url}`);
|
||||
const controller = new AbortController();
|
||||
const timeout = setTimeout(() => controller.abort(), 10_000);
|
||||
try {
|
||||
recordRequest();
|
||||
const response = await fetch(url, {
|
||||
signal: controller.signal,
|
||||
headers: { Accept: 'application/json' },
|
||||
});
|
||||
if (!response.ok) {
|
||||
const text = await response.text().catch(() => '');
|
||||
throw new Error(`Represent API error ${response.status}: ${text}`);
|
||||
}
|
||||
return (await response.json());
|
||||
}
|
||||
finally {
|
||||
clearTimeout(timeout);
|
||||
}
|
||||
}
|
||||
async testConnection() {
|
||||
try {
|
||||
const url = `${this.baseUrl}/boundary-sets/?limit=1`;
|
||||
const controller = new AbortController();
|
||||
const timeout = setTimeout(() => controller.abort(), 10_000);
|
||||
try {
|
||||
const response = await fetch(url, {
|
||||
signal: controller.signal,
|
||||
headers: { Accept: 'application/json' },
|
||||
});
|
||||
if (!response.ok) {
|
||||
return { ok: false, message: `HTTP ${response.status}` };
|
||||
}
|
||||
return { ok: true, message: 'Represent API is reachable' };
|
||||
}
|
||||
finally {
|
||||
clearTimeout(timeout);
|
||||
}
|
||||
}
|
||||
catch (err) {
|
||||
const message = err instanceof Error ? err.message : 'Unknown error';
|
||||
return { ok: false, message };
|
||||
}
|
||||
}
|
||||
}
|
||||
exports.representApiClient = new RepresentApiClient();
|
||||
//# sourceMappingURL=represent-api.client.js.map
|
||||
1
api/dist/modules/influence/representatives/represent-api.client.js.map
vendored
Normal file
1
api/dist/modules/influence/representatives/represent-api.client.js.map
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"represent-api.client.js","sourceRoot":"","sources":["../../../../src/modules/influence/representatives/represent-api.client.ts"],"names":[],"mappings":";;;AAAA,6CAA0C;AAC1C,kDAA+C;AA+B/C,iFAAiF;AAEjF,MAAM,UAAU,GAAG,EAAE,CAAC;AACtB,MAAM,cAAc,GAAG,MAAM,CAAC;AAC9B,MAAM,iBAAiB,GAAa,EAAE,CAAC;AAEvC,SAAS,cAAc;IACrB,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;IACvB,uCAAuC;IACvC,OAAO,iBAAiB,CAAC,MAAM,GAAG,CAAC,IAAI,iBAAiB,CAAC,CAAC,CAAC,GAAG,GAAG,GAAG,cAAc,EAAE,CAAC;QACnF,iBAAiB,CAAC,KAAK,EAAE,CAAC;IAC5B,CAAC;IACD,OAAO,iBAAiB,CAAC,MAAM,GAAG,UAAU,CAAC;AAC/C,CAAC;AAED,SAAS,aAAa;IACpB,iBAAiB,CAAC,IAAI,CAA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QAClB,IAAI,CAAC;YACH,MAAM,GAAG,GAAG,GAAG,IAAI,CAAC,OAAO,yBAAyB,CAAC;YACrD,MAAM,UAAU,GAAG,IAAI,eAAe,EAAE,CAAC;YACzC,MAAM,OAAO,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC,UAAU,CAAC,KAAK,EAAE,EAAE,MAAM,CAAC,CAAC;YAE7D,IAAI,CAAC;gBACH,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,EAAE;oBAChC,MAAM,EAAE,UAAU,CAAC,MAAM;oBACzB,OAAO,EAAE,EAAE,MAAM,EAAE,kBAAkB,EAAE;iBACxC,CAAC,CAAC;gBAEH,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;oBACjB,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE,QAAQ,QAAQ,CAAC,MAAM,EAAE,EAAE,CAAC;gBAC3D,CAAC;gBAED,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,4BAA4B,EAAE,CAAC;YAC7D,CAAC;oBAAS,CAAC;gBACT,YAAY,CAAC,OAAO,CAAC,CAAC;YACxB,CAAC;QACH,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,MAAM,OAAO,GAAG,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,eAAe,CAAC;YACrE,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC;QAChC,CAAC;IACH,CAAC;CACF;AAEY,QAAA,kBAAkB,GAAG,IAAI,kBAAkB,EAAE,CAAC"}
|
||||
3
api/dist/modules/influence/representatives/representatives.routes.d.ts
vendored
Normal file
3
api/dist/modules/influence/representatives/representatives.routes.d.ts
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
declare const router: import("express-serve-static-core").Router;
|
||||
export { router as representativesRouter };
|
||||
//# sourceMappingURL=representatives.routes.d.ts.map
|
||||
1
api/dist/modules/influence/representatives/representatives.routes.d.ts.map
vendored
Normal file
1
api/dist/modules/influence/representatives/representatives.routes.d.ts.map
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"representatives.routes.d.ts","sourceRoot":"","sources":["../../../../src/modules/influence/representatives/representatives.routes.ts"],"names":[],"mappings":"AAWA,QAAA,MAAM,MAAM,4CAAW,CAAC;AAiHxB,OAAO,EAAE,MAAM,IAAI,qBAAqB,EAAE,CAAC"}
|
||||
98
api/dist/modules/influence/representatives/representatives.routes.js
vendored
Normal file
98
api/dist/modules/influence/representatives/representatives.routes.js
vendored
Normal file
@@ -0,0 +1,98 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.representativesRouter = void 0;
|
||||
const express_1 = require("express");
|
||||
const client_1 = require("@prisma/client");
|
||||
const representatives_service_1 = require("./representatives.service");
|
||||
const representatives_schemas_1 = require("./representatives.schemas");
|
||||
const postal_codes_schemas_1 = require("../postal-codes/postal-codes.schemas");
|
||||
const validate_1 = require("../../../middleware/validate");
|
||||
const auth_middleware_1 = require("../../../middleware/auth.middleware");
|
||||
const rbac_middleware_1 = require("../../../middleware/rbac.middleware");
|
||||
const ADMIN_ROLES = [client_1.UserRole.SUPER_ADMIN, client_1.UserRole.INFLUENCE_ADMIN, client_1.UserRole.MAP_ADMIN];
|
||||
const router = (0, express_1.Router)();
|
||||
exports.representativesRouter = router;
|
||||
// =============================================
|
||||
// PUBLIC ROUTES (no auth required)
|
||||
// =============================================
|
||||
// GET /api/representatives/by-postal/:postalCode — cache-first lookup
|
||||
router.get('/by-postal/:postalCode', (0, validate_1.validate)(postal_codes_schemas_1.postalCodeParamSchema, 'params'), (0, validate_1.validate)(postal_codes_schemas_1.postalCodeQuerySchema, 'query'), async (req, res, next) => {
|
||||
try {
|
||||
const code = req.params.postalCode;
|
||||
const refresh = req.query.refresh === 'true';
|
||||
const result = await representatives_service_1.representativesService.lookupByPostalCode(code, refresh);
|
||||
res.json(result);
|
||||
}
|
||||
catch (err) {
|
||||
next(err);
|
||||
}
|
||||
});
|
||||
// GET /api/representatives/test-connection — Represent API health check
|
||||
router.get('/test-connection', async (_req, res, next) => {
|
||||
try {
|
||||
const result = await representatives_service_1.representativesService.testApiConnection();
|
||||
res.json(result);
|
||||
}
|
||||
catch (err) {
|
||||
next(err);
|
||||
}
|
||||
});
|
||||
// =============================================
|
||||
// ADMIN ROUTES (auth + role required)
|
||||
// =============================================
|
||||
router.use(auth_middleware_1.authenticate);
|
||||
router.use((0, rbac_middleware_1.requireRole)(...ADMIN_ROLES));
|
||||
// GET /api/representatives/cache-stats — cache statistics
|
||||
router.get('/cache-stats', async (_req, res, next) => {
|
||||
try {
|
||||
const stats = await representatives_service_1.representativesService.getCacheStats();
|
||||
res.json(stats);
|
||||
}
|
||||
catch (err) {
|
||||
next(err);
|
||||
}
|
||||
});
|
||||
// GET /api/representatives — list all cached reps (paginated)
|
||||
router.get('/', (0, validate_1.validate)(representatives_schemas_1.listRepresentativesSchema, 'query'), async (req, res, next) => {
|
||||
try {
|
||||
const result = await representatives_service_1.representativesService.findAll(req.query);
|
||||
res.json(result);
|
||||
}
|
||||
catch (err) {
|
||||
next(err);
|
||||
}
|
||||
});
|
||||
// GET /api/representatives/:id — single cached rep
|
||||
router.get('/:id', async (req, res, next) => {
|
||||
try {
|
||||
const id = req.params.id;
|
||||
const rep = await representatives_service_1.representativesService.findById(id);
|
||||
res.json(rep);
|
||||
}
|
||||
catch (err) {
|
||||
next(err);
|
||||
}
|
||||
});
|
||||
// DELETE /api/representatives/by-postal/:postalCode — clear cache for postal code
|
||||
router.delete('/by-postal/:postalCode', (0, validate_1.validate)(postal_codes_schemas_1.postalCodeParamSchema, 'params'), async (req, res, next) => {
|
||||
try {
|
||||
const code = req.params.postalCode;
|
||||
const result = await representatives_service_1.representativesService.clearByPostalCode(code);
|
||||
res.json(result);
|
||||
}
|
||||
catch (err) {
|
||||
next(err);
|
||||
}
|
||||
});
|
||||
// DELETE /api/representatives/:id — delete single cached rep
|
||||
router.delete('/:id', async (req, res, next) => {
|
||||
try {
|
||||
const id = req.params.id;
|
||||
await representatives_service_1.representativesService.deleteById(id);
|
||||
res.status(204).send();
|
||||
}
|
||||
catch (err) {
|
||||
next(err);
|
||||
}
|
||||
});
|
||||
//# sourceMappingURL=representatives.routes.js.map
|
||||
1
api/dist/modules/influence/representatives/representatives.routes.js.map
vendored
Normal file
1
api/dist/modules/influence/representatives/representatives.routes.js.map
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"representatives.routes.js","sourceRoot":"","sources":["../../../../src/modules/influence/representatives/representatives.routes.ts"],"names":[],"mappings":";;;AAAA,qCAAkE;AAClE,2CAA0C;AAC1C,uEAAmE;AACnE,uEAAsE;AACtE,+EAAoG;AACpG,2DAAwD;AACxD,yEAAmE;AACnE,yEAAkE;AAElE,MAAM,WAAW,GAAe,CAAC,iBAAQ,CAAC,WAAW,EAAE,iBAAQ,CAAC,eAAe,EAAE,iBAAQ,CAAC,SAAS,CAAC,CAAC;AAErG,MAAM,MAAM,GAAG,IAAA,gBAAM,GAAE,CAAC;AAiHL,uCAAqB;AA/GxC,gDAAgD;AAChD,mCAAmC;AACnC,gDAAgD;AAEhD,sEAAsE;AACtE,MAAM,CAAC,GAAG,CACR,wBAAwB,EACxB,IAAA,mBAAQ,EAAC,4CAAqB,EAAE,QAAQ,CAAC,EACzC,IAAA,mBAAQ,EAAC,4CAAqB,EAAE,OAAO,CAAC,EACxC,KAAK,EAAE,GAAY,EAAE,GAAa,EAAE,IAAkB,EAAE,EAAE;IACxD,IAAI,CAAC;QACH,MAAM,IAAI,GAAG,GAAG,CAAC,MAAM,CAAC,UAAoB,CAAC;QAC7C,MAAM,OAAO,GAAG,GAAG,CAAC,KAAK,CAAC,OAAO,KAAK,MAAM,CAAC;QAC7C,MAAM,MAAM,GAAG,MAAM,gDAAsB,CAAC,kBAAkB,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;QA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EAAE,EAAE;IACxD,IAAI,CAAC;QACH,MAAM,EAAE,GAAG,GAAG,CAAC,MAAM,CAAC,EAAY,CAAC;QACnC,MAAM,gDAAsB,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC;QAC5C,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC;IACzB,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,IAAI,CAAC,GAAG,CAAC,CAAC;IACZ,CAAC;AACH,CAAC,CACF,CAAC"}
|
||||
19
api/dist/modules/influence/representatives/representatives.schemas.d.ts
vendored
Normal file
19
api/dist/modules/influence/representatives/representatives.schemas.d.ts
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
import { z } from 'zod';
|
||||
export declare const listRepresentativesSchema: z.ZodObject<{
|
||||
page: z.ZodDefault<z.ZodNumber>;
|
||||
limit: z.ZodDefault<z.ZodNumber>;
|
||||
search: z.ZodOptional<z.ZodString>;
|
||||
postalCode: z.ZodOptional<z.ZodString>;
|
||||
}, "strip", z.ZodTypeAny, {
|
||||
limit: number;
|
||||
page: number;
|
||||
search?: string | undefined;
|
||||
postalCode?: string | undefined;
|
||||
}, {
|
||||
search?: string | undefined;
|
||||
limit?: number | undefined;
|
||||
page?: number | undefined;
|
||||
postalCode?: string | undefined;
|
||||
}>;
|
||||
export type ListRepresentativesInput = z.infer<typeof listRepresentativesSchema>;
|
||||
//# sourceMappingURL=representatives.schemas.d.ts.map
|
||||
1
api/dist/modules/influence/representatives/representatives.schemas.d.ts.map
vendored
Normal file
1
api/dist/modules/influence/representatives/representatives.schemas.d.ts.map
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"representatives.schemas.d.ts","sourceRoot":"","sources":["../../../../src/modules/influence/representatives/representatives.schemas.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,eAAO,MAAM,yBAAyB;;;;;;;;;;;;;;;EAKpC,CAAC;AAEH,MAAM,MAAM,wBAAwB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,yBAAyB,CAAC,CAAC"}
|
||||
11
api/dist/modules/influence/representatives/representatives.schemas.js
vendored
Normal file
11
api/dist/modules/influence/representatives/representatives.schemas.js
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.listRepresentativesSchema = void 0;
|
||||
const zod_1 = require("zod");
|
||||
exports.listRepresentativesSchema = zod_1.z.object({
|
||||
page: zod_1.z.coerce.number().int().positive().default(1),
|
||||
limit: zod_1.z.coerce.number().int().positive().max(100).default(20),
|
||||
search: zod_1.z.string().optional(),
|
||||
postalCode: zod_1.z.string().optional(),
|
||||
});
|
||||
//# sourceMappingURL=representatives.schemas.js.map
|
||||
1
api/dist/modules/influence/representatives/representatives.schemas.js.map
vendored
Normal file
1
api/dist/modules/influence/representatives/representatives.schemas.js.map
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"representatives.schemas.js","sourceRoot":"","sources":["../../../../src/modules/influence/representatives/representatives.schemas.ts"],"names":[],"mappings":";;;AAAA,6BAAwB;AAEX,QAAA,yBAAyB,GAAG,OAAC,CAAC,MAAM,CAAC;IAChD,IAAI,EAAE,OAAC,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,QAAQ,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC;IACnD,KAAK,EAAE,OAAC,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,QAAQ,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,EAAE,CAAC;IAC9D,MAAM,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAC7B,UAAU,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;CAClC,CAAC,CAAC"}
|
||||
98
api/dist/modules/influence/representatives/representatives.service.d.ts
vendored
Normal file
98
api/dist/modules/influence/representatives/representatives.service.d.ts
vendored
Normal file
@@ -0,0 +1,98 @@
|
||||
import { Prisma } from '@prisma/client';
|
||||
import type { ListRepresentativesInput } from './representatives.schemas';
|
||||
export declare const representativesService: {
|
||||
lookupByPostalCode(code: string, forceRefresh?: boolean): Promise<{
|
||||
source: "cache";
|
||||
postalCode: string;
|
||||
location: {
|
||||
city: string | null;
|
||||
province: string | null;
|
||||
};
|
||||
representatives: {
|
||||
id: string;
|
||||
email: string | null;
|
||||
name: string | null;
|
||||
url: string | null;
|
||||
postalCode: string;
|
||||
districtName: string | null;
|
||||
electedOffice: string | null;
|
||||
partyName: string | null;
|
||||
representativeSetName: string | null;
|
||||
photoUrl: string | null;
|
||||
offices: Prisma.JsonValue | null;
|
||||
cachedAt: Date;
|
||||
}[];
|
||||
} | {
|
||||
source: "api";
|
||||
postalCode: string;
|
||||
location: {
|
||||
city: string | null;
|
||||
province: string | null;
|
||||
};
|
||||
representatives: {
|
||||
id: null;
|
||||
postalCode: string;
|
||||
name: string | null;
|
||||
email: string | null;
|
||||
districtName: string | null;
|
||||
electedOffice: string | null;
|
||||
partyName: string | null;
|
||||
representativeSetName: string | null;
|
||||
url: string | null;
|
||||
photoUrl: string | null;
|
||||
offices: import("./represent-api.client").RepresentOffice[];
|
||||
cachedAt: string;
|
||||
}[];
|
||||
}>;
|
||||
findAll(filters: ListRepresentativesInput): Promise<{
|
||||
representatives: {
|
||||
id: string;
|
||||
email: string | null;
|
||||
name: string | null;
|
||||
url: string | null;
|
||||
postalCode: string;
|
||||
districtName: string | null;
|
||||
electedOffice: string | null;
|
||||
partyName: string | null;
|
||||
representativeSetName: string | null;
|
||||
photoUrl: string | null;
|
||||
offices: Prisma.JsonValue | null;
|
||||
cachedAt: Date;
|
||||
}[];
|
||||
pagination: {
|
||||
page: number;
|
||||
limit: number;
|
||||
total: number;
|
||||
totalPages: number;
|
||||
};
|
||||
}>;
|
||||
findById(id: string): Promise<{
|
||||
id: string;
|
||||
email: string | null;
|
||||
name: string | null;
|
||||
url: string | null;
|
||||
postalCode: string;
|
||||
districtName: string | null;
|
||||
electedOffice: string | null;
|
||||
partyName: string | null;
|
||||
representativeSetName: string | null;
|
||||
photoUrl: string | null;
|
||||
offices: Prisma.JsonValue | null;
|
||||
cachedAt: Date;
|
||||
}>;
|
||||
clearByPostalCode(code: string): Promise<{
|
||||
deleted: number;
|
||||
postalCode: string;
|
||||
}>;
|
||||
deleteById(id: string): Promise<void>;
|
||||
testApiConnection(): Promise<{
|
||||
ok: boolean;
|
||||
message: string;
|
||||
}>;
|
||||
getCacheStats(): Promise<{
|
||||
totalRepresentatives: number;
|
||||
postalCodesWithRepresentatives: number;
|
||||
totalPostalCodes: number;
|
||||
}>;
|
||||
};
|
||||
//# sourceMappingURL=representatives.service.d.ts.map
|
||||
1
api/dist/modules/influence/representatives/representatives.service.d.ts.map
vendored
Normal file
1
api/dist/modules/influence/representatives/representatives.service.d.ts.map
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"representatives.service.d.ts","sourceRoot":"","sources":["../../../../src/modules/influence/representatives/representatives.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAMxC,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,2BAA2B,CAAC;AAY1E,eAAO,MAAM,sBAAsB;6BACF,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;qBAiGd,wBAAwB;;;;;;;;;;;;;;;;;;;;;;iBAmC5B,MAAM;;;;;;;;;;;;;;4BAQK,MAAM;;;;mBAOf,MAAM;;;;;;;;;;CAyB5B,CAAC"}
|
||||
175
api/dist/modules/influence/representatives/representatives.service.js
vendored
Normal file
175
api/dist/modules/influence/representatives/representatives.service.js
vendored
Normal file
@@ -0,0 +1,175 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.representativesService = void 0;
|
||||
const client_1 = require("@prisma/client");
|
||||
const database_1 = require("../../../config/database");
|
||||
const logger_1 = require("../../../utils/logger");
|
||||
const error_handler_1 = require("../../../middleware/error-handler");
|
||||
const represent_api_client_1 = require("./represent-api.client");
|
||||
const postal_codes_service_1 = require("../postal-codes/postal-codes.service");
|
||||
function deduplicateReps(reps) {
|
||||
const seen = new Set();
|
||||
return reps.filter((rep) => {
|
||||
const key = `${rep.name}|${rep.elected_office}`;
|
||||
if (seen.has(key))
|
||||
return false;
|
||||
seen.add(key);
|
||||
return true;
|
||||
});
|
||||
}
|
||||
exports.representativesService = {
|
||||
async lookupByPostalCode(code, forceRefresh = false) {
|
||||
// 1. Check cache unless forcing refresh
|
||||
if (!forceRefresh) {
|
||||
const cached = await database_1.prisma.representative.findMany({
|
||||
where: { postalCode: code },
|
||||
});
|
||||
if (cached.length > 0) {
|
||||
const postalInfo = await postal_codes_service_1.postalCodesService.findByPostalCode(code);
|
||||
return {
|
||||
source: 'cache',
|
||||
postalCode: code,
|
||||
location: {
|
||||
city: postalInfo?.city ?? null,
|
||||
province: postalInfo?.province ?? null,
|
||||
},
|
||||
representatives: cached,
|
||||
};
|
||||
}
|
||||
}
|
||||
// 2. Call Represent API
|
||||
const apiResponse = await represent_api_client_1.representApiClient.getByPostalCode(code);
|
||||
// Merge centroid + concordance reps and deduplicate
|
||||
const allReps = [
|
||||
...(apiResponse.representatives_centroid || []),
|
||||
...(apiResponse.representatives_concordance || []),
|
||||
];
|
||||
const uniqueReps = deduplicateReps(allReps);
|
||||
// 3. Fire-and-forget cache write
|
||||
const cacheWrite = async () => {
|
||||
try {
|
||||
// Delete old cached reps for this postal code
|
||||
await database_1.prisma.representative.deleteMany({ where: { postalCode: code } });
|
||||
// Cache new reps
|
||||
if (uniqueReps.length > 0) {
|
||||
await database_1.prisma.representative.createMany({
|
||||
data: uniqueReps.map((rep) => ({
|
||||
postalCode: code,
|
||||
name: rep.name || null,
|
||||
email: rep.email || null,
|
||||
districtName: rep.district_name || null,
|
||||
electedOffice: rep.elected_office || null,
|
||||
partyName: rep.party_name || null,
|
||||
representativeSetName: rep.representative_set_name || null,
|
||||
url: rep.url || null,
|
||||
photoUrl: rep.photo_url || null,
|
||||
offices: rep.offices ? rep.offices : client_1.Prisma.JsonNull,
|
||||
})),
|
||||
});
|
||||
}
|
||||
// Upsert postal code cache
|
||||
const coords = apiResponse.centroid?.coordinates;
|
||||
await postal_codes_service_1.postalCodesService.upsert({
|
||||
postalCode: code,
|
||||
city: apiResponse.city,
|
||||
province: apiResponse.province,
|
||||
centroidLat: coords ? coords[1] : null,
|
||||
centroidLng: coords ? coords[0] : null,
|
||||
});
|
||||
}
|
||||
catch (err) {
|
||||
logger_1.logger.error('Failed to cache representatives', { postalCode: code, error: err });
|
||||
}
|
||||
};
|
||||
// Don't await — fire and forget
|
||||
cacheWrite();
|
||||
// 4. Build response from API data
|
||||
return {
|
||||
source: 'api',
|
||||
postalCode: code,
|
||||
location: {
|
||||
city: apiResponse.city ?? null,
|
||||
province: apiResponse.province ?? null,
|
||||
},
|
||||
representatives: uniqueReps.map((rep) => ({
|
||||
id: null,
|
||||
postalCode: code,
|
||||
name: rep.name || null,
|
||||
email: rep.email || null,
|
||||
districtName: rep.district_name || null,
|
||||
electedOffice: rep.elected_office || null,
|
||||
partyName: rep.party_name || null,
|
||||
representativeSetName: rep.representative_set_name || null,
|
||||
url: rep.url || null,
|
||||
photoUrl: rep.photo_url || null,
|
||||
offices: rep.offices ?? null,
|
||||
cachedAt: new Date().toISOString(),
|
||||
})),
|
||||
};
|
||||
},
|
||||
async findAll(filters) {
|
||||
const { page, limit, search, postalCode } = filters;
|
||||
const skip = (page - 1) * limit;
|
||||
const where = {};
|
||||
if (postalCode) {
|
||||
where.postalCode = postalCode;
|
||||
}
|
||||
if (search) {
|
||||
where.OR = [
|
||||
{ name: { contains: search, mode: 'insensitive' } },
|
||||
{ email: { contains: search, mode: 'insensitive' } },
|
||||
{ districtName: { contains: search, mode: 'insensitive' } },
|
||||
{ electedOffice: { contains: search, mode: 'insensitive' } },
|
||||
];
|
||||
}
|
||||
const [representatives, total] = await Promise.all([
|
||||
database_1.prisma.representative.findMany({
|
||||
where,
|
||||
skip,
|
||||
take: limit,
|
||||
orderBy: { cachedAt: 'desc' },
|
||||
}),
|
||||
database_1.prisma.representative.count({ where }),
|
||||
]);
|
||||
return {
|
||||
representatives,
|
||||
pagination: { page, limit, total, totalPages: Math.ceil(total / limit) },
|
||||
};
|
||||
},
|
||||
async findById(id) {
|
||||
const rep = await database_1.prisma.representative.findUnique({ where: { id } });
|
||||
if (!rep) {
|
||||
throw new error_handler_1.AppError(404, 'Representative not found', 'REPRESENTATIVE_NOT_FOUND');
|
||||
}
|
||||
return rep;
|
||||
},
|
||||
async clearByPostalCode(code) {
|
||||
const result = await database_1.prisma.representative.deleteMany({
|
||||
where: { postalCode: code },
|
||||
});
|
||||
return { deleted: result.count, postalCode: code };
|
||||
},
|
||||
async deleteById(id) {
|
||||
const existing = await database_1.prisma.representative.findUnique({ where: { id } });
|
||||
if (!existing) {
|
||||
throw new error_handler_1.AppError(404, 'Representative not found', 'REPRESENTATIVE_NOT_FOUND');
|
||||
}
|
||||
await database_1.prisma.representative.delete({ where: { id } });
|
||||
},
|
||||
async testApiConnection() {
|
||||
return represent_api_client_1.representApiClient.testConnection();
|
||||
},
|
||||
async getCacheStats() {
|
||||
const [totalReps, postalCodesWithReps, totalPostalCodes] = await Promise.all([
|
||||
database_1.prisma.representative.count(),
|
||||
database_1.prisma.representative.groupBy({ by: ['postalCode'] }).then((g) => g.length),
|
||||
database_1.prisma.postalCodeCache.count(),
|
||||
]);
|
||||
return {
|
||||
totalRepresentatives: totalReps,
|
||||
postalCodesWithRepresentatives: postalCodesWithReps,
|
||||
totalPostalCodes,
|
||||
};
|
||||
},
|
||||
};
|
||||
//# sourceMappingURL=representatives.service.js.map
|
||||
1
api/dist/modules/influence/representatives/representatives.service.js.map
vendored
Normal file
1
api/dist/modules/influence/representatives/representatives.service.js.map
vendored
Normal file
File diff suppressed because one or more lines are too long
5
api/dist/modules/influence/responses/responses.routes.d.ts
vendored
Normal file
5
api/dist/modules/influence/responses/responses.routes.d.ts
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
declare const campaignPublicRouter: import("express-serve-static-core").Router;
|
||||
declare const responsesPublicRouter: import("express-serve-static-core").Router;
|
||||
declare const responsesAdminRouter: import("express-serve-static-core").Router;
|
||||
export { campaignPublicRouter as responseCampaignPublicRouter, responsesPublicRouter, responsesAdminRouter };
|
||||
//# sourceMappingURL=responses.routes.d.ts.map
|
||||
1
api/dist/modules/influence/responses/responses.routes.d.ts.map
vendored
Normal file
1
api/dist/modules/influence/responses/responses.routes.d.ts.map
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"responses.routes.d.ts","sourceRoot":"","sources":["../../../../src/modules/influence/responses/responses.routes.ts"],"names":[],"mappings":"AAkBA,QAAA,MAAM,oBAAoB,4CAAW,CAAC;AAiDtC,QAAA,MAAM,qBAAqB,4CAAW,CAAC;AA6EvC,QAAA,MAAM,oBAAoB,4CAAW,CAAC;AA6DtC,OAAO,EAAE,oBAAoB,IAAI,4BAA4B,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,CAAC"}
|
||||
199
api/dist/modules/influence/responses/responses.routes.js
vendored
Normal file
199
api/dist/modules/influence/responses/responses.routes.js
vendored
Normal file
@@ -0,0 +1,199 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.responsesAdminRouter = exports.responsesPublicRouter = exports.responseCampaignPublicRouter = void 0;
|
||||
const express_1 = require("express");
|
||||
const client_1 = require("@prisma/client");
|
||||
const responses_service_1 = require("./responses.service");
|
||||
const responses_schemas_1 = require("./responses.schemas");
|
||||
const validate_1 = require("../../../middleware/validate");
|
||||
const auth_middleware_1 = require("../../../middleware/auth.middleware");
|
||||
const auth_middleware_2 = require("../../../middleware/auth.middleware");
|
||||
const rbac_middleware_1 = require("../../../middleware/rbac.middleware");
|
||||
const rate_limit_1 = require("../../../middleware/rate-limit");
|
||||
const ADMIN_ROLES = [client_1.UserRole.SUPER_ADMIN, client_1.UserRole.INFLUENCE_ADMIN, client_1.UserRole.MAP_ADMIN];
|
||||
// --- Campaign-scoped public routes (mount at /api/campaigns) ---
|
||||
const campaignPublicRouter = (0, express_1.Router)();
|
||||
exports.responseCampaignPublicRouter = campaignPublicRouter;
|
||||
// GET /api/campaigns/:slug/responses
|
||||
campaignPublicRouter.get('/:slug/responses', (0, validate_1.validate)(responses_schemas_1.listPublicResponsesSchema, 'query'), async (req, res, next) => {
|
||||
try {
|
||||
const slug = req.params.slug;
|
||||
const result = await responses_service_1.responsesService.listApproved(slug, req.query);
|
||||
res.json(result);
|
||||
}
|
||||
catch (err) {
|
||||
next(err);
|
||||
}
|
||||
});
|
||||
// GET /api/campaigns/:slug/response-stats
|
||||
campaignPublicRouter.get('/:slug/response-stats', async (req, res, next) => {
|
||||
try {
|
||||
const slug = req.params.slug;
|
||||
const stats = await responses_service_1.responsesService.getStats(slug);
|
||||
res.json(stats);
|
||||
}
|
||||
catch (err) {
|
||||
next(err);
|
||||
}
|
||||
});
|
||||
// POST /api/campaigns/:slug/responses
|
||||
campaignPublicRouter.post('/:slug/responses', rate_limit_1.responseRateLimit, (0, validate_1.validate)(responses_schemas_1.submitResponseSchema), async (req, res, next) => {
|
||||
try {
|
||||
const slug = req.params.slug;
|
||||
const senderIp = req.ip || req.socket.remoteAddress;
|
||||
const result = await responses_service_1.responsesService.submitResponse(slug, req.body, senderIp);
|
||||
res.status(201).json(result);
|
||||
}
|
||||
catch (err) {
|
||||
next(err);
|
||||
}
|
||||
});
|
||||
// --- Response-scoped public routes (mount at /api/responses) ---
|
||||
const responsesPublicRouter = (0, express_1.Router)();
|
||||
exports.responsesPublicRouter = responsesPublicRouter;
|
||||
// POST /api/responses/:id/upvote
|
||||
responsesPublicRouter.post('/:id/upvote', auth_middleware_2.optionalAuth, async (req, res, next) => {
|
||||
try {
|
||||
const id = req.params.id;
|
||||
const userIp = req.ip || req.socket.remoteAddress;
|
||||
const userId = req.user?.id;
|
||||
const result = await responses_service_1.responsesService.upvote(id, userIp, userId);
|
||||
res.json(result);
|
||||
}
|
||||
catch (err) {
|
||||
next(err);
|
||||
}
|
||||
});
|
||||
// DELETE /api/responses/:id/upvote
|
||||
responsesPublicRouter.delete('/:id/upvote', auth_middleware_2.optionalAuth, async (req, res, next) => {
|
||||
try {
|
||||
const id = req.params.id;
|
||||
const userIp = req.ip || req.socket.remoteAddress;
|
||||
const userId = req.user?.id;
|
||||
const result = await responses_service_1.responsesService.removeUpvote(id, userIp, userId);
|
||||
res.json(result);
|
||||
}
|
||||
catch (err) {
|
||||
next(err);
|
||||
}
|
||||
});
|
||||
// GET /api/responses/:id/verify/:token — returns HTML page
|
||||
responsesPublicRouter.get('/:id/verify/:token', async (req, res, next) => {
|
||||
try {
|
||||
const id = req.params.id;
|
||||
const token = req.params.token;
|
||||
const result = await responses_service_1.responsesService.verify(id, token);
|
||||
const html = result.success
|
||||
? buildResultPage('Response Verified', `Thank you for verifying this response for the "${result.campaignTitle}" campaign. The response has been approved and will now appear on the public response wall.`, '#16a34a')
|
||||
: buildResultPage('Verification Failed', result.reason || 'Unable to verify this response.', '#dc2626');
|
||||
res.type('html').send(html);
|
||||
}
|
||||
catch (err) {
|
||||
next(err);
|
||||
}
|
||||
});
|
||||
// GET /api/responses/:id/report/:token — returns HTML page
|
||||
responsesPublicRouter.get('/:id/report/:token', async (req, res, next) => {
|
||||
try {
|
||||
const id = req.params.id;
|
||||
const token = req.params.token;
|
||||
const result = await responses_service_1.responsesService.report(id, token);
|
||||
const html = result.success
|
||||
? buildResultPage('Response Reported', `This response for the "${result.campaignTitle}" campaign has been flagged as invalid and removed from the public response wall. Thank you for letting us know.`, '#dc2626')
|
||||
: buildResultPage('Report Failed', result.reason || 'Unable to process this report.', '#dc2626');
|
||||
res.type('html').send(html);
|
||||
}
|
||||
catch (err) {
|
||||
next(err);
|
||||
}
|
||||
});
|
||||
// --- Admin routes (mount at /api/responses) ---
|
||||
const responsesAdminRouter = (0, express_1.Router)();
|
||||
exports.responsesAdminRouter = responsesAdminRouter;
|
||||
responsesAdminRouter.use(auth_middleware_1.authenticate);
|
||||
responsesAdminRouter.use((0, rbac_middleware_1.requireRole)(...ADMIN_ROLES));
|
||||
// GET /api/responses
|
||||
responsesAdminRouter.get('/', (0, validate_1.validate)(responses_schemas_1.listAdminResponsesSchema, 'query'), async (req, res, next) => {
|
||||
try {
|
||||
const result = await responses_service_1.responsesService.findAll(req.query);
|
||||
res.json(result);
|
||||
}
|
||||
catch (err) {
|
||||
next(err);
|
||||
}
|
||||
});
|
||||
// PATCH /api/responses/:id/status
|
||||
responsesAdminRouter.patch('/:id/status', (0, validate_1.validate)(responses_schemas_1.updateResponseStatusSchema), async (req, res, next) => {
|
||||
try {
|
||||
const id = req.params.id;
|
||||
const result = await responses_service_1.responsesService.updateStatus(id, req.body);
|
||||
res.json(result);
|
||||
}
|
||||
catch (err) {
|
||||
next(err);
|
||||
}
|
||||
});
|
||||
// POST /api/responses/:id/resend-verification
|
||||
responsesAdminRouter.post('/:id/resend-verification', async (req, res, next) => {
|
||||
try {
|
||||
const id = req.params.id;
|
||||
const result = await responses_service_1.responsesService.resendVerification(id);
|
||||
res.json(result);
|
||||
}
|
||||
catch (err) {
|
||||
next(err);
|
||||
}
|
||||
});
|
||||
// DELETE /api/responses/:id
|
||||
responsesAdminRouter.delete('/:id', async (req, res, next) => {
|
||||
try {
|
||||
const id = req.params.id;
|
||||
await responses_service_1.responsesService.deleteResponse(id);
|
||||
res.status(204).send();
|
||||
}
|
||||
catch (err) {
|
||||
next(err);
|
||||
}
|
||||
});
|
||||
// --- HTML page builder for verify/report endpoints ---
|
||||
function escapeHtml(unsafe) {
|
||||
return unsafe
|
||||
.replace(/&/g, '&')
|
||||
.replace(/</g, '<')
|
||||
.replace(/>/g, '>')
|
||||
.replace(/"/g, '"')
|
||||
.replace(/'/g, ''');
|
||||
}
|
||||
function buildResultPage(title, message, accentColor) {
|
||||
const escapedTitle = escapeHtml(title);
|
||||
const escapedMessage = escapeHtml(message);
|
||||
return `<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>${escapedTitle} - Changemaker Lite</title>
|
||||
<style>
|
||||
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; margin: 0; padding: 40px 20px; background: #f8fafc; color: #334155; }
|
||||
.container { max-width: 500px; margin: 0 auto; text-align: center; }
|
||||
.card { background: white; border-radius: 12px; padding: 40px; box-shadow: 0 1px 3px rgba(0,0,0,0.1); }
|
||||
.icon { font-size: 48px; margin-bottom: 16px; }
|
||||
h1 { color: ${accentColor}; font-size: 24px; margin: 0 0 16px; }
|
||||
p { font-size: 16px; line-height: 1.6; color: #64748b; margin: 0; }
|
||||
.brand { margin-top: 32px; font-size: 14px; color: #94a3b8; }
|
||||
.brand strong { color: #2563eb; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<div class="card">
|
||||
<div class="icon">${accentColor === '#16a34a' ? '✓' : '✗'}</div>
|
||||
<h1>${escapedTitle}</h1>
|
||||
<p>${escapedMessage}</p>
|
||||
</div>
|
||||
<div class="brand">Powered by <strong>Changemaker Lite</strong></div>
|
||||
</div>
|
||||
</body>
|
||||
</html>`;
|
||||
}
|
||||
//# sourceMappingURL=responses.routes.js.map
|
||||
1
api/dist/modules/influence/responses/responses.routes.js.map
vendored
Normal file
1
api/dist/modules/influence/responses/responses.routes.js.map
vendored
Normal file
File diff suppressed because one or more lines are too long
110
api/dist/modules/influence/responses/responses.schemas.d.ts
vendored
Normal file
110
api/dist/modules/influence/responses/responses.schemas.d.ts
vendored
Normal file
@@ -0,0 +1,110 @@
|
||||
import { z } from 'zod';
|
||||
export declare const submitResponseSchema: z.ZodObject<{
|
||||
representativeName: z.ZodString;
|
||||
representativeLevel: z.ZodNativeEnum<{
|
||||
FEDERAL: "FEDERAL";
|
||||
PROVINCIAL: "PROVINCIAL";
|
||||
MUNICIPAL: "MUNICIPAL";
|
||||
SCHOOL_BOARD: "SCHOOL_BOARD";
|
||||
}>;
|
||||
responseType: z.ZodNativeEnum<{
|
||||
EMAIL: "EMAIL";
|
||||
LETTER: "LETTER";
|
||||
PHONE_CALL: "PHONE_CALL";
|
||||
MEETING: "MEETING";
|
||||
SOCIAL_MEDIA: "SOCIAL_MEDIA";
|
||||
OTHER: "OTHER";
|
||||
}>;
|
||||
responseText: z.ZodString;
|
||||
representativeTitle: z.ZodOptional<z.ZodString>;
|
||||
representativeEmail: z.ZodOptional<z.ZodString>;
|
||||
userComment: z.ZodOptional<z.ZodString>;
|
||||
submittedByName: z.ZodOptional<z.ZodString>;
|
||||
submittedByEmail: z.ZodOptional<z.ZodString>;
|
||||
isAnonymous: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
||||
sendVerification: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
||||
}, "strip", z.ZodTypeAny, {
|
||||
representativeName: string;
|
||||
representativeLevel: "FEDERAL" | "PROVINCIAL" | "MUNICIPAL" | "SCHOOL_BOARD";
|
||||
responseType: "EMAIL" | "LETTER" | "PHONE_CALL" | "MEETING" | "SOCIAL_MEDIA" | "OTHER";
|
||||
responseText: string;
|
||||
isAnonymous: boolean;
|
||||
sendVerification: boolean;
|
||||
representativeTitle?: string | undefined;
|
||||
representativeEmail?: string | undefined;
|
||||
userComment?: string | undefined;
|
||||
submittedByName?: string | undefined;
|
||||
submittedByEmail?: string | undefined;
|
||||
}, {
|
||||
representativeName: string;
|
||||
representativeLevel: "FEDERAL" | "PROVINCIAL" | "MUNICIPAL" | "SCHOOL_BOARD";
|
||||
responseType: "EMAIL" | "LETTER" | "PHONE_CALL" | "MEETING" | "SOCIAL_MEDIA" | "OTHER";
|
||||
responseText: string;
|
||||
representativeTitle?: string | undefined;
|
||||
representativeEmail?: string | undefined;
|
||||
userComment?: string | undefined;
|
||||
submittedByName?: string | undefined;
|
||||
submittedByEmail?: string | undefined;
|
||||
isAnonymous?: boolean | undefined;
|
||||
sendVerification?: boolean | undefined;
|
||||
}>;
|
||||
export declare const listPublicResponsesSchema: z.ZodObject<{
|
||||
page: z.ZodDefault<z.ZodNumber>;
|
||||
limit: z.ZodDefault<z.ZodNumber>;
|
||||
sort: z.ZodDefault<z.ZodOptional<z.ZodEnum<["recent", "upvotes", "verified"]>>>;
|
||||
level: z.ZodOptional<z.ZodNativeEnum<{
|
||||
FEDERAL: "FEDERAL";
|
||||
PROVINCIAL: "PROVINCIAL";
|
||||
MUNICIPAL: "MUNICIPAL";
|
||||
SCHOOL_BOARD: "SCHOOL_BOARD";
|
||||
}>>;
|
||||
}, "strip", z.ZodTypeAny, {
|
||||
sort: "upvotes" | "recent" | "verified";
|
||||
limit: number;
|
||||
page: number;
|
||||
level?: "FEDERAL" | "PROVINCIAL" | "MUNICIPAL" | "SCHOOL_BOARD" | undefined;
|
||||
}, {
|
||||
sort?: "upvotes" | "recent" | "verified" | undefined;
|
||||
level?: "FEDERAL" | "PROVINCIAL" | "MUNICIPAL" | "SCHOOL_BOARD" | undefined;
|
||||
limit?: number | undefined;
|
||||
page?: number | undefined;
|
||||
}>;
|
||||
export declare const listAdminResponsesSchema: z.ZodObject<{
|
||||
page: z.ZodDefault<z.ZodNumber>;
|
||||
limit: z.ZodDefault<z.ZodNumber>;
|
||||
status: z.ZodOptional<z.ZodNativeEnum<{
|
||||
PENDING: "PENDING";
|
||||
APPROVED: "APPROVED";
|
||||
REJECTED: "REJECTED";
|
||||
}>>;
|
||||
campaignId: z.ZodOptional<z.ZodString>;
|
||||
search: z.ZodOptional<z.ZodString>;
|
||||
}, "strip", z.ZodTypeAny, {
|
||||
limit: number;
|
||||
page: number;
|
||||
status?: "PENDING" | "APPROVED" | "REJECTED" | undefined;
|
||||
search?: string | undefined;
|
||||
campaignId?: string | undefined;
|
||||
}, {
|
||||
status?: "PENDING" | "APPROVED" | "REJECTED" | undefined;
|
||||
search?: string | undefined;
|
||||
limit?: number | undefined;
|
||||
page?: number | undefined;
|
||||
campaignId?: string | undefined;
|
||||
}>;
|
||||
export declare const updateResponseStatusSchema: z.ZodObject<{
|
||||
status: z.ZodNativeEnum<{
|
||||
PENDING: "PENDING";
|
||||
APPROVED: "APPROVED";
|
||||
REJECTED: "REJECTED";
|
||||
}>;
|
||||
}, "strip", z.ZodTypeAny, {
|
||||
status: "PENDING" | "APPROVED" | "REJECTED";
|
||||
}, {
|
||||
status: "PENDING" | "APPROVED" | "REJECTED";
|
||||
}>;
|
||||
export type SubmitResponseInput = z.infer<typeof submitResponseSchema>;
|
||||
export type ListPublicResponsesInput = z.infer<typeof listPublicResponsesSchema>;
|
||||
export type ListAdminResponsesInput = z.infer<typeof listAdminResponsesSchema>;
|
||||
export type UpdateResponseStatusInput = z.infer<typeof updateResponseStatusSchema>;
|
||||
//# sourceMappingURL=responses.schemas.d.ts.map
|
||||
1
api/dist/modules/influence/responses/responses.schemas.d.ts.map
vendored
Normal file
1
api/dist/modules/influence/responses/responses.schemas.d.ts.map
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"responses.schemas.d.ts","sourceRoot":"","sources":["../../../../src/modules/influence/responses/responses.schemas.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB,eAAO,MAAM,oBAAoB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAY/B,CAAC;AAEH,eAAO,MAAM,yBAAyB;;;;;;;;;;;;;;;;;;;;EAKpC,CAAC;AAEH,eAAO,MAAM,wBAAwB;;;;;;;;;;;;;;;;;;;;;;EAMnC,CAAC;AAEH,eAAO,MAAM,0BAA0B;;;;;;;;;;EAErC,CAAC;AAEH,MAAM,MAAM,mBAAmB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAC;AACvE,MAAM,MAAM,wBAAwB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,yBAAyB,CAAC,CAAC;AACjF,MAAM,MAAM,uBAAuB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,wBAAwB,CAAC,CAAC;AAC/E,MAAM,MAAM,yBAAyB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,0BAA0B,CAAC,CAAC"}
|
||||
35
api/dist/modules/influence/responses/responses.schemas.js
vendored
Normal file
35
api/dist/modules/influence/responses/responses.schemas.js
vendored
Normal file
@@ -0,0 +1,35 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.updateResponseStatusSchema = exports.listAdminResponsesSchema = exports.listPublicResponsesSchema = exports.submitResponseSchema = void 0;
|
||||
const zod_1 = require("zod");
|
||||
const client_1 = require("@prisma/client");
|
||||
exports.submitResponseSchema = zod_1.z.object({
|
||||
representativeName: zod_1.z.string().min(1, 'Representative name is required'),
|
||||
representativeLevel: zod_1.z.nativeEnum(client_1.GovernmentLevel),
|
||||
responseType: zod_1.z.nativeEnum(client_1.ResponseType),
|
||||
responseText: zod_1.z.string().min(1, 'Response text is required'),
|
||||
representativeTitle: zod_1.z.string().optional(),
|
||||
representativeEmail: zod_1.z.string().email().optional(),
|
||||
userComment: zod_1.z.string().optional(),
|
||||
submittedByName: zod_1.z.string().optional(),
|
||||
submittedByEmail: zod_1.z.string().email().optional(),
|
||||
isAnonymous: zod_1.z.boolean().optional().default(false),
|
||||
sendVerification: zod_1.z.boolean().optional().default(false),
|
||||
});
|
||||
exports.listPublicResponsesSchema = zod_1.z.object({
|
||||
page: zod_1.z.coerce.number().int().positive().default(1),
|
||||
limit: zod_1.z.coerce.number().int().positive().max(100).default(20),
|
||||
sort: zod_1.z.enum(['recent', 'upvotes', 'verified']).optional().default('recent'),
|
||||
level: zod_1.z.nativeEnum(client_1.GovernmentLevel).optional(),
|
||||
});
|
||||
exports.listAdminResponsesSchema = zod_1.z.object({
|
||||
page: zod_1.z.coerce.number().int().positive().default(1),
|
||||
limit: zod_1.z.coerce.number().int().positive().max(100).default(20),
|
||||
status: zod_1.z.nativeEnum(client_1.ResponseStatus).optional(),
|
||||
campaignId: zod_1.z.string().optional(),
|
||||
search: zod_1.z.string().optional(),
|
||||
});
|
||||
exports.updateResponseStatusSchema = zod_1.z.object({
|
||||
status: zod_1.z.nativeEnum(client_1.ResponseStatus),
|
||||
});
|
||||
//# sourceMappingURL=responses.schemas.js.map
|
||||
1
api/dist/modules/influence/responses/responses.schemas.js.map
vendored
Normal file
1
api/dist/modules/influence/responses/responses.schemas.js.map
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"responses.schemas.js","sourceRoot":"","sources":["../../../../src/modules/influence/responses/responses.schemas.ts"],"names":[],"mappings":";;;AAAA,6BAAwB;AACxB,2CAA+E;AAElE,QAAA,oBAAoB,GAAG,OAAC,CAAC,MAAM,CAAC;IAC3C,kBAAkB,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,EAAE,iCAAiC,CAAC;IACxE,mBAAmB,EAAE,OAAC,CAAC,UAAU,CAAC,wBAAe,CAAC;IAClD,YAAY,EAAE,OAAC,CAAC,UAAU,CAAC,qBAAY,CAAC;IACxC,YAAY,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,EAAE,2BAA2B,CAAC;IAC5D,mBAAmB,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAC1C,mBAAmB,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,KAAK,EAAE,CAAC,QAAQ,EAAE;IAClD,WAAW,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAClC,eAAe,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IACtC,gBAAgB,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,KAAK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