Skip to content

Commit ac578dd

Browse files
committed
chore: clean up husky scripts and enhance README with security policy and features
1 parent 4ce3d29 commit ac578dd

File tree

5 files changed

+183
-47
lines changed

5 files changed

+183
-47
lines changed

.husky/commit-msg

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1 @@
1-
#!/usr/bin/env sh
2-
. "$(dirname -- "$0")/_/husky.sh"
3-
41
npx commitlint --edit $1

.husky/pre-commit

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1 @@
1-
#!/bin/sh
2-
. "$(dirname "$0")/_/husky.sh"
3-
41
npx lint-staged

README.md

Lines changed: 73 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,51 @@
1-
First DI
2-
=====
1+
# first-di
32

4-
Easy dependency injection for TypeScript applications
3+
[![npm version](https://img.shields.io/npm/v/first-di.svg)](https://www.npmjs.com/package/first-di)
4+
[![npm downloads](https://img.shields.io/npm/dm/first-di.svg)](https://www.npmjs.com/package/first-di)
5+
[![license](https://img.shields.io/npm/l/first-di.svg)](https://github.com/LabEG/first-di/blob/master/LICENSE)
6+
[![Build Status](https://github.com/LabEG/first-di/workflows/Test%20Pull%20Request/badge.svg)](https://github.com/LabEG/first-di/actions)
57

6-
Installation
7-
------
8+
Lightweight and powerful dependency injection container for TypeScript applications
9+
10+
---
11+
12+
## Overview
13+
14+
**first-di** is a modern, type-safe dependency injection container designed specifically for TypeScript applications. It provides a clean and intuitive API for managing dependencies with minimal configuration and zero runtime dependencies.
15+
16+
### Key Features
17+
18+
- 🚀 **Zero Dependencies** - No external runtime dependencies required
19+
- 💡 **Two Operation Modes** - Optional DI for simplicity, Classic DI for advanced scenarios
20+
- 🔄 **Multiple Lifecycles** - Singleton, Transient, Per-Instance, and Per-Access patterns
21+
- 🎯 **Type-Safe** - Full TypeScript support with decorator-based metadata
22+
- 🔧 **Flexible Scoping** - Support for multiple isolated DI containers
23+
- 🧪 **Test-Friendly** - Easy mocking and overriding for unit tests
24+
- 📦 **Extensible** - Built on OOP/SOLID principles for easy customization
25+
26+
---
27+
28+
## Installation
829

930
For the latest stable version:
1031

11-
```Bash
32+
```bash
1233
npm i first-di
1334
```
1435

15-
Features
16-
------
36+
## Quick Start
1737

18-
- Easy and powerful dependency injection for any TypeScript application.
19-
- 2 modes of work. Optional DI - for most apps. Classic DI - for advanced apps.
20-
- Support for multiple scopes.
21-
- Supports multiple life cycles.
22-
- Dependency-free. Dependencies are used only for development.
38+
### Prerequisites
2339

24-
Setup
25-
------
40+
Install [reflect-metadata](https://www.npmjs.com/package/reflect-metadata) package and import it in your application entry point:
2641

27-
Install [reflect-metadata](https://www.npmjs.com/package/reflect-metadata) package and import it in the root TypeScript file. This package is needed to support reflection and is a mandatory requirement of TypeScript.
42+
```bash
43+
npm install reflect-metadata
44+
```
2845

29-
In tsconfig.json enable compiler options:
46+
Enable the following compiler options in `tsconfig.json`:
3047

31-
```Json
48+
```json
3249
{
3350
"compilerOptions": {
3451
...
@@ -40,10 +57,13 @@ In tsconfig.json enable compiler options:
4057

4158
```
4259

43-
Using in Optional DI mode
44-
------
60+
---
61+
62+
## Usage
63+
64+
### Optional DI Mode
4565

46-
Just write classes and inject dependencies through class constructors. When the 'resolve' function is called, all dependencies will be resolved.
66+
The simplest approach - write classes and inject dependencies through constructors. All dependencies are automatically resolved when calling `resolve()`.
4767

4868
```typescript
4969
import { resolve, override, reflection } from "first-di";
@@ -109,10 +129,9 @@ if (process.env.NODE_ENV === "test") {
109129
}
110130
```
111131

112-
Using in Classic DI mode
113-
------
132+
### Classic DI Mode
114133

115-
In professional mode Abstract classes are used instead of interfaces. TypeScript does not generate interfaces for working in runtime. Abstract classes serve as the abstract base class. So instead of interfaces, you need to write Abstract classes.
134+
For advanced scenarios, use abstract classes as contracts instead of interfaces. Abstract classes generate runtime metadata that TypeScript interfaces cannot provide.
116135

117136
```typescript
118137
import { resolve, override, reflection } from "first-di";
@@ -193,8 +212,7 @@ if (process.env.NODE_ENV === "test") {
193212
}
194213
```
195214

196-
Options
197-
------
215+
## Options
198216

199217
First DI has several points for customizing dependency options:
200218

@@ -214,8 +232,7 @@ Options have the following properties:
214232

215233
PER_ACCESS - Create new instance on each access to resolved property.
216234

217-
Scopes
218-
------
235+
## Scopes
219236

220237
Support multiple scopes
221238

@@ -233,18 +250,21 @@ const serviceScopeB = scopeB.resolve(ProductionService);
233250
const dataB = await serviceScopeB.getData();
234251
```
235252

236-
API
237-
------
253+
---
238254

239-
First DI also has an API for extended use.
255+
## API Reference
240256

241-
- override - Function. Override dependency and resolve options.
242-
- resolve - Function. Resolves dependency with default options or specified.
243-
- singleton - Function. Resolve singleton.
244-
- instance - Function. Resolve new instance.
245-
- reset - Function. Reset all singleton list and override list, but doesn't reset global options.
257+
### Core Functions
246258

247-
Resolve, singleton, instance - can be used to implement the Service Locator.
259+
- **`override(fromClass, toClass, options?)`** - Override dependency resolution with custom implementation
260+
- **`resolve(class, options?)`** - Resolve dependency with specified or default options
261+
- **`singleton(class)`** - Resolve as singleton instance
262+
- **`instance(class)`** - Always create new instance
263+
- **`reset()`** - Clear all singletons and overrides (preserves global options)
264+
265+
### Service Locator Pattern
266+
267+
The API functions can be used to implement the Service Locator pattern:
248268

249269
```typescript
250270
import { singleton, instance, resolve, AutowiredLifetimes } from "first-di";
@@ -260,10 +280,13 @@ class ApiDemo {
260280
}
261281
```
262282

263-
Extension DI
264-
------
283+
---
284+
285+
## Advanced Usage
265286

266-
First DI uses OOP and SOLID design principles. Each part of DI can be overridden or extended after inheritance from the base class.
287+
### Extending the DI Container
288+
289+
Built on OOP and SOLID principles, every component can be extended or customized:
267290

268291
```typescript
269292
import { DI } from "first-di";
@@ -275,3 +298,13 @@ class MyDI extends DI {
275298
}
276299
}
277300
```
301+
302+
---
303+
304+
## Contributing
305+
306+
Contributions are welcome! Please read our [Contributing Guide](CONTRIBUTING.md) and [Code of Conduct](CODE_OF_CONDUCT.md) before submitting pull requests.
307+
308+
## License
309+
310+
MIT © [Eugene Labutin](https://github.com/LabEG)

SECURITY.md

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
# Security Policy
2+
3+
## Supported Versions
4+
5+
We actively support the following versions of `first-di` with security updates:
6+
7+
| Version | Supported |
8+
| ------- | ------------------ |
9+
| 3.x | :white_check_mark: |
10+
| 2.x | :x: |
11+
| < 2.0 | :x: |
12+
13+
## Reporting a Vulnerability
14+
15+
We take the security of `first-di` seriously. If you discover a security vulnerability, please follow these steps:
16+
17+
### How to Report
18+
19+
1. **DO NOT** open a public GitHub issue for security vulnerabilities
20+
2. Send a detailed report to the repository maintainer via:
21+
- GitHub Security Advisory: [Report a vulnerability](https://github.com/LabEG/first-di/security/advisories/new)
22+
- Email: Create an issue in the [issue tracker](https://github.com/LabEG/first-di/issues) marked as **Security** (if no sensitive details need to be shared)
23+
24+
### What to Include
25+
26+
Please provide the following information in your report:
27+
28+
- **Description**: A clear description of the vulnerability
29+
- **Impact**: What could an attacker accomplish by exploiting this vulnerability
30+
- **Reproduction**: Step-by-step instructions to reproduce the issue
31+
- **Version**: The version of `first-di` affected
32+
- **Environment**: Relevant environment details (Node.js version, TypeScript version, etc.)
33+
- **Suggested Fix** (optional): If you have ideas on how to fix the vulnerability
34+
35+
### Response Timeline
36+
37+
- **Initial Response**: Within 48 hours of receiving the report
38+
- **Status Update**: Within 7 days with either a fix timeline or request for more information
39+
- **Resolution**: Security patches will be released as soon as possible, typically within 14 days for critical issues
40+
41+
### Security Update Process
42+
43+
1. The vulnerability is confirmed and assessed
44+
2. A fix is developed and tested
45+
3. A security advisory is prepared
46+
4. A new version is released with the fix
47+
5. The security advisory is published with CVE (if applicable)
48+
49+
## Security Best Practices
50+
51+
When using `first-di`:
52+
53+
### For Package Consumers
54+
55+
- Always use the latest stable version
56+
- Regularly update dependencies using `npm update` or `npm audit fix`
57+
- Review the [CHANGELOG](./CHANGELOG.md) for security-related updates
58+
- Use `npm audit` to check for known vulnerabilities in dependencies
59+
60+
### For Contributors
61+
62+
- Follow secure coding practices
63+
- Run `npm audit` before submitting pull requests
64+
- Never commit sensitive information (API keys, passwords, tokens)
65+
- Test changes thoroughly with various configurations
66+
67+
## Dependency Security
68+
69+
This package has minimal dependencies (only reflect-metadata as peer dependency). We:
70+
71+
- Monitor security advisories for all dependencies
72+
- Update dependencies promptly when security issues are discovered
73+
- Use `npm audit` in our CI/CD pipeline
74+
- Follow semantic versioning to ensure stable updates
75+
76+
## Known Security Considerations
77+
78+
As a dependency injection library, `first-di`:
79+
80+
- **Executes constructor code** - ensure dependencies are from trusted sources
81+
- **Does not access network resources** - all operations are local
82+
- **Does not handle sensitive data** - it only manages object instantiation
83+
- **Runs in all environments** - part of your application runtime
84+
85+
However, always ensure you:
86+
87+
- Install packages from official npm registry
88+
- Verify package integrity using `npm audit`
89+
- Review configuration changes before applying
90+
91+
## Disclosure Policy
92+
93+
When a security vulnerability is fixed:
94+
95+
1. We will credit the reporter (unless they wish to remain anonymous)
96+
2. Details will be disclosed after a fix is available
97+
3. We will publish a security advisory on GitHub
98+
4. The vulnerability will be documented in the CHANGELOG
99+
100+
## Contact
101+
102+
For any security-related questions or concerns, please:
103+
104+
- Open a [GitHub Security Advisory](https://github.com/LabEG/first-di/security/advisories/new)
105+
- Create an issue at: <https://github.com/LabEG/first-di/issues>
106+
107+
---
108+
109+
Thank you for helping keep `first-di` and its users safe!

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
"build": "rm -rf dist/ && tsc --project tsconfig.build.json && node ./dist/index.js",
3737
"release": "cliff-jumper --name 'first-di' --package-path '.' --no-skip-changelog --no-skip-tag",
3838
"prepublishOnly": "npm run lint && npm run build && npm run test",
39-
"prepare": "husky install"
39+
"prepare": "husky"
4040
},
4141
"peerDependencies": {
4242
"reflect-metadata": ">=0.1.0"

0 commit comments

Comments
 (0)