@moshaver/cmb-health 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Mobin Karam
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,15 @@
1
- # Temporary Holding Version
1
+ # @moshaver/cmb-health
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Framework-neutral health/readiness capability. Applications provide named probes and decide how failures map to HTTP, process, orchestration, or platform-specific behavior.
4
+
5
+ ## Install and use
6
+
7
+ ```bash
8
+ npm install @moshaver/cmb-health
9
+ ```
10
+
11
+ ```js
12
+ const { CmbHealthService } = require("@moshaver/cmb-health");
13
+ const health = new CmbHealthService({ serviceName: "api", probes: [] });
14
+ await health.ready();
15
+ ```
package/package.json CHANGED
@@ -1,6 +1,47 @@
1
1
  {
2
2
  "name": "@moshaver/cmb-health",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0",
4
+ "description": "Composable Modular Backend health primitives.",
5
+ "type": "commonjs",
6
+ "main": "./src/index.js",
7
+ "types": "./src/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./src/index.d.ts",
11
+ "require": "./src/index.js",
12
+ "default": "./src/index.js"
13
+ }
14
+ },
15
+ "files": [
16
+ "src",
17
+ "README.md",
18
+ "LICENSE"
19
+ ],
20
+ "keywords": [
21
+ "cmb",
22
+ "modular-backend",
23
+ "backend",
24
+ "framework-agnostic",
25
+ "health"
26
+ ],
27
+ "engines": {
28
+ "node": ">=22.13.0 <23"
29
+ },
30
+ "repository": {
31
+ "type": "git",
32
+ "url": "git+https://github.com/Mobin-Karam/moshaver.git",
33
+ "directory": "packages/cmb/health"
34
+ },
35
+ "bugs": {
36
+ "url": "https://github.com/Mobin-Karam/moshaver/issues"
37
+ },
38
+ "homepage": "https://github.com/Mobin-Karam/moshaver/tree/main/packages/cmb",
39
+ "publishConfig": {
40
+ "access": "public"
41
+ },
42
+ "license": "MIT",
43
+ "sideEffects": false,
44
+ "dependencies": {
45
+ "@moshaver/cmb-kernel": "^0.1.0"
46
+ }
47
+ }
package/src/index.d.ts ADDED
@@ -0,0 +1,20 @@
1
+ import type { CmbModuleDescriptor } from "@moshaver/cmb-kernel";
2
+
3
+ export const HEALTH_MODULE: CmbModuleDescriptor;
4
+
5
+ export type ReadinessProbe = Readonly<{
6
+ name: string;
7
+ check: () => void | Promise<void>;
8
+ }>;
9
+
10
+ export class ReadinessError extends Error {
11
+ readonly probe: string;
12
+ readonly cause: unknown;
13
+ constructor(probe: string, cause: unknown);
14
+ }
15
+
16
+ export class CmbHealthService {
17
+ constructor(options: { serviceName: string; probes?: readonly ReadinessProbe[] });
18
+ health(): { service: string; status: "ok" };
19
+ ready(): Promise<Record<string, "ready">>;
20
+ }
package/src/index.js ADDED
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+
3
+ const { defineModule } = require("@moshaver/cmb-kernel");
4
+
5
+ const HEALTH_MODULE = defineModule({
6
+ id: "health",
7
+ version: "0.1.0",
8
+ kind: "foundation",
9
+ dependencies: ["kernel"],
10
+ provides: ["health.service"],
11
+ health: ["liveness", "readiness"],
12
+ configuration: { serviceName: "required", probes: "optional" },
13
+ });
14
+
15
+ class ReadinessError extends Error {
16
+ constructor(probe, cause) {
17
+ super(`Readiness probe failed: ${probe}`);
18
+ this.name = "ReadinessError";
19
+ this.probe = probe;
20
+ this.cause = cause;
21
+ }
22
+ }
23
+
24
+ class CmbHealthService {
25
+ constructor(options) {
26
+ if (!options || typeof options !== "object") throw new TypeError("Health options are required.");
27
+ this.serviceName = String(options.serviceName ?? "").trim();
28
+ if (!this.serviceName) throw new TypeError("Health serviceName is required.");
29
+
30
+ this.probes = Array.from(options.probes ?? []);
31
+ const names = new Set();
32
+ for (const probe of this.probes) {
33
+ if (!probe || typeof probe !== "object" || typeof probe.check !== "function") throw new TypeError("Each readiness probe requires a check() function.");
34
+ const name = String(probe.name ?? "").trim();
35
+ if (!name) throw new TypeError("Each readiness probe requires a name.");
36
+ if (names.has(name)) throw new TypeError(`Duplicate readiness probe: ${name}`);
37
+ names.add(name);
38
+ }
39
+ }
40
+
41
+ health() {
42
+ return { service: this.serviceName, status: "ok" };
43
+ }
44
+
45
+ async ready() {
46
+ const result = {};
47
+ for (const probe of this.probes) {
48
+ try {
49
+ await probe.check();
50
+ result[probe.name] = "ready";
51
+ } catch (cause) {
52
+ throw new ReadinessError(probe.name, cause);
53
+ }
54
+ }
55
+ return result;
56
+ }
57
+ }
58
+
59
+ module.exports = {
60
+ HEALTH_MODULE,
61
+ ReadinessError,
62
+ CmbHealthService,
63
+ };