{"_id":"@454creative/easy-security","name":"@454creative/easy-security","dist-tags":{"latest":"2.0.0"},"versions":{"2.0.0":{"name":"@454creative/easy-security","version":"2.0.0","description":"Comprehensive security library for NestJS applications with authentication, authorization, rate limiting, and AWS integration","main":"dist/index.js","types":"dist/index.d.ts","scripts":{"build":"tsc","test":"jest","test:watch":"jest --watch","test:coverage":"jest --coverage","test:ci":"jest --ci --coverage --watchAll=false","lint":"eslint src/**/*.ts","lint:fix":"eslint src/**/*.ts --fix","prepublishOnly":"npm run build && npm run test:ci"},"keywords":["nestjs","security","authentication","authorization","rate-limiting","aws","cognito","jwt","iam","rbac","financial","compliance"],"author":{"name":"454 Creative"},"license":"MIT","publishConfig":{"registry":"https://registry.npmjs.org/"},"peerDependencies":{"@nestjs/common":"^10.0.0","@nestjs/config":"^3.2.3","@nestjs/core":"^10.0.0","@nestjs/jwt":"^10.2.0","@nestjs/passport":"^10.0.0","amazon-cognito-identity-js":"^6.0.0","aws-sdk":"^2.1000.0","aws4":"^1.13.2","ioredis":"^5.4.1","jwks-rsa":"^3.1.0","passport":"^0.7.0","passport-custom":"^1.1.1","passport-jwt":"^4.0.1","reflect-metadata":"^0.2.0","rxjs":"^7.8.1"},"optionalDependencies":{"@nestjs/common":"^10.0.0","@nestjs/config":"^3.2.3","@nestjs/core":"^10.0.0","@nestjs/jwt":"^10.2.0","@nestjs/passport":"^10.0.0"},"devDependencies":{"@aws-sdk/client-s3":"^3.872.0","@nestjs/swagger":"^8.1.1","@nestjs/testing":"^10.4.20","@types/aws-lambda":"^8.10.0","@types/jest":"^29.0.0","@types/node":"^20.0.0","@types/passport-jwt":"^4.0.1","@typescript-eslint/eslint-plugin":"^6.0.0","@typescript-eslint/parser":"^6.0.0","amazon-cognito-identity-js":"^6.3.15","aws-sdk":"^2.1692.0","eslint":"^8.0.0","ioredis":"^5.7.0","jest":"^29.0.0","jwks-rsa":"^3.2.0","passport-custom":"^1.1.1","ts-jest":"^29.0.0","typescript":"^5.0.0"},"repository":{"type":"git","url":"git+ssh://git@bitbucket.org/454creative/easy-security.git"},"bugs":{"url":"https://bitbucket.org/454creative/easy-security/issues"},"homepage":"https://bitbucket.org/454creative/easy-security#readme","_id":"@454creative/easy-security@2.0.0","gitHead":"11eb4a0f08a3bffa6958d199bb4a8960b4f32974","_nodeVersion":"20.13.1","_npmVersion":"10.5.2","dist":{"integrity":"sha512-0y0W/lmwkyvgV5H27rH8KO3KOUrjBxjM2wGsEdgrlPOwopFpNnTdNCEjb9FydA9PPb0xO9LylGLhf6LDkEppKA==","shasum":"f8447e82c9136d8f7e24c229944b84f4aff68dbd","tarball":"https://registry.npmjs.org/@454creative/easy-security/-/easy-security-2.0.0.tgz","fileCount":199,"unpackedSize":642930,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEYCIQDcl+R+yT5KzkJYJjGMHGQa8KZtYFumsxWZOLKXTcLmfQIhAMmgkaglmO7Z69fh0H8q68lOSguE4Rn9e6hfIAoCS9nC"}]},"_npmUser":{"name":"454-creative","email":"technology@454creative.com"},"directories":{},"maintainers":[{"name":"454-creative","email":"technology@454creative.com"},{"name":"454-marissa","email":"marissa@454creative.com"},{"name":"will_454creative","email":"will@454creative.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/easy-security_2.0.0_1755718921573_0.777297902220202"},"_hasShrinkwrap":false}},"time":{"created":"2025-08-20T19:42:01.504Z","2.0.0":"2025-08-20T19:42:01.782Z","modified":"2025-08-20T19:42:02.146Z"},"maintainers":[{"name":"454-creative","email":"technology@454creative.com"},{"name":"454-marissa","email":"marissa@454creative.com"},{"name":"will_454creative","email":"will@454creative.com"}],"description":"Comprehensive security library for NestJS applications with authentication, authorization, rate limiting, and AWS integration","homepage":"https://bitbucket.org/454creative/easy-security#readme","keywords":["nestjs","security","authentication","authorization","rate-limiting","aws","cognito","jwt","iam","rbac","financial","compliance"],"repository":{"type":"git","url":"git+ssh://git@bitbucket.org/454creative/easy-security.git"},"author":{"name":"454 Creative"},"bugs":{"url":"https://bitbucket.org/454creative/easy-security/issues"},"license":"MIT","readme":"# Easy Security Library\n\nA comprehensive security library for NestJS applications providing authentication, authorization, rate limiting, and AWS integration.\n\n## 🎯 **Core Philosophy**\n\nThis library focuses on **business logic** and **core security services** rather than presentation layer concerns. Controllers are provided as examples only - implement your own controllers to match your application's API design.\n\n## 🚀 **Quick Start**\n\n### Installation\n\n```bash\nnpm install @454creative/easy-security\n```\n\n### Basic Setup\n\n```typescript\nimport { EasySecurityModule } from '@454creative/easy-security';\n\n@Module({\n  imports: [\n    EasySecurityModule.forRoot({\n      // AWS Cognito configuration\n      cognito: {\n        userPoolId: process.env.AWS_COGNITO_USER_POOL_ID,\n        clientId: process.env.AWS_COGNITO_CLIENT_ID,\n        region: process.env.AWS_REGION,\n      },\n      \n      // JWT configuration\n      jwt: {\n        secret: process.env.JWT_SECRET,\n        expiresIn: '1d',\n        issuer: process.env.JWT_ISSUER,\n        audience: process.env.JWT_AUDIENCE,\n      },\n    }),\n  ],\n})\nexport class AppModule {}\n```\n\n## 🔧 **Core Services**\n\n### Authentication Services\n\n```typescript\nimport { CognitoService, AuthService } from '@454creative/easy-security';\n\n@Injectable()\nexport class MyAuthService {\n  constructor(\n    private cognitoService: CognitoService,\n    private authService: AuthService,\n  ) {}\n\n  async login(credentials: AuthLoginDto) {\n    return this.cognitoService.authenticateUser(credentials);\n  }\n\n  async register(userData: AuthRegisterDto) {\n    return this.cognitoService.registerUser(userData);\n  }\n}\n```\n\n### Authorization Services\n\n```typescript\nimport { PermissionService } from '@454creative/easy-security';\n\n@Injectable()\nexport class MyAuthorizationService {\n  constructor(private permissionService: PermissionService) {}\n\n  async checkAccess(userRoles: string[], requiredPermissions: string[]) {\n    return this.permissionService.hasRequiredPermissions(userRoles, requiredPermissions);\n  }\n}\n```\n\n### Rate Limiting\n\n```typescript\nimport { RateLimiterService } from '@454creative/easy-security';\n\n@Injectable()\nexport class MyRateLimitService {\n  constructor(private rateLimiterService: RateLimiterService) {}\n\n  async checkRateLimit(userId: string, action: string) {\n    return this.rateLimiterService.checkRateLimit(userId, action);\n  }\n}\n```\n\n## 🛡️ **Guards & Decorators**\n\n### Guards\n\n```typescript\nimport { AuthGuard, RolesGuard, RateLimiterGuard } from '@454creative/easy-security';\n\n@Controller('api')\nexport class MyController {\n  @Get('protected')\n  @UseGuards(AuthGuard)\n  getProtectedData() {\n    return { message: 'Protected data' };\n  }\n\n  @Get('admin')\n  @UseGuards(RolesGuard)\n  @Roles('ADMIN')\n  getAdminData() {\n    return { message: 'Admin data' };\n  }\n\n  @Post('api-call')\n  @UseGuards(RateLimiterGuard)\n  @RateLimit(100, 60000) // 100 requests per minute\n  makeApiCall() {\n    return { message: 'API call' };\n  }\n}\n```\n\n### Decorators\n\n```typescript\nimport { Roles, Permissions, RateLimit } from '@454creative/easy-security';\n\n@Controller('users')\nexport class UserController {\n  @Get()\n  @Roles('ADMIN', 'USER')\n  @Permissions('READ_USERS')\n  getUsers() {\n    // Implementation\n  }\n\n  @Post()\n  @Roles('ADMIN')\n  @Permissions('CREATE_USERS')\n  @RateLimit(10, 60000) // 10 requests per minute\n  createUser() {\n    // Implementation\n  }\n}\n```\n\n## 🔐 **Authentication Strategies**\n\nThe library supports multiple authentication strategies:\n\n- **JWT Strategy** - Standard JWT token authentication\n- **Lambda Strategy** - AWS Lambda function authentication\n- **AWS SigV4 Strategy** - AWS signature authentication\n- **Task Role Strategy** - AWS ECS task role authentication\n- **Auto Strategy** - Automatically selects the best strategy\n\n```typescript\nimport { JwtStrategy, AutoStrategy } from '@454creative/easy-security';\n\n// Use specific strategy\n@UseGuards(AuthGuard('jwt'))\ngetData() { }\n\n// Use auto strategy (recommended)\n@UseGuards(AuthGuard('auto'))\ngetData() { }\n```\n\n## 📝 **Implementing Your Own Controllers**\n\n### Basic Authentication Controller\n\n```typescript\nimport { Controller, Post, Body, UseGuards } from '@nestjs/common';\nimport { CognitoService, AuthGuard } from '@454creative/easy-security';\n\n@Controller('auth')\nexport class AuthController {\n  constructor(private cognitoService: CognitoService) {}\n\n  @Post('login')\n  async login(@Body() credentials: AuthLoginDto) {\n    return this.cognitoService.authenticateUser(credentials);\n  }\n\n  @Post('register')\n  async register(@Body() userData: AuthRegisterDto) {\n    return this.cognitoService.registerUser(userData);\n  }\n\n  @Get('profile')\n  @UseGuards(AuthGuard)\n  async getProfile(@Request() req) {\n    return req.user;\n  }\n}\n```\n\n### Advanced Token Management Controller\n\n```typescript\nimport { Controller, Post, Param, UseGuards } from '@nestjs/common';\nimport { CognitoService, AuthGuard } from '@454creative/easy-security';\n\n@Controller('token-management')\n@UseGuards(AuthGuard)\nexport class TokenManagementController {\n  constructor(private cognitoService: CognitoService) {}\n\n  @Post('revoke-user-tokens/:username')\n  async revokeUserTokens(@Param('username') username: string) {\n    return this.cognitoService.revokeUserTokens(username);\n  }\n\n  @Post('revoke-refresh-token')\n  async revokeRefreshToken(@Body() body: { refreshToken: string }) {\n    return this.cognitoService.revokeRefreshToken(body.refreshToken);\n  }\n}\n```\n\n## 📚 **Examples**\n\nThe library includes example controllers in the `examples/` folder:\n\n- `AuthController` - Basic authentication endpoints\n- `TokenManagementController` - Advanced token management\n- `AuthTestController` - Testing endpoints\n\nThese are for reference only - implement your own controllers to match your application's needs.\n\n## 🔧 **Configuration**\n\n### Full Configuration Example\n\n```typescript\nconst securityConfig: EasySecurityConfig = {\n  // AWS Cognito\n  cognito: {\n    userPoolId: process.env.AWS_COGNITO_USER_POOL_ID,\n    clientId: process.env.AWS_COGNITO_CLIENT_ID,\n    region: process.env.AWS_REGION,\n    authority: process.env.AWS_COGNITO_AUTHORITY,\n  },\n\n  // JWT Configuration\n  jwt: {\n    secret: process.env.JWT_SECRET,\n    expiresIn: '1d',\n    issuer: process.env.JWT_ISSUER,\n    audience: process.env.JWT_AUDIENCE,\n    algorithms: ['RS256'],\n  },\n\n  // Rate Limiting\n  rateLimiting: {\n    enabled: true,\n    redis: {\n      host: process.env.REDIS_HOST,\n      port: parseInt(process.env.REDIS_PORT),\n      password: process.env.REDIS_PASSWORD,\n    },\n  },\n\n  // Feature Flags\n  features: {\n    authentication: true,\n    authorization: true,\n    rateLimiting: true,\n    auditLogging: true,\n  },\n\n  // RBAC Configuration\n  rbac: {\n    adminRole: 'ADMIN',\n    defaultRole: 'USER',\n    roles: ['ADMIN', 'USER', 'READONLY'],\n  },\n};\n```\n\n## 🧪 **Testing**\n\n```bash\n# Run all tests\nnpm test\n\n# Run tests with coverage\nnpm run test:coverage\n\n# Run specific test file\nnpm test -- --testPathPattern=auth.service.spec.ts\n```\n\n## 📦 **Exports**\n\n### Core Services\n- `CognitoService` - AWS Cognito integration\n- `AuthService` - JWT token management\n- `PermissionService` - Role-based access control\n- `RateLimiterService` - Rate limiting functionality\n- `FeatureFlagService` - Feature flag management\n\n### Guards\n- `AuthGuard` - Authentication guard\n- `RolesGuard` - Role-based authorization guard\n- `RateLimiterGuard` - Rate limiting guard\n\n### Decorators\n- `@Roles()` - Role-based access control\n- `@Permissions()` - Permission-based access control\n- `@RateLimit()` - Rate limiting configuration\n\n### Strategies\n- `JwtStrategy` - JWT authentication\n- `LambdaStrategy` - AWS Lambda authentication\n- `AwsSigV4Strategy` - AWS signature authentication\n- `TaskRoleStrategy` - AWS task role authentication\n- `AutoStrategy` - Automatic strategy selection\n\n### Utilities\n- `AuthUtils` - Authentication utilities\n- `ROLES` - Role constants\n- `PERMISSIONS` - Permission constants\n\n## 🤝 **Contributing**\n\n1. Fork the repository\n2. Create a feature branch\n3. Make your changes\n4. Add tests\n5. Submit a pull request\n\n## 📄 **License**\n\nMIT License - see LICENSE file for details. ","readmeFilename":"README.md","_rev":"1-0db9f09d09037858c92b0e9918072dae"}