Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
afcf4dd
chore(config): add @interfaces/* and @indicators/* path aliases
SAAD-MOUMOU Mar 31, 2026
2e42a1d
chore(config): rename eslint.config.js to .mjs to fix ESM loading
SAAD-MOUMOU Mar 31, 2026
f856137
chore(git): fix husky pre-commit hook for v10 compatibility
SAAD-MOUMOU Mar 31, 2026
c74b8ae
feat(interfaces): add IHealthIndicator, HealthStatus, HealthIndicator…
SAAD-MOUMOU Mar 31, 2026
41d7af3
feat(indicators): add PostgresHealthIndicator (SELECT 1 + timeout)
SAAD-MOUMOU Mar 31, 2026
8f9af5e
test(indicators): add PostgresHealthIndicator unit tests (success/err…
SAAD-MOUMOU Mar 31, 2026
5dff0e2
feat(indicators): add RedisHealthIndicator (PING + timeout)
SAAD-MOUMOU Mar 31, 2026
af6f235
test(indicators): add RedisHealthIndicator unit tests (success/error/…
SAAD-MOUMOU Mar 31, 2026
a5d8377
feat(indicators): add HttpHealthIndicator (GET + 2xx check + timeout)
SAAD-MOUMOU Mar 31, 2026
914f341
test(indicators): add HttpHealthIndicator unit tests (2xx/non-2xx/net…
SAAD-MOUMOU Mar 31, 2026
60eedae
chore(deps): update package-lock after npm install
SAAD-MOUMOU Mar 31, 2026
f27a411
chore(config): set module to CommonJS and moduleResolution to Node fo…
SAAD-MOUMOU Apr 1, 2026
a3ff296
chore(package): rename to @ciscode/health-kit
SAAD-MOUMOU Apr 1, 2026
e732894
chore(deps): update package-lock
SAAD-MOUMOU Apr 1, 2026
15f7b7f
feat(indicators): add MongoHealthIndicator with ping command and timeout
SAAD-MOUMOU Apr 1, 2026
686dc9e
test(indicators): add MongoHealthIndicator unit tests (success/error/…
SAAD-MOUMOU Apr 1, 2026
90f4e9d
feat(services): add HealthService with Promise.allSettled orchestration
SAAD-MOUMOU Apr 1, 2026
e0c0e53
test(services): add HealthService unit tests (liveness/readiness/conc…
SAAD-MOUMOU Apr 1, 2026
de52d73
feat(controllers): add HealthController factory (GET live/ready, plat…
SAAD-MOUMOU Apr 1, 2026
224ad90
test(controllers): add HealthController unit tests (200 ok / 503 Serv…
SAAD-MOUMOU Apr 1, 2026
831dcc1
feat(module): add HealthKitModule.register() dynamic module
SAAD-MOUMOU Apr 1, 2026
5b5f872
feat(exports): update public API exports for health-kit
SAAD-MOUMOU Apr 1, 2026
bcdc00c
feat(indicators): add createIndicator inline factory with timeout sup…
SAAD-MOUMOU Apr 2, 2026
3cb5a91
test(indicators): add createIndicator unit tests (true/false/void/thr…
SAAD-MOUMOU Apr 2, 2026
dcf3e60
feat(indicators): add BaseHealthIndicator abstract class with result(…
SAAD-MOUMOU Apr 2, 2026
84b2254
test(indicators): add BaseHealthIndicator unit tests
SAAD-MOUMOU Apr 2, 2026
b285d64
feat(decorators): add @HealthIndicator decorator for auto-registratio…
SAAD-MOUMOU Apr 2, 2026
cbd5cf2
test(decorators): add @HealthIndicator decorator unit tests
SAAD-MOUMOU Apr 2, 2026
bdcd32c
feat(module): extend HealthKitModule.register() with indicators[] opt…
SAAD-MOUMOU Apr 2, 2026
881d0f2
feat(exports): export createIndicator, BaseHealthIndicator, @HealthIn…
SAAD-MOUMOU Apr 2, 2026
9bfea9f
chore(package): update description to mention MongoDB
SAAD-MOUMOU Apr 2, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

npx lint-staged
Copy link

Copilot AI Apr 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Husky hook header was removed. Without the shebang and sourcing ./_/husky.sh, the hook can fail in some environments (e.g., PATH not set to include local node binaries). Restore the standard Husky pre-commit header like the pre-push hook uses.

Copilot uses AI. Check for mistakes.
80 changes: 0 additions & 80 deletions eslint.config.js

This file was deleted.

76 changes: 57 additions & 19 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -1,42 +1,80 @@
// @ts-check
import eslint from "@eslint/js";
import eslintPluginPrettierRecommended from "eslint-plugin-prettier/recommended";
import globals from "globals";
import importPlugin from "eslint-plugin-import";
import tseslint from "typescript-eslint";

export default tseslint.config(
export default [
{
ignores: ["eslint.config.mjs"],
ignores: [
"dist/**",
"coverage/**",
"node_modules/**",
// Ignore all example files for CSR architecture
"src/example-kit.*",
"src/controllers/example.controller.ts",
"src/services/example.service.ts",
"src/entities/example.entity.ts",
"src/repositories/example.repository.ts",
"src/guards/example.guard.ts",
"src/decorators/example.decorator.ts",
"src/dto/create-example.dto.ts",
"src/dto/update-example.dto.ts",
],
},

eslint.configs.recommended,
...tseslint.configs.recommendedTypeChecked,
eslintPluginPrettierRecommended,

// TypeScript ESLint (includes recommended rules)
...tseslint.configs.recommended,

// Base TS rules (all TS files)
{
files: ["**/*.ts"],
languageOptions: {
globals: {
...globals.node,
...globals.jest,
},
sourceType: "commonjs",
parser: tseslint.parser,
parserOptions: {
projectService: true,
project: "./tsconfig.eslint.json",
tsconfigRootDir: import.meta.dirname,
ecmaVersion: "latest",
sourceType: "module",
},
globals: { ...globals.node, ...globals.jest },
},
plugins: {
"@typescript-eslint": tseslint.plugin,
import: importPlugin,
},
rules: {
"@typescript-eslint/no-unused-vars": ["error", { argsIgnorePattern: "^_" }],
"@typescript-eslint/consistent-type-imports": ["error", { prefer: "type-imports" }],

"import/no-duplicates": "error",
"import/order": [
"error",
{
"newlines-between": "always",
alphabetize: { order: "asc", caseInsensitive: true },
},
],
},
},

// Architecture boundary: core must not import Nest
{
files: ["src/core/**/*.ts"],
rules: {
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-floating-promises": "warn",
"@typescript-eslint/no-unsafe-argument": "warn",
"@typescript-eslint/no-unused-vars": [
"no-restricted-imports": [
"error",
{
argsIgnorePattern: "^_",
varsIgnorePattern: "^_",
patterns: [
{
group: ["@nestjs/*"],
message: "Do not import NestJS in core/. Keep core framework-free.",
},
],
},
],
"no-unused-vars": "off",
},
},
);
];
2 changes: 2 additions & 0 deletions jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ const config: Config = {
"^@filters/(.*)$": "<rootDir>/src/filters/$1",
"^@middleware/(.*)$": "<rootDir>/src/middleware/$1",
"^@utils/(.*)$": "<rootDir>/src/utils/$1",
"^@interfaces/(.*)$": "<rootDir>/src/interfaces/$1",
"^@indicators/(.*)$": "<rootDir>/src/indicators/$1",
},
};

Expand Down
File renamed without changes.
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@ciscode/nestjs-developerkit",
"name": "@ciscode/health-kit",
"version": "1.0.0",
"description": "Template for NestJS developer kits (npm packages).",
"description": "NestJS health-check module — liveness & readiness probes with built-in MongoDB, Redis, and HTTP indicators.",
"author": "CisCode",
"publishConfig": {
"access": "public"
Expand Down Expand Up @@ -45,7 +45,6 @@
"peerDependencies": {
"@nestjs/common": "^10 || ^11",
"@nestjs/core": "^10 || ^11",
"@nestjs/platform-express": "^10 || ^11",
"reflect-metadata": "^0.2.2",
"rxjs": "^7"
},
Expand Down
62 changes: 62 additions & 0 deletions src/controllers/health.controller.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import { ServiceUnavailableException } from "@nestjs/common";
import type { TestingModule } from "@nestjs/testing";
import { Test } from "@nestjs/testing";
import { HealthService } from "@services/health.service";
import type { HealthCheckResult } from "@services/health.service";

import { createHealthController } from "./health.controller";

// ── Helpers ──────────────────────────────────────────────────────────────────

const makeService = (liveness: "ok" | "error", readiness: "ok" | "error") =>
({
checkLiveness: jest.fn().mockResolvedValue({ status: liveness, indicators: [] }),
checkReadiness: jest.fn().mockResolvedValue({ status: readiness, indicators: [] }),
}) as unknown as HealthService;

interface HealthControllerInstance {
live(): Promise<HealthCheckResult>;
ready(): Promise<HealthCheckResult>;
}

async function buildController(
liveness: "ok" | "error",
readiness: "ok" | "error",
): Promise<HealthControllerInstance> {
const HealthController = createHealthController("health");
const moduleRef: TestingModule = await Test.createTestingModule({
controllers: [HealthController],
providers: [{ provide: HealthService, useValue: makeService(liveness, readiness) }],
}).compile();
return moduleRef.get<HealthControllerInstance>(HealthController as never);
}

// ── Tests ─────────────────────────────────────────────────────────────────────

describe("HealthController (factory)", () => {
describe("GET /health/live", () => {
it("returns result when all liveness indicators are up", async () => {
const controller = await buildController("ok", "ok");
const result = await controller.live();
expect(result.status).toBe("ok");
});

it("throws ServiceUnavailableException (503) when any liveness indicator is down", async () => {
const controller = await buildController("error", "ok");
await expect(controller.live()).rejects.toThrow(ServiceUnavailableException);
});
});

describe("GET /health/ready", () => {
it("returns result when all readiness indicators are up", async () => {
const controller = await buildController("ok", "ok");
const result = await controller.ready();
expect(result.status).toBe("ok");
});

it("throws ServiceUnavailableException (503) when any readiness indicator is down", async () => {
const controller = await buildController("ok", "error");
await expect(controller.ready()).rejects.toThrow(ServiceUnavailableException);
});
});
});
43 changes: 43 additions & 0 deletions src/controllers/health.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import {
Controller,
Get,
HttpCode,
HttpStatus,
ServiceUnavailableException,
Type,
} from "@nestjs/common";
import { HealthService } from "@services/health.service";
import type { HealthCheckResult } from "@services/health.service";

/**
* Factory that returns a NestJS controller class configured with the
* caller-supplied `path` prefix (e.g. `"health"`).
*
* Platform-agnostic — works with Express and Fastify.
* Returns 200 when all indicators are "up",
* throws ServiceUnavailableException (503) when any indicator is "down".
*/
export function createHealthController(path: string): Type<unknown> {
@Controller(path)
class HealthController {
constructor(private readonly healthService: HealthService) {}

@Get("live")
@HttpCode(HttpStatus.OK)
async live(): Promise<HealthCheckResult> {
const result = await this.healthService.checkLiveness();
if (result.status === "error") throw new ServiceUnavailableException(result);
return result;
}

@Get("ready")
@HttpCode(HttpStatus.OK)
async ready(): Promise<HealthCheckResult> {
const result = await this.healthService.checkReadiness();
if (result.status === "error") throw new ServiceUnavailableException(result);
return result;
}
}

return HealthController;
}
36 changes: 36 additions & 0 deletions src/decorators/health-indicator.decorator.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import "reflect-metadata";
import { HEALTH_INDICATOR_METADATA, HealthIndicator } from "./health-indicator.decorator";

class SomeIndicator {}

Check warning on line 4 in src/decorators/health-indicator.decorator.spec.ts

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unexpected empty class.

See more on https://sonarcloud.io/project/issues?id=CISCODE-MA_HealthKit&issues=AZ1OC1nolePA0yZROfR2&open=AZ1OC1nolePA0yZROfR2&pullRequest=11
class AnotherIndicator {}

Check warning on line 5 in src/decorators/health-indicator.decorator.spec.ts

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unexpected empty class.

See more on https://sonarcloud.io/project/issues?id=CISCODE-MA_HealthKit&issues=AZ1OC1nolePA0yZROfR3&open=AZ1OC1nolePA0yZROfR3&pullRequest=11
class UndecotratedIndicator {}

Check warning on line 6 in src/decorators/health-indicator.decorator.spec.ts

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unexpected empty class.

See more on https://sonarcloud.io/project/issues?id=CISCODE-MA_HealthKit&issues=AZ1OC1nolePA0yZROfR4&open=AZ1OC1nolePA0yZROfR4&pullRequest=11

Comment on lines +4 to +7
Copy link

Copilot AI Apr 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo in class name UndecotratedIndicatorUndecoratedIndicator. This is user-facing in test names/examples and makes the intent harder to read.

Copilot uses AI. Check for mistakes.
@HealthIndicator("liveness")
class LivenessIndicator extends SomeIndicator {}

@HealthIndicator("readiness")
class ReadinessIndicator extends AnotherIndicator {}

describe("@HealthIndicator decorator", () => {
it("attaches liveness metadata to the target class", () => {
const scope = Reflect.getMetadata(HEALTH_INDICATOR_METADATA, LivenessIndicator);
expect(scope).toBe("liveness");
});

it("attaches readiness metadata to the target class", () => {
const scope = Reflect.getMetadata(HEALTH_INDICATOR_METADATA, ReadinessIndicator);
expect(scope).toBe("readiness");
});

it("returns undefined for undecorated classes", () => {
const scope = Reflect.getMetadata(HEALTH_INDICATOR_METADATA, UndecotratedIndicator);
expect(scope).toBeUndefined();
});

it("does not affect other classes when decorating one", () => {
const livScope = Reflect.getMetadata(HEALTH_INDICATOR_METADATA, LivenessIndicator);
const readScope = Reflect.getMetadata(HEALTH_INDICATOR_METADATA, ReadinessIndicator);
expect(livScope).toBe("liveness");
expect(readScope).toBe("readiness");
});
});
Loading
Loading