Compare commits
26
Commits
4abeb3c62a
..
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8a278281ce | ||
|
|
06f4fd06ff | ||
|
|
1bba2b518e | ||
|
|
4401695e21 | ||
|
|
c3ce5c2f22 | ||
|
|
e6c115164e | ||
|
|
a50b57b5ea | ||
|
|
6ee7a7cda4 | ||
|
|
6ffff9ef7b | ||
|
|
e0bf3882be | ||
|
|
a5db9d69b3 | ||
|
|
583dd9bc4b | ||
|
|
54c01e3c6c | ||
|
|
b78a6bce2c | ||
|
|
737c4fa5d1 | ||
|
|
6f81463280 | ||
|
|
2cd377ca7a | ||
|
|
470396c2f1 | ||
|
|
1826bc789e | ||
|
|
6d6a771c7c | ||
|
|
95d03bb987 | ||
|
|
81e8258c1a | ||
|
|
0bb9212a10 | ||
|
|
d3a8eab118 | ||
|
|
f8f115ae26 | ||
|
|
ae30b9bf16 |
@@ -12,8 +12,13 @@ jobs:
|
||||
steps:
|
||||
- name: Deploy
|
||||
run: |
|
||||
git config --global --add safe.directory /DATA/git/RayLab-Core
|
||||
|
||||
cd /DATA/git/RayLab-Core
|
||||
|
||||
git fetch origin
|
||||
git reset --hard origin/main
|
||||
|
||||
cd /DATA/docker/raylab-core
|
||||
|
||||
docker compose up -d --build
|
||||
|
||||
+1
-1
@@ -2,4 +2,4 @@ node_modules
|
||||
RayLab-Core.zip
|
||||
RayLab-Core.rar
|
||||
.env
|
||||
dist
|
||||
dist/
|
||||
|
||||
@@ -1,165 +0,0 @@
|
||||
Phase 1 Deliverables - RayLab Core
|
||||
=================================
|
||||
|
||||
Contents
|
||||
--------
|
||||
1. Architecture explanation
|
||||
2. Folder structure
|
||||
3. Source code references (what was added/changed)
|
||||
4. Database schema (Prisma)
|
||||
5. Migration (SQL)
|
||||
6. Seed data (script)
|
||||
7. API design (initial endpoints)
|
||||
8. Design decisions
|
||||
9. Advantages
|
||||
10. Possible future extensions
|
||||
11. How to run (migrate & seed)
|
||||
|
||||
1) Architecture explanation
|
||||
--------------------------
|
||||
Phase 1 establishes the foundational data model and project layout for RayLab Core. It prepares the system for secure integration with Authentik (OIDC) and supports role/permission based authorization owned by RayLab Core. The design follows Clean Architecture, SOLID principles, modular NestJS structure, and Prisma for type-safe DB access.
|
||||
|
||||
Key principles applied:
|
||||
- RayLab Core does NOT implement authentication; it only validates external OIDC tokens (Phase 2).
|
||||
- Roles, permissions, role mappings, users, and audit logs are owned by RayLab Core. Media Manager and Scheduler are intentionally excluded from Phase 1 and will be implemented in Phase 3.
|
||||
- No Group entity is created in RayLab Core; only mapping configuration (auth group name string -> role) is stored.
|
||||
- Critical operations (synchronization) will be transactional (Phase 2 implementation).
|
||||
|
||||
2) Folder structure
|
||||
-------------------
|
||||
(Only top-level relevant directories shown)
|
||||
|
||||
- prisma/
|
||||
- schema.prisma // Prisma schema (source of truth for DB)
|
||||
- migrations/0001_init/ // Initial SQL migration
|
||||
- seed.ts // Seed script (idempotent upserts)
|
||||
|
||||
- src/
|
||||
- main.ts
|
||||
- app.module.ts
|
||||
- modules/
|
||||
- identity/ // DDD-based users/roles/permissions implementation
|
||||
- auth/ // (Phase 2) OIDC integration
|
||||
- authorization/ // (Phase 2) permission guards & services
|
||||
- health/ // basic health endpoint (added)
|
||||
- media/ // media manager module (phase 3)
|
||||
- audit/ // audit module (phase 3)
|
||||
- ... other domain modules
|
||||
- shared/
|
||||
- prisma.service.ts
|
||||
- ...
|
||||
|
||||
3) Source code (what was added/changed)
|
||||
---------------------------------------
|
||||
- prisma/schema.prisma (UPDATED): replaced with production-ready schema containing:
|
||||
User, Role, Permission, RolePermission, UserRole, AuthGroupRoleMapping, AuditLog
|
||||
|
||||
- prisma/migrations/0001_init/migration.sql (ADDED): initial SQL migration DDL
|
||||
|
||||
- prisma/seed.ts (UPDATED): seed script that creates default roles, permissions, role-permission assignments, and Authentik group -> role mappings
|
||||
|
||||
- src/modules/health/* (ADDED): HealthModule, Controller, Service (thin controller)
|
||||
|
||||
- src/shared/prisma.service.ts (EXISTING): PrismaService (already present)
|
||||
|
||||
4) Database schema
|
||||
------------------
|
||||
The Prisma schema (prisma/schema.prisma) is the authoritative schema. High-level model summary:
|
||||
- User: id (uuid), externalId (unique), email, name, picture, metadata, createdAt, updatedAt
|
||||
- Role: id, name (unique), displayName, description
|
||||
- Permission: id, name (unique), description
|
||||
- RolePermission: join table role <-> permission (unique constraint roleId+permissionId)
|
||||
- UserRole: join table user <-> role with source (e.g., 'authentik') and syncedAt timestamp (unique userId+roleId)
|
||||
- AuthGroupRoleMapping: mapping table authGroup (string) -> roleId. One authGroup may map to multiple roles (no uniqueness enforced on authGroup).
|
||||
- AuditLog: append-only audit logs with JSON details
|
||||
|
||||
|
||||
Indexes and constraints are included for common lookup paths. The migration SQL contains explicit DDL statements.
|
||||
|
||||
5) Migration
|
||||
------------
|
||||
- prisma/migrations/0001_init/migration.sql contains the SQL to create the schema.
|
||||
- The migration file includes CREATE EXTENSION IF NOT EXISTS "pgcrypto" to provide gen_random_uuid().
|
||||
- Recommended migration procedure in production:
|
||||
1. Ensure backups and schedule maintenance window for initial deployment.
|
||||
2. Run migrations with Prisma or psql: "psql < migration.sql" or use "prisma migrate deploy" after generating migrations from schema.prisma.
|
||||
|
||||
6) Seed data
|
||||
------------
|
||||
- prisma/seed.ts seeds the following:
|
||||
- Default roles: Owner, Employee, Family
|
||||
- Default permissions following resource.action naming convention (users.create, users.read, ..., scheduler.manage)
|
||||
- RolePermission assignments:
|
||||
- Owner receives all permissions
|
||||
- Employee and Family receive reasonable subsets (editable later)
|
||||
- Authentik group mappings:
|
||||
- RL-Owner -> Owner
|
||||
- RL-Employee -> Employee
|
||||
- RL-Family -> Family
|
||||
|
||||
The seed script is idempotent using upsert operations.
|
||||
|
||||
7) API design (initial)
|
||||
-----------------------
|
||||
Phase 1 provides a minimal, safe public surface to verify system health and readiness.
|
||||
- GET /api/health
|
||||
- Returns: { status: 'ok', timestamp, service }
|
||||
|
||||
Identity module controllers (users, roles, permissions) are present under src/modules/identity/presentation/controllers and follow RESTful conventions, but full auth/guards are implemented in Phase 2.
|
||||
|
||||
8) Design decisions
|
||||
-------------------
|
||||
- Prisma selected for type-safe DB access and migrations. (User requested Prisma)
|
||||
- UUID primary keys (Postgres gen_random_uuid()) for scalability and horizontal distribution.
|
||||
- JSONB (Prisma Json) used for flexible metadata and audit details.
|
||||
- AuthGroupRoleMapping stores external group string only; RayLab Core does NOT model Groups as domain entities.
|
||||
- Seed sets conservative permission assignments; owners get full permissions.
|
||||
- Minimal initial API surface (health) avoids unintentionally exposing functionality before auth & guards are in place.
|
||||
|
||||
9) Advantages
|
||||
-------------
|
||||
- Production-ready DB schema with indices and constraints for performance and data integrity.
|
||||
- Modular NestJS structure aligned with Clean Architecture / DDD; easy to extend in subsequent phases.
|
||||
- Prisma provides type-safety and reduces runtime errors.
|
||||
- Seed script allows reproducible environments and CI setup.
|
||||
- Audit and media tables are present to support required domain features.
|
||||
|
||||
10) Possible future extensions
|
||||
------------------------------
|
||||
Planned for Phase 2 and 3 (once Phase 1 is approved):
|
||||
- OIDC validation using openid-client and configuration from env vars
|
||||
- Role synchronization flow (validate token -> read groups -> map -> compute hash -> replace UserRole in transaction -> invalidate permission cache -> write audit)
|
||||
- Permission cache using Redis, invalidation hooks
|
||||
- Auth guards and AuthorizationService for permission checks
|
||||
- Media Manager: presigned URLs, storage backend (S3/MinIO)
|
||||
- Scheduler: BullMQ integration with Redis
|
||||
- Monitoring: Prometheus metrics, structured logging, Sentry
|
||||
|
||||
11) How to run (migrate & seed)
|
||||
-------------------------------
|
||||
Prerequisites:
|
||||
- Node 20+
|
||||
- PostgreSQL reachable via DATABASE_URL env var
|
||||
- Install dependencies: npm ci
|
||||
|
||||
Generate Prisma client and run migration:
|
||||
|
||||
1) Generate Prisma client:
|
||||
npm run prisma:generate
|
||||
|
||||
2) Apply migration (development):
|
||||
npm run prisma:migrate
|
||||
|
||||
Or run SQL directly against the database:
|
||||
psql "$DATABASE_URL" -f prisma/migrations/0001_init/migration.sql
|
||||
|
||||
3) Run seed script:
|
||||
npm run prisma:seed
|
||||
|
||||
4) Start the app (development):
|
||||
npm run start:dev
|
||||
|
||||
Next steps
|
||||
----------
|
||||
Please review Phase 1 deliverables. After your approval I will implement Phase 2 (OIDC module, Authentik integration, Group->Role Sync, Authorization Guard, Permission Cache, Audit logging) following the same level of production-quality implementation.
|
||||
|
||||
+155
-150
@@ -1,146 +1,174 @@
|
||||
API Spec - Contoh REST API (Bahasa Indonesia)
|
||||
API Spec - Identity & Authorization API (Bahasa Indonesia)
|
||||
|
||||
Ringkasan
|
||||
--------
|
||||
API ini adalah contoh RESTful API yang bisa dipakai untuk manajemen pengguna, item, dan pesanan. Menggunakan JSON untuk request/response. Autentikasi memakai Bearer Token (JWT).
|
||||
Spesifikasi berikut disesuaikan dengan controller aktual pada aplikasi: modul Auth (OIDC + internal JWT), modul Identity (Users, Roles, Permissions) dan mekanisme otorisasi berbasis permission.
|
||||
|
||||
Base URL
|
||||
--------
|
||||
- https://api.example.com/v1
|
||||
- https://api.example.com
|
||||
|
||||
Header Umum
|
||||
-----------
|
||||
- Authorization: Bearer <token> (kecuali endpoint login/register)
|
||||
Header Umum & Auth
|
||||
------------------
|
||||
- Content-Type: application/json
|
||||
- Accept: application/json
|
||||
- Otentikasi dapat diberikan dalam dua cara:
|
||||
1) Cookie internal (default flow):
|
||||
- raylab_jwt (internal JWT, httpOnly cookie)
|
||||
- raylab_refresh (internal refresh token, httpOnly cookie)
|
||||
2) Authorization header: Bearer <internal_jwt>
|
||||
- Banyak endpoint melindungi akses dengan JWT dan permission checks. Respons sukses dari controller umumnya dibungkus sebagai:
|
||||
{ "success": true, "data": ..., "meta": { ... } }
|
||||
|
||||
Autentikasi
|
||||
-----------
|
||||
- POST /auth/login
|
||||
- Body (application/json):
|
||||
{
|
||||
"email": "user@example.com",
|
||||
"password": "string"
|
||||
}
|
||||
- Response 200:
|
||||
{
|
||||
"access_token": "<jwt_token>",
|
||||
"token_type": "Bearer",
|
||||
"expires_in": 3600
|
||||
}
|
||||
- Kesalahan: 400 (invalid input), 401 (invalid credentials)
|
||||
Auth (modul /auth)
|
||||
-------------------
|
||||
1) GET /auth/login
|
||||
- Deskripsi: Mulai flow Authorization Code + PKCE. Redirect (302) ke Identity Provider.
|
||||
- Query params:
|
||||
- returnTo (optional) - URL tujuan setelah login
|
||||
- Response: 302 Redirect
|
||||
|
||||
- POST /auth/register
|
||||
- Body:
|
||||
{
|
||||
"name": "Nama User",
|
||||
"email": "user@example.com",
|
||||
"password": "password123"
|
||||
}
|
||||
- Response 201: user created (id, name, email)
|
||||
2) GET /auth/callback
|
||||
- Deskripsi: Endpoint callback OIDC. Menukarkan code/state, membuat internal JWT & refresh token, dan menyetel cookie httpOnly.
|
||||
- Response: 302 Redirect ke returnTo atau '/'
|
||||
- Cookie yang disetel:
|
||||
- raylab_jwt (internal JWT, maxAge sesuai expiresIn)
|
||||
- raylab_refresh (refresh token)
|
||||
|
||||
3) POST /auth/logout
|
||||
- Deskripsi: Invalidate internal refresh token (opsional) dan redirect ke logout identity provider.
|
||||
- Body (optional): { "refreshToken": "..." }
|
||||
- Response: 302 Redirect
|
||||
|
||||
4) POST /auth/refresh
|
||||
- Deskripsi: Tukar refresh token menjadi internal JWT baru.
|
||||
- Input: refresh token di cookie raylab_refresh atau di body { "refreshToken": "..." }
|
||||
- Response 200: { "success": true, "data": { "accessToken": "...", "expiresIn": 3600, ... } }
|
||||
|
||||
5) GET /auth/me
|
||||
- Deskripsi: Ambil data user saat ini dari internal JWT (cookie atau Authorization header).
|
||||
- Response 200: { "success": true, "data": { /* user object */ } }
|
||||
|
||||
Catatan: tidak ada endpoint "/auth/register" atau POST /auth/login berbasis email/password pada controller saat ini — login terjadi via OIDC dan internal session cookies.
|
||||
|
||||
Users (modul /users)
|
||||
--------------------
|
||||
Semua endpoint Users dijalankan di bawah guards: JwtAuthGuard, CurrentUserGuard dan PermissionGuard. Respons mengikuti format { success, data, meta }.
|
||||
|
||||
Endpoint Pengguna (Users)
|
||||
-------------------------
|
||||
1) GET /users
|
||||
- Deskripsi: Mendapatkan daftar pengguna (admin)
|
||||
- Query params:
|
||||
- page (int, optional, default=1)
|
||||
- per_page (int, optional, default=20, max=100)
|
||||
- sort (string, optional, contoh: "created_at:desc")
|
||||
- q (string, optional) - pencarian nama/email
|
||||
- Permission: PermissionType.USER_READ
|
||||
- Deskripsi: List pengguna (paged)
|
||||
- Query params umum: page, per_page, sort, q
|
||||
- Response 200:
|
||||
{
|
||||
"data": [ {"id":1, "name":"...", "email":"..."} , ...],
|
||||
"meta": {"page":1, "per_page":20, "total":123}
|
||||
}
|
||||
{ "success": true, "data": [ /* user list (toResponse) */ ], "meta": { "total": 123 } }
|
||||
|
||||
2) GET /users/{id}
|
||||
- Path params:
|
||||
- id (integer, required)
|
||||
- Response 200: user object
|
||||
- Errors: 404 jika tidak ditemukan
|
||||
2) GET /users/me
|
||||
- Deskripsi: Ambil profil user saat ini (token harus ada di cookie atau header)
|
||||
- Response 200: { "success": true, "data": { /* current user */ }, "meta": {} }
|
||||
|
||||
3) PUT /users/{id}
|
||||
- Path params: id
|
||||
- Body (application/json):
|
||||
{
|
||||
"name": "Nama Baru",
|
||||
"email": "email@baru.com"
|
||||
}
|
||||
- Validasi: email harus format valid; name min 2 karakter
|
||||
- Response 200: updated user
|
||||
|
||||
4) DELETE /users/{id}
|
||||
- Path params: id
|
||||
- Response 204: no content
|
||||
- Permissions: hanya admin
|
||||
|
||||
Endpoint Item (Items)
|
||||
---------------------
|
||||
1) GET /items
|
||||
- Query params:
|
||||
- page, per_page, sort (lihat Users)
|
||||
- category (string, optional)
|
||||
- min_price, max_price (decimal, optional)
|
||||
- Response: list items dengan fields id, name, description, price, stock
|
||||
|
||||
2) POST /items
|
||||
- Body:
|
||||
{
|
||||
"name": "Nama Item",
|
||||
"description": "Deskripsi...",
|
||||
"price": 125000.50,
|
||||
"stock": 10,
|
||||
"category": "Elektronik"
|
||||
}
|
||||
- Validasi:
|
||||
- name (required, max 255)
|
||||
- price (required, >=0)
|
||||
- stock (integer, >=0)
|
||||
- Response 201: created item
|
||||
- Permissions: admin atau vendor
|
||||
|
||||
3) GET /items/{id}
|
||||
- Response 200: item object
|
||||
3) GET /users/:id
|
||||
- Permission: PermissionType.USER_READ
|
||||
- Deskripsi: Ambil user berdasarkan id
|
||||
- Response 200: { "success": true, "data": { /* user */ }, "meta": {} }
|
||||
- 404 jika tidak ditemukan
|
||||
|
||||
4) PUT /items/{id}
|
||||
- Body: fields yang boleh diupdate (name, description, price, stock, category)
|
||||
4) PATCH /users/:id/enable
|
||||
- Permission: PermissionType.USER_UPDATE
|
||||
- Deskripsi: Enable user
|
||||
- Response 200: { "success": true, "data": { /* updated user */ }, "meta": {} }
|
||||
|
||||
5) PATCH /users/:id/disable
|
||||
- Permission: PermissionType.USER_UPDATE
|
||||
- Deskripsi: Disable user
|
||||
- Response 200
|
||||
|
||||
5) DELETE /items/{id}
|
||||
- Response 204
|
||||
6) PATCH /users/:id
|
||||
- Permission: PermissionType.USER_UPDATE
|
||||
- Deskripsi: Update profil user (body berisi fields yang diperbolehkan)
|
||||
- Body contoh: { "name": "Nama Baru", "email": "baru@example.com" }
|
||||
- Response 200: { "success": true, "data": { /* updated user */ }, "meta": {} }
|
||||
|
||||
Endpoint Pesanan (Orders)
|
||||
-------------------------
|
||||
1) POST /orders
|
||||
- Body:
|
||||
{
|
||||
"user_id": 12, // optional jika token sudah mewakili user
|
||||
"items": [
|
||||
{"item_id": 5, "quantity": 2},
|
||||
{"item_id": 7, "quantity": 1}
|
||||
],
|
||||
"shipping_address": "Alamat lengkap",
|
||||
"note": "Catatan opsional"
|
||||
}
|
||||
- Validasi: setiap item quantity >= 1 dan tersedia di stock
|
||||
- Response 201:
|
||||
{
|
||||
"order_id": 987,
|
||||
"status": "pending",
|
||||
"total": 375000.00
|
||||
}
|
||||
7) DELETE /users/:id
|
||||
- Permission: PermissionType.USER_DELETE
|
||||
- Deskripsi: Soft delete user
|
||||
- Response 200: { "success": true, "data": null, "meta": {} }
|
||||
|
||||
2) GET /orders/{id}
|
||||
- Path param: id
|
||||
- Response 200: full order detail (items, prices, shipping, status)
|
||||
- Permissions: hanya pemilik order atau admin
|
||||
8) POST /users/:id/restore
|
||||
- Permission: PermissionType.USER_UPDATE
|
||||
- Deskripsi: Restore user yang di-soft-delete
|
||||
- Response 200: { "success": true, "data": { /* restored user */ }, "meta": {} }
|
||||
|
||||
3) PATCH /orders/{id}/status
|
||||
- Body: {"status": "shipped"}
|
||||
- Allowed status: pending, confirmed, shipped, delivered, cancelled
|
||||
- Permissions: hanya admin atau staff
|
||||
Roles (modul /roles)
|
||||
--------------------
|
||||
Semua route dilindungi oleh JwtAuthGuard, CurrentUserGuard dan PermissionGuard.
|
||||
|
||||
1) GET /roles
|
||||
- Permission: PermissionType.ROLE_READ
|
||||
- Deskripsi: List roles
|
||||
- Query params: page, per_page, q
|
||||
- Response 200: { "success": true, "data": [ /* roles */ ], "meta": { "total": 10 } }
|
||||
|
||||
2) GET /roles/:id
|
||||
- Permission: PermissionType.ROLE_READ
|
||||
- Deskripsi: Ambil role
|
||||
- Response 200
|
||||
|
||||
3) POST /roles
|
||||
- Permission: PermissionType.ROLE_CREATE
|
||||
- Deskripsi: Buat role baru
|
||||
- Body contoh: { "name": "editor", "description": "..." }
|
||||
- Response 200: { "success": true, "data": { /* created role */ }, "meta": {} }
|
||||
|
||||
4) PATCH /roles/:id
|
||||
- Permission: PermissionType.ROLE_UPDATE
|
||||
- Deskripsi: Update role
|
||||
- Response 200
|
||||
|
||||
5) DELETE /roles/:id
|
||||
- Permission: PermissionType.ROLE_DELETE
|
||||
- Deskripsi: Hapus role
|
||||
- Response 200: { "success": true, "data": null, "meta": {} }
|
||||
|
||||
6) POST /roles/:id/permissions
|
||||
- Permission: PermissionType.ROLE_UPDATE
|
||||
- Deskripsi: Assign permission ke role
|
||||
- Body: { "permissionId": "..." }
|
||||
- Response 200: { "success": true, "data": { /* updated role */ }, "meta": {} }
|
||||
|
||||
7) DELETE /roles/:id/permissions/:permissionId
|
||||
- Permission: PermissionType.ROLE_UPDATE
|
||||
- Deskripsi: Remove permission dari role
|
||||
- Response 200
|
||||
|
||||
Permissions (modul /permissions)
|
||||
-------------------------------
|
||||
Semua route dilindungi oleh JwtAuthGuard, CurrentUserGuard dan PermissionGuard.
|
||||
|
||||
1) GET /permissions
|
||||
- Permission: PermissionType.PERMISSION_READ
|
||||
- Deskripsi: List permissions
|
||||
- Response 200: { "success": true, "data": [ /* permissions */ ], "meta": { "total": 20 } }
|
||||
|
||||
2) GET /permissions/:id
|
||||
- Permission: PermissionType.PERMISSION_READ
|
||||
- Deskripsi: Ambil permission
|
||||
- Response 200
|
||||
|
||||
3) POST /permissions
|
||||
- Permission: PermissionType.PERMISSION_CREATE
|
||||
- Deskripsi: Buat permission baru
|
||||
- Body contoh: { "name": "user:create", "description": "..." }
|
||||
- Response 200: { "success": true, "data": { /* created */ }, "meta": {} }
|
||||
|
||||
4) PATCH /permissions/:id
|
||||
- Permission: PermissionType.PERMISSION_UPDATE
|
||||
- Deskripsi: Update permission
|
||||
- Response 200
|
||||
|
||||
5) DELETE /permissions/:id
|
||||
- Permission: PermissionType.PERMISSION_DELETE
|
||||
- Deskripsi: Delete permission
|
||||
- Response 200: { "success": true, "data": null, "meta": {} }
|
||||
|
||||
Format Tanggal dan Numerik
|
||||
--------------------------
|
||||
@@ -150,12 +178,13 @@ Format Tanggal dan Numerik
|
||||
Pagination
|
||||
----------
|
||||
- Gunakan page & per_page
|
||||
- Meta object harus mengandung total, page, per_page, total_pages
|
||||
- Meta object pada controller ini biasanya minimal: { total }
|
||||
|
||||
Response Error Umum
|
||||
-------------------
|
||||
- 400 Bad Request - payload tidak valid
|
||||
{
|
||||
"success": false,
|
||||
"error": "invalid_request",
|
||||
"message": "Deskripsi kesalahan",
|
||||
"details": { "field": ["pesan validasi"] }
|
||||
@@ -166,38 +195,14 @@ Response Error Umum
|
||||
- 429 Too Many Requests - rate limit
|
||||
- 500 Internal Server Error
|
||||
|
||||
Rate Limiting
|
||||
-------------
|
||||
- Contoh: 1000 requests per 1 jam per API key
|
||||
- Header terkait:
|
||||
- X-RateLimit-Limit: 1000
|
||||
- X-RateLimit-Remaining: 750
|
||||
- X-RateLimit-Reset: 1650000000 (epoch seconds)
|
||||
|
||||
Keamanan dan Persyaratan
|
||||
------------------------
|
||||
- Semua permintaan harus lewat HTTPS (TLS 1.2+)
|
||||
- Gunakan header Authorization: Bearer <token>
|
||||
- CORS: domain yang diijinkan harus didaftarkan
|
||||
- Gunakan cookie httpOnly (raylab_jwt / raylab_refresh) untuk flow internal atau header Authorization: Bearer <token>
|
||||
- Validasi input di server (length, tipe, range)
|
||||
- Sanitasi data untuk mencegah injection
|
||||
|
||||
Versioning
|
||||
----------
|
||||
- Versi di URL: /v1/
|
||||
- Buat v2 jika ada breaking change
|
||||
|
||||
Contoh Request/Response (cURL)
|
||||
-----------------------------
|
||||
Login:
|
||||
curl -X POST "https://api.example.com/v1/auth/login" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{"email":"user@example.com","password":"password123"}'
|
||||
|
||||
Ambil daftar item:
|
||||
curl "https://api.example.com/v1/items?page=1&per_page=20" \
|
||||
-H "Authorization: Bearer <token>"
|
||||
|
||||
Footer
|
||||
------
|
||||
Spesifikasi ini adalah contoh umum. Sesuaikan endpoint, nama field, aturan autentikasi, dan kebijakan rate limit sesuai kebutuhan aplikasi Anda.
|
||||
Catatan Akhir
|
||||
------------
|
||||
- Spesifikasi ini disesuaikan dengan controller yang ada: /auth, /users, /roles, /permissions dan mekanisme otorisasi berbasis PermissionType.
|
||||
- Perhatikan bahwa detail field respons (mis. bentuk toResponse pada entitas) dapat berbeda antar resource. Untuk integrasi, gunakan endpoint /auth/me dan /users/me untuk memvalidasi data user yang tersedia.
|
||||
+131
@@ -0,0 +1,131 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.CoreApiClient = exports.CoreApiClientError = void 0;
|
||||
class CoreApiClientError extends Error {
|
||||
status;
|
||||
constructor(message, status) {
|
||||
super(message);
|
||||
this.name = 'CoreApiClientError';
|
||||
this.status = status;
|
||||
}
|
||||
}
|
||||
exports.CoreApiClientError = CoreApiClientError;
|
||||
class CoreApiClient {
|
||||
apiUrl;
|
||||
clientId;
|
||||
clientSecret;
|
||||
timeoutMs;
|
||||
cachedToken = null;
|
||||
tokenExpiry = 0; // epoch ms
|
||||
tokenMarginSec = 60; // safety margin in seconds
|
||||
constructor(options) {
|
||||
this.apiUrl = options?.apiUrl ?? process.env.RAYLAB_CORE_API_URL ?? 'http://localhost:3000';
|
||||
this.clientId = options?.clientId ?? process.env.RAYLAB_BOT_CLIENT_ID ?? '';
|
||||
this.clientSecret = options?.clientSecret ?? process.env.RAYLAB_BOT_CLIENT_SECRET ?? '';
|
||||
this.timeoutMs = options?.timeoutMs ?? 5000;
|
||||
if (!this.clientId || !this.clientSecret) {
|
||||
// keep construction allowed but operations will fail with clear errors
|
||||
}
|
||||
}
|
||||
async fetchWithTimeout(url, init) {
|
||||
const controller = new AbortController();
|
||||
const id = setTimeout(() => controller.abort(), this.timeoutMs);
|
||||
try {
|
||||
const res = await fetch(url, { ...init, signal: controller.signal });
|
||||
return res;
|
||||
}
|
||||
finally {
|
||||
clearTimeout(id);
|
||||
}
|
||||
}
|
||||
isTokenValid() {
|
||||
return !!this.cachedToken && Date.now() < this.tokenExpiry;
|
||||
}
|
||||
async requestAccessToken() {
|
||||
if (!this.clientId || !this.clientSecret) {
|
||||
throw new CoreApiClientError('Missing client credentials');
|
||||
}
|
||||
const url = `${this.apiUrl.replace(/\/$/, '')}/api/v1/auth/token`;
|
||||
const body = JSON.stringify({ client_id: this.clientId, client_secret: this.clientSecret, grant_type: 'client_credentials' });
|
||||
let res;
|
||||
try {
|
||||
res = await this.fetchWithTimeout(url, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body,
|
||||
});
|
||||
}
|
||||
catch (err) {
|
||||
if (err.name === 'AbortError') {
|
||||
throw new CoreApiClientError('Request timeout');
|
||||
}
|
||||
throw new CoreApiClientError('Network error');
|
||||
}
|
||||
if (res.status === 401) {
|
||||
throw new CoreApiClientError('Invalid client credentials', 401);
|
||||
}
|
||||
if (res.status >= 400) {
|
||||
throw new CoreApiClientError(`Token request failed with status ${res.status}`, res.status);
|
||||
}
|
||||
const payload = await res.json();
|
||||
// Expecting { success: true, data: { access_token, token_type, expires_in }, ... }
|
||||
const data = payload?.data;
|
||||
if (!data || !data.access_token) {
|
||||
throw new CoreApiClientError('Invalid token response');
|
||||
}
|
||||
// Cache token
|
||||
this.cachedToken = data.access_token;
|
||||
const expiresIn = typeof data.expires_in === 'number' ? data.expires_in : parseInt(data.expires_in, 10) || 3600;
|
||||
const effective = Math.max(0, expiresIn - this.tokenMarginSec);
|
||||
this.tokenExpiry = Date.now() + effective * 1000;
|
||||
return { access_token: data.access_token, token_type: data.token_type ?? 'Bearer', expires_in: expiresIn };
|
||||
}
|
||||
async getToken() {
|
||||
if (this.isTokenValid()) {
|
||||
return this.cachedToken;
|
||||
}
|
||||
const tokenResp = await this.requestAccessToken();
|
||||
return tokenResp.access_token;
|
||||
}
|
||||
async authenticatedRequest(input, init, retry = true) {
|
||||
const token = await this.getToken();
|
||||
const headers = new Headers(init?.headers);
|
||||
headers.set('Authorization', `Bearer ${token}`);
|
||||
headers.set('Accept', 'application/json');
|
||||
let res;
|
||||
try {
|
||||
res = await this.fetchWithTimeout(typeof input === 'string' ? input : input.url, {
|
||||
...init,
|
||||
headers,
|
||||
});
|
||||
}
|
||||
catch (err) {
|
||||
if (err.name === 'AbortError') {
|
||||
throw new CoreApiClientError('Request timeout');
|
||||
}
|
||||
throw new CoreApiClientError('Network error');
|
||||
}
|
||||
if (res.status === 401 && retry) {
|
||||
// invalidate token and retry once
|
||||
this.cachedToken = null;
|
||||
this.tokenExpiry = 0;
|
||||
try {
|
||||
const newToken = await this.getToken();
|
||||
const headers2 = new Headers(init?.headers);
|
||||
headers2.set('Authorization', `Bearer ${newToken}`);
|
||||
headers2.set('Accept', 'application/json');
|
||||
const res2 = await this.fetchWithTimeout(typeof input === 'string' ? input : input.url, {
|
||||
...init,
|
||||
headers: headers2,
|
||||
});
|
||||
return res2;
|
||||
}
|
||||
catch (e) {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
}
|
||||
exports.CoreApiClient = CoreApiClient;
|
||||
//# sourceMappingURL=core-api-client.js.map
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"core-api-client.js","sourceRoot":"","sources":["../../../src/adapters/notification/core-api-client.ts"],"names":[],"mappings":";;;AAMA,MAAa,kBAAmB,SAAQ,KAAK;IACpC,MAAM,CAAU;IACvB,YAAY,OAAe,EAAE,MAAe;QAC1C,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,oBAAoB,CAAC;QACjC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;CACF;AAPD,gDAOC;AAED,MAAa,aAAa;IAChB,MAAM,CAAS;IACf,QAAQ,CAAS;IACjB,YAAY,CAAS;IACrB,SAAS,CAAS;IAElB,WAAW,GAAkB,IAAI,CAAC;IAClC,WAAW,GAAW,CAAC,CAAC,CAAC,WAAW;IACpC,cAAc,GAAG,EAAE,CAAC,CAAC,2BAA2B;IAExD,YAAY,OAA2F;QACrG,IAAI,CAAC,MAAM,GAAG,OAAO,EAAE,MAAM,IAAI,OAAO,CAAC,GAAG,CAAC,mBAAmB,IAAI,uBAAuB,CAAC;QAC5F,IAAI,CAAC,QAAQ,GAAG,OAAO,EAAE,QAAQ,IAAI,OAAO,CAAC,GAAG,CAAC,oBAAoB,IAAI,EAAE,CAAC;QAC5E,IAAI,CAAC,YAAY,GAAG,OAAO,EAAE,YAAY,IAAI,OAAO,CAAC,GAAG,CAAC,wBAAwB,IAAI,EAAE,CAAC;QACxF,IAAI,CAAC,SAAS,GAAG,OAAO,EAAE,SAAS,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,CAAC,CAAC;YAClD,CAAC;YACD,MAAM,IAAI,kBAAkB,CAAC,eAAe,CAAC,CAAC;QAChD,CAAC;QAED,IAAI,GAAG,CAAC,MAAM,KAAK,GAAG,IAAI,KAAK,EAAE,CAAC;YAChC,kCAAkC;YAClC,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC;YACxB,IAAI,CAAC,WAAW,GAAG,CAAC,CAAC;YACrB,IAAI,CAAC;gBACH,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,QAAQ,EAAE,CAAC;gBACvC,MAAM,QAAQ,GAAG,IAAI,OAAO,CAAC,IAAI,EAAE,OAAsB,CAAC,CAAC;gBAC3D,QAAQ,CAAC,GAAG,CAAC,eAAe,EAAE,UAAU,QAAQ,EAAE,CAAC,CAAC;gBACpD,QAAQ,CAAC,GAAG,CAAC,QAAQ,EAAE,kBAAkB,CAAC,CAAC;gBAC3C,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,gBAAgB,CAAC,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAE,KAAiB,CAAC,GAAG,EAAE;oBACnG,GAAG,IAAI;oBACP,OAAO,EAAE,QAAQ;iBAClB,CAAC,CAAC;gBACH,OAAO,IAAI,CAAC;YACd,CAAC;YAAC,OAAO,CAAC,EAAE,CAAC;gBACX,MAAM,CAAC,CAAC;YACV,CAAC;QACH,CAAC;QAED,OAAO,GAAG,CAAC;IACb,CAAC;CACF;AArID,sCAqIC"}
|
||||
Vendored
+25
@@ -15,6 +15,7 @@ const health_module_1 = require("./modules/health/health.module");
|
||||
const authorization_module_1 = require("./modules/authorization/authorization.module");
|
||||
const audit_module_1 = require("./modules/audit/audit.module");
|
||||
const application_module_1 = require("./modules/application/application.module");
|
||||
const debt_module_1 = require("./modules/bot-debt/debt.module");
|
||||
let AppModule = class AppModule {
|
||||
};
|
||||
exports.AppModule = AppModule;
|
||||
@@ -23,6 +24,29 @@ exports.AppModule = AppModule = __decorate([
|
||||
imports: [
|
||||
config_1.ConfigModule.forRoot({
|
||||
isGlobal: true,
|
||||
// Load .env files depending on NODE_ENV. Default to development .env
|
||||
envFilePath: process.env.NODE_ENV === 'production' ? '.env.production' : '.env',
|
||||
// Basic validation: ensure expected frontend URLs and OIDC settings are present
|
||||
validate: (env) => {
|
||||
const errors = [];
|
||||
const nodeEnv = env.NODE_ENV || process.env.NODE_ENV || 'development';
|
||||
if (!env.FRONTEND_URL)
|
||||
errors.push('FRONTEND_URL is not set');
|
||||
if (nodeEnv === 'production' && !env.PRODUCTION_FRONTEND_URL)
|
||||
errors.push('PRODUCTION_FRONTEND_URL is not set');
|
||||
// OIDC required settings
|
||||
if (!env.AUTHENTIK_ISSUER)
|
||||
errors.push('AUTHENTIK_ISSUER is not set');
|
||||
if (!env.AUTHENTIK_CLIENT_ID)
|
||||
errors.push('AUTHENTIK_CLIENT_ID is not set');
|
||||
if (!env.AUTHENTIK_CLIENT_SECRET)
|
||||
errors.push('AUTHENTIK_CLIENT_SECRET is not set');
|
||||
if (!env.AUTHENTIK_REDIRECT_URI)
|
||||
errors.push('AUTHENTIK_REDIRECT_URI is not set');
|
||||
if (errors.length > 0)
|
||||
throw new Error('Environment validation error: ' + errors.join('; '));
|
||||
return env;
|
||||
},
|
||||
}),
|
||||
identity_module_1.IdentityModule,
|
||||
auth_module_1.AuthModule,
|
||||
@@ -31,6 +55,7 @@ exports.AppModule = AppModule = __decorate([
|
||||
authorization_module_1.AuthorizationModule,
|
||||
audit_module_1.AuditModule,
|
||||
application_module_1.ApplicationModule,
|
||||
debt_module_1.DebtModule,
|
||||
],
|
||||
})
|
||||
], AppModule);
|
||||
|
||||
Vendored
+1
-1
@@ -1 +1 @@
|
||||
{"version":3,"file":"app.module.js","sourceRoot":"","sources":["../src/app.module.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAAwC;AACxC,2CAA8C;AAE9C,wEAAoE;AACpE,4DAAwD;AACxD,kEAA8D;AAC9D,uFAAmF;AACnF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AAC,IAAI,CAAC,oCAAoC,CAAC,CAAC;oBAEhH,yBAAyB;oBACzB,IAAI,CAAC,GAAG,CAAC,gBAAgB;wBAAE,MAAM,CAAC,IAAI,CAAC,6BAA6B,CAAC,CAAC;oBACtE,IAAI,CAAC,GAAG,CAAC,mBAAmB;wBAAE,MAAM,CAAC,IAAI,CAAC,gCAAgC,CAAC,CAAC;oBAC5E,IAAI,CAAC,GAAG,CAAC,uBAAuB;wBAAE,MAAM,CAAC,IAAI,CAAC,oCAAoC,CAAC,CAAC;oBACpF,IAAI,CAAC,GAAG,CAAC,sBAAsB;wBAAE,MAAM,CAAC,IAAI,CAAC,mCAAmC,CAAC,CAAC;oBAElF,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC;wBAAE,MAAM,IAAI,KAAK,CAAC,gCAAgC,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;oBAC7F,OAAO,GAAG,CAAC;gBACb,CAAC;aACF,CAAC;YAEF,gCAAc;YACd,wBAAU;YACV,4BAAY;YACZ,4DAA4D;YACpD,0CAAmB;YACnB,0BAAW;YACX,sCAAiB;YACjB,wBAAU;SAEvB;KACF,CAAC;GACW,SAAS,CAAG"}
|
||||
-18
@@ -1,18 +0,0 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.PermissionType = void 0;
|
||||
exports.PermissionType = {
|
||||
USER_CREATE: 'USER_CREATE',
|
||||
USER_READ: 'USER_READ',
|
||||
USER_UPDATE: 'USER_UPDATE',
|
||||
USER_DELETE: 'USER_DELETE',
|
||||
ROLE_CREATE: 'ROLE_CREATE',
|
||||
ROLE_READ: 'ROLE_READ',
|
||||
ROLE_UPDATE: 'ROLE_UPDATE',
|
||||
ROLE_DELETE: 'ROLE_DELETE',
|
||||
PERMISSION_CREATE: 'PERMISSION_CREATE',
|
||||
PERMISSION_READ: 'PERMISSION_READ',
|
||||
PERMISSION_UPDATE: 'PERMISSION_UPDATE',
|
||||
PERMISSION_DELETE: 'PERMISSION_DELETE',
|
||||
};
|
||||
//# sourceMappingURL=permission.constants.js.map
|
||||
@@ -1 +0,0 @@
|
||||
{"version":3,"file":"permission.constants.js","sourceRoot":"","sources":["../../../src/common/constants/permission.constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,cAAc,GAAG;IAC5B,WAAW,EAAE,aAAa;IAC1B,SAAS,EAAE,WAAW;IACtB,WAAW,EAAE,aAAa;IAC1B,WAAW,EAAE,aAAa;IAE1B,WAAW,EAAE,aAAa;IAC1B,SAAS,EAAE,WAAW;IACtB,WAAW,EAAE,aAAa;IAC1B,WAAW,EAAE,aAAa;IAE1B,iBAAiB,EAAE,mBAAmB;IACtC,eAAe,EAAE,iBAAiB;IAClC,iBAAiB,EAAE,mBAAmB;IACtC,iBAAiB,EAAE,mBAAmB;CAC9B,CAAC"}
|
||||
+26
-5
@@ -53,16 +53,28 @@ const jwt = __importStar(require("jsonwebtoken"));
|
||||
*/
|
||||
let JwtAuthGuard = class JwtAuthGuard {
|
||||
jwks = null;
|
||||
logger = new common_1.Logger('JwtAuthGuard');
|
||||
constructor() { }
|
||||
async canActivate(context) {
|
||||
const request = context.switchToHttp().getRequest();
|
||||
let token;
|
||||
const authHeader = request.headers.authorization;
|
||||
if (!authHeader) {
|
||||
throw new common_1.UnauthorizedException('Authorization header is missing.');
|
||||
if (authHeader) {
|
||||
const [type, t] = authHeader.split(' ');
|
||||
if (type === 'Bearer' && t)
|
||||
token = t;
|
||||
}
|
||||
const [type, token] = authHeader.split(' ');
|
||||
if (type !== 'Bearer' || !token) {
|
||||
throw new common_1.UnauthorizedException('Invalid authorization header.');
|
||||
// fallback to cookie if no Authorization header
|
||||
if (!token) {
|
||||
token = request.cookies?.raylab_jwt;
|
||||
this.logger.debug(`No Authorization header. Trying cookie. cookiePresent=${!!request.cookies} tokenFromCookie=${!!token}`);
|
||||
}
|
||||
else {
|
||||
this.logger.debug('Authorization header found. Using Bearer token.');
|
||||
}
|
||||
if (!token) {
|
||||
this.logger.debug('No token found in Authorization header or cookie.');
|
||||
throw new common_1.UnauthorizedException('Authorization token is missing.');
|
||||
}
|
||||
const jwksUri = process.env.AUTHENTIK_JWKS_URI;
|
||||
// First try verifying with external JWKS (Authentik)
|
||||
@@ -76,24 +88,33 @@ let JwtAuthGuard = class JwtAuthGuard {
|
||||
});
|
||||
const identity = new identity_data_1.IdentityData(payload.sub, payload.preferred_username, payload.email, payload);
|
||||
request.identity = identity;
|
||||
// mark as external (verified by Authentik JWKS)
|
||||
request.identitySource = 'external';
|
||||
this.logger.debug(`Verified token using external JWKS. sub=${payload.sub}`);
|
||||
return true;
|
||||
}
|
||||
catch (err) {
|
||||
this.logger.debug(`External JWKS verification failed: ${err.message}`);
|
||||
// ignore and try internal verification
|
||||
}
|
||||
}
|
||||
// Fallback: verify with internal symmetric secret
|
||||
const secret = process.env.RAYLAB_JWT_SECRET;
|
||||
if (!secret) {
|
||||
this.logger.error('RAYLAB_JWT_SECRET is not configured.');
|
||||
throw new common_1.UnauthorizedException('Invalid or expired token.');
|
||||
}
|
||||
try {
|
||||
const payload = jwt.verify(token, secret);
|
||||
const identity = new identity_data_1.IdentityData(payload.sub, payload.preferred_username, payload.email, payload);
|
||||
request.identity = identity;
|
||||
// mark as internal (verified by RayLab internal secret)
|
||||
request.identitySource = 'internal';
|
||||
this.logger.debug(`Verified token using internal secret. sub=${payload.sub}`);
|
||||
return true;
|
||||
}
|
||||
catch (err) {
|
||||
this.logger.debug(`Internal token verification failed: ${err.message}`);
|
||||
throw new common_1.UnauthorizedException('Invalid or expired token.');
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -1 +1 @@
|
||||
{"version":3,"file":"jwt-auth.guard.js","sourceRoot":"","sources":["../../../../src/core/auth/guards/jwt-auth.guard.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,2CAKwB;AAExB,+BAAqD;AACrD,+DAA2D;AAC3D,k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,CAAC,MAAM,CAAC,KAAK,CAAC,6CAA6C,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC;YAC9E,OAAO,IAAI,CAAC;QACd,CAAC;QAAC,OAAO,GAAQ,EAAE,CAAC;YAClB,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,uCAAwC,GAAa,CAAC,OAAO,EAAE,CAAC,CAAC;YACnF,MAAM,IAAI,8BAAqB,CAAC,2BAA2B,CAAC,CAAC;QAC/D,CAAC;IACH,CAAC;CACF,CAAA;AAvFY,oCAAY;uBAAZ,YAAY;IADxB,IAAA,mBAAU,GAAE;;GACA,YAAY,CAuFxB"}
|
||||
-17
@@ -1,17 +0,0 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.IdentityData = void 0;
|
||||
class IdentityData {
|
||||
sub;
|
||||
preferred_username;
|
||||
email;
|
||||
claims;
|
||||
constructor(sub, preferred_username, email, claims) {
|
||||
this.sub = sub;
|
||||
this.preferred_username = preferred_username;
|
||||
this.email = email;
|
||||
this.claims = claims;
|
||||
}
|
||||
}
|
||||
exports.IdentityData = IdentityData;
|
||||
//# sourceMappingURL=identity-data.js.map
|
||||
@@ -1 +0,0 @@
|
||||
{"version":3,"file":"identity-data.js","sourceRoot":"","sources":["../../../../src/core/auth/interfaces/identity-data.ts"],"names":[],"mappings":";;;AAAA,MAAa,YAAY;IAEL;IACA;IACA;IACA;IAJlB,YACkB,GAAW,EACX,kBAA2B,EAC3B,KAAc,EACd,MAA4B;QAH5B,QAAG,GAAH,GAAG,CAAQ;QACX,uBAAkB,GAAlB,kBAAkB,CAAS;QAC3B,UAAK,GAAL,KAAK,CAAS;QACd,WAAM,GAAN,MAAM,CAAsB;IAC3C,CAAC;CACL;AAPD,oCAOC"}
|
||||
-44
@@ -1,44 +0,0 @@
|
||||
"use strict";
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
var EventBus_1;
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.EventBus = void 0;
|
||||
const common_1 = require("@nestjs/common");
|
||||
let EventBus = EventBus_1 = class EventBus {
|
||||
handlers = new Map();
|
||||
logger = new common_1.Logger(EventBus_1.name);
|
||||
// Accept either an EventEnvelope or (type, payload) signature for backward compatibility
|
||||
publish(eventOrType, payload) {
|
||||
let envelope;
|
||||
if (typeof eventOrType === 'string') {
|
||||
envelope = { id: require('crypto').randomUUID(), timestamp: new Date().toISOString(), type: eventOrType, payload: payload ?? {} };
|
||||
}
|
||||
else {
|
||||
envelope = eventOrType;
|
||||
}
|
||||
const handlers = this.handlers.get(envelope.type) || [];
|
||||
for (const h of handlers) {
|
||||
try {
|
||||
Promise.resolve(h(envelope)).catch((err) => this.logger.error('Event handler error', err));
|
||||
}
|
||||
catch (e) {
|
||||
this.logger.error('Event handler threw', e);
|
||||
}
|
||||
}
|
||||
}
|
||||
subscribe(eventType, handler) {
|
||||
const list = this.handlers.get(eventType) || [];
|
||||
list.push(handler);
|
||||
this.handlers.set(eventType, list);
|
||||
}
|
||||
};
|
||||
exports.EventBus = EventBus;
|
||||
exports.EventBus = EventBus = EventBus_1 = __decorate([
|
||||
(0, common_1.Injectable)()
|
||||
], EventBus);
|
||||
//# sourceMappingURL=event-bus.service.js.map
|
||||
@@ -1 +0,0 @@
|
||||
{"version":3,"file":"event-bus.service.js","sourceRoot":"","sources":["../../../src/core/event-bus/event-bus.service.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,2CAAoD;AAO7C,IAAM,QAAQ,gBAA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,QAAQ,CAAC,GAAG,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;IACrC,CAAC;CACF,CAAA;AA5BY,4BAAQ;mBAAR,QAAQ;IADpB,IAAA,mBAAU,GAAE;GACA,QAAQ,CA4BpB"}
|
||||
-3
@@ -1,3 +0,0 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
//# sourceMappingURL=event.interface.js.map
|
||||
-1
@@ -1 +0,0 @@
|
||||
{"version":3,"file":"event.interface.js","sourceRoot":"","sources":["../../../src/core/event-bus/event.interface.ts"],"names":[],"mappings":""}
|
||||
Vendored
+30
-2
@@ -1,6 +1,10 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const common_1 = require("@nestjs/common");
|
||||
const cookie_parser_1 = __importDefault(require("cookie-parser"));
|
||||
const core_1 = require("@nestjs/core");
|
||||
const config_1 = require("@nestjs/config");
|
||||
const swagger_1 = require("@nestjs/swagger");
|
||||
@@ -8,13 +12,35 @@ const app_module_1 = require("./app.module");
|
||||
async function bootstrap() {
|
||||
const app = await core_1.NestFactory.create(app_module_1.AppModule);
|
||||
const config = app.get(config_1.ConfigService);
|
||||
const logger = new common_1.Logger('Bootstrap');
|
||||
// enable cookie parser so req.cookies is populated
|
||||
app.use((0, cookie_parser_1.default)());
|
||||
app.setGlobalPrefix('');
|
||||
app.useGlobalPipes(new common_1.ValidationPipe({
|
||||
whitelist: true,
|
||||
transform: true,
|
||||
forbidNonWhitelisted: true,
|
||||
}));
|
||||
app.enableCors();
|
||||
// CORS configuration: only allow configured frontend origins and enable credentials
|
||||
const allowedOrigins = [];
|
||||
const frontend = config.get('FRONTEND_URL');
|
||||
const prodFrontend = config.get('PRODUCTION_FRONTEND_URL');
|
||||
if (frontend)
|
||||
allowedOrigins.push(frontend);
|
||||
if (prodFrontend)
|
||||
allowedOrigins.push(prodFrontend);
|
||||
app.enableCors({
|
||||
origin: allowedOrigins,
|
||||
credentials: true,
|
||||
methods: ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'OPTIONS'],
|
||||
allowedHeaders: [
|
||||
'Content-Type',
|
||||
'Authorization',
|
||||
'Accept',
|
||||
'Origin',
|
||||
'X-Requested-With',
|
||||
],
|
||||
});
|
||||
const swaggerEnabled = config.get('SWAGGER_ENABLED') === 'true';
|
||||
if (swaggerEnabled) {
|
||||
const swaggerConfig = new swagger_1.DocumentBuilder()
|
||||
@@ -27,8 +53,10 @@ async function bootstrap() {
|
||||
swagger_1.SwaggerModule.setup('ApiList', app, document);
|
||||
}
|
||||
const port = config.get('PORT') || 3000;
|
||||
logger.log(`Allowed CORS origins: ${JSON.stringify(allowedOrigins)}`);
|
||||
logger.log(`Server listening on port ${port}`);
|
||||
await app.listen(port);
|
||||
console.log(`Server running on http://localhost:${port}`);
|
||||
logger.log(`Server running on http://localhost:${port}`);
|
||||
}
|
||||
bootstrap();
|
||||
//# sourceMappingURL=main.js.map
|
||||
Vendored
+1
-1
@@ -1 +1 @@
|
||||
{"version":3,"file":"main.js","sourceRoot":"","sources":["../src/main.ts"],"names":[],"mappings":";;AAAA,2CAAgD;AAChD,uCAA2C;AAC3C,2CAA+C;AAC/C,6CAAiE;AAEjE,6CAAyC;AAEzC,KAAK,UAAU,SAAS;IACtB,MAAM,GAAG,GAAG,MAAM,kBAAW,CAAC,MAAM,CAAC,sBAAS,CAAC,CAAC;IAEhD,MAAM,MAAM,GAAG,GAAG,CAAC,GAAG,CAAC,sBAAa,CAAC,CAAC;IAEtC,GAAG,CAAC,eAAe,CAAC,EAAE,CAAC,CAAC;IAExB,GAAG,CAAC,cAAc,CAChB,IAAI,uBAAc,CAAC;QACjB,SAAS,EAAE,IAAI;QACf,SAAS,EAAE,IAAI;QACf,oBAAoB,EAAE,IAAI;KAC3B,CAAC,CACH,CAAC;IAEF,GAAG,CAAC,U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GAAG,CAAS,MAAM,CAAC,IAAI,IAAI,CAAC;IAElD,MAAM,CAAC,GAAG,CAAC,yBAAyB,IAAI,CAAC,SAAS,CAAC,cAAc,CAAC,EAAE,CAAC,CAAC;IACtE,MAAM,CAAC,GAAG,CAAC,4BAA4B,IAAI,EAAE,CAAC,CAAC;IAE/C,MAAM,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IAEvB,MAAM,CAAC,GAAG,CAAC,sCAAsC,IAAI,EAAE,CAAC,CAAC;AAC3D,CAAC;AAED,SAAS,EAAE,CAAC"}
|
||||
-49
@@ -1,49 +0,0 @@
|
||||
"use strict";
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.ApplicationModule = void 0;
|
||||
const common_1 = require("@nestjs/common");
|
||||
const prisma_service_1 = require("../../shared/prisma.service");
|
||||
const applications_controller_1 = require("./presentation/controllers/applications.controller");
|
||||
const prisma_application_repository_1 = require("./infrastructure/repositories/prisma-application.repository");
|
||||
const application_interface_1 = require("./domain/repositories/application.interface");
|
||||
const get_applications_handler_1 = require("./application/handlers/get-applications.handler");
|
||||
const get_application_handler_1 = require("./application/handlers/get-application.handler");
|
||||
const create_application_handler_1 = require("./application/handlers/create-application.handler");
|
||||
const update_application_handler_1 = require("./application/handlers/update-application.handler");
|
||||
const delete_application_handler_1 = require("./application/handlers/delete-application.handler");
|
||||
const get_me_applications_handler_1 = require("./application/handlers/get-me-applications.handler");
|
||||
const application_validator_1 = require("./application/validators/application.validator");
|
||||
const jwt_auth_guard_1 = require("../../core/auth/guards/jwt-auth.guard");
|
||||
const identity_module_1 = require("../identity/identity.module");
|
||||
let ApplicationModule = class ApplicationModule {
|
||||
};
|
||||
exports.ApplicationModule = ApplicationModule;
|
||||
exports.ApplicationModule = ApplicationModule = __decorate([
|
||||
(0, common_1.Module)({
|
||||
imports: [identity_module_1.IdentityModule],
|
||||
providers: [
|
||||
prisma_service_1.PrismaService,
|
||||
prisma_application_repository_1.PrismaApplicationRepository,
|
||||
get_applications_handler_1.GetApplicationsHandler,
|
||||
get_application_handler_1.GetApplicationHandler,
|
||||
create_application_handler_1.CreateApplicationHandler,
|
||||
update_application_handler_1.UpdateApplicationHandler,
|
||||
delete_application_handler_1.DeleteApplicationHandler,
|
||||
get_me_applications_handler_1.GetMeApplicationsHandler,
|
||||
application_validator_1.ApplicationValidator,
|
||||
jwt_auth_guard_1.JwtAuthGuard,
|
||||
{
|
||||
provide: application_interface_1.IApplication,
|
||||
useClass: prisma_application_repository_1.PrismaApplicationRepository,
|
||||
},
|
||||
],
|
||||
controllers: [applications_controller_1.ApplicationsController],
|
||||
})
|
||||
], ApplicationModule);
|
||||
//# sourceMappingURL=application.module.js.map
|
||||
@@ -1 +0,0 @@
|
||||
{"version":3,"file":"application.module.js","sourceRoot":"","sources":["../../../src/modules/application/application.module.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAAwC;AACxC,gEAA4D;AAC5D,gGAA4F;AAC5F,+GAA0G;AAC1G,uFAA2E;AAC3E,8FAAyF;AACzF,4FAAuF;AACvF,kGAA6F;AAC7F,kGAA6F;AAC7F,kGAA6F;AAC7F,oGAA8F;AAC9F,0FAAsF;AACtF,0EAAqE;AACrE,iEAA6D;AAsBtD,IAAM,iBAAiB,GAAvB,MAAM,iBAAiB;CAAG,CAAA;AAApB,8CAAiB;4BAAjB,iBAAiB;IApB7B,IAAA,eAAM,EAAC;QACN,OAAO,EAAE,CAAC,gCAAc,CAAC;QACzB,SAAS,EAAE;YACT,8BAAa;YACb,2DAA2B;YAC3B,iDAAsB;YACtB,+CAAqB;YACrB,qDAAwB;YACxB,qDAAwB;YACxB,qDAAwB;YACxB,sDAAwB;YACxB,4CAAoB;YACpB,6BAAY;YACZ;gBACE,OAAO,EAAE,oCAAY;gBACrB,QAAQ,EAAE,2DAA2B;aACtC;SACF;QACD,WAAW,EAAE,CAAC,gDAAsB,CAAC;KACtC,CAAC;GACW,iBAAiB,CAAG"}
|
||||
@@ -1,44 +0,0 @@
|
||||
"use strict";
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
var __metadata = (this && this.__metadata) || function (k, v) {
|
||||
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.CreateApplicationHandler = void 0;
|
||||
const common_1 = require("@nestjs/common");
|
||||
const application_interface_1 = require("../../domain/repositories/application.interface");
|
||||
const application_validator_1 = require("../../application/validators/application.validator");
|
||||
const application_entity_1 = require("../../domain/entities/application.entity");
|
||||
let CreateApplicationHandler = class CreateApplicationHandler {
|
||||
appRepo;
|
||||
validator;
|
||||
constructor(appRepo, validator) {
|
||||
this.appRepo = appRepo;
|
||||
this.validator = validator;
|
||||
}
|
||||
async execute(payload) {
|
||||
await this.validator.validateCreate(payload);
|
||||
const app = application_entity_1.ApplicationData.create({
|
||||
code: payload.code,
|
||||
name: payload.name,
|
||||
description: payload.description,
|
||||
icon: payload.icon,
|
||||
url: payload.url,
|
||||
applicationsClaim: payload.applicationsClaim,
|
||||
displayOrder: payload.displayOrder,
|
||||
});
|
||||
const created = await this.appRepo.create(app);
|
||||
return created;
|
||||
}
|
||||
};
|
||||
exports.CreateApplicationHandler = CreateApplicationHandler;
|
||||
exports.CreateApplicationHandler = CreateApplicationHandler = __decorate([
|
||||
(0, common_1.Injectable)(),
|
||||
__metadata("design:paramtypes", [application_interface_1.IApplication, application_validator_1.ApplicationValidator])
|
||||
], CreateApplicationHandler);
|
||||
//# sourceMappingURL=create-application.handler.js.map
|
||||
-1
@@ -1 +0,0 @@
|
||||
{"version":3,"file":"create-application.handler.js","sourceRoot":"","sources":["../../../../../src/modules/application/application/handlers/create-application.handler.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAAiE;AACjE,2FAA+E;AAC/E,8FAA0F;AAC1F,iFAA2E;AAGpE,IAAM,wBAAwB,GAA9B,MAAM,wBAAwB;IACN;IAAwC;IAArE,YAA6B,OAAqB,EAAmB,SAA+B;QAAvE,YAAO,GAAP,OAAO,CAAc;QAAmB,cAAS,GAAT,SAAS,CAAsB;IAAG,CAAC;IAExG,KAAK,CAAC,OAAO,CAAC,OAAY;QACxB,MAAM,IAAI,CAAC,SAAS,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC;QAE7C,MAAM,GAAG,GAAG,oCAAe,CAAC,MAAM,CAAC;YACjC,IAAI,EAAE,OAAO,CAAC,IAAI;YAClB,IAAI,EAAE,OAAO,CAAC,IAAI;YAClB,WAAW,EAAE,OAAO,CAAC,WAAW;YAChC,IAAI,EAAE,OAAO,CAAC,IAAI;YAClB,GAAG,EAAE,OAAO,CAAC,GAAG;YAChB,iBAAiB,EAAE,OAAO,CAAC,iBAAiB;YAC5C,YAAY,EAAE,OAAO,CAAC,YAAY;SACnC,CAAC,CAAC;QAEH,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QAC/C,OAAO,OAAO,CAAC;IACjB,CAAC;CACF,CAAA;AAnBY,4DAAwB;mCAAxB,wBAAwB;IADpC,IAAA,mBAAU,GAAE;qCAE2B,oCAAY,EAA8B,4CAAoB;GADzF,wBAAwB,CAmBpC"}
|
||||
@@ -1,31 +0,0 @@
|
||||
"use strict";
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
var __metadata = (this && this.__metadata) || function (k, v) {
|
||||
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.DeleteApplicationHandler = void 0;
|
||||
const common_1 = require("@nestjs/common");
|
||||
const application_interface_1 = require("../../domain/repositories/application.interface");
|
||||
let DeleteApplicationHandler = class DeleteApplicationHandler {
|
||||
appRepo;
|
||||
constructor(appRepo) {
|
||||
this.appRepo = appRepo;
|
||||
}
|
||||
async execute(id) {
|
||||
// ensure exists
|
||||
await this.appRepo.findById(id);
|
||||
await this.appRepo.delete(id);
|
||||
}
|
||||
};
|
||||
exports.DeleteApplicationHandler = DeleteApplicationHandler;
|
||||
exports.DeleteApplicationHandler = DeleteApplicationHandler = __decorate([
|
||||
(0, common_1.Injectable)(),
|
||||
__metadata("design:paramtypes", [application_interface_1.IApplication])
|
||||
], DeleteApplicationHandler);
|
||||
//# sourceMappingURL=delete-application.handler.js.map
|
||||
-1
@@ -1 +0,0 @@
|
||||
{"version":3,"file":"delete-application.handler.js","sourceRoot":"","sources":["../../../../../src/modules/application/application/handlers/delete-application.handler.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAA4C;AAC5C,2FAA+E;AAGxE,IAAM,wBAAwB,GAA9B,MAAM,wBAAwB;IACN;IAA7B,YAA6B,OAAqB;QAArB,YAAO,GAAP,OAAO,CAAc;IAAG,CAAC;IAEtD,KAAK,CAAC,OAAO,CAAC,EAAU;QACtB,gBAAgB;QAChB,MAAM,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;QAChC,MAAM,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;IAChC,CAAC;CACF,CAAA;AARY,4DAAwB;mCAAxB,wBAAwB;IADpC,IAAA,mBAAU,GAAE;qCAE2B,oCAAY;GADvC,wBAAwB,CAQpC"}
|
||||
@@ -1,30 +0,0 @@
|
||||
"use strict";
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
var __metadata = (this && this.__metadata) || function (k, v) {
|
||||
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.GetApplicationHandler = void 0;
|
||||
const common_1 = require("@nestjs/common");
|
||||
const application_interface_1 = require("../../domain/repositories/application.interface");
|
||||
let GetApplicationHandler = class GetApplicationHandler {
|
||||
appRepo;
|
||||
constructor(appRepo) {
|
||||
this.appRepo = appRepo;
|
||||
}
|
||||
async execute(id) {
|
||||
const app = await this.appRepo.findById(id);
|
||||
return app;
|
||||
}
|
||||
};
|
||||
exports.GetApplicationHandler = GetApplicationHandler;
|
||||
exports.GetApplicationHandler = GetApplicationHandler = __decorate([
|
||||
(0, common_1.Injectable)(),
|
||||
__metadata("design:paramtypes", [application_interface_1.IApplication])
|
||||
], GetApplicationHandler);
|
||||
//# sourceMappingURL=get-application.handler.js.map
|
||||
@@ -1 +0,0 @@
|
||||
{"version":3,"file":"get-application.handler.js","sourceRoot":"","sources":["../../../../../src/modules/application/application/handlers/get-application.handler.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAA4C;AAC5C,2FAA+E;AAGxE,IAAM,qBAAqB,GAA3B,MAAM,qBAAqB;IACH;IAA7B,YAA6B,OAAqB;QAArB,YAAO,GAAP,OAAO,CAAc;IAAG,CAAC;IAEtD,KAAK,CAAC,OAAO,CAAC,EAAU;QACtB,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;QAC5C,OAAO,GAAG,CAAC;IACb,CAAC;CACF,CAAA;AAPY,sDAAqB;gCAArB,qBAAqB;IADjC,IAAA,mBAAU,GAAE;qCAE2B,oCAAY;GADvC,qBAAqB,CAOjC"}
|
||||
@@ -1,30 +0,0 @@
|
||||
"use strict";
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
var __metadata = (this && this.__metadata) || function (k, v) {
|
||||
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.GetApplicationsHandler = void 0;
|
||||
const common_1 = require("@nestjs/common");
|
||||
const application_interface_1 = require("../../domain/repositories/application.interface");
|
||||
let GetApplicationsHandler = class GetApplicationsHandler {
|
||||
appRepo;
|
||||
constructor(appRepo) {
|
||||
this.appRepo = appRepo;
|
||||
}
|
||||
async execute(query) {
|
||||
const res = await this.appRepo.find({ page: query.page, limit: query.limit, search: query.search || null });
|
||||
return res;
|
||||
}
|
||||
};
|
||||
exports.GetApplicationsHandler = GetApplicationsHandler;
|
||||
exports.GetApplicationsHandler = GetApplicationsHandler = __decorate([
|
||||
(0, common_1.Injectable)(),
|
||||
__metadata("design:paramtypes", [application_interface_1.IApplication])
|
||||
], GetApplicationsHandler);
|
||||
//# sourceMappingURL=get-applications.handler.js.map
|
||||
@@ -1 +0,0 @@
|
||||
{"version":3,"file":"get-applications.handler.js","sourceRoot":"","sources":["../../../../../src/modules/application/application/handlers/get-applications.handler.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAA4C;AAC5C,2FAA+E;AAGxE,IAAM,sBAAsB,GAA5B,MAAM,sBAAsB;IACJ;IAA7B,YAA6B,OAAqB;QAArB,YAAO,GAAP,OAAO,CAAc;IAAG,CAAC;IAEtD,KAAK,CAAC,OAAO,CAAC,KAAyD;QACrE,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,IAAI,IAAI,EAAE,CAAC,CAAC;QAC5G,OAAO,GAAG,CAAC;IACb,CAAC;CACF,CAAA;AAPY,wDAAsB;iCAAtB,sBAAsB;IADlC,IAAA,mBAAU,GAAE;qCAE2B,oCAAY;GADvC,sBAAsB,CAOlC"}
|
||||
@@ -1,35 +0,0 @@
|
||||
"use strict";
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
var __metadata = (this && this.__metadata) || function (k, v) {
|
||||
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.GetMeApplicationsHandler = void 0;
|
||||
const common_1 = require("@nestjs/common");
|
||||
const application_interface_1 = require("../../domain/repositories/application.interface");
|
||||
let GetMeApplicationsHandler = class GetMeApplicationsHandler {
|
||||
appRepo;
|
||||
constructor(appRepo) {
|
||||
this.appRepo = appRepo;
|
||||
}
|
||||
async execute(applicationsClaimList) {
|
||||
if (!applicationsClaimList || applicationsClaimList.length === 0)
|
||||
return { data: [], total: 0 };
|
||||
// Only return active applications whose applicationsClaim exists in provided list
|
||||
const res = await this.appRepo.find({ page: 1, limit: 1000, isActive: true, applicationsClaimIn: applicationsClaimList });
|
||||
// sort by displayOrder asc
|
||||
res.data.sort((a, b) => (a.displayOrder ?? 0) - (b.displayOrder ?? 0));
|
||||
return res;
|
||||
}
|
||||
};
|
||||
exports.GetMeApplicationsHandler = GetMeApplicationsHandler;
|
||||
exports.GetMeApplicationsHandler = GetMeApplicationsHandler = __decorate([
|
||||
(0, common_1.Injectable)(),
|
||||
__metadata("design:paramtypes", [application_interface_1.IApplication])
|
||||
], GetMeApplicationsHandler);
|
||||
//# sourceMappingURL=get-me-applications.handler.js.map
|
||||
-1
@@ -1 +0,0 @@
|
||||
{"version":3,"file":"get-me-applications.handler.js","sourceRoot":"","sources":["../../../../../src/modules/application/application/handlers/get-me-applications.handler.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAA4C;AAC5C,2FAA+E;AAGxE,IAAM,wBAAwB,GAA9B,MAAM,wBAAwB;IACN;IAA7B,YAA6B,OAAqB;QAArB,YAAO,GAAP,OAAO,CAAc;IAAG,CAAC;IAEtD,KAAK,CAAC,OAAO,CAAC,qBAAkD;QAC9D,IAAI,CAAC,qBAAqB,IAAI,qBAAqB,CAAC,MAAM,KAAK,CAAC;YAAE,OAAO,EAAE,IAAI,EAAE,EAAE,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC;QAEhG,kFAAkF;QAClF,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,mBAAmB,EAAE,qBAAqB,EAAE,CAAC,CAAC;QAC1H,2BAA2B;QAC3B,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,YAAY,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,YAAY,IAAI,CAAC,CAAC,CAAC,CAAC;QACvE,OAAO,GAAG,CAAC;IACb,CAAC;CACF,CAAA;AAZY,4DAAwB;mCAAxB,wBAAwB;IADpC,IAAA,mBAAU,GAAE;qCAE2B,oCAAY;GADvC,wBAAwB,CAYpC"}
|
||||
@@ -1,38 +0,0 @@
|
||||
"use strict";
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
var __metadata = (this && this.__metadata) || function (k, v) {
|
||||
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.UpdateApplicationHandler = void 0;
|
||||
const common_1 = require("@nestjs/common");
|
||||
const application_interface_1 = require("../../domain/repositories/application.interface");
|
||||
const application_validator_1 = require("../../application/validators/application.validator");
|
||||
let UpdateApplicationHandler = class UpdateApplicationHandler {
|
||||
appRepo;
|
||||
validator;
|
||||
constructor(appRepo, validator) {
|
||||
this.appRepo = appRepo;
|
||||
this.validator = validator;
|
||||
}
|
||||
async execute(id, payload) {
|
||||
const existing = await this.appRepo.findById(id);
|
||||
if (!existing)
|
||||
throw new Error('Application not found');
|
||||
await this.validator.validateUpdate(id, payload);
|
||||
existing.update(payload);
|
||||
const updated = await this.appRepo.update(existing);
|
||||
return updated;
|
||||
}
|
||||
};
|
||||
exports.UpdateApplicationHandler = UpdateApplicationHandler;
|
||||
exports.UpdateApplicationHandler = UpdateApplicationHandler = __decorate([
|
||||
(0, common_1.Injectable)(),
|
||||
__metadata("design:paramtypes", [application_interface_1.IApplication, application_validator_1.ApplicationValidator])
|
||||
], UpdateApplicationHandler);
|
||||
//# sourceMappingURL=update-application.handler.js.map
|
||||
-1
@@ -1 +0,0 @@
|
||||
{"version":3,"file":"update-application.handler.js","sourceRoot":"","sources":["../../../../../src/modules/application/application/handlers/update-application.handler.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAA4C;AAC5C,2FAA+E;AAC/E,8FAA0F;AAGnF,IAAM,wBAAwB,GAA9B,MAAM,wBAAwB;IACN;IAAwC;IAArE,YAA6B,OAAqB,EAAmB,SAA+B;QAAvE,YAAO,GAAP,OAAO,CAAc;QAAmB,cAAS,GAAT,SAAS,CAAsB;IAAG,CAAC;IAExG,KAAK,CAAC,OAAO,CAAC,EAAU,EAAE,OAAY;QACpC,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;QACjD,IAAI,CAAC,QAAQ;YAAE,MAAM,IAAI,KAAK,CAAC,uBAAuB,CAAC,CAAC;QAExD,MAAM,IAAI,CAAC,SAAS,CAAC,cAAc,CAAC,EAAE,EAAE,OAAO,CAAC,CAAC;QAEjD,QAAQ,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QACzB,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;QACpD,OAAO,OAAO,CAAC;IACjB,CAAC;CACF,CAAA;AAbY,4DAAwB;mCAAxB,wBAAwB;IADpC,IAAA,mBAAU,GAAE;qCAE2B,oCAAY,EAA8B,4CAAoB;GADzF,wBAAwB,CAapC"}
|
||||
@@ -1,84 +0,0 @@
|
||||
"use strict";
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
var __metadata = (this && this.__metadata) || function (k, v) {
|
||||
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.ApplicationValidator = void 0;
|
||||
const common_1 = require("@nestjs/common");
|
||||
const application_interface_1 = require("../../domain/repositories/application.interface");
|
||||
let ApplicationValidator = class ApplicationValidator {
|
||||
appRepo;
|
||||
constructor(appRepo) {
|
||||
this.appRepo = appRepo;
|
||||
}
|
||||
async validateCreate(payload) {
|
||||
if (!payload || !payload.code)
|
||||
throw new common_1.BadRequestException('code is required');
|
||||
if (!payload.name)
|
||||
throw new common_1.BadRequestException('name is required');
|
||||
if (!payload.applicationsClaim)
|
||||
throw new common_1.BadRequestException('applicationsClaim is required');
|
||||
// url validation if provided
|
||||
if (payload.url) {
|
||||
try {
|
||||
// allow relative urls
|
||||
if (!payload.url.startsWith('/') && !payload.url.startsWith('http')) {
|
||||
throw new Error('invalid');
|
||||
}
|
||||
// new URL(payload.url) // avoid throwing for relative
|
||||
}
|
||||
catch (e) {
|
||||
throw new common_1.BadRequestException('invalid url');
|
||||
}
|
||||
}
|
||||
// displayOrder
|
||||
if (payload.displayOrder !== undefined && typeof payload.displayOrder !== 'number') {
|
||||
throw new common_1.BadRequestException('invalid displayOrder');
|
||||
}
|
||||
// unique code
|
||||
const byCode = await this.appRepo.findByCode(payload.code);
|
||||
if (byCode)
|
||||
throw new common_1.BadRequestException('duplicate code');
|
||||
const byClaim = await this.appRepo.findByApplicationsClaim(payload.applicationsClaim);
|
||||
if (byClaim)
|
||||
throw new common_1.BadRequestException('duplicate applicationsClaim');
|
||||
}
|
||||
async validateUpdate(id, payload) {
|
||||
if (!payload)
|
||||
return;
|
||||
if (payload.url) {
|
||||
try {
|
||||
if (!payload.url.startsWith('/') && !payload.url.startsWith('http'))
|
||||
throw new Error('invalid');
|
||||
}
|
||||
catch (e) {
|
||||
throw new common_1.BadRequestException('invalid url');
|
||||
}
|
||||
}
|
||||
if (payload.displayOrder !== undefined && typeof payload.displayOrder !== 'number') {
|
||||
throw new common_1.BadRequestException('invalid displayOrder');
|
||||
}
|
||||
if (payload.code) {
|
||||
const existing = await this.appRepo.findByCode(payload.code);
|
||||
if (existing && existing.id !== id)
|
||||
throw new common_1.BadRequestException('duplicate code');
|
||||
}
|
||||
if (payload.applicationsClaim) {
|
||||
const existing = await this.appRepo.findByApplicationsClaim(payload.applicationsClaim);
|
||||
if (existing && existing.id !== id)
|
||||
throw new common_1.BadRequestException('duplicate applicationsClaim');
|
||||
}
|
||||
}
|
||||
};
|
||||
exports.ApplicationValidator = ApplicationValidator;
|
||||
exports.ApplicationValidator = ApplicationValidator = __decorate([
|
||||
(0, common_1.Injectable)(),
|
||||
__metadata("design:paramtypes", [application_interface_1.IApplication])
|
||||
], ApplicationValidator);
|
||||
//# sourceMappingURL=application.validator.js.map
|
||||
@@ -1 +0,0 @@
|
||||
{"version":3,"file":"application.validator.js","sourceRoot":"","sources":["../../../../../src/modules/application/application/validators/application.validator.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAAiE;AACjE,2FAA+E;AAGxE,IAAM,oBAAoB,GAA1B,MAAM,oBAAoB;IACF;IAA7B,YAA6B,OAAqB;QAArB,YAAO,GAAP,OAAO,CAAc;IAAG,CAAC;IAEtD,KAAK,CAAC,cAAc,CAAC,OAAY;QAC/B,IAAI,CAAC,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI;YAAE,MAAM,IAAI,4BAAmB,CAAC,kBAAkB,CAAC,CAAC;QACjF,IAAI,CAAC,OAAO,CAAC,IAAI;YAAE,MAAM,IAAI,4BAAmB,CAAC,kBAAkB,CAAC,CAAC;QACrE,IAAI,CAAC,OAAO,CAAC,iBAAiB;YAAE,MAAM,IAAI,4BAAmB,CAAC,+BAA+B,CAAC,CAAC;QAE/F,6BAA6B;QAC7B,IAAI,OAAO,CAAC,GAAG,EAAE,CAAC;YAChB,IAAI,CAAC;gBACH,sBAAsB;gBACtB,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE,CAAC;oBACpE,MAAM,IAAI,KAAK,CAAC,SAAS,CAAC,CAAC;gBAC7B,CAAC;gBACD,sDAAsD;YACxD,CAAC;YAAC,OAAO,CAAC,E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AAO,CAAC,IAAI,EAAE,CAAC;YACjB,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;YAC7D,IAAI,QAAQ,IAAI,QAAQ,CAAC,EAAE,KAAK,EAAE;gBAAE,MAAM,IAAI,4BAAmB,CAAC,gBAAgB,CAAC,CAAC;QACtF,CAAC;QAED,IAAI,OAAO,CAAC,iBAAiB,EAAE,CAAC;YAC9B,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,uBAAuB,CAAC,OAAO,CAAC,iBAAiB,CAAC,CAAC;YACvF,IAAI,QAAQ,IAAI,QAAQ,CAAC,EAAE,KAAK,EAAE;gBAAE,MAAM,IAAI,4BAAmB,CAAC,6BAA6B,CAAC,CAAC;QACnG,CAAC;IACH,CAAC;CACF,CAAA;AA3DY,oDAAoB;+BAApB,oBAAoB;IADhC,IAAA,mBAAU,GAAE;qCAE2B,oCAAY;GADvC,oBAAoB,CA2DhC"}
|
||||
@@ -1,67 +0,0 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.ApplicationData = void 0;
|
||||
class ApplicationData {
|
||||
id;
|
||||
code;
|
||||
name;
|
||||
description;
|
||||
icon;
|
||||
url;
|
||||
applicationsClaim;
|
||||
isActive;
|
||||
displayOrder;
|
||||
createdAt;
|
||||
updatedAt;
|
||||
constructor(id, code, name, description, icon, url, applicationsClaim, isActive, displayOrder, createdAt, updatedAt) {
|
||||
this.id = id;
|
||||
this.code = code;
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
this.icon = icon;
|
||||
this.url = url;
|
||||
this.applicationsClaim = applicationsClaim;
|
||||
this.isActive = isActive;
|
||||
this.displayOrder = displayOrder;
|
||||
this.createdAt = createdAt;
|
||||
this.updatedAt = updatedAt;
|
||||
}
|
||||
static create(data) {
|
||||
return new ApplicationData(crypto.randomUUID(), data.code, data.name, data.description ?? null, data.icon ?? null, data.url ?? null, data.applicationsClaim, true, data.displayOrder ?? 0, new Date(), new Date());
|
||||
}
|
||||
static restore(props) {
|
||||
return new ApplicationData(props.id, props.code, props.name, props.description ?? null, props.icon ?? null, props.url ?? null, props.applicationsClaim, props.isActive !== undefined ? props.isActive : true, props.displayOrder ?? 0, props.createdAt ?? null, props.updatedAt ?? null);
|
||||
}
|
||||
update(data) {
|
||||
if (data.code !== undefined)
|
||||
this.code = data.code;
|
||||
if (data.name !== undefined)
|
||||
this.name = data.name;
|
||||
if (data.description !== undefined)
|
||||
this.description = data.description;
|
||||
if (data.icon !== undefined)
|
||||
this.icon = data.icon;
|
||||
if (data.url !== undefined)
|
||||
this.url = data.url;
|
||||
if (data.applicationsClaim !== undefined)
|
||||
this.applicationsClaim = data.applicationsClaim;
|
||||
if (data.isActive !== undefined)
|
||||
this.isActive = data.isActive;
|
||||
if (data.displayOrder !== undefined)
|
||||
this.displayOrder = data.displayOrder;
|
||||
this.updatedAt = new Date();
|
||||
}
|
||||
toResponse() {
|
||||
return {
|
||||
id: this.id,
|
||||
code: this.code,
|
||||
name: this.name,
|
||||
description: this.description,
|
||||
icon: this.icon,
|
||||
url: this.url,
|
||||
displayOrder: this.displayOrder,
|
||||
};
|
||||
}
|
||||
}
|
||||
exports.ApplicationData = ApplicationData;
|
||||
//# sourceMappingURL=application.entity.js.map
|
||||
@@ -1 +0,0 @@
|
||||
{"version":3,"file":"application.entity.js","sourceRoot":"","sources":["../../../../../src/modules/application/domain/entities/application.entity.ts"],"names":[],"mappings":";;;AAAA,MAAa,eAAe;IAER;IACT;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IAXT,YACkB,EAAU,EACnB,IAAY,EACZ,IAAY,EACZ,WAA0B,EAC1B,IAAmB,EACnB,GAAkB,EAClB,iBAAyB,EACzB,QAAiB,EACjB,YAAoB,EACpB,SAAsB,EACtB,SAAsB;QAVb,OAAE,GAAF,EAAE,CAAQ;QACnB,SAAI,GAAJ,IAAI,C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ication = void 0;
|
||||
class IApplication {
|
||||
}
|
||||
exports.IApplication = IApplication;
|
||||
//# sourceMappingURL=application.interface.js.map
|
||||
@@ -1 +0,0 @@
|
||||
{"version":3,"file":"application.interface.js","sourceRoot":"","sources":["../../../../../src/modules/application/domain/repositories/application.interface.ts"],"names":[],"mappings":";;;AAEA,MAAsB,YAAY;CASjC;AATD,oCASC"}
|
||||
@@ -1,23 +0,0 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.PrismaApplicationMapper = void 0;
|
||||
const application_entity_1 = require("../../domain/entities/application.entity");
|
||||
class PrismaApplicationMapper {
|
||||
static toDomain(model) {
|
||||
return application_entity_1.ApplicationData.restore({
|
||||
id: model.id,
|
||||
code: model.code,
|
||||
name: model.name,
|
||||
description: model.description,
|
||||
icon: model.icon,
|
||||
url: model.url,
|
||||
applicationsClaim: model.applicationsClaim,
|
||||
isActive: model.isActive,
|
||||
displayOrder: model.displayOrder,
|
||||
createdAt: model.createdAt,
|
||||
updatedAt: model.updatedAt,
|
||||
});
|
||||
}
|
||||
}
|
||||
exports.PrismaApplicationMapper = PrismaApplicationMapper;
|
||||
//# sourceMappingURL=prisma-application.mapper.js.map
|
||||
-1
@@ -1 +0,0 @@
|
||||
{"version":3,"file":"prisma-application.mapper.js","sourceRoot":"","sources":["../../../../../src/modules/application/infrastructure/mappers/prisma-application.mapper.ts"],"names":[],"mappings":";;;AAAA,iFAA2E;AAE3E,MAAa,uBAAuB;IAClC,MAAM,CAAC,QAAQ,CAAC,KAAU;QACxB,OAAO,oCAAe,CAAC,OAAO,CAAC;YAC7B,EAAE,EAAE,KAAK,CAAC,EAAE;YACZ,IAAI,EAAE,KAAK,CAAC,IAAI;YAChB,IAAI,EAAE,KAAK,CAAC,IAAI;YAChB,WAAW,EAAE,KAAK,CAAC,WAAW;YAC9B,IAAI,EAAE,KAAK,CAAC,IAAI;YAChB,GAAG,EAAE,KAAK,CAAC,GAAG;YACd,iBAAiB,EAAE,KAAK,CAAC,iBAAiB;YAC1C,QAAQ,EAAE,KAAK,CAAC,QAAQ;YACxB,YAAY,EAAE,KAAK,CAAC,YAAY;YAChC,SAAS,EAAE,KAAK,CAAC,SAAS;YAC1B,SAAS,EAAE,KAAK,CAAC,SAAS;SAC3B,CAAC,CAAC;IACL,CAAC;CACF;AAhBD,0DAgBC"}
|
||||
-98
@@ -1,98 +0,0 @@
|
||||
"use strict";
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
var __metadata = (this && this.__metadata) || function (k, v) {
|
||||
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.PrismaApplicationRepository = void 0;
|
||||
const common_1 = require("@nestjs/common");
|
||||
const prisma_service_1 = require("../../../../shared/prisma.service");
|
||||
const prisma_application_mapper_1 = require("../mappers/prisma-application.mapper");
|
||||
let PrismaApplicationRepository = class PrismaApplicationRepository {
|
||||
prisma;
|
||||
constructor(prisma) {
|
||||
this.prisma = prisma;
|
||||
}
|
||||
async find(params) {
|
||||
const page = params.page && params.page > 0 ? params.page : 1;
|
||||
const limit = params.limit && params.limit > 0 ? params.limit : 25;
|
||||
const where = {};
|
||||
if (params.search) {
|
||||
where.OR = [
|
||||
{ name: { contains: params.search, mode: 'insensitive' } },
|
||||
{ code: { contains: params.search, mode: 'insensitive' } },
|
||||
{ description: { contains: params.search, mode: 'insensitive' } },
|
||||
];
|
||||
}
|
||||
if (params.isActive !== undefined && params.isActive !== null) {
|
||||
where.isActive = params.isActive;
|
||||
}
|
||||
if (params.applicationsClaimIn && params.applicationsClaimIn.length > 0) {
|
||||
where.applicationsClaim = { in: params.applicationsClaimIn };
|
||||
}
|
||||
const [total, items] = await Promise.all([
|
||||
this.prisma.application.count({ where }),
|
||||
this.prisma.application.findMany({ where, skip: (page - 1) * limit, take: limit, orderBy: { displayOrder: 'asc', createdAt: 'asc' } }),
|
||||
]);
|
||||
return { data: items.map(i => prisma_application_mapper_1.PrismaApplicationMapper.toDomain(i)), total };
|
||||
}
|
||||
async findById(id) {
|
||||
const row = await this.prisma.application.findUnique({ where: { id } });
|
||||
if (!row)
|
||||
throw new Error('Application not found');
|
||||
return prisma_application_mapper_1.PrismaApplicationMapper.toDomain(row);
|
||||
}
|
||||
async findByCode(code) {
|
||||
const row = await this.prisma.application.findUnique({ where: { code } });
|
||||
if (!row)
|
||||
return null;
|
||||
return prisma_application_mapper_1.PrismaApplicationMapper.toDomain(row);
|
||||
}
|
||||
async findByApplicationsClaim(claim) {
|
||||
const row = await this.prisma.application.findUnique({ where: { applicationsClaim: claim } });
|
||||
if (!row)
|
||||
return null;
|
||||
return prisma_application_mapper_1.PrismaApplicationMapper.toDomain(row);
|
||||
}
|
||||
async create(app) {
|
||||
const created = await this.prisma.application.create({ data: {
|
||||
id: app.id,
|
||||
code: app.code,
|
||||
name: app.name,
|
||||
description: app.description,
|
||||
icon: app.icon,
|
||||
url: app.url,
|
||||
applicationsClaim: app.applicationsClaim,
|
||||
isActive: app.isActive,
|
||||
displayOrder: app.displayOrder,
|
||||
} });
|
||||
return prisma_application_mapper_1.PrismaApplicationMapper.toDomain(created);
|
||||
}
|
||||
async update(app) {
|
||||
const updated = await this.prisma.application.update({ where: { id: app.id }, data: {
|
||||
code: app.code,
|
||||
name: app.name,
|
||||
description: app.description,
|
||||
icon: app.icon,
|
||||
url: app.url,
|
||||
applicationsClaim: app.applicationsClaim,
|
||||
isActive: app.isActive,
|
||||
displayOrder: app.displayOrder,
|
||||
} });
|
||||
return prisma_application_mapper_1.PrismaApplicationMapper.toDomain(updated);
|
||||
}
|
||||
async delete(appId) {
|
||||
await this.prisma.application.delete({ where: { id: appId } });
|
||||
}
|
||||
};
|
||||
exports.PrismaApplicationRepository = PrismaApplicationRepository;
|
||||
exports.PrismaApplicationRepository = PrismaApplicationRepository = __decorate([
|
||||
(0, common_1.Injectable)(),
|
||||
__metadata("design:paramtypes", [prisma_service_1.PrismaService])
|
||||
], PrismaApplicationRepository);
|
||||
//# sourceMappingURL=prisma-application.repository.js.map
|
||||
-1
@@ -1 +0,0 @@
|
||||
{"version":3,"file":"prisma-application.repository.js","sourceRoot":"","sources":["../../../../../src/modules/application/infrastructure/repositories/prisma-application.repository.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAA4C;AAC5C,sEAAkE;AAElE,oFAA+E;AAIxE,IAAM,2BAA2B,GAAjC,MAAM,2BAA2B;IACT;IAA7B,YAA6B,MAAqB;QAArB,WAAM,GAAN,MAAM,CAAe;IAAG,CAAC;IAEtD,KAAK,CAAC,IAAI,CAAC,MAAmI;QAC5I,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,IAAI,MAAM,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;QAC9D,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,IAAI,MAAM,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC;QAEnE,MAAM,KAAK,GAAQ,EAAE,CAAC;QACtB,IAAI,MAAM,CAAC,MAAM,EAAE,CAAC;YAClB,KAAK,CAAC,EAAE,GAAG;gBACT,EAAE,IAAI,EAAE,EAAE,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,EAAE,aAAa,EAAE,EAAE;gBAC1D,EAAE,IAAI,EAAE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gBACtB,YAAY,EAAE,GAAG,CAAC,YAAY;aAC/B,EAAE,CAAC,CAAC;QAEL,OAAO,mDAAuB,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;IACnD,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,GAAoB;QAC/B,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,EAAE,GAAG,CAAC,EAAE,EAAE,EAAE,IAAI,EAAE;gBAClF,IAAI,EAAE,GAAG,CAAC,IAAI;gBACd,IAAI,EAAE,GAAG,CAAC,IAAI;gBACd,WAAW,EAAE,GAAG,CAAC,WAAW;gBAC5B,IAAI,EAAE,GAAG,CAAC,IAAI;gBACd,GAAG,EAAE,GAAG,CAAC,GAAG;gBACZ,iBAAiB,EAAE,GAAG,CAAC,iBAAiB;gBACxC,QAAQ,EAAE,GAAG,CAAC,QAAQ;gBACtB,YAAY,EAAE,GAAG,CAAC,YAAY;aAC/B,EAAE,CAAC,CAAC;QAEL,OAAO,mDAAuB,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;IACnD,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,KAAa;QACxB,MAAM,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,EAAE,KAAK,EAAE,EAAE,CAAC,CAAC;IACjE,CAAC;CACF,CAAA;AApFY,kEAA2B;sCAA3B,2BAA2B;IADvC,IAAA,mBAAU,GAAE;qCAE0B,8BAAa;GADvC,2BAA2B,CAoFvC"}
|
||||
-136
@@ -1,136 +0,0 @@
|
||||
"use strict";
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
var __metadata = (this && this.__metadata) || function (k, v) {
|
||||
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
||||
};
|
||||
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
||||
return function (target, key) { decorator(target, key, paramIndex); }
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.ApplicationsController = void 0;
|
||||
const common_1 = require("@nestjs/common");
|
||||
const swagger_1 = require("@nestjs/swagger");
|
||||
const jwt_auth_guard_1 = require("../../../../core/auth/guards/jwt-auth.guard");
|
||||
const current_user_guard_1 = require("../../../identity/presentation/guards/current-user.guard");
|
||||
const get_applications_handler_1 = require("../../application/handlers/get-applications.handler");
|
||||
const get_application_handler_1 = require("../../application/handlers/get-application.handler");
|
||||
const create_application_handler_1 = require("../../application/handlers/create-application.handler");
|
||||
const update_application_handler_1 = require("../../application/handlers/update-application.handler");
|
||||
const delete_application_handler_1 = require("../../application/handlers/delete-application.handler");
|
||||
const get_me_applications_handler_1 = require("../../application/handlers/get-me-applications.handler");
|
||||
let ApplicationsController = class ApplicationsController {
|
||||
getApplicationsHandler;
|
||||
getApplicationHandler;
|
||||
createApplicationHandler;
|
||||
updateApplicationHandler;
|
||||
deleteApplicationHandler;
|
||||
getMeApplicationsHandler;
|
||||
constructor(getApplicationsHandler, getApplicationHandler, createApplicationHandler, updateApplicationHandler, deleteApplicationHandler, getMeApplicationsHandler) {
|
||||
this.getApplicationsHandler = getApplicationsHandler;
|
||||
this.getApplicationHandler = getApplicationHandler;
|
||||
this.createApplicationHandler = createApplicationHandler;
|
||||
this.updateApplicationHandler = updateApplicationHandler;
|
||||
this.deleteApplicationHandler = deleteApplicationHandler;
|
||||
this.getMeApplicationsHandler = getMeApplicationsHandler;
|
||||
}
|
||||
async findAll(query) {
|
||||
const res = await this.getApplicationsHandler.execute({ page: query.page, limit: query.limit, search: query.search });
|
||||
return { success: true, data: res.data.map(a => a.toResponse ? a.toResponse() : a), meta: { total: res.total } };
|
||||
}
|
||||
async findOne(id) {
|
||||
const app = await this.getApplicationHandler.execute(id);
|
||||
return { success: true, data: app.toResponse(), meta: {} };
|
||||
}
|
||||
async create(body) {
|
||||
const created = await this.createApplicationHandler.execute(body);
|
||||
return { success: true, data: created.toResponse(), meta: {} };
|
||||
}
|
||||
async update(id, body) {
|
||||
const updated = await this.updateApplicationHandler.execute(id, body);
|
||||
return { success: true, data: updated.toResponse(), meta: {} };
|
||||
}
|
||||
async remove(id) {
|
||||
await this.deleteApplicationHandler.execute(id);
|
||||
return { success: true, data: null, meta: {} };
|
||||
}
|
||||
// Dashboard endpoint
|
||||
async me(req) {
|
||||
const ctx = req.raylabContext;
|
||||
const identity = ctx && ctx.identity ? ctx.identity : {};
|
||||
const applicationsClaimList = identity.applications || [];
|
||||
const res = await this.getMeApplicationsHandler.execute(applicationsClaimList);
|
||||
return { success: true, data: res.data.map(a => a.toResponse ? a.toResponse() : a), meta: { total: res.total } };
|
||||
}
|
||||
};
|
||||
exports.ApplicationsController = ApplicationsController;
|
||||
__decorate([
|
||||
(0, common_1.Get)('applications'),
|
||||
(0, common_1.UseGuards)(jwt_auth_guard_1.JwtAuthGuard, current_user_guard_1.CurrentUserGuard),
|
||||
(0, swagger_1.ApiOperation)({ summary: 'List applications' }),
|
||||
__param(0, (0, common_1.Query)()),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", [Object]),
|
||||
__metadata("design:returntype", Promise)
|
||||
], ApplicationsController.prototype, "findAll", null);
|
||||
__decorate([
|
||||
(0, common_1.Get)('applications/:id'),
|
||||
(0, common_1.UseGuards)(jwt_auth_guard_1.JwtAuthGuard, current_user_guard_1.CurrentUserGuard),
|
||||
(0, swagger_1.ApiOperation)({ summary: 'Get application by id' }),
|
||||
__param(0, (0, common_1.Param)('id')),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", [String]),
|
||||
__metadata("design:returntype", Promise)
|
||||
], ApplicationsController.prototype, "findOne", null);
|
||||
__decorate([
|
||||
(0, common_1.Post)('applications'),
|
||||
(0, common_1.UseGuards)(jwt_auth_guard_1.JwtAuthGuard, current_user_guard_1.CurrentUserGuard),
|
||||
(0, swagger_1.ApiOperation)({ summary: 'Create application' }),
|
||||
__param(0, (0, common_1.Body)()),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", [Object]),
|
||||
__metadata("design:returntype", Promise)
|
||||
], ApplicationsController.prototype, "create", null);
|
||||
__decorate([
|
||||
(0, common_1.Patch)('applications/:id'),
|
||||
(0, common_1.UseGuards)(jwt_auth_guard_1.JwtAuthGuard, current_user_guard_1.CurrentUserGuard),
|
||||
(0, swagger_1.ApiOperation)({ summary: 'Update application' }),
|
||||
__param(0, (0, common_1.Param)('id')),
|
||||
__param(1, (0, common_1.Body)()),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", [String, Object]),
|
||||
__metadata("design:returntype", Promise)
|
||||
], ApplicationsController.prototype, "update", null);
|
||||
__decorate([
|
||||
(0, common_1.Delete)('applications/:id'),
|
||||
(0, common_1.UseGuards)(jwt_auth_guard_1.JwtAuthGuard, current_user_guard_1.CurrentUserGuard),
|
||||
(0, swagger_1.ApiOperation)({ summary: 'Delete application' }),
|
||||
__param(0, (0, common_1.Param)('id')),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", [String]),
|
||||
__metadata("design:returntype", Promise)
|
||||
], ApplicationsController.prototype, "remove", null);
|
||||
__decorate([
|
||||
(0, common_1.Get)('me/applications'),
|
||||
(0, common_1.UseGuards)(jwt_auth_guard_1.JwtAuthGuard, current_user_guard_1.CurrentUserGuard),
|
||||
(0, swagger_1.ApiOperation)({ summary: "Get current user's applications (filtered by Authentik claims)" }),
|
||||
__param(0, (0, common_1.Req)()),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", [Object]),
|
||||
__metadata("design:returntype", Promise)
|
||||
], ApplicationsController.prototype, "me", null);
|
||||
exports.ApplicationsController = ApplicationsController = __decorate([
|
||||
(0, swagger_1.ApiTags)('Applications'),
|
||||
(0, common_1.Controller)(),
|
||||
__metadata("design:paramtypes", [get_applications_handler_1.GetApplicationsHandler,
|
||||
get_application_handler_1.GetApplicationHandler,
|
||||
create_application_handler_1.CreateApplicationHandler,
|
||||
update_application_handler_1.UpdateApplicationHandler,
|
||||
delete_application_handler_1.DeleteApplicationHandler,
|
||||
get_me_applications_handler_1.GetMeApplicationsHandler])
|
||||
], ApplicationsController);
|
||||
//# sourceMappingURL=applications.controller.js.map
|
||||
-1
@@ -1 +0,0 @@
|
||||
{"version":3,"file":"applications.controller.js","sourceRoot":"","sources":["../../../../../src/modules/application/presentation/controllers/applications.controller.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAA0G;AAC1G,6CAAwD;AACxD,gFAA2E;AAC3E,iGAA4F;AAC5F,kGAA6F;AAC7F,gGAA2F;AAC3F,sGAAiG;AACjG,sGAAiG;AACjG,sGAAiG;AACjG,wGAAkG;AAI3F,IAAM,sBAAsB,GAA5B,MAAM,sBAAsB;IAEd;IACA;IACA;IACA;IACA;IACA;IANnB,YACmB,sBAA8C,EAC9C,qBAA4C,EAC5C,wBAAkD,EAClD,wBAAkD,EAClD,wBAAkD,EAClD,wBAAkD;QALlD,2BAAsB,GAAtB,sBAAsB,CAAwB;QAC9C,0BAAqB,GAArB,qBAAqB,CAAuB;QAC5C,6BAAwB,GAAxB,wBAAwB,CAA0B;QAClD,6BAAwB,GAAxB,wBAAwB,CAA0B;QAClD,6BAAwB,GAAxB,wBAAwB,CAA0B;QAClD,6BAAwB,GAAxB,wBAAwB,CAA0B;IAClE,CAAC;IAKE,AAAN,KAAK,CAAC,OAAO,CAAU,KAAU;QAC/B,MAAM,GAA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C"}
|
||||
-65
@@ -1,65 +0,0 @@
|
||||
"use strict";
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
var __metadata = (this && this.__metadata) || function (k, v) {
|
||||
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
||||
};
|
||||
var AuditEventHandler_1;
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.AuditEventHandler = void 0;
|
||||
const common_1 = require("@nestjs/common");
|
||||
const event_bus_service_1 = require("../../core/event-bus/event-bus.service");
|
||||
const audit_service_1 = require("./audit.service");
|
||||
let AuditEventHandler = AuditEventHandler_1 = class AuditEventHandler {
|
||||
events;
|
||||
auditService;
|
||||
logger = new common_1.Logger(AuditEventHandler_1.name);
|
||||
constructor(events, auditService) {
|
||||
this.events = events;
|
||||
this.auditService = auditService;
|
||||
this.events.subscribe('RolesSynchronized', (e) => this.handleRolesSynchronized(e));
|
||||
this.events.subscribe('UserAuthenticated', (e) => this.handleUserAuthenticated(e));
|
||||
this.events.subscribe('RoleCreated', (e) => this.handleGeneric(e));
|
||||
this.events.subscribe('RoleUpdated', (e) => this.handleGeneric(e));
|
||||
this.events.subscribe('RoleDeleted', (e) => this.handleGeneric(e));
|
||||
this.events.subscribe('PermissionCreated', (e) => this.handleGeneric(e));
|
||||
this.events.subscribe('PermissionUpdated', (e) => this.handleGeneric(e));
|
||||
this.events.subscribe('PermissionDeleted', (e) => this.handleGeneric(e));
|
||||
this.events.subscribe('UserActivated', (e) => this.handleGeneric(e));
|
||||
this.events.subscribe('UserDeactivated', (e) => this.handleGeneric(e));
|
||||
}
|
||||
async handleRolesSynchronized(event) {
|
||||
try {
|
||||
await this.auditService.createFromEvent(event);
|
||||
}
|
||||
catch (e) {
|
||||
this.logger.error('Audit handler failed', e);
|
||||
}
|
||||
}
|
||||
async handleUserAuthenticated(event) {
|
||||
try {
|
||||
await this.auditService.createFromEvent(event);
|
||||
}
|
||||
catch (e) {
|
||||
this.logger.error('Audit handler failed', e);
|
||||
}
|
||||
}
|
||||
async handleGeneric(event) {
|
||||
try {
|
||||
await this.auditService.createFromEvent(event);
|
||||
}
|
||||
catch (e) {
|
||||
this.logger.error('Audit handler failed', e);
|
||||
}
|
||||
}
|
||||
};
|
||||
exports.AuditEventHandler = AuditEventHandler;
|
||||
exports.AuditEventHandler = AuditEventHandler = AuditEventHandler_1 = __decorate([
|
||||
(0, common_1.Injectable)(),
|
||||
__metadata("design:paramtypes", [event_bus_service_1.EventBus, audit_service_1.AuditService])
|
||||
], AuditEventHandler);
|
||||
//# sourceMappingURL=audit.event-handler.js.map
|
||||
@@ -1 +0,0 @@
|
||||
{"version":3,"file":"audit.event-handler.js","sourceRoot":"","sources":["../../../src/modules/audit/audit.event-handler.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,2CAAoD;AACpD,8EAAkE;AAElE,mDAA+C;AAGxC,IAAM,iBAAiB,yBAAvB,MAAM,iBAAiB;IAGC;IAAmC;IAF/C,MAAM,GAAG,IAAI,eAAM,CAAC,mBAAiB,CAAC,IAAI,CAAC,CAAC;IAE7D,YAA6B,MAAgB,EAAmB,YAA0B;QAA7D,WAAM,GAAN,MAAM,CAAU;QAAmB,iBAAY,GAAZ,YAAY,CAAc;QACxF,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,mBAAmB,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,uBAAuB,CAAC,CAAC,CAAC,CAAC,CAAC;QACnF,IAAI,CAAC,MAAM,C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ACrD,IAAI,CAAC;YACH,MAAM,IAAI,CAAC,YAAY,CAAC,eAAe,CAAC,KAAK,CAAC,CAAC;QACjD,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,sBAAsB,EAAE,CAAQ,CAAC,CAAC;QACtD,CAAC;IACH,CAAC;IAED,KAAK,CAAC,uBAAuB,CAAC,KAAyB;QACrD,IAAI,CAAC;YACH,MAAM,IAAI,CAAC,YAAY,CAAC,eAAe,CAAC,KAAK,CAAC,CAAC;QACjD,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,sBAAsB,EAAE,CAAQ,CAAC,CAAC;QACtD,CAAC;IACH,CAAC;IAED,KAAK,CAAC,aAAa,CAAC,KAAyB;QAC3C,IAAI,CAAC;YACH,MAAM,IAAI,CAAC,YAAY,CAAC,eAAe,CAAC,KAAK,CAAC,CAAC;QACjD,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,sBAAsB,EAAE,CAAQ,CAAC,CAAC;QACtD,CAAC;IACH,CAAC;CACF,CAAA;AAvCY,8CAAiB;4BAAjB,iBAAiB;IAD7B,IAAA,mBAAU,GAAE;qCAI0B,4BAAQ,EAAiC,4BAAY;GAH/E,iBAAiB,CAuC7B"}
|
||||
Vendored
-24
@@ -1,24 +0,0 @@
|
||||
"use strict";
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.AuditModule = void 0;
|
||||
const common_1 = require("@nestjs/common");
|
||||
const audit_service_1 = require("./audit.service");
|
||||
const audit_event_handler_1 = require("./audit.event-handler");
|
||||
const prisma_service_1 = require("../../shared/prisma.service");
|
||||
const event_bus_service_1 = require("../../core/event-bus/event-bus.service");
|
||||
let AuditModule = class AuditModule {
|
||||
};
|
||||
exports.AuditModule = AuditModule;
|
||||
exports.AuditModule = AuditModule = __decorate([
|
||||
(0, common_1.Module)({
|
||||
providers: [audit_service_1.AuditService, audit_event_handler_1.AuditEventHandler, prisma_service_1.PrismaService, event_bus_service_1.EventBus],
|
||||
exports: [audit_service_1.AuditService],
|
||||
})
|
||||
], AuditModule);
|
||||
//# sourceMappingURL=audit.module.js.map
|
||||
-1
@@ -1 +0,0 @@
|
||||
{"version":3,"file":"audit.module.js","sourceRoot":"","sources":["../../../src/modules/audit/audit.module.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAAwC;AACxC,mDAA+C;AAC/C,+DAA0D;AAC1D,gEAA4D;AAC5D,8EAAkE;AAM3D,IAAM,WAAW,GAAjB,MAAM,WAAW;CAAG,CAAA;AAAd,kCAAW;sBAAX,WAAW;IAJvB,IAAA,eAAM,EAAC;QACN,SAAS,EAAE,CAAC,4BAAY,EAAE,uCAAiB,EAAE,8BAAa,EAAE,4BAAQ,CAAC;QACrE,OAAO,EAAE,CAAC,4BAAY,CAAC;KACxB,CAAC;GACW,WAAW,CAAG"}
|
||||
Vendored
-46
@@ -1,46 +0,0 @@
|
||||
"use strict";
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
var __metadata = (this && this.__metadata) || function (k, v) {
|
||||
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
||||
};
|
||||
var AuditService_1;
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.AuditService = void 0;
|
||||
const common_1 = require("@nestjs/common");
|
||||
const prisma_service_1 = require("../../shared/prisma.service");
|
||||
let AuditService = AuditService_1 = class AuditService {
|
||||
prisma;
|
||||
logger = new common_1.Logger(AuditService_1.name);
|
||||
constructor(prisma) {
|
||||
this.prisma = prisma;
|
||||
}
|
||||
async createFromEvent(event) {
|
||||
try {
|
||||
// Map standard events to AuditLog entries
|
||||
await this.prisma.auditLog.create({
|
||||
data: {
|
||||
userId: event.payload?.userId || null,
|
||||
action: event.type,
|
||||
resource: event.payload?.resource || null,
|
||||
resourceId: event.payload?.resourceId || null,
|
||||
details: event.payload,
|
||||
createdAt: new Date(event.timestamp),
|
||||
},
|
||||
});
|
||||
}
|
||||
catch (e) {
|
||||
this.logger.error('Failed to write audit log', e);
|
||||
}
|
||||
}
|
||||
};
|
||||
exports.AuditService = AuditService;
|
||||
exports.AuditService = AuditService = AuditService_1 = __decorate([
|
||||
(0, common_1.Injectable)(),
|
||||
__metadata("design:paramtypes", [prisma_service_1.PrismaService])
|
||||
], AuditService);
|
||||
//# sourceMappingURL=audit.service.js.map
|
||||
-1
@@ -1 +0,0 @@
|
||||
{"version":3,"file":"audit.service.js","sourceRoot":"","sources":["../../../src/modules/audit/audit.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,2CAAoD;AACpD,gEAA4D;AAIrD,IAAM,YAAY,oBAAlB,MAAM,YAAY;IAGM;IAFZ,MAAM,GAAG,IAAI,eAAM,CAAC,cAAY,CAAC,IAAI,CAAC,CAAC;IAExD,YAA6B,MAAqB;QAArB,WAAM,GAAN,MAAM,CAAe;IAAG,CAAC;IAEtD,KAAK,CAAC,eAAe,CAAC,KAAyB;QAC7C,IAAI,CAAC;YACH,0CAA0C;YAC1C,MAAM,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC;gBAChC,IAAI,EAAE;oBACJ,MAAM,EAAE,KAAK,CAAC,OAAO,EAAE,MAAM,IAAI,IAAI;oBACrC,MAAM,EAAE,KAAK,CAAC,IAAI;oBAClB,QAAQ,EAAE,KAAK,CAAC,OAAO,EAAE,QAAQ,IAAI,IAAI;oBACzC,UAAU,EAAE,KAAK,CAAC,OAAO,EAAE,UAAU,IAAI,IAAI;oBAC7C,OAAO,EAAE,KAAK,CAAC,OAAO;oBACtB,SAAS,EAAE,IAAI,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC;iBACrC;aACF,CAAC,CAAC;QACL,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,2BAA2B,EAAE,CAAQ,CAAC,CAAC;QAC3D,CAAC;IACH,CAAC;CACF,CAAA;AAtBY,oCAAY;uBAAZ,YAAY;IADxB,IAAA,mBAAU,GAAE;qCAI0B,8BAAa;GAHvC,YAAY,CAsBxB"}
|
||||
Vendored
-110
@@ -1,110 +0,0 @@
|
||||
"use strict";
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
var __metadata = (this && this.__metadata) || function (k, v) {
|
||||
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
||||
};
|
||||
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
||||
return function (target, key) { decorator(target, key, paramIndex); }
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.AuthController = void 0;
|
||||
const common_1 = require("@nestjs/common");
|
||||
const swagger_1 = require("@nestjs/swagger");
|
||||
const auth_service_1 = require("./auth.service");
|
||||
let AuthController = class AuthController {
|
||||
authService;
|
||||
constructor(authService) {
|
||||
this.authService = authService;
|
||||
}
|
||||
async login(returnTo, res) {
|
||||
const redirect = await this.authService.createAuthorizationRedirect(returnTo);
|
||||
return res.redirect(302, redirect);
|
||||
}
|
||||
async callback(code, state, res) {
|
||||
const result = await this.authService.handleCallback(code, state);
|
||||
// set cookies
|
||||
const cookieOptions = {
|
||||
httpOnly: true,
|
||||
secure: process.env.NODE_ENV === 'production',
|
||||
sameSite: 'lax',
|
||||
path: '/',
|
||||
};
|
||||
// access token cookie (internal JWT)
|
||||
res.cookie('raylab_jwt', result.accessToken, { ...cookieOptions, maxAge: result.expiresIn * 1000 });
|
||||
// refresh token cookie
|
||||
res.cookie('raylab_refresh', result.refreshToken, { ...cookieOptions, maxAge: result.refreshTtl * 1000 });
|
||||
return res.redirect(302, result.returnTo || '/');
|
||||
}
|
||||
async logout(req, res) {
|
||||
const refreshToken = req.cookies?.raylab_refresh || req.body?.refreshToken;
|
||||
const redirect = await this.authService.logout(refreshToken);
|
||||
return res.redirect(302, redirect);
|
||||
}
|
||||
async refresh(req) {
|
||||
const refreshToken = req.cookies?.raylab_refresh || req.body?.refreshToken;
|
||||
const result = await this.authService.refresh(refreshToken);
|
||||
return { success: true, data: result };
|
||||
}
|
||||
async me(req) {
|
||||
const token = (req.cookies?.raylab_jwt) || (req.headers.authorization && req.headers.authorization.replace(/^Bearer\s+/i, ''));
|
||||
const user = await this.authService.me(token);
|
||||
return { success: true, data: user };
|
||||
}
|
||||
};
|
||||
exports.AuthController = AuthController;
|
||||
__decorate([
|
||||
(0, common_1.Get)('login'),
|
||||
(0, swagger_1.ApiOperation)({ summary: 'Start Authorization Code + PKCE login (redirect to Identity Provider)' }),
|
||||
__param(0, (0, common_1.Query)('returnTo')),
|
||||
__param(1, (0, common_1.Res)()),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", [Object, Object]),
|
||||
__metadata("design:returntype", Promise)
|
||||
], AuthController.prototype, "login", null);
|
||||
__decorate([
|
||||
(0, common_1.Get)('callback'),
|
||||
(0, swagger_1.ApiOperation)({ summary: 'OIDC callback endpoint' }),
|
||||
__param(0, (0, common_1.Query)('code')),
|
||||
__param(1, (0, common_1.Query)('state')),
|
||||
__param(2, (0, common_1.Res)()),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", [String, String, Object]),
|
||||
__metadata("design:returntype", Promise)
|
||||
], AuthController.prototype, "callback", null);
|
||||
__decorate([
|
||||
(0, common_1.Post)('logout'),
|
||||
(0, common_1.HttpCode)(common_1.HttpStatus.OK),
|
||||
(0, swagger_1.ApiOperation)({ summary: 'Logout (invalidate internal session and redirect to identity provider logout)' }),
|
||||
__param(0, (0, common_1.Req)()),
|
||||
__param(1, (0, common_1.Res)()),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", [Object, Object]),
|
||||
__metadata("design:returntype", Promise)
|
||||
], AuthController.prototype, "logout", null);
|
||||
__decorate([
|
||||
(0, common_1.Post)('refresh'),
|
||||
(0, swagger_1.ApiOperation)({ summary: 'Refresh internal JWT using internal refresh token' }),
|
||||
__param(0, (0, common_1.Req)()),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", [Object]),
|
||||
__metadata("design:returntype", Promise)
|
||||
], AuthController.prototype, "refresh", null);
|
||||
__decorate([
|
||||
(0, common_1.Get)('me'),
|
||||
(0, swagger_1.ApiOperation)({ summary: 'Get current user from internal JWT (cookie or Authorization header)' }),
|
||||
__param(0, (0, common_1.Req)()),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", [Object]),
|
||||
__metadata("design:returntype", Promise)
|
||||
], AuthController.prototype, "me", null);
|
||||
exports.AuthController = AuthController = __decorate([
|
||||
(0, swagger_1.ApiTags)('Auth'),
|
||||
(0, common_1.Controller)('auth'),
|
||||
__metadata("design:paramtypes", [auth_service_1.AuthService])
|
||||
], AuthController);
|
||||
//# sourceMappingURL=auth.controller.js.map
|
||||
-1
@@ -1 +0,0 @@
|
||||
{"version":3,"file":"auth.controller.js","sourceRoot":"","sources":["../../../src/modules/auth/auth.controller.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AACA,2CAAoG;AACpG,6CAAwD;AACxD,iDAA6C;AAKtC,IAAM,cAAc,GAApB,MAAM,cAAc;IACI;IAA7B,YAA6B,WAAwB;QAAxB,gBAAW,GAAX,WAAW,CAAa;IAAG,CAAC;IAInD,AAAN,KAAK,CAAC,KAAK,CAAoB,QAA4B,EAAS,GAAa;QAC/E,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,WAAW,CAAC,2BAA2B,CAAC,QAAQ,CAAC,CAAC;QAC9E,OAAO,GAAG,CAAC,QAAQ,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC;IACrC,CAAC;IAIK,AAAN,KAAK,CAAC,QAAQ,CAAgB,IAAY,EAAkB,KAAa,EAAS,GAAa;QAC7F,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,WAAW,CAAC,cAAc,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;QAElE,cAAc;QACd,MAAM,aAAa,GAAQ;YACzB,QAAQ,EAAE,IAAI;YACd,MAAM,EAAE,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY;YAC7C,QAAQ,EAAE,KAAK;YACf,IAAI,EAAE,GAAG;SACV,CAAC;QAEF,qCAAqC;QACrC,GAAG,CAAC,MAAM,CAAC,YAAY,EAAE,MAAM,CAAC,WAAW,EAAE,EAAE,GAAG,aAAa,EAAE,MAAM,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AA,mBAAU,EAAC,MAAM,CAAC;qCAEyB,0BAAW;GAD1C,cAAc,CAwD1B"}
|
||||
Vendored
-75
@@ -1,75 +0,0 @@
|
||||
"use strict";
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.AuthModule = void 0;
|
||||
const common_1 = require("@nestjs/common");
|
||||
const auth_controller_1 = require("./auth.controller");
|
||||
const auth_service_1 = require("./auth.service");
|
||||
const config_1 = require("@nestjs/config");
|
||||
const jwt_1 = require("@nestjs/jwt");
|
||||
const prisma_service_1 = require("../../shared/prisma.service");
|
||||
const user_interface_1 = require("../identity/domain/repositories/user.interface");
|
||||
const prisma_user_repository_1 = require("../identity/infrastructure/repositories/prisma-user.repository");
|
||||
const sync_identity_handler_1 = require("../identity/application/handlers/user/sync-identity.handler");
|
||||
const role_interface_1 = require("../identity/domain/repositories/role.interface");
|
||||
const prisma_role_repository_1 = require("../identity/infrastructure/repositories/prisma-role.repository");
|
||||
const i_auth_config_1 = require("../identity/application/config/i-auth-config");
|
||||
const env_auth_config_1 = require("../identity/application/config/env-auth-config");
|
||||
const redis_pkce_store_1 = require("./pkce/redis-pkce.store");
|
||||
const inmemory_refresh_store_1 = require("./refresh/inmemory-refresh.store");
|
||||
const oidc_service_1 = require("./oidc.service");
|
||||
const role_sync_service_1 = require("./role-sync.service");
|
||||
const redis_service_1 = require("../../shared/redis.service");
|
||||
const group_hash_service_1 = require("./group-hash.service");
|
||||
const authentication_service_1 = require("./authentication.service");
|
||||
const event_bus_service_1 = require("../../core/event-bus/event-bus.service");
|
||||
const audit_service_1 = require("../audit/audit.service");
|
||||
const authorization_module_1 = require("../authorization/authorization.module");
|
||||
let AuthModule = class AuthModule {
|
||||
};
|
||||
exports.AuthModule = AuthModule;
|
||||
exports.AuthModule = AuthModule = __decorate([
|
||||
(0, common_1.Module)({
|
||||
imports: [
|
||||
config_1.ConfigModule,
|
||||
authorization_module_1.AuthorizationModule,
|
||||
jwt_1.JwtModule.registerAsync({
|
||||
imports: [config_1.ConfigModule],
|
||||
useFactory: async (config) => ({
|
||||
secret: config.get('RAYLAB_JWT_SECRET') || 'raylab-secret',
|
||||
signOptions: { algorithm: 'HS256' },
|
||||
}),
|
||||
inject: [config_1.ConfigService],
|
||||
}),
|
||||
],
|
||||
controllers: [auth_controller_1.AuthController],
|
||||
providers: [
|
||||
auth_service_1.AuthService,
|
||||
prisma_service_1.PrismaService,
|
||||
prisma_user_repository_1.PrismaUserRepository,
|
||||
prisma_role_repository_1.PrismaRoleRepository,
|
||||
sync_identity_handler_1.SyncIdentityHandler,
|
||||
{ provide: user_interface_1.IUser, useClass: prisma_user_repository_1.PrismaUserRepository },
|
||||
{ provide: role_interface_1.IRole, useClass: prisma_role_repository_1.PrismaRoleRepository },
|
||||
{ provide: i_auth_config_1.IAuthConfig, useClass: env_auth_config_1.EnvAuthConfig },
|
||||
// In-memory PKCE and Refresh stores (Redis removed)
|
||||
redis_pkce_store_1.RedisPkceStore,
|
||||
inmemory_refresh_store_1.InMemoryRefreshStore,
|
||||
// OIDC & Role Sync
|
||||
oidc_service_1.OidcService,
|
||||
role_sync_service_1.RoleSyncService,
|
||||
group_hash_service_1.GroupHashService,
|
||||
authentication_service_1.AuthenticationService,
|
||||
event_bus_service_1.EventBus,
|
||||
audit_service_1.AuditService,
|
||||
redis_service_1.RedisService,
|
||||
],
|
||||
exports: [auth_service_1.AuthService, oidc_service_1.OidcService, role_sync_service_1.RoleSyncService, authentication_service_1.AuthenticationService, event_bus_service_1.EventBus],
|
||||
})
|
||||
], AuthModule);
|
||||
//# sourceMappingURL=auth.module.js.map
|
||||
Vendored
-1
@@ -1 +0,0 @@
|
||||
{"version":3,"file":"auth.module.js","sourceRoot":"","sources":["../../../src/modules/auth/auth.module.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAAwC;AACxC,uDAAmD;AACnD,iDAA6C;AAC7C,2CAA6D;AAC7D,qCAAwC;AACxC,gEAA4D;AAC5D,mFAAuE;AACvE,2GAAsG;AACtG,uGAAkG;AAClG,mFAAuE;AACvE,2GAAsG;AACtG,gFAA2E;AAC3E,oFAA+E;AAC/E,8DAAyD;AACzD,6EAAwE;AACxE,iDAA6C;AAC7C,2DAAsD;AACtD,8DAA0D;AAC1D,6DAAwD;AACxD,qEAAiE;AACjE,8EAAkE;AAClE,0DAAsD;AACtD,gFAA4E;AA0CrE,IAAM,UAAU,GAAhB,MAAM,UAAU;CAAG,CAAA;AAAb,gCAAU;qBAAV,UAAU;IAvCtB,IAAA,eAAM,EAAC;QACN,OAAO,EAAE;YACP,qBAAY;YACZ,0CAAmB;YACnB,eAAS,CAAC,aAAa,CAAC;gBACtB,OAAO,EAAE,CAAC,qBAAY,CAAC;gBACvB,UAAU,EAAE,KAAK,EAAE,MAAqB,EAAE,EAAE,CAAC,CAAC;oBAC5C,MAAM,EAAE,MAAM,CAAC,GAAG,CAAC,mBAAmB,CAAC,IAAI,eAAe;oBAC1D,WAAW,EAAE,EAAE,SAAS,EAAE,OAAO,EAAE;iBACpC,CAAC;gBACF,MAAM,EAAE,CAAC,sBAAa,CAAC;aACxB,CAAC;SACH;QACD,WAAW,EAAE,CAAC,gCAAc,CAAC;QAC7B,SAAS,EAAE;YACT,0BAAW;YACX,8BAAa;YACb,6CAAoB;YACpB,6CAAoB;YACpB,2CAAmB;YACnB,EAAE,OAAO,EAAE,sBAAK,EAAE,QAAQ,EAAE,6CAAoB,EAAE;YAClD,EAAE,OAAO,EAAE,sBAAK,EAAE,QAAQ,EAAE,6CAAoB,EAAE;YAClD,EAAE,OAAO,EAAE,2BAAW,EAAE,QAAQ,EAAE,+BAAa,EAAE;YAEjD,oDAAoD;YACpD,iCAAc;YACd,6CAAoB;YAEpB,mBAAmB;YACnB,0BAAW;YACX,mCAAe;YACf,qCAAgB;YAChB,8CAAqB;YACrB,4BAAQ;YACR,4BAAY;YACZ,4BAAY;SACb;QACD,OAAO,EAAE,CAAC,0BAAW,EAAE,0BAAW,EAAE,mCAAe,EAAE,8CAAqB,EAAE,4BAAQ,CAAC;KACtF,CAAC;GACW,UAAU,CAAG"}
|
||||
Vendored
-209
@@ -1,209 +0,0 @@
|
||||
"use strict";
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
var __metadata = (this && this.__metadata) || function (k, v) {
|
||||
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
||||
};
|
||||
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
||||
return function (target, key) { decorator(target, key, paramIndex); }
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.AuthService = void 0;
|
||||
const common_1 = require("@nestjs/common");
|
||||
const config_1 = require("@nestjs/config");
|
||||
const jwt_1 = require("@nestjs/jwt");
|
||||
const sync_identity_handler_1 = require("../identity/application/handlers/user/sync-identity.handler");
|
||||
const user_interface_1 = require("../identity/domain/repositories/user.interface");
|
||||
const prisma_service_1 = require("../../shared/prisma.service");
|
||||
const redis_pkce_store_1 = require("./pkce/redis-pkce.store");
|
||||
const inmemory_refresh_store_1 = require("./refresh/inmemory-refresh.store");
|
||||
const openidClient = require('openid-client');
|
||||
let AuthService = class AuthService {
|
||||
config;
|
||||
jwtService;
|
||||
prisma;
|
||||
userRepository;
|
||||
syncIdentityHandler;
|
||||
pkceStore;
|
||||
refreshStore;
|
||||
constructor(config, jwtService, prisma, userRepository, syncIdentityHandler, pkceStore, refreshStore) {
|
||||
this.config = config;
|
||||
this.jwtService = jwtService;
|
||||
this.prisma = prisma;
|
||||
this.userRepository = userRepository;
|
||||
this.syncIdentityHandler = syncIdentityHandler;
|
||||
this.pkceStore = pkceStore;
|
||||
this.refreshStore = refreshStore;
|
||||
}
|
||||
issuer = null;
|
||||
client = null;
|
||||
async getIssuer() {
|
||||
if (this.issuer)
|
||||
return this.issuer;
|
||||
const issuerUrl = this.config.get('AUTHENTIK_ISSUER');
|
||||
if (!issuerUrl)
|
||||
throw new Error('AUTHENTIK_ISSUER not configured');
|
||||
this.issuer = await openidClient.Issuer.discover(issuerUrl);
|
||||
return this.issuer;
|
||||
}
|
||||
async getClient() {
|
||||
if (this.client)
|
||||
return this.client;
|
||||
const issuer = await this.getIssuer();
|
||||
const clientId = this.config.get('AUTHENTIK_CLIENT_ID');
|
||||
const clientSecret = this.config.get('AUTHENTIK_CLIENT_SECRET');
|
||||
if (!clientId)
|
||||
throw new Error('AUTHENTIK_CLIENT_ID not configured');
|
||||
this.client = new issuer.Client({ client_id: clientId, client_secret: clientSecret });
|
||||
return this.client;
|
||||
}
|
||||
async createAuthorizationRedirect(returnTo) {
|
||||
const client = await this.getClient();
|
||||
const redirectUri = this.config.get('AUTH_CALLBACK_URL') || `${this.config.get('APP_URL') || ''}/auth/callback`;
|
||||
const state = require('crypto').randomUUID();
|
||||
const code_verifier = openidClient.generators.codeVerifier();
|
||||
const code_challenge = await openidClient.generators.codeChallenge(code_verifier);
|
||||
const nonce = openidClient.generators.nonce();
|
||||
await this.pkceStore.save(state, { code_verifier, nonce, returnTo }, 300);
|
||||
const url = client.authorizationUrl({
|
||||
redirect_uri: redirectUri,
|
||||
scope: this.config.get('AUTHENTIK_DEFAULT_SCOPE') || 'openid email profile',
|
||||
response_type: 'code',
|
||||
code_challenge,
|
||||
code_challenge_method: 'S256',
|
||||
state,
|
||||
nonce,
|
||||
});
|
||||
return url;
|
||||
}
|
||||
async handleCallback(code, state) {
|
||||
const client = await this.getClient();
|
||||
const pkce = await this.pkceStore.get(state);
|
||||
if (!pkce)
|
||||
throw new common_1.UnauthorizedException('Invalid or expired state');
|
||||
// remove one-time state
|
||||
await this.pkceStore.remove(state);
|
||||
const redirectUri = this.config.get('AUTH_CALLBACK_URL') || `${this.config.get('APP_URL') || ''}/auth/callback`;
|
||||
// exchange code
|
||||
const tokenSet = await client.callback(redirectUri, { code, state }, { code_verifier: pkce.code_verifier, nonce: pkce.nonce });
|
||||
// verify id_token and get claims
|
||||
const claims = tokenSet.claims();
|
||||
// fetch userinfo if available
|
||||
let userInfo = null;
|
||||
try {
|
||||
if (tokenSet.access_token && client.userinfo) {
|
||||
userInfo = await client.userinfo(tokenSet.access_token);
|
||||
}
|
||||
}
|
||||
catch (e) {
|
||||
// ignore
|
||||
}
|
||||
const identity = {
|
||||
sub: userInfo?.sub || claims.sub || null,
|
||||
preferred_username: userInfo?.preferred_username || userInfo?.username || userInfo?.email || claims.preferred_username || claims.email,
|
||||
email: userInfo?.email || claims.email,
|
||||
raw: { tokenSet, userInfo, claims },
|
||||
};
|
||||
// Sync identity to local user (create if needed)
|
||||
const domainUser = await this.syncIdentityHandler.execute(identity);
|
||||
// ensure active/not deleted
|
||||
if (!domainUser.isActive)
|
||||
throw new common_1.UnauthorizedException('User is not active');
|
||||
if (domainUser.deletedAt)
|
||||
throw new common_1.UnauthorizedException('User is deleted');
|
||||
// create internal JWT
|
||||
const jwtPayload = {
|
||||
sub: domainUser.id,
|
||||
preferred_username: domainUser.username,
|
||||
email: domainUser.email,
|
||||
};
|
||||
const expiresIn = Number(this.config.get('RAYLAB_JWT_EXPIRES_IN') || 3600);
|
||||
const access = this.jwtService.sign(jwtPayload, { expiresIn });
|
||||
// create internal refresh token
|
||||
const refreshToken = require('crypto').randomUUID();
|
||||
const refreshTtl = Number(this.config.get('RAYLAB_REFRESH_EXPIRES_IN') || 30 * 24 * 3600); // default 30 days
|
||||
await this.refreshStore.set(refreshToken, { userId: domainUser.id }, refreshTtl);
|
||||
return {
|
||||
accessToken: access,
|
||||
refreshToken,
|
||||
expiresIn,
|
||||
refreshTtl,
|
||||
user: {
|
||||
id: domainUser.id,
|
||||
username: domainUser.username,
|
||||
email: domainUser.email,
|
||||
roles: domainUser.roles || [],
|
||||
},
|
||||
returnTo: pkce.returnTo,
|
||||
};
|
||||
}
|
||||
async refresh(refreshToken) {
|
||||
if (!refreshToken)
|
||||
throw new common_1.UnauthorizedException('Missing refresh token');
|
||||
const data = await this.refreshStore.get(refreshToken);
|
||||
if (!data)
|
||||
throw new common_1.UnauthorizedException('Invalid refresh token');
|
||||
const userId = data.userId;
|
||||
// load user
|
||||
const domainUser = await this.userRepository.getById(userId);
|
||||
if (!domainUser)
|
||||
throw new common_1.UnauthorizedException('User not found');
|
||||
if (!domainUser.isActive)
|
||||
throw new common_1.UnauthorizedException('User is not active');
|
||||
// rotate refresh token
|
||||
await this.refreshStore.del(refreshToken);
|
||||
const newRefresh = require('crypto').randomUUID();
|
||||
const refreshTtl = Number(this.config.get('RAYLAB_REFRESH_EXPIRES_IN') || 30 * 24 * 3600);
|
||||
await this.refreshStore.set(newRefresh, { userId }, refreshTtl);
|
||||
const expiresIn = Number(this.config.get('RAYLAB_JWT_EXPIRES_IN') || 3600);
|
||||
const access = this.jwtService.sign({ sub: domainUser.id, preferred_username: domainUser.username, email: domainUser.email }, { expiresIn });
|
||||
return { accessToken: access, refreshToken: newRefresh, expiresIn, refreshTtl };
|
||||
}
|
||||
async logout(refreshToken) {
|
||||
if (refreshToken) {
|
||||
await this.refreshStore.del(refreshToken);
|
||||
}
|
||||
const issuer = await this.getIssuer();
|
||||
const endSession = issuer.metadata.end_session_endpoint;
|
||||
const postLogout = this.config.get('APP_URL') || '/';
|
||||
if (endSession) {
|
||||
// Redirect to identity provider logout
|
||||
const url = new URL(endSession);
|
||||
if (postLogout)
|
||||
url.searchParams.set('post_logout_redirect_uri', postLogout);
|
||||
return url.toString();
|
||||
}
|
||||
return postLogout;
|
||||
}
|
||||
async me(token) {
|
||||
if (!token)
|
||||
throw new common_1.UnauthorizedException('Missing token');
|
||||
try {
|
||||
const payload = this.jwtService.verify(token);
|
||||
const user = await this.userRepository.getById(payload.sub);
|
||||
if (!user)
|
||||
throw new common_1.UnauthorizedException('User not found');
|
||||
return { id: user.id, username: user.username, email: user.email, roles: user.roles || [] };
|
||||
}
|
||||
catch (e) {
|
||||
throw new common_1.UnauthorizedException('Invalid token');
|
||||
}
|
||||
}
|
||||
};
|
||||
exports.AuthService = AuthService;
|
||||
exports.AuthService = AuthService = __decorate([
|
||||
(0, common_1.Injectable)(),
|
||||
__param(3, (0, common_1.Inject)(user_interface_1.IUser)),
|
||||
__metadata("design:paramtypes", [config_1.ConfigService,
|
||||
jwt_1.JwtService,
|
||||
prisma_service_1.PrismaService,
|
||||
user_interface_1.IUser,
|
||||
sync_identity_handler_1.SyncIdentityHandler,
|
||||
redis_pkce_store_1.RedisPkceStore,
|
||||
inmemory_refresh_store_1.InMemoryRefreshStore])
|
||||
], AuthService);
|
||||
//# sourceMappingURL=auth.service.js.map
|
||||
-1
File diff suppressed because one or more lines are too long
-70
@@ -1,70 +0,0 @@
|
||||
"use strict";
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
var __metadata = (this && this.__metadata) || function (k, v) {
|
||||
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
||||
};
|
||||
var AuthenticationService_1;
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.AuthenticationService = void 0;
|
||||
const common_1 = require("@nestjs/common");
|
||||
const oidc_service_1 = require("./oidc.service");
|
||||
const prisma_service_1 = require("../../shared/prisma.service");
|
||||
const role_sync_service_1 = require("./role-sync.service");
|
||||
const authorization_service_1 = require("../authorization/authorization.service");
|
||||
const event_bus_service_1 = require("../../core/event-bus/event-bus.service");
|
||||
let AuthenticationService = AuthenticationService_1 = class AuthenticationService {
|
||||
oidc;
|
||||
prisma;
|
||||
roleSync;
|
||||
authorization;
|
||||
events;
|
||||
logger = new common_1.Logger(AuthenticationService_1.name);
|
||||
constructor(oidc, prisma, roleSync, authorization, events) {
|
||||
this.oidc = oidc;
|
||||
this.prisma = prisma;
|
||||
this.roleSync = roleSync;
|
||||
this.authorization = authorization;
|
||||
this.events = events;
|
||||
}
|
||||
async authenticate(bearerToken) {
|
||||
// Validate token (signature/iss/aud/exp)
|
||||
const claims = await this.oidc.verifyToken(bearerToken);
|
||||
const sub = claims.sub;
|
||||
if (!sub)
|
||||
throw new Error('Invalid token: missing sub');
|
||||
// Resolve identity
|
||||
const identity = { sub, email: claims.email, preferred_username: claims.preferred_username, raw: claims };
|
||||
// Find or create user (materialize)
|
||||
let user = await this.prisma.user.findUnique({ where: { authentikId: sub } });
|
||||
if (!user) {
|
||||
user = await this.prisma.user.create({ data: { authentikId: sub, username: identity.preferred_username || identity.email || sub, email: identity.email || null } });
|
||||
}
|
||||
// Synchronize roles
|
||||
const groups = Array.isArray(claims.groups) ? claims.groups : [];
|
||||
await this.roleSync.syncUserRolesFromAuthentik(user.id, groups);
|
||||
// Load permissions
|
||||
const permissions = await this.authorization.getUserPermissions(user.id);
|
||||
// Build request context
|
||||
const rolesRows = await this.prisma.userRole.findMany({ where: { userId: user.id } });
|
||||
const roles = rolesRows.map((r) => r.roleId);
|
||||
const ctx = { user, identity, roles, permissions };
|
||||
// Publish domain event (legacy string event name expected by some subscribers/tests)
|
||||
this.events.publish('user.authenticated', { userId: user.id, identity });
|
||||
return ctx;
|
||||
}
|
||||
};
|
||||
exports.AuthenticationService = AuthenticationService;
|
||||
exports.AuthenticationService = AuthenticationService = AuthenticationService_1 = __decorate([
|
||||
(0, common_1.Injectable)(),
|
||||
__metadata("design:paramtypes", [oidc_service_1.OidcService,
|
||||
prisma_service_1.PrismaService,
|
||||
role_sync_service_1.RoleSyncService,
|
||||
authorization_service_1.AuthorizationService,
|
||||
event_bus_service_1.EventBus])
|
||||
], AuthenticationService);
|
||||
//# sourceMappingURL=authentication.service.js.map
|
||||
@@ -1 +0,0 @@
|
||||
{"version":3,"file":"authentication.service.js","sourceRoot":"","sources":["../../../src/modules/auth/authentication.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,2CAAoD;AACpD,iDAA6C;AAC7C,gEAA4D;AAC5D,2DAAsD;AACtD,kFAA8E;AAC9E,8EAAkE;AAI3D,IAAM,qBAAqB,6BAA3B,MAAM,qBAAqB;IAIb;IACA;IACA;IACA;IACA;IAPF,MAAM,GAAG,IAAI,eAAM,CAAC,uBAAqB,CAAC,IAAI,CAAC,CAAC;IAEjE,YACmB,IAAiB,EACjB,MAAqB,EACrB,QAAyB,EACzB,aAAmC,EACnC,MAAgB;QAJhB,SAAI,GAAJ,IAAI,CAAa;QACjB,WAAM,GAAN,MAAM,CAAe;QACrB,aAAQ,GAAR,QAAQ,CAAiB;QACzB,kBAAa,GAAb,aAAa,CAAsB;QACnC,WAAM,GAAN,MAAM,CAAU;IAChC,CAAC;IAEJ,KAAK,CAAC,YAAY,CAAC,WAAmB;QACpC,yCAAyC;QACzC,MAAM,MAAM,GAAG,MAAM,IAAI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Ac,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE,KAAK,EAAE,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;QAC/F,MAAM,KAAK,GAAG,SAAS,CAAC,GAAG,CAAC,CAAC,CAAM,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;QAElD,MAAM,GAAG,GAAmB,EAAE,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,WAAW,EAAE,CAAC;QAEnE,qFAAqF;QACrF,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,oBAAoB,EAAE,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,EAAE,QAAQ,EAAE,CAAC,CAAC;QAEzE,OAAO,GAAG,CAAC;IACb,CAAC;CACF,CAAA;AA7CY,sDAAqB;gCAArB,qBAAqB;IADjC,IAAA,mBAAU,GAAE;qCAKc,0BAAW;QACT,8BAAa;QACX,mCAAe;QACV,4CAAoB;QAC3B,4BAAQ;GARxB,qBAAqB,CA6CjC"}
|
||||
Vendored
-4
@@ -1,4 +0,0 @@
|
||||
"use strict";
|
||||
// Login DTO removed. Password grant has been removed in favor of Authorization Code + PKCE flow.
|
||||
// Formerly contained username/password properties.
|
||||
//# sourceMappingURL=login.dto.js.map
|
||||
-1
@@ -1 +0,0 @@
|
||||
{"version":3,"file":"login.dto.js","sourceRoot":"","sources":["../../../../src/modules/auth/dto/login.dto.ts"],"names":[],"mappings":";AAAA,iGAAiG;AACjG,mDAAmD"}
|
||||
-56
@@ -1,56 +0,0 @@
|
||||
"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 __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
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.GroupHashService = void 0;
|
||||
const common_1 = require("@nestjs/common");
|
||||
const crypto = __importStar(require("crypto"));
|
||||
let GroupHashService = class GroupHashService {
|
||||
compute(groups) {
|
||||
const sorted = (groups || []).slice().sort();
|
||||
const data = sorted.join(',');
|
||||
return crypto.createHash('sha256').update(data, 'utf8').digest('hex');
|
||||
}
|
||||
};
|
||||
exports.GroupHashService = GroupHashService;
|
||||
exports.GroupHashService = GroupHashService = __decorate([
|
||||
(0, common_1.Injectable)()
|
||||
], GroupHashService);
|
||||
//# sourceMappingURL=group-hash.service.js.map
|
||||
-1
@@ -1 +0,0 @@
|
||||
{"version":3,"file":"group-hash.service.js","sourceRoot":"","sources":["../../../src/modules/auth/group-hash.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,2CAA4C;AAC5C,+CAAiC;AAG1B,IAAM,gBAAgB,GAAtB,MAAM,gBAAgB;IAC3B,OAAO,CAAC,MAAgB;QACtB,MAAM,MAAM,GAAG,CAAC,MAAM,IAAI,EAAE,CAAC,CAAC,KAAK,EAAE,CAAC,IAAI,EAAE,CAAC;QAC7C,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAC9B,OAAO,MAAM,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IACxE,CAAC;CACF,CAAA;AANY,4CAAgB;2BAAhB,gBAAgB;IAD5B,IAAA,mBAAU,GAAE;GACA,gBAAgB,CAM5B"}
|
||||
-48
@@ -1,48 +0,0 @@
|
||||
"use strict";
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
var __metadata = (this && this.__metadata) || function (k, v) {
|
||||
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
||||
};
|
||||
var OidcGuard_1;
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.OidcGuard = void 0;
|
||||
const common_1 = require("@nestjs/common");
|
||||
const oidc_service_1 = require("../oidc.service");
|
||||
const authentication_service_1 = require("../authentication.service");
|
||||
let OidcGuard = OidcGuard_1 = class OidcGuard {
|
||||
oidc;
|
||||
authn;
|
||||
logger = new common_1.Logger(OidcGuard_1.name);
|
||||
constructor(oidc, authn) {
|
||||
this.oidc = oidc;
|
||||
this.authn = authn;
|
||||
}
|
||||
async canActivate(context) {
|
||||
const req = context.switchToHttp().getRequest();
|
||||
const auth = req.headers['authorization'] || req.headers['Authorization'];
|
||||
if (!auth || typeof auth !== 'string' || !auth.startsWith('Bearer '))
|
||||
throw new common_1.UnauthorizedException('Missing bearer token');
|
||||
const token = auth.substring(7).trim();
|
||||
try {
|
||||
const ctx = await this.authn.authenticate(token);
|
||||
// attach context to request under a structured key
|
||||
req.raylabContext = ctx;
|
||||
return true;
|
||||
}
|
||||
catch (e) {
|
||||
this.logger.debug('Authentication failed', e.message);
|
||||
throw new common_1.UnauthorizedException('Invalid token or authentication failed');
|
||||
}
|
||||
}
|
||||
};
|
||||
exports.OidcGuard = OidcGuard;
|
||||
exports.OidcGuard = OidcGuard = OidcGuard_1 = __decorate([
|
||||
(0, common_1.Injectable)(),
|
||||
__metadata("design:paramtypes", [oidc_service_1.OidcService, authentication_service_1.AuthenticationService])
|
||||
], OidcGuard);
|
||||
//# sourceMappingURL=oidc.guard.js.map
|
||||
-1
@@ -1 +0,0 @@
|
||||
{"version":3,"file":"oidc.guard.js","sourceRoot":"","sources":["../../../../src/modules/auth/guards/oidc.guard.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,2CAAkH;AAClH,kDAA8C;AAC9C,sEAAkE;AAG3D,IAAM,SAAS,iBAAf,MAAM,SAAS;IAES;IAAoC;IADhD,MAAM,GAAG,IAAI,eAAM,CAAC,WAAS,CAAC,IAAI,CAAC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QAAQ,EAAE,IAAI,CAAC,QAAQ;aACjB,CAAC,CAAC;YAEV,OAAO,OAA8B,CAAC;QACxC,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,2BAA2B,EAAG,CAAW,CAAC,OAAO,CAAC,CAAC;YACrE,MAAM,CAAC,CAAC;QACV,CAAC;IACH,CAAC;CACF,CAAA;AAhCY,kCAAW;sBAAX,WAAW;IADvB,IAAA,mBAAU,GAAE;qCAO0B,sBAAa;GANvC,WAAW,CAgCvB"}
|
||||
-56
@@ -1,56 +0,0 @@
|
||||
"use strict";
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
var __metadata = (this && this.__metadata) || function (k, v) {
|
||||
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.RedisPkceStore = void 0;
|
||||
const common_1 = require("@nestjs/common");
|
||||
let RedisPkceStore = class RedisPkceStore {
|
||||
// In-memory PKCE store replacing Redis-backed implementation
|
||||
map = new Map();
|
||||
cleanupInterval;
|
||||
constructor() {
|
||||
// periodic cleanup
|
||||
this.cleanupInterval = setInterval(() => {
|
||||
const now = Date.now();
|
||||
for (const [k, v] of this.map.entries()) {
|
||||
if (v.expiresAt <= now)
|
||||
this.map.delete(k);
|
||||
}
|
||||
}, 60 * 1000);
|
||||
}
|
||||
key(state) { return state; }
|
||||
async save(state, data, ttlSeconds = 300) {
|
||||
const expiresAt = Date.now() + ttlSeconds * 1000;
|
||||
this.map.set(this.key(state), { ...data, expiresAt });
|
||||
}
|
||||
async get(state) {
|
||||
const v = this.map.get(this.key(state));
|
||||
if (!v)
|
||||
return null;
|
||||
if (v.expiresAt <= Date.now()) {
|
||||
this.map.delete(this.key(state));
|
||||
return null;
|
||||
}
|
||||
return { code_verifier: v.code_verifier, nonce: v.nonce, returnTo: v.returnTo };
|
||||
}
|
||||
async remove(state) {
|
||||
this.map.delete(this.key(state));
|
||||
}
|
||||
onModuleDestroy() {
|
||||
if (this.cleanupInterval)
|
||||
clearInterval(this.cleanupInterval);
|
||||
}
|
||||
};
|
||||
exports.RedisPkceStore = RedisPkceStore;
|
||||
exports.RedisPkceStore = RedisPkceStore = __decorate([
|
||||
(0, common_1.Injectable)(),
|
||||
__metadata("design:paramtypes", [])
|
||||
], RedisPkceStore);
|
||||
//# sourceMappingURL=redis-pkce.store.js.map
|
||||
@@ -1 +0,0 @@
|
||||
{"version":3,"file":"redis-pkce.store.js","sourceRoot":"","sources":["../../../../src/modules/auth/pkce/redis-pkce.store.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAA6D;AAKtD,IAAM,cAAc,GAApB,MAAM,cAAc;IACzB,6DAA6D;IACrD,GAAG,GAAG,IAAI,GAAG,EAAqB,CAAC;IACnC,eAAe,CAAkB;IAEzC;QACE,mBAAmB;QACnB,IAAI,CAAC,eAAe,GAAG,WAAW,CAAC,GAAG,EAAE;YACtC,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;YACvB,KAAK,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE,EAAE,CAAC;gBACxC,IAAI,CAAC,CAAC,SAAS,IAAI,GAAG;oBAAE,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;YAC7C,CAAC;QACH,CAAC,EAAE,EAAE,GAAG,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cAAc,CAoC1B"}
|
||||
@@ -1,53 +0,0 @@
|
||||
"use strict";
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
var __metadata = (this && this.__metadata) || function (k, v) {
|
||||
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.InMemoryRefreshStore = void 0;
|
||||
const common_1 = require("@nestjs/common");
|
||||
let InMemoryRefreshStore = class InMemoryRefreshStore {
|
||||
map = new Map();
|
||||
cleanupInterval;
|
||||
constructor() {
|
||||
this.cleanupInterval = setInterval(() => {
|
||||
const now = Date.now();
|
||||
for (const [k, v] of this.map.entries()) {
|
||||
if (v.expiresAt <= now)
|
||||
this.map.delete(k);
|
||||
}
|
||||
}, 60 * 1000);
|
||||
}
|
||||
async set(token, data, ttlSeconds) {
|
||||
const expiresAt = Date.now() + ttlSeconds * 1000;
|
||||
this.map.set(token, { userId: data.userId, expiresAt });
|
||||
}
|
||||
async get(token) {
|
||||
const v = this.map.get(token);
|
||||
if (!v)
|
||||
return null;
|
||||
if (v.expiresAt <= Date.now()) {
|
||||
this.map.delete(token);
|
||||
return null;
|
||||
}
|
||||
return { userId: v.userId };
|
||||
}
|
||||
async del(token) {
|
||||
this.map.delete(token);
|
||||
}
|
||||
onModuleDestroy() {
|
||||
if (this.cleanupInterval)
|
||||
clearInterval(this.cleanupInterval);
|
||||
}
|
||||
};
|
||||
exports.InMemoryRefreshStore = InMemoryRefreshStore;
|
||||
exports.InMemoryRefreshStore = InMemoryRefreshStore = __decorate([
|
||||
(0, common_1.Injectable)(),
|
||||
__metadata("design:paramtypes", [])
|
||||
], InMemoryRefreshStore);
|
||||
//# sourceMappingURL=inmemory-refresh.store.js.map
|
||||
@@ -1 +0,0 @@
|
||||
{"version":3,"file":"inmemory-refresh.store.js","sourceRoot":"","sources":["../../../../src/modules/auth/refresh/inmemory-refresh.store.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAA6D;AAKtD,IAAM,oBAAoB,GAA1B,MAAM,oBAAoB;IACvB,GAAG,GAAG,IAAI,GAAG,EAAwB,CAAC;IACtC,eAAe,CAAkB;IAEzC;QACE,IAAI,CAAC,eAAe,GAAG,WAAW,CAAC,GAAG,EAAE;YACtC,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;YACvB,KAAK,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE,EAAE,CAAC;gBACxC,IAAI,CAAC,CAAC,SAAS,IAAI,GAAG;oBAAE,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;YAC7C,CAAC;QACH,CAAC,EAAE,EAAE,GAAG,IAAI,CAAC,CAAC;IAChB,CAAC;IAED,KAAK,CAAC,GAAG,CAAC,KAAa,EAAE,IAAwB,EAAE,UAAkB;QACnE,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,UAAU,GAAG,IAAI,CAAC;QACjD,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,KAAK,EAAE,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,SAAS,EAAE,CAAC,CAAC;IAC1D,CAAC;IAED,KAAK,CAAC,GAAG,CAAC,KAAa;QACrB,MAAM,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;QAC9B,IAAI,CAAC,CAAC;YAAE,OAAO,IAAI,CAAC;QACpB,IAAI,CAAC,CAAC,SAAS,IAAI,IAAI,CAAC,GAAG,EAAE,EAAE,CAAC;YAAC,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;YAAC,OAAO,IAAI,CAAC;QAAC,CAAC;QACvE,OAAO,EAAE,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC;IAC9B,CAAC;IAED,KAAK,CAAC,GAAG,CAAC,KAAa;QACrB,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IACzB,CAAC;IAED,eAAe;QACb,IAAI,IAAI,CAAC,eAAe;YAAE,aAAa,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;IAChE,CAAC;CACF,CAAA;AAhCY,oDAAoB;+BAApB,oBAAoB;IADhC,IAAA,mBAAU,GAAE;;GACA,oBAAoB,CAgChC"}
|
||||
-88
@@ -1,88 +0,0 @@
|
||||
"use strict";
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
var __metadata = (this && this.__metadata) || function (k, v) {
|
||||
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
||||
};
|
||||
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
||||
return function (target, key) { decorator(target, key, paramIndex); }
|
||||
};
|
||||
var RoleSyncService_1;
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.RoleSyncService = void 0;
|
||||
const common_1 = require("@nestjs/common");
|
||||
const prisma_service_1 = require("../../shared/prisma.service");
|
||||
const event_bus_service_1 = require("../../core/event-bus/event-bus.service");
|
||||
const group_hash_service_1 = require("./group-hash.service");
|
||||
const authorization_service_1 = require("../authorization/authorization.service");
|
||||
let RoleSyncService = RoleSyncService_1 = class RoleSyncService {
|
||||
prisma;
|
||||
groupHash;
|
||||
permissionCache;
|
||||
events;
|
||||
logger = new common_1.Logger(RoleSyncService_1.name);
|
||||
constructor(prisma, groupHash, permissionCache, events) {
|
||||
this.prisma = prisma;
|
||||
this.groupHash = groupHash;
|
||||
this.permissionCache = permissionCache;
|
||||
this.events = events;
|
||||
}
|
||||
computeGroupHash(groups) {
|
||||
return this.groupHash.compute(groups || []);
|
||||
}
|
||||
async mapGroupsToRoleIds(groups) {
|
||||
if (!groups || groups.length === 0)
|
||||
return [];
|
||||
const mappings = await this.prisma.authGroupRoleMapping.findMany({ where: { authGroup: { in: groups } } });
|
||||
const roleIds = mappings.map((m) => m.roleId);
|
||||
return Array.from(new Set(roleIds));
|
||||
}
|
||||
async syncUserRolesFromAuthentik(userId, groups) {
|
||||
const groupHash = this.computeGroupHash(groups || []);
|
||||
const user = await this.prisma.user.findUnique({ where: { id: userId } });
|
||||
if (!user)
|
||||
throw new Error('User not found');
|
||||
if (user.lastGroupHash === groupHash) {
|
||||
this.logger.debug('Group hash unchanged, skipping sync');
|
||||
return { skipped: true };
|
||||
}
|
||||
const roleIds = await this.mapGroupsToRoleIds(groups || []);
|
||||
const previousRoleRows = await this.prisma.userRole.findMany({ where: { userId, source: 'AUTHENTIK' }, select: { roleId: true } });
|
||||
const previousRoles = previousRoleRows.map((r) => r.roleId);
|
||||
await this.prisma.$transaction(async (tx) => {
|
||||
await tx.userRole.deleteMany({ where: { userId: userId, source: 'AUTHENTIK' } });
|
||||
if (roleIds.length > 0) {
|
||||
const createData = roleIds.map((rid) => ({ userId, roleId: rid, source: 'AUTHENTIK' }));
|
||||
await tx.userRole.createMany({ data: createData, skipDuplicates: true });
|
||||
}
|
||||
await tx.user.update({ where: { id: userId }, data: { lastGroupHash: groupHash } });
|
||||
});
|
||||
// Invalidate permission cache through abstraction
|
||||
try {
|
||||
await this.permissionCache.invalidate(userId);
|
||||
}
|
||||
catch (e) {
|
||||
this.logger.error('Failed to invalidate permission cache', e);
|
||||
}
|
||||
// Publish event for audit and other subscribers
|
||||
this.events.publish({
|
||||
id: require('crypto').randomUUID(),
|
||||
timestamp: new Date().toISOString(),
|
||||
type: 'RolesSynchronized',
|
||||
payload: { userId, groups, assignedRoleIds: roleIds, previousRoles },
|
||||
});
|
||||
return { skipped: false, assignedRoleIds: roleIds };
|
||||
}
|
||||
};
|
||||
exports.RoleSyncService = RoleSyncService;
|
||||
exports.RoleSyncService = RoleSyncService = RoleSyncService_1 = __decorate([
|
||||
(0, common_1.Injectable)(),
|
||||
__param(2, (0, common_1.Inject)(authorization_service_1.PERMISSION_CACHE)),
|
||||
__metadata("design:paramtypes", [prisma_service_1.PrismaService,
|
||||
group_hash_service_1.GroupHashService, Object, event_bus_service_1.EventBus])
|
||||
], RoleSyncService);
|
||||
//# sourceMappingURL=role-sync.service.js.map
|
||||
-1
@@ -1 +0,0 @@
|
||||
{"version":3,"file":"role-sync.service.js","sourceRoot":"","sources":["../../../src/modules/auth/role-sync.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAA4D;AAC5D,gEAA4D;AAE5D,8EAAkE;AAClE,6DAAwD;AACxD,kFAA0E;AAGnE,IAAM,eAAe,uBAArB,MAAM,eAAe;IAIP;IACA;IAC0B;IAC1B;IANF,MAAM,GAAG,IAAI,eAAM,CAAC,iBAAe,CAAC,IAAI,CAAC,CAAC;IAE3D,YACmB,MAAqB,EACrB,SAA2B,EACD,eAAgC,EAC1D,MAAgB;QAHhB,WAAM,GAAN,MAAM,CAAe;QACrB,cAAS,GAAT,SAAS,CAAkB;QACD,oBAAe,GAAf,eAAe,CAAiB;QAC1D,WAAM,GAAN,MAAM,CAAU;IAChC,CAAC;IAEJ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C,MAAM,CAAC,KAAK,CAAC,uCAAuC,EAAE,CAAQ,CAAC,CAAC;QACvE,CAAC;QAED,gDAAgD;QAChD,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC;YAClB,EAAE,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC,UAAU,EAAE;YAClC,SAAS,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;YACnC,IAAI,EAAE,mBAAmB;YACzB,OAAO,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,eAAe,EAAE,OAAO,EAAE,aAAa,EAAE;SACrE,CAAC,CAAC;QAEH,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,eAAe,EAAE,OAAO,EAAE,CAAC;IACtD,CAAC;CACF,CAAA;AAjEY,0CAAe;0BAAf,eAAe;IAD3B,IAAA,mBAAU,GAAE;IAOR,WAAA,IAAA,eAAM,EAAC,wCAAgB,CAAC,CAAA;qCAFA,8BAAa;QACV,qCAAgB,UAEnB,4BAAQ;GAPxB,eAAe,CAiE3B"}
|
||||
@@ -1,29 +0,0 @@
|
||||
"use strict";
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.AuthorizationModule = void 0;
|
||||
const common_1 = require("@nestjs/common");
|
||||
const authorization_service_1 = require("./authorization.service");
|
||||
const prisma_service_1 = require("../../shared/prisma.service");
|
||||
const redis_service_1 = require("../../shared/redis.service");
|
||||
const redis_permission_cache_service_1 = require("./cache/redis-permission-cache.service");
|
||||
let AuthorizationModule = class AuthorizationModule {
|
||||
};
|
||||
exports.AuthorizationModule = AuthorizationModule;
|
||||
exports.AuthorizationModule = AuthorizationModule = __decorate([
|
||||
(0, common_1.Module)({
|
||||
providers: [
|
||||
authorization_service_1.AuthorizationService,
|
||||
prisma_service_1.PrismaService,
|
||||
redis_service_1.RedisService,
|
||||
{ provide: authorization_service_1.PERMISSION_CACHE, useClass: redis_permission_cache_service_1.RedisPermissionCache },
|
||||
],
|
||||
exports: [authorization_service_1.AuthorizationService, authorization_service_1.PERMISSION_CACHE],
|
||||
})
|
||||
], AuthorizationModule);
|
||||
//# sourceMappingURL=authorization.module.js.map
|
||||
@@ -1 +0,0 @@
|
||||
{"version":3,"file":"authorization.module.js","sourceRoot":"","sources":["../../../src/modules/authorization/authorization.module.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAAwC;AACxC,mEAAiF;AACjF,gEAA4D;AAC5D,8DAA0D;AAC1D,2FAA8E;AAWvE,IAAM,mBAAmB,GAAzB,MAAM,mBAAmB;CAAG,CAAA;AAAtB,kDAAmB;8BAAnB,mBAAmB;IAT/B,IAAA,eAAM,EAAC;QACN,SAAS,EAAE;YACT,4CAAoB;YACpB,8BAAa;YACb,4BAAY;YACZ,EAAE,OAAO,EAAE,wCAAgB,EAAE,QAAQ,EAAE,qDAAoB,EAAE;SAC9D;QACD,OAAO,EAAE,CAAC,4CAAoB,EAAE,wCAAgB,CAAC;KAClD,CAAC;GACW,mBAAmB,CAAG"}
|
||||
@@ -1,71 +0,0 @@
|
||||
"use strict";
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
var __metadata = (this && this.__metadata) || function (k, v) {
|
||||
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
||||
};
|
||||
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
||||
return function (target, key) { decorator(target, key, paramIndex); }
|
||||
};
|
||||
var AuthorizationService_1;
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.AuthorizationService = exports.PERMISSION_CACHE = void 0;
|
||||
const common_1 = require("@nestjs/common");
|
||||
const prisma_service_1 = require("../../shared/prisma.service");
|
||||
exports.PERMISSION_CACHE = 'PERMISSION_CACHE';
|
||||
let AuthorizationService = AuthorizationService_1 = class AuthorizationService {
|
||||
prisma;
|
||||
cache;
|
||||
logger = new common_1.Logger(AuthorizationService_1.name);
|
||||
constructor(prisma, cache) {
|
||||
this.prisma = prisma;
|
||||
this.cache = cache;
|
||||
}
|
||||
async getUserPermissions(userId) {
|
||||
try {
|
||||
const cached = await this.cache.get(userId);
|
||||
if (cached)
|
||||
return cached;
|
||||
}
|
||||
catch (e) {
|
||||
this.logger.debug('PermissionCache get failed', e);
|
||||
}
|
||||
const rows = await this.prisma.$queryRaw `
|
||||
SELECT p.code as code
|
||||
FROM "UserRole" ur
|
||||
JOIN "RolePermission" rp ON rp.role_id = ur.role_id
|
||||
JOIN "Permission" p ON p.id = rp.permission_id
|
||||
WHERE ur.user_id = ${userId}`;
|
||||
const perms = Array.isArray(rows) ? rows.map((r) => r.code) : [];
|
||||
try {
|
||||
await this.cache.set(userId, perms);
|
||||
}
|
||||
catch (e) {
|
||||
this.logger.debug('PermissionCache set failed', e);
|
||||
}
|
||||
return perms;
|
||||
}
|
||||
async hasPermission(userId, permissionCode) {
|
||||
const perms = await this.getUserPermissions(userId);
|
||||
return perms.includes(permissionCode);
|
||||
}
|
||||
async invalidateUserPermissions(userId) {
|
||||
try {
|
||||
await this.cache.invalidate(userId);
|
||||
}
|
||||
catch (e) {
|
||||
this.logger.debug('PermissionCache invalidate failed', e);
|
||||
}
|
||||
}
|
||||
};
|
||||
exports.AuthorizationService = AuthorizationService;
|
||||
exports.AuthorizationService = AuthorizationService = AuthorizationService_1 = __decorate([
|
||||
(0, common_1.Injectable)(),
|
||||
__param(1, (0, common_1.Inject)(exports.PERMISSION_CACHE)),
|
||||
__metadata("design:paramtypes", [prisma_service_1.PrismaService, Object])
|
||||
], AuthorizationService);
|
||||
//# sourceMappingURL=authorization.service.js.map
|
||||
@@ -1 +0,0 @@
|
||||
{"version":3,"file":"authorization.service.js","sourceRoot":"","sources":["../../../src/modules/authorization/authorization.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAA4D;AAC5D,gEAA4D;AAG/C,QAAA,gBAAgB,GAAG,kBAAkB,CAAC;AAG5C,IAAM,oBAAoB,4BAA1B,MAAM,oBAAoB;IAGF;IAAkE;IAF9E,MAAM,GAAG,IAAI,eAAM,CAAC,sBAAoB,CAAC,IAAI,CAAC,CAAC;IAEhE,YAA6B,MAAqB,EAA6C,KAAsB;QAAxF,WAAM,GAAN,MAAM,CAAe;QAA6C,UAAK,GAAL,KAAK,CAAiB;IAAG,CAAC;IAEzH,KAAK,CAAC,kBAAkB,CAAC,MAAc;QACrC,IAAI,CAAC;YACH,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;YAC5C,IAAI,MAAM;gBAAE,OAAO,MAAM,CAAC;QAC5B,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,4BAA4B,EAAE,CAAQ,CAAC,CAAC;QAC5D,CAAC;QAED,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,SAAS,CAAA;;;;;2BAKjB,MAAM,EAAE,CAAC;QAEhC,MAAM,KAAK,GAAG,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAM,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QAEtE,IAAI,CAAC;YACH,MAAM,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;QACtC,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,4BAA4B,EAAE,CAAQ,CAAC,CAAC;QAC5D,CAAC;QAED,OAAO,KAAK,CAAC;IACf,CAAC;IAED,KAAK,CAAC,aAAa,CAAC,MAAc,EAAE,cAAsB;QACxD,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,kBAAkB,CAAC,MAAM,CAAC,CAAC;QACpD,OAAO,KAAK,CAAC,QAAQ,CAAC,cAAc,CAAC,CAAC;IACxC,CAAC;IAED,KAAK,CAAC,yBAAyB,CAAC,MAAc;QAC5C,IAAI,CAAC;YACH,MAAM,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;QACtC,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,mCAAmC,EAAE,CAAQ,CAAC,CAAC;QACnE,CAAC;IACH,CAAC;CACF,CAAA;AA3CY,oDAAoB;+BAApB,oBAAoB;IADhC,IAAA,mBAAU,GAAE;IAI0C,WAAA,IAAA,eAAM,EAAC,wBAAgB,CAAC,CAAA;qCAAxC,8BAAa;GAHvC,oBAAoB,CA2ChC"}
|
||||
@@ -1,3 +0,0 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
//# sourceMappingURL=permission-cache.interface.js.map
|
||||
@@ -1 +0,0 @@
|
||||
{"version":3,"file":"permission-cache.interface.js","sourceRoot":"","sources":["../../../../src/modules/authorization/cache/permission-cache.interface.ts"],"names":[],"mappings":""}
|
||||
@@ -1,48 +0,0 @@
|
||||
"use strict";
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
var __metadata = (this && this.__metadata) || function (k, v) {
|
||||
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.RedisPermissionCache = void 0;
|
||||
const common_1 = require("@nestjs/common");
|
||||
const redis_service_1 = require("../../../shared/redis.service");
|
||||
let RedisPermissionCache = class RedisPermissionCache {
|
||||
redis;
|
||||
TTL = 60 * 5;
|
||||
constructor(redis) {
|
||||
this.redis = redis;
|
||||
}
|
||||
key(userId) {
|
||||
const { CacheKeys } = require('../../../shared/cache-keys');
|
||||
return CacheKeys.permission(userId);
|
||||
}
|
||||
async get(userId) {
|
||||
const data = await this.redis.get(this.key(userId));
|
||||
if (!data)
|
||||
return null;
|
||||
try {
|
||||
return JSON.parse(data);
|
||||
}
|
||||
catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
async set(userId, permissions, ttlSeconds) {
|
||||
await this.redis.set(this.key(userId), JSON.stringify(permissions), ttlSeconds ?? this.TTL);
|
||||
}
|
||||
async invalidate(userId) {
|
||||
await this.redis.del(this.key(userId));
|
||||
}
|
||||
};
|
||||
exports.RedisPermissionCache = RedisPermissionCache;
|
||||
exports.RedisPermissionCache = RedisPermissionCache = __decorate([
|
||||
(0, common_1.Injectable)(),
|
||||
__metadata("design:paramtypes", [redis_service_1.RedisService])
|
||||
], RedisPermissionCache);
|
||||
//# sourceMappingURL=redis-permission-cache.service.js.map
|
||||
@@ -1 +0,0 @@
|
||||
{"version":3,"file":"redis-permission-cache.service.js","sourceRoot":"","sources":["../../../../src/modules/authorization/cache/redis-permission-cache.service.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAA4C;AAE5C,iEAA6D;AAGtD,IAAM,oBAAoB,GAA1B,MAAM,oBAAoB;IAGF;IAFZ,GAAG,GAAG,EAAE,GAAG,CAAC,CAAC;IAE9B,YAA6B,KAAmB;QAAnB,UAAK,GAAL,KAAK,CAAc;IAAG,CAAC;IAE5C,GAAG,CAAC,MAAc;QACxB,MAAM,EAAE,SAAS,EAAE,GAAG,OAAO,CAAC,4BAA4B,CAAC,CAAC;QAC5D,OAAO,SAAS,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;IACtC,CAAC;IAED,KAAK,CAAC,GAAG,CAAC,MAAc;QACtB,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC;QACpD,IAAI,CAAC,IAAI;YAAE,OAAO,IAAI,CAAC;QACvB,IAAI,CAAC;YACH,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAa,CAAC;QACtC,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,IAAI,CAAC;QACd,CAAC;IACH,CAAC;IAED,KAAK,CAAC,GAAG,CAAC,MAAc,EAAE,WAAqB,EAAE,UAAmB;QAClE,MAAM,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,IAAI,CAAC,SAAS,CAAC,WAAW,CAAC,EAAE,UAAU,IAAI,IAAI,CAAC,GAAG,CAAC,CAAC;IAC9F,CAAC;IAED,KAAK,CAAC,UAAU,CAAC,MAAc;QAC7B,MAAM,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC;IACzC,CAAC;CACF,CAAA;AA3BY,oDAAoB;+BAApB,oBAAoB;IADhC,IAAA,mBAAU,GAAE;qCAIyB,4BAAY;GAHrC,oBAAoB,CA2BhC"}
|
||||
@@ -1,52 +0,0 @@
|
||||
"use strict";
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
var __metadata = (this && this.__metadata) || function (k, v) {
|
||||
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.createPermissionGuard = exports.PermissionGuard = void 0;
|
||||
const common_1 = require("@nestjs/common");
|
||||
const authorization_service_1 = require("../authorization.service");
|
||||
let PermissionGuard = class PermissionGuard {
|
||||
authz;
|
||||
permission;
|
||||
constructor(authz, permission) {
|
||||
this.authz = authz;
|
||||
this.permission = permission;
|
||||
}
|
||||
async canActivate(context) {
|
||||
const req = context.switchToHttp().getRequest();
|
||||
const user = req.raylab?.user;
|
||||
if (!user)
|
||||
throw new common_1.ForbiddenException('Missing user');
|
||||
const allowed = await this.authz.hasPermission(user.id, this.permission);
|
||||
if (!allowed)
|
||||
throw new common_1.ForbiddenException('Forbidden');
|
||||
return true;
|
||||
}
|
||||
};
|
||||
exports.PermissionGuard = PermissionGuard;
|
||||
exports.PermissionGuard = PermissionGuard = __decorate([
|
||||
(0, common_1.Injectable)(),
|
||||
__metadata("design:paramtypes", [authorization_service_1.AuthorizationService, String])
|
||||
], PermissionGuard);
|
||||
// Factory to create guard instances with permission string (used in decorators)
|
||||
const createPermissionGuard = (permission) => {
|
||||
let _Guard = class _Guard extends PermissionGuard {
|
||||
constructor(authz) {
|
||||
super(authz, permission);
|
||||
}
|
||||
};
|
||||
_Guard = __decorate([
|
||||
(0, common_1.Injectable)(),
|
||||
__metadata("design:paramtypes", [authorization_service_1.AuthorizationService])
|
||||
], _Guard);
|
||||
return _Guard;
|
||||
};
|
||||
exports.createPermissionGuard = createPermissionGuard;
|
||||
//# sourceMappingURL=permission.guard.js.map
|
||||
@@ -1 +0,0 @@
|
||||
{"version":3,"file":"permission.guard.js","sourceRoot":"","sources":["../../../../src/modules/authorization/guards/permission.guard.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAA+F;AAC/F,oEAAgE;AAGzD,IAAM,eAAe,GAArB,MAAM,eAAe;IACG;IAA8C;IAA3E,YAA6B,KAA2B,EAAmB,UAAkB;QAAhE,UAAK,GAAL,KAAK,CAAsB;QAAmB,eAAU,GAAV,UAAU,CAAQ;IAAG,CAAC;IAEjG,KAAK,CAAC,WAAW,CAAC,OAAyB;QACzC,MAAM,GAAG,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC,UAAU,EAAE,CAAC;QAChD,MAAM,IAAI,GAAG,GAAG,CAAC,MAAM,EAAE,IAAI,CAAC;QAC9B,IAAI,CAAC,IAAI;YAAE,MAAM,IAAI,2BAAkB,CAAC,cAAc,CAAC,CAAC;QAExD,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,aAAa,CAAC,IAAI,CAAC,EAAE,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC;QACzE,IAAI,CAAC,OAAO;YAAE,MAAM,IAAI,2BAAkB,CAAC,WAAW,CAAC,CAAC;QACxD,OAAO,IAAI,CAAC;IACd,CAAC;CACF,CAAA;AAZY,0CAAe;0BAAf,eAAe;IAD3B,IAAA,mBAAU,GAAE;qCAEyB,4CAAoB;GAD7C,eAAe,CAY3B;AAED,gFAAgF;AACzE,MAAM,qBAAqB,GAAG,CAAC,UAAkB,EAAE,EAAE;IAC1D,IACM,MAAM,GADZ,MACM,MAAO,SAAQ,eAAe;QAClC,YAAY,KAA2B;YACrC,KAAK,CAAC,KAAK,EAAE,UAAU,CAAC,CAAC;QAC3B,CAAC;KACF,CAAA;IAJK,MAAM;QADX,IAAA,mBAAU,GAAE;yCAEQ,4CAAoB;OADnC,MAAM,CAIX;IACD,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC;AARW,QAAA,qBAAqB,yBAQhC"}
|
||||
-35
@@ -1,35 +0,0 @@
|
||||
"use strict";
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
var __metadata = (this && this.__metadata) || function (k, v) {
|
||||
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.HealthController = void 0;
|
||||
const common_1 = require("@nestjs/common");
|
||||
const health_service_1 = require("./health.service");
|
||||
let HealthController = class HealthController {
|
||||
healthService;
|
||||
constructor(healthService) {
|
||||
this.healthService = healthService;
|
||||
}
|
||||
async get() {
|
||||
return this.healthService.getHealth();
|
||||
}
|
||||
};
|
||||
exports.HealthController = HealthController;
|
||||
__decorate([
|
||||
(0, common_1.Get)(),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", []),
|
||||
__metadata("design:returntype", Promise)
|
||||
], HealthController.prototype, "get", null);
|
||||
exports.HealthController = HealthController = __decorate([
|
||||
(0, common_1.Controller)('api/health'),
|
||||
__metadata("design:paramtypes", [health_service_1.HealthService])
|
||||
], HealthController);
|
||||
//# sourceMappingURL=health.controller.js.map
|
||||
@@ -1 +0,0 @@
|
||||
{"version":3,"file":"health.controller.js","sourceRoot":"","sources":["../../../src/modules/health/health.controller.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAAiD;AACjD,qDAAiD;AAG1C,IAAM,gBAAgB,GAAtB,MAAM,gBAAgB;IACE;IAA7B,YAA6B,aAA4B;QAA5B,kBAAa,GAAb,aAAa,CAAe;IAAG,CAAC;IAGvD,AAAN,KAAK,CAAC,GAAG;QACP,OAAO,IAAI,CAAC,aAAa,CAAC,SAAS,EAAE,CAAC;IACxC,CAAC;CACF,CAAA;AAPY,4CAAgB;AAIrB;IADL,IAAA,YAAG,GAAE;;;;2CAGL;2BANU,gBAAgB;IAD5B,IAAA,mBAAU,EAAC,YAAY,CAAC;qCAEqB,8BAAa;GAD9C,gBAAgB,CAO5B"}
|
||||
Vendored
-23
@@ -1,23 +0,0 @@
|
||||
"use strict";
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.HealthModule = void 0;
|
||||
const common_1 = require("@nestjs/common");
|
||||
const health_controller_1 = require("./health.controller");
|
||||
const health_service_1 = require("./health.service");
|
||||
let HealthModule = class HealthModule {
|
||||
};
|
||||
exports.HealthModule = HealthModule;
|
||||
exports.HealthModule = HealthModule = __decorate([
|
||||
(0, common_1.Module)({
|
||||
controllers: [health_controller_1.HealthController],
|
||||
providers: [health_service_1.HealthService],
|
||||
exports: [health_service_1.HealthService],
|
||||
})
|
||||
], HealthModule);
|
||||
//# sourceMappingURL=health.module.js.map
|
||||
-1
@@ -1 +0,0 @@
|
||||
{"version":3,"file":"health.module.js","sourceRoot":"","sources":["../../../src/modules/health/health.module.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAAwC;AACxC,2DAAuD;AACvD,qDAAiD;AAO1C,IAAM,YAAY,GAAlB,MAAM,YAAY;CAAG,CAAA;AAAf,oCAAY;uBAAZ,YAAY;IALxB,IAAA,eAAM,EAAC;QACN,WAAW,EAAE,CAAC,oCAAgB,CAAC;QAC/B,SAAS,EAAE,CAAC,8BAAa,CAAC;QAC1B,OAAO,EAAE,CAAC,8BAAa,CAAC;KACzB,CAAC;GACW,YAAY,CAAG"}
|
||||
-24
@@ -1,24 +0,0 @@
|
||||
"use strict";
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.HealthService = void 0;
|
||||
const common_1 = require("@nestjs/common");
|
||||
let HealthService = class HealthService {
|
||||
async getHealth() {
|
||||
return {
|
||||
status: 'ok',
|
||||
timestamp: new Date().toISOString(),
|
||||
service: 'raylab-core',
|
||||
};
|
||||
}
|
||||
};
|
||||
exports.HealthService = HealthService;
|
||||
exports.HealthService = HealthService = __decorate([
|
||||
(0, common_1.Injectable)()
|
||||
], HealthService);
|
||||
//# sourceMappingURL=health.service.js.map
|
||||
-1
@@ -1 +0,0 @@
|
||||
{"version":3,"file":"health.service.js","sourceRoot":"","sources":["../../../src/modules/health/health.service.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAA4C;AAGrC,IAAM,aAAa,GAAnB,MAAM,aAAa;IACxB,KAAK,CAAC,SAAS;QACb,OAAO;YACL,MAAM,EAAE,IAAI;YACZ,SAAS,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;YACnC,OAAO,EAAE,aAAa;SACvB,CAAC;IACJ,CAAC;CACF,CAAA;AARY,sCAAa;wBAAb,aAAa;IADzB,IAAA,mBAAU,GAAE;GACA,aAAa,CAQzB"}
|
||||
@@ -1,16 +0,0 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.EnvAuthConfig = void 0;
|
||||
class EnvAuthConfig {
|
||||
autoCreateUser() {
|
||||
return (process.env.AUTH_AUTO_CREATE_USER ?? 'true') === 'true';
|
||||
}
|
||||
syncEmail() {
|
||||
return (process.env.AUTH_SYNC_EMAIL ?? 'true') === 'true';
|
||||
}
|
||||
syncUsername() {
|
||||
return (process.env.AUTH_SYNC_USERNAME ?? 'false') === 'true';
|
||||
}
|
||||
}
|
||||
exports.EnvAuthConfig = EnvAuthConfig;
|
||||
//# sourceMappingURL=env-auth-config.js.map
|
||||
@@ -1 +0,0 @@
|
||||
{"version":3,"file":"env-auth-config.js","sourceRoot":"","sources":["../../../../../src/modules/identity/application/config/env-auth-config.ts"],"names":[],"mappings":";;;AAEA,MAAa,aAAa;IACxB,cAAc;QACZ,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,qBAAqB,IAAI,MAAM,CAAC,KAAK,MAAM,CAAC;IAClE,CAAC;IAED,SAAS;QACP,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,eAAe,IAAI,MAAM,CAAC,KAAK,MAAM,CAAC;IAC5D,CAAC;IAED,YAAY;QACV,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,kBAAkB,IAAI,OAAO,CAAC,KAAK,MAAM,CAAC;IAChE,CAAC;CACF;AAZD,sCAYC"}
|
||||
@@ -1,7 +0,0 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.IAuthConfig = void 0;
|
||||
class IAuthConfig {
|
||||
}
|
||||
exports.IAuthConfig = IAuthConfig;
|
||||
//# sourceMappingURL=i-auth-config.js.map
|
||||
@@ -1 +0,0 @@
|
||||
{"version":3,"file":"i-auth-config.js","sourceRoot":"","sources":["../../../../../src/modules/identity/application/config/i-auth-config.ts"],"names":[],"mappings":";;;AAAA,MAAsB,WAAW;CAIhC;AAJD,kCAIC"}
|
||||
+11
-14
@@ -9,21 +9,18 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
||||
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.GetRolesHandler = void 0;
|
||||
exports.CreateUserHandler = void 0;
|
||||
const common_1 = require("@nestjs/common");
|
||||
const role_interface_1 = require("../../../domain/repositories/role.interface");
|
||||
let GetRolesHandler = class GetRolesHandler {
|
||||
roleRepository;
|
||||
constructor(roleRepository) {
|
||||
this.roleRepository = roleRepository;
|
||||
}
|
||||
async execute(query) {
|
||||
return this.roleRepository.find({ page: query.page, limit: query.limit, search: query.search || null });
|
||||
let CreateUserHandler = class CreateUserHandler {
|
||||
constructor() { }
|
||||
async execute(dto) {
|
||||
// Legacy handler - creation via this path is deprecated. Use the new handlers under application/handlers/user.
|
||||
throw new common_1.BadRequestException('Deprecated handler. User creation via this endpoint is not supported.');
|
||||
}
|
||||
};
|
||||
exports.GetRolesHandler = GetRolesHandler;
|
||||
exports.GetRolesHandler = GetRolesHandler = __decorate([
|
||||
exports.CreateUserHandler = CreateUserHandler;
|
||||
exports.CreateUserHandler = CreateUserHandler = __decorate([
|
||||
(0, common_1.Injectable)(),
|
||||
__metadata("design:paramtypes", [role_interface_1.IRole])
|
||||
], GetRolesHandler);
|
||||
//# sourceMappingURL=get-roles.handler.js.map
|
||||
__metadata("design:paramtypes", [])
|
||||
], CreateUserHandler);
|
||||
//# sourceMappingURL=create-user.handler.js.map
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"create-user.handler.js","sourceRoot":"","sources":["../../../../../src/modules/identity/application/handlers/create-user.handler.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAAiE;AAI1D,IAAM,iBAAiB,GAAvB,MAAM,iBAAiB;IAC5B,gBAAe,CAAC;IAEhB,KAAK,CAAC,OAAO,CAAC,GAAkB;QAC9B,+GAA+G;QAC/G,MAAM,IAAI,4BAAmB,CAAC,uEAAuE,CAAC,CAAC;IACzG,CAAC;CACF,CAAA;AAPY,8CAAiB;4BAAjB,iBAAiB;IAD7B,IAAA,mBAAU,GAAE;;GACA,iBAAiB,CAO7B"}
|
||||
+9
-5
@@ -11,22 +11,26 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.DeleteUserHandler = void 0;
|
||||
const common_1 = require("@nestjs/common");
|
||||
const user_interface_1 = require("../../../domain/repositories/user.interface");
|
||||
const user_repository_interface_1 = require("../../domain/repositories/user.repository.interface");
|
||||
let DeleteUserHandler = class DeleteUserHandler {
|
||||
userRepository;
|
||||
constructor(userRepository) {
|
||||
this.userRepository = userRepository;
|
||||
}
|
||||
async execute(id) {
|
||||
const exists = await this.userRepository.existsById(id);
|
||||
if (!exists)
|
||||
const user = await this.userRepository.findById(id);
|
||||
if (!user) {
|
||||
throw new common_1.NotFoundException('User not found.');
|
||||
await this.userRepository.softDelete(id);
|
||||
}
|
||||
user.delete();
|
||||
await this.userRepository.update(user);
|
||||
// TODO:
|
||||
// Publish UserDeletedEvent
|
||||
}
|
||||
};
|
||||
exports.DeleteUserHandler = DeleteUserHandler;
|
||||
exports.DeleteUserHandler = DeleteUserHandler = __decorate([
|
||||
(0, common_1.Injectable)(),
|
||||
__metadata("design:paramtypes", [user_interface_1.IUser])
|
||||
__metadata("design:paramtypes", [user_repository_interface_1.UserRepository])
|
||||
], DeleteUserHandler);
|
||||
//# sourceMappingURL=delete-user.handler.js.map
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"delete-user.handler.js","sourceRoot":"","sources":["../../../../../src/modules/identity/application/handlers/delete-user.handler.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAGwB;AAExB,mGAAqF;AAG9E,IAAM,iBAAiB,GAAvB,MAAM,iBAAiB;IAET;IADnB,YACmB,cAA8B;QAA9B,mBAAc,GAAd,cAAc,CAAgB;IAC9C,CAAC;IAEJ,KAAK,CAAC,OAAO,CAAC,EAAU;QACtB,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,cAAc,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;QAEpD,IAAI,CAAC,IAAI,EAAE,CAAC;YACV,MAAM,IAAI,0BAAiB,CAAC,iBAAiB,CAAC,CAAC;QACjD,CAAC;QAED,IAAI,CAAC,MAAM,EAAE,CAAC;QAEd,MAAM,IAAI,CAAC,cAAc,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QAEvC,QAAQ;QACR,2BAA2B;IAC7B,CAAC;CACF,CAAA;AAnBY,8CAAiB;4BAAjB,iBAAiB;IAD7B,IAAA,mBAAU,GAAE;qCAGwB,0CAAc;GAFtC,iBAAiB,CAmB7B"}
|
||||
+12
-11
@@ -9,24 +9,25 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
||||
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.EnableUserHandler = void 0;
|
||||
exports.FindUserHandler = void 0;
|
||||
const common_1 = require("@nestjs/common");
|
||||
const user_interface_1 = require("../../../domain/repositories/user.interface");
|
||||
let EnableUserHandler = class EnableUserHandler {
|
||||
const user_repository_interface_1 = require("../../domain/repositories/user.repository.interface");
|
||||
let FindUserHandler = class FindUserHandler {
|
||||
userRepository;
|
||||
constructor(userRepository) {
|
||||
this.userRepository = userRepository;
|
||||
}
|
||||
async execute(id) {
|
||||
const exists = await this.userRepository.existsById(id);
|
||||
if (!exists)
|
||||
const user = await this.userRepository.findById(id);
|
||||
if (!user) {
|
||||
throw new common_1.NotFoundException('User not found.');
|
||||
return this.userRepository.enable(id);
|
||||
}
|
||||
return user;
|
||||
}
|
||||
};
|
||||
exports.EnableUserHandler = EnableUserHandler;
|
||||
exports.EnableUserHandler = EnableUserHandler = __decorate([
|
||||
exports.FindUserHandler = FindUserHandler;
|
||||
exports.FindUserHandler = FindUserHandler = __decorate([
|
||||
(0, common_1.Injectable)(),
|
||||
__metadata("design:paramtypes", [user_interface_1.IUser])
|
||||
], EnableUserHandler);
|
||||
//# sourceMappingURL=enable-user.handler.js.map
|
||||
__metadata("design:paramtypes", [user_repository_interface_1.UserRepository])
|
||||
], FindUserHandler);
|
||||
//# sourceMappingURL=find-user.handler.js.map
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"find-user.handler.js","sourceRoot":"","sources":["../../../../../src/modules/identity/application/handlers/find-user.handler.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAGwB;AAExB,mGAAqF;AAI9E,IAAM,eAAe,GAArB,MAAM,eAAe;IAEP;IADnB,YACmB,cAA8B;QAA9B,mBAAc,GAAd,cAAc,CAAgB;IAC9C,CAAC;IAEJ,KAAK,CAAC,OAAO,CAAC,EAAU;QACtB,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,cAAc,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;QAEpD,IAAI,CAAC,IAAI,EAAE,CAAC;YACV,MAAM,IAAI,0BAAiB,CAAC,iBAAiB,CAAC,CAAC;QACjD,CAAC;QAED,OAAO,IAAI,CAAC;IACd,CAAC;CACF,CAAA;AAdY,0CAAe;0BAAf,eAAe;IAD3B,IAAA,mBAAU,GAAE;qCAGwB,0CAAc;GAFtC,eAAe,CAc3B"}
|
||||
+10
-10
@@ -9,21 +9,21 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
||||
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.GetUserHandler = void 0;
|
||||
exports.FindUsersHandler = void 0;
|
||||
const common_1 = require("@nestjs/common");
|
||||
const user_interface_1 = require("../../../domain/repositories/user.interface");
|
||||
let GetUserHandler = class GetUserHandler {
|
||||
const user_repository_interface_1 = require("../../domain/repositories/user.repository.interface");
|
||||
let FindUsersHandler = class FindUsersHandler {
|
||||
userRepository;
|
||||
constructor(userRepository) {
|
||||
this.userRepository = userRepository;
|
||||
}
|
||||
async execute(id) {
|
||||
return this.userRepository.getById(id);
|
||||
async execute() {
|
||||
return await this.userRepository.findAll();
|
||||
}
|
||||
};
|
||||
exports.GetUserHandler = GetUserHandler;
|
||||
exports.GetUserHandler = GetUserHandler = __decorate([
|
||||
exports.FindUsersHandler = FindUsersHandler;
|
||||
exports.FindUsersHandler = FindUsersHandler = __decorate([
|
||||
(0, common_1.Injectable)(),
|
||||
__metadata("design:paramtypes", [user_interface_1.IUser])
|
||||
], GetUserHandler);
|
||||
//# sourceMappingURL=get-user.handler.js.map
|
||||
__metadata("design:paramtypes", [user_repository_interface_1.UserRepository])
|
||||
], FindUsersHandler);
|
||||
//# sourceMappingURL=find-users.handler.js.map
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user