@saltsquareio/nestjs-backend-platform 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +72 -0
- package/dist/cli/migrate.d.ts +2 -0
- package/dist/cli/migrate.js +34 -0
- package/dist/cli/migrate.js.map +1 -0
- package/dist/core/ai/ai.module.d.ts +5 -0
- package/dist/core/ai/ai.module.js +53 -0
- package/dist/core/ai/ai.module.js.map +1 -0
- package/dist/core/ai/ai.options.d.ts +33 -0
- package/dist/core/ai/ai.options.js +14 -0
- package/dist/core/ai/ai.options.js.map +1 -0
- package/dist/core/ai/ai.service.d.ts +49 -0
- package/dist/core/ai/ai.service.js +381 -0
- package/dist/core/ai/ai.service.js.map +1 -0
- package/dist/core/ai/ai.types.d.ts +133 -0
- package/dist/core/ai/ai.types.js +3 -0
- package/dist/core/ai/ai.types.js.map +1 -0
- package/dist/core/ai/context/context-formatter.service.d.ts +9 -0
- package/dist/core/ai/context/context-formatter.service.js +66 -0
- package/dist/core/ai/context/context-formatter.service.js.map +1 -0
- package/dist/core/ai/cost/cost-tracking.service.d.ts +12 -0
- package/dist/core/ai/cost/cost-tracking.service.js +65 -0
- package/dist/core/ai/cost/cost-tracking.service.js.map +1 -0
- package/dist/core/ai/entities/ai-invocation-log.entity.d.ts +19 -0
- package/dist/core/ai/entities/ai-invocation-log.entity.js +116 -0
- package/dist/core/ai/entities/ai-invocation-log.entity.js.map +1 -0
- package/dist/core/ai/entities/prompt-template.entity.d.ts +13 -0
- package/dist/core/ai/entities/prompt-template.entity.js +75 -0
- package/dist/core/ai/entities/prompt-template.entity.js.map +1 -0
- package/dist/core/ai/index.d.ts +18 -0
- package/dist/core/ai/index.js +36 -0
- package/dist/core/ai/index.js.map +1 -0
- package/dist/core/ai/llm/dummy-llm-model.d.ts +9 -0
- package/dist/core/ai/llm/dummy-llm-model.js +18 -0
- package/dist/core/ai/llm/dummy-llm-model.js.map +1 -0
- package/dist/core/ai/llm/index.d.ts +2 -0
- package/dist/core/ai/llm/index.js +19 -0
- package/dist/core/ai/llm/index.js.map +1 -0
- package/dist/core/ai/llm/openai-llm-model.d.ts +10 -0
- package/dist/core/ai/llm/openai-llm-model.js +46 -0
- package/dist/core/ai/llm/openai-llm-model.js.map +1 -0
- package/dist/core/ai/llm-model.d.ts +17 -0
- package/dist/core/ai/llm-model.js +3 -0
- package/dist/core/ai/llm-model.js.map +1 -0
- package/dist/core/ai/memory/memory.service.d.ts +18 -0
- package/dist/core/ai/memory/memory.service.js +157 -0
- package/dist/core/ai/memory/memory.service.js.map +1 -0
- package/dist/core/ai/memory/memory.types.d.ts +6 -0
- package/dist/core/ai/memory/memory.types.js +3 -0
- package/dist/core/ai/memory/memory.types.js.map +1 -0
- package/dist/core/ai/memory/memory.utils.d.ts +1 -0
- package/dist/core/ai/memory/memory.utils.js +17 -0
- package/dist/core/ai/memory/memory.utils.js.map +1 -0
- package/dist/core/ai/model-registry.service.d.ts +19 -0
- package/dist/core/ai/model-registry.service.js +60 -0
- package/dist/core/ai/model-registry.service.js.map +1 -0
- package/dist/core/ai/model-resolver.service.d.ts +6 -0
- package/dist/core/ai/model-resolver.service.js +28 -0
- package/dist/core/ai/model-resolver.service.js.map +1 -0
- package/dist/core/ai/prompt-builder.service.d.ts +16 -0
- package/dist/core/ai/prompt-builder.service.js +34 -0
- package/dist/core/ai/prompt-builder.service.js.map +1 -0
- package/dist/core/ai/provider/provider-factory.service.d.ts +18 -0
- package/dist/core/ai/provider/provider-factory.service.js +60 -0
- package/dist/core/ai/provider/provider-factory.service.js.map +1 -0
- package/dist/core/ai/safety/safety-guardrail.service.d.ts +9 -0
- package/dist/core/ai/safety/safety-guardrail.service.js +65 -0
- package/dist/core/ai/safety/safety-guardrail.service.js.map +1 -0
- package/dist/core/ai/summarization/summarization.service.d.ts +24 -0
- package/dist/core/ai/summarization/summarization.service.js +66 -0
- package/dist/core/ai/summarization/summarization.service.js.map +1 -0
- package/dist/core/ai/template/template.service.d.ts +14 -0
- package/dist/core/ai/template/template.service.js +88 -0
- package/dist/core/ai/template/template.service.js.map +1 -0
- package/dist/core/audit-log/audit-log.entity.d.ts +13 -0
- package/dist/core/audit-log/audit-log.entity.js +72 -0
- package/dist/core/audit-log/audit-log.entity.js.map +1 -0
- package/dist/core/audit-log/audit-log.module.d.ts +2 -0
- package/dist/core/audit-log/audit-log.module.js +25 -0
- package/dist/core/audit-log/audit-log.module.js.map +1 -0
- package/dist/core/audit-log/audit-log.service.d.ts +20 -0
- package/dist/core/audit-log/audit-log.service.js +59 -0
- package/dist/core/audit-log/audit-log.service.js.map +1 -0
- package/dist/core/audit-log/index.d.ts +6 -0
- package/dist/core/audit-log/index.js +11 -0
- package/dist/core/audit-log/index.js.map +1 -0
- package/dist/core/auth/auth.provider.d.ts +4 -0
- package/dist/core/auth/auth.provider.js +3 -0
- package/dist/core/auth/auth.provider.js.map +1 -0
- package/dist/core/auth/decorators.d.ts +4 -0
- package/dist/core/auth/decorators.js +11 -0
- package/dist/core/auth/decorators.js.map +1 -0
- package/dist/core/auth/index.d.ts +6 -0
- package/dist/core/auth/index.js +23 -0
- package/dist/core/auth/index.js.map +1 -0
- package/dist/core/auth/params.d.ts +2 -0
- package/dist/core/auth/params.js +23 -0
- package/dist/core/auth/params.js.map +1 -0
- package/dist/core/auth/role.can-activate.d.ts +10 -0
- package/dist/core/auth/role.can-activate.js +42 -0
- package/dist/core/auth/role.can-activate.js.map +1 -0
- package/dist/core/auth/types.d.ts +6 -0
- package/dist/core/auth/types.js +3 -0
- package/dist/core/auth/types.js.map +1 -0
- package/dist/core/auth/utils.d.ts +4 -0
- package/dist/core/auth/utils.js +22 -0
- package/dist/core/auth/utils.js.map +1 -0
- package/dist/core/configuration/coerce.d.ts +2 -0
- package/dist/core/configuration/coerce.js +8 -0
- package/dist/core/configuration/coerce.js.map +1 -0
- package/dist/core/configuration/configuration.module.d.ts +9 -0
- package/dist/core/configuration/configuration.module.js +38 -0
- package/dist/core/configuration/configuration.module.js.map +1 -0
- package/dist/core/configuration/define-config.d.ts +2 -0
- package/dist/core/configuration/define-config.js +20 -0
- package/dist/core/configuration/define-config.js.map +1 -0
- package/dist/core/configuration/env-files.d.ts +1 -0
- package/dist/core/configuration/env-files.js +7 -0
- package/dist/core/configuration/env-files.js.map +1 -0
- package/dist/core/configuration/index.d.ts +5 -0
- package/dist/core/configuration/index.js +22 -0
- package/dist/core/configuration/index.js.map +1 -0
- package/dist/core/configuration/schemas/app.schema.d.ts +16 -0
- package/dist/core/configuration/schemas/app.schema.js +23 -0
- package/dist/core/configuration/schemas/app.schema.js.map +1 -0
- package/dist/core/database/common.d.ts +12 -0
- package/dist/core/database/common.js +15 -0
- package/dist/core/database/common.js.map +1 -0
- package/dist/core/database/custom-snake-case-naming-strategy.d.ts +9 -0
- package/dist/core/database/custom-snake-case-naming-strategy.js +28 -0
- package/dist/core/database/custom-snake-case-naming-strategy.js.map +1 -0
- package/dist/core/database/database.config.d.ts +4 -0
- package/dist/core/database/database.config.js +39 -0
- package/dist/core/database/database.config.js.map +1 -0
- package/dist/core/database/database.module.d.ts +7 -0
- package/dist/core/database/database.module.js +58 -0
- package/dist/core/database/database.module.js.map +1 -0
- package/dist/core/database/database.schema.d.ts +41 -0
- package/dist/core/database/database.schema.js +33 -0
- package/dist/core/database/database.schema.js.map +1 -0
- package/dist/core/database/index.d.ts +5 -0
- package/dist/core/database/index.js +22 -0
- package/dist/core/database/index.js.map +1 -0
- package/dist/core/database/ssl-config.d.ts +3 -0
- package/dist/core/database/ssl-config.js +8 -0
- package/dist/core/database/ssl-config.js.map +1 -0
- package/dist/core/exception/all-exceptions.filter.d.ts +8 -0
- package/dist/core/exception/all-exceptions.filter.js +56 -0
- package/dist/core/exception/all-exceptions.filter.js.map +1 -0
- package/dist/core/exception/index.d.ts +1 -0
- package/dist/core/exception/index.js +18 -0
- package/dist/core/exception/index.js.map +1 -0
- package/dist/core/exception/utils.d.ts +6 -0
- package/dist/core/exception/utils.js +15 -0
- package/dist/core/exception/utils.js.map +1 -0
- package/dist/core/health/health.controller.d.ts +9 -0
- package/dist/core/health/health.controller.js +52 -0
- package/dist/core/health/health.controller.js.map +1 -0
- package/dist/core/health/health.module.d.ts +2 -0
- package/dist/core/health/health.module.js +24 -0
- package/dist/core/health/health.module.js.map +1 -0
- package/dist/core/health/index.d.ts +1 -0
- package/dist/core/health/index.js +18 -0
- package/dist/core/health/index.js.map +1 -0
- package/dist/core/health/shutdown-handler.d.ts +2 -0
- package/dist/core/health/shutdown-handler.js +20 -0
- package/dist/core/health/shutdown-handler.js.map +1 -0
- package/dist/core/health/shutdown.service.d.ts +11 -0
- package/dist/core/health/shutdown.service.js +54 -0
- package/dist/core/health/shutdown.service.js.map +1 -0
- package/dist/core/http/http.circuit-breaker.d.ts +4 -0
- package/dist/core/http/http.circuit-breaker.js +25 -0
- package/dist/core/http/http.circuit-breaker.js.map +1 -0
- package/dist/core/http/http.client.factory.d.ts +3 -0
- package/dist/core/http/http.client.factory.js +32 -0
- package/dist/core/http/http.client.factory.js.map +1 -0
- package/dist/core/http/http.module.d.ts +2 -0
- package/dist/core/http/http.module.js +19 -0
- package/dist/core/http/http.module.js.map +1 -0
- package/dist/core/http/http.open-api.d.ts +8 -0
- package/dist/core/http/http.open-api.js +22 -0
- package/dist/core/http/http.open-api.js.map +1 -0
- package/dist/core/http/http.types.d.ts +6 -0
- package/dist/core/http/http.types.js +3 -0
- package/dist/core/http/http.types.js.map +1 -0
- package/dist/core/http/index.d.ts +4 -0
- package/dist/core/http/index.js +21 -0
- package/dist/core/http/index.js.map +1 -0
- package/dist/core/info/index.d.ts +1 -0
- package/dist/core/info/index.js +18 -0
- package/dist/core/info/index.js.map +1 -0
- package/dist/core/info/info.controller.d.ts +3 -0
- package/dist/core/info/info.controller.js +33 -0
- package/dist/core/info/info.controller.js.map +1 -0
- package/dist/core/info/info.module.d.ts +6 -0
- package/dist/core/info/info.module.js +27 -0
- package/dist/core/info/info.module.js.map +1 -0
- package/dist/core/info/info.utils.d.ts +13 -0
- package/dist/core/info/info.utils.js +32 -0
- package/dist/core/info/info.utils.js.map +1 -0
- package/dist/core/logger/hash-pii.d.ts +1 -0
- package/dist/core/logger/hash-pii.js +13 -0
- package/dist/core/logger/hash-pii.js.map +1 -0
- package/dist/core/logger/index.d.ts +4 -0
- package/dist/core/logger/index.js +21 -0
- package/dist/core/logger/index.js.map +1 -0
- package/dist/core/logger/logger.module.d.ts +2 -0
- package/dist/core/logger/logger.module.js +30 -0
- package/dist/core/logger/logger.module.js.map +1 -0
- package/dist/core/logger/logging.interceptor.d.ts +8 -0
- package/dist/core/logger/logging.interceptor.js +51 -0
- package/dist/core/logger/logging.interceptor.js.map +1 -0
- package/dist/core/logger/pino.config.d.ts +9 -0
- package/dist/core/logger/pino.config.js +47 -0
- package/dist/core/logger/pino.config.js.map +1 -0
- package/dist/core/migrations/create-migration-data-source.d.ts +8 -0
- package/dist/core/migrations/create-migration-data-source.js +18 -0
- package/dist/core/migrations/create-migration-data-source.js.map +1 -0
- package/dist/core/migrations/index.d.ts +3 -0
- package/dist/core/migrations/index.js +20 -0
- package/dist/core/migrations/index.js.map +1 -0
- package/dist/core/migrations/platform-entities.d.ts +2 -0
- package/dist/core/migrations/platform-entities.js +10 -0
- package/dist/core/migrations/platform-entities.js.map +1 -0
- package/dist/core/migrations/run-migrations.d.ts +3 -0
- package/dist/core/migrations/run-migrations.js +80 -0
- package/dist/core/migrations/run-migrations.js.map +1 -0
- package/dist/core/newrelic/index.d.ts +1 -0
- package/dist/core/newrelic/index.js +18 -0
- package/dist/core/newrelic/index.js.map +1 -0
- package/dist/core/newrelic/newrelic.utils.d.ts +2 -0
- package/dist/core/newrelic/newrelic.utils.js +31 -0
- package/dist/core/newrelic/newrelic.utils.js.map +1 -0
- package/dist/core/scheduler/index.d.ts +3 -0
- package/dist/core/scheduler/index.js +20 -0
- package/dist/core/scheduler/index.js.map +1 -0
- package/dist/core/scheduler/scheduled-cron.decorator.d.ts +6 -0
- package/dist/core/scheduler/scheduled-cron.decorator.js +31 -0
- package/dist/core/scheduler/scheduled-cron.decorator.js.map +1 -0
- package/dist/core/scheduler/scheduler-control.service.d.ts +14 -0
- package/dist/core/scheduler/scheduler-control.service.js +42 -0
- package/dist/core/scheduler/scheduler-control.service.js.map +1 -0
- package/dist/core/scheduler/scheduler.module.d.ts +4 -0
- package/dist/core/scheduler/scheduler.module.js +27 -0
- package/dist/core/scheduler/scheduler.module.js.map +1 -0
- package/dist/core/throttler/index.d.ts +7 -0
- package/dist/core/throttler/index.js +25 -0
- package/dist/core/throttler/index.js.map +1 -0
- package/dist/core/throttler/pg-throttler.storage.d.ts +10 -0
- package/dist/core/throttler/pg-throttler.storage.js +58 -0
- package/dist/core/throttler/pg-throttler.storage.js.map +1 -0
- package/dist/core/throttler/rate-limit-hit.entity.d.ts +6 -0
- package/dist/core/throttler/rate-limit-hit.entity.js +36 -0
- package/dist/core/throttler/rate-limit-hit.entity.js.map +1 -0
- package/dist/core/throttler/throttler-cleanup.service.d.ts +7 -0
- package/dist/core/throttler/throttler-cleanup.service.js +41 -0
- package/dist/core/throttler/throttler-cleanup.service.js.map +1 -0
- package/dist/core/throttler/throttler-tracker.d.ts +2 -0
- package/dist/core/throttler/throttler-tracker.js +29 -0
- package/dist/core/throttler/throttler-tracker.js.map +1 -0
- package/dist/core/throttler/throttler.module.d.ts +2 -0
- package/dist/core/throttler/throttler.module.js +41 -0
- package/dist/core/throttler/throttler.module.js.map +1 -0
- package/dist/core/utils/app-initializer.d.ts +5 -0
- package/dist/core/utils/app-initializer.js +37 -0
- package/dist/core/utils/app-initializer.js.map +1 -0
- package/dist/core/utils/feature-flag.d.ts +1 -0
- package/dist/core/utils/feature-flag.js +10 -0
- package/dist/core/utils/feature-flag.js.map +1 -0
- package/dist/core/utils/index.d.ts +5 -0
- package/dist/core/utils/index.js +22 -0
- package/dist/core/utils/index.js.map +1 -0
- package/dist/core/utils/parse-allowed-origins.d.ts +1 -0
- package/dist/core/utils/parse-allowed-origins.js +21 -0
- package/dist/core/utils/parse-allowed-origins.js.map +1 -0
- package/dist/core/utils/security-middleware.d.ts +2 -0
- package/dist/core/utils/security-middleware.js +19 -0
- package/dist/core/utils/security-middleware.js.map +1 -0
- package/dist/core/utils/with-timeout.d.ts +4 -0
- package/dist/core/utils/with-timeout.js +23 -0
- package/dist/core/utils/with-timeout.js.map +1 -0
- package/dist/core/ws/index.d.ts +4 -0
- package/dist/core/ws/index.js +23 -0
- package/dist/core/ws/index.js.map +1 -0
- package/dist/core/ws/validate-ws-dto.d.ts +1 -0
- package/dist/core/ws/validate-ws-dto.js +14 -0
- package/dist/core/ws/validate-ws-dto.js.map +1 -0
- package/dist/core/ws/ws-token.module.d.ts +2 -0
- package/dist/core/ws/ws-token.module.js +21 -0
- package/dist/core/ws/ws-token.module.js.map +1 -0
- package/dist/core/ws/ws-token.service.d.ts +8 -0
- package/dist/core/ws/ws-token.service.js +57 -0
- package/dist/core/ws/ws-token.service.js.map +1 -0
- package/dist/core/ws/ws.constants.d.ts +7 -0
- package/dist/core/ws/ws.constants.js +11 -0
- package/dist/core/ws/ws.constants.js.map +1 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.js +32 -0
- package/dist/index.js.map +1 -0
- package/package.json +167 -0
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
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;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
14
|
+
var SummarizationService_1;
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
exports.SummarizationService = void 0;
|
|
17
|
+
const common_1 = require("@nestjs/common");
|
|
18
|
+
const ai_service_1 = require("../ai.service");
|
|
19
|
+
const ai_options_1 = require("../ai.options");
|
|
20
|
+
const DEFAULT_TARGET_TOKENS = 1000;
|
|
21
|
+
const DEFAULT_THRESHOLD = 50;
|
|
22
|
+
let SummarizationService = SummarizationService_1 = class SummarizationService {
|
|
23
|
+
constructor(aiService, options) {
|
|
24
|
+
this.aiService = aiService;
|
|
25
|
+
this.options = options;
|
|
26
|
+
this.logger = new common_1.Logger(SummarizationService_1.name);
|
|
27
|
+
}
|
|
28
|
+
shouldSummarize(messages, threshold) {
|
|
29
|
+
const limit = threshold ?? this.options.summarization?.threshold ?? DEFAULT_THRESHOLD;
|
|
30
|
+
return messages.length > limit;
|
|
31
|
+
}
|
|
32
|
+
async summarize(messages, config) {
|
|
33
|
+
const targetTokens = config?.targetTokens ??
|
|
34
|
+
this.options.summarization?.targetTokens ??
|
|
35
|
+
DEFAULT_TARGET_TOKENS;
|
|
36
|
+
const systemPrompt = this.options.summarization?.systemPrompt ?? ai_options_1.DEFAULT_SUMMARIZATION_PROMPT;
|
|
37
|
+
const transcript = messages
|
|
38
|
+
.map((m) => `${m.role === 'assistant' ? 'Assistant' : 'User'}: ${m.content}`)
|
|
39
|
+
.join('\n\n');
|
|
40
|
+
const result = await this.aiService.invokeText({
|
|
41
|
+
template: `${systemPrompt}\nLength target: about ${targetTokens} tokens.`,
|
|
42
|
+
templateSlug: 'summarization',
|
|
43
|
+
model: this.options.summarization?.model ??
|
|
44
|
+
this.options.defaultModel ??
|
|
45
|
+
ai_options_1.ECHO_MODEL,
|
|
46
|
+
messages: [{ role: 'user', content: transcript }],
|
|
47
|
+
userId: config?.userId,
|
|
48
|
+
});
|
|
49
|
+
if (!result.success) {
|
|
50
|
+
this.logger.warn(`Summarization failed: ${result.error}`);
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
return result.output || null;
|
|
54
|
+
}
|
|
55
|
+
getMessageWindow(messages, windowSize = 25) {
|
|
56
|
+
return messages.slice(-windowSize);
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
exports.SummarizationService = SummarizationService;
|
|
60
|
+
exports.SummarizationService = SummarizationService = SummarizationService_1 = __decorate([
|
|
61
|
+
(0, common_1.Injectable)(),
|
|
62
|
+
__param(0, (0, common_1.Inject)((0, common_1.forwardRef)(() => ai_service_1.AiService))),
|
|
63
|
+
__param(1, (0, common_1.Inject)(ai_options_1.AI_MODULE_OPTIONS)),
|
|
64
|
+
__metadata("design:paramtypes", [ai_service_1.AiService, Object])
|
|
65
|
+
], SummarizationService);
|
|
66
|
+
//# sourceMappingURL=summarization.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"summarization.service.js","sourceRoot":"","sources":["../../../../src/core/ai/summarization/summarization.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAAwE;AACxE,8CAA0C;AAC1C,8CAKuB;AAGvB,MAAM,qBAAqB,GAAG,IAAI,CAAC;AACnC,MAAM,iBAAiB,GAAG,EAAE,CAAC;AAGtB,IAAM,oBAAoB,4BAA1B,MAAM,oBAAoB;IAG/B,YAEE,SAAqC,EACV,OAAyC;QADnD,cAAS,GAAT,SAAS,CAAW;QACO,YAAO,GAAP,OAAO,CAAiB;QALrD,WAAM,GAAG,IAAI,eAAM,CAAC,sBAAoB,CAAC,IAAI,CAAC,CAAC;IAM7D,CAAC;IAEJ,eAAe,CACb,QAAkD,EAClD,SAAkB;QAElB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IAAI,IAAI,CAAC;IAC/B,CAAC;IAED,gBAAgB,CACd,QAAkD,EAClD,UAAU,GAAG,EAAE;QAEf,OAAO,QAAQ,CAAC,KAAK,CAAC,CAAC,UAAU,CAAC,CAAC;IACrC,CAAC;CACF,CAAA;AA3DY,oDAAoB;+BAApB,oBAAoB;IADhC,IAAA,mBAAU,GAAE;IAKR,WAAA,IAAA,eAAM,EAAC,IAAA,mBAAU,EAAC,GAAG,EAAE,CAAC,sBAAS,CAAC,CAAC,CAAA;IAEnC,WAAA,IAAA,eAAM,EAAC,8BAAiB,CAAC,CAAA;qCADE,sBAAS;GAL5B,oBAAoB,CA2DhC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Repository } from 'typeorm';
|
|
2
|
+
import { PromptTemplate } from '../entities/prompt-template.entity';
|
|
3
|
+
export declare class TemplateService {
|
|
4
|
+
private readonly templateRepository;
|
|
5
|
+
private readonly logger;
|
|
6
|
+
private readonly cache;
|
|
7
|
+
constructor(templateRepository: Repository<PromptTemplate>);
|
|
8
|
+
resolve(templateOrId: string): Promise<string>;
|
|
9
|
+
substitute(template: string, vars: Record<string, string>): string;
|
|
10
|
+
resolveSlug(templateOrId: string): string | undefined;
|
|
11
|
+
private isInlineTemplate;
|
|
12
|
+
private getFromCache;
|
|
13
|
+
private setCache;
|
|
14
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
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;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
14
|
+
var TemplateService_1;
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
exports.TemplateService = void 0;
|
|
17
|
+
const common_1 = require("@nestjs/common");
|
|
18
|
+
const typeorm_1 = require("@nestjs/typeorm");
|
|
19
|
+
const typeorm_2 = require("typeorm");
|
|
20
|
+
const prompt_template_entity_1 = require("../entities/prompt-template.entity");
|
|
21
|
+
const CACHE_TTL_MS = 5 * 60 * 1000;
|
|
22
|
+
const MAX_CACHE_SIZE = 50;
|
|
23
|
+
let TemplateService = TemplateService_1 = class TemplateService {
|
|
24
|
+
constructor(templateRepository) {
|
|
25
|
+
this.templateRepository = templateRepository;
|
|
26
|
+
this.logger = new common_1.Logger(TemplateService_1.name);
|
|
27
|
+
this.cache = new Map();
|
|
28
|
+
}
|
|
29
|
+
async resolve(templateOrId) {
|
|
30
|
+
if (this.isInlineTemplate(templateOrId)) {
|
|
31
|
+
return templateOrId;
|
|
32
|
+
}
|
|
33
|
+
const cached = this.getFromCache(templateOrId);
|
|
34
|
+
if (cached !== undefined) {
|
|
35
|
+
return cached;
|
|
36
|
+
}
|
|
37
|
+
try {
|
|
38
|
+
const entry = await this.templateRepository.findOne({
|
|
39
|
+
where: { slug: templateOrId, isActive: true },
|
|
40
|
+
});
|
|
41
|
+
if (entry) {
|
|
42
|
+
this.setCache(templateOrId, entry.template);
|
|
43
|
+
return entry.template;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
catch (error) {
|
|
47
|
+
this.logger.warn(`Failed to resolve template slug "${templateOrId}": ${error instanceof Error ? error.message : String(error)}`);
|
|
48
|
+
}
|
|
49
|
+
return templateOrId;
|
|
50
|
+
}
|
|
51
|
+
substitute(template, vars) {
|
|
52
|
+
return Object.entries(vars).reduce((acc, [key, value]) => {
|
|
53
|
+
const pattern = new RegExp(`\\{\\{${key}\\}\\}`, 'g');
|
|
54
|
+
return acc.replace(pattern, value);
|
|
55
|
+
}, template);
|
|
56
|
+
}
|
|
57
|
+
resolveSlug(templateOrId) {
|
|
58
|
+
return this.isInlineTemplate(templateOrId) ? undefined : templateOrId;
|
|
59
|
+
}
|
|
60
|
+
isInlineTemplate(input) {
|
|
61
|
+
return input.includes('{{') || input.includes(' ') || input.length > 100;
|
|
62
|
+
}
|
|
63
|
+
getFromCache(slug) {
|
|
64
|
+
const entry = this.cache.get(slug);
|
|
65
|
+
if (!entry)
|
|
66
|
+
return undefined;
|
|
67
|
+
if (Date.now() > entry.expiresAt) {
|
|
68
|
+
this.cache.delete(slug);
|
|
69
|
+
return undefined;
|
|
70
|
+
}
|
|
71
|
+
return entry.value;
|
|
72
|
+
}
|
|
73
|
+
setCache(slug, value) {
|
|
74
|
+
if (this.cache.size >= MAX_CACHE_SIZE) {
|
|
75
|
+
const firstKey = this.cache.keys().next().value;
|
|
76
|
+
if (firstKey)
|
|
77
|
+
this.cache.delete(firstKey);
|
|
78
|
+
}
|
|
79
|
+
this.cache.set(slug, { value, expiresAt: Date.now() + CACHE_TTL_MS });
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
exports.TemplateService = TemplateService;
|
|
83
|
+
exports.TemplateService = TemplateService = TemplateService_1 = __decorate([
|
|
84
|
+
(0, common_1.Injectable)(),
|
|
85
|
+
__param(0, (0, typeorm_1.InjectRepository)(prompt_template_entity_1.PromptTemplate)),
|
|
86
|
+
__metadata("design:paramtypes", [typeorm_2.Repository])
|
|
87
|
+
], TemplateService);
|
|
88
|
+
//# sourceMappingURL=template.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"template.service.js","sourceRoot":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AE,CAAC;YACtC,MAAM,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,IAAI,EAAE,CAAC,KAA2B,CAAC;YACtE,IAAI,QAAQ;gBAAE,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;QAC5C,CAAC;QACD,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,EAAE,EAAE,KAAK,EAAE,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,YAAY,EAAE,CAAC,CAAC;IACxE,CAAC;CACF,CAAA;AApEY,0CAAe;0BAAf,eAAe;IAD3B,IAAA,mBAAU,GAAE;IAMR,WAAA,IAAA,0BAAgB,EAAC,uCAAc,CAAC,CAAA;qCACI,oBAAU;GANtC,eAAe,CAoE3B"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export declare class AuditLogEntry {
|
|
2
|
+
id: string;
|
|
3
|
+
ts: Date;
|
|
4
|
+
actorId: string | null;
|
|
5
|
+
actorRole: string | null;
|
|
6
|
+
action: string;
|
|
7
|
+
resourceType: string | null;
|
|
8
|
+
resourceId: string | null;
|
|
9
|
+
ip: string | null;
|
|
10
|
+
userAgent: string | null;
|
|
11
|
+
status: number | null;
|
|
12
|
+
metadata: Record<string, unknown> | null;
|
|
13
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
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;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.AuditLogEntry = void 0;
|
|
13
|
+
const typeorm_1 = require("typeorm");
|
|
14
|
+
let AuditLogEntry = class AuditLogEntry {
|
|
15
|
+
};
|
|
16
|
+
exports.AuditLogEntry = AuditLogEntry;
|
|
17
|
+
__decorate([
|
|
18
|
+
(0, typeorm_1.PrimaryGeneratedColumn)('uuid'),
|
|
19
|
+
__metadata("design:type", String)
|
|
20
|
+
], AuditLogEntry.prototype, "id", void 0);
|
|
21
|
+
__decorate([
|
|
22
|
+
(0, typeorm_1.CreateDateColumn)({ name: 'ts', type: 'timestamptz' }),
|
|
23
|
+
__metadata("design:type", Date)
|
|
24
|
+
], AuditLogEntry.prototype, "ts", void 0);
|
|
25
|
+
__decorate([
|
|
26
|
+
(0, typeorm_1.Column)({ name: 'actor_id', type: 'varchar', length: 255, nullable: true }),
|
|
27
|
+
__metadata("design:type", Object)
|
|
28
|
+
], AuditLogEntry.prototype, "actorId", void 0);
|
|
29
|
+
__decorate([
|
|
30
|
+
(0, typeorm_1.Column)({ name: 'actor_role', type: 'varchar', length: 32, nullable: true }),
|
|
31
|
+
__metadata("design:type", Object)
|
|
32
|
+
], AuditLogEntry.prototype, "actorRole", void 0);
|
|
33
|
+
__decorate([
|
|
34
|
+
(0, typeorm_1.Column)({ type: 'varchar', length: 64 }),
|
|
35
|
+
__metadata("design:type", String)
|
|
36
|
+
], AuditLogEntry.prototype, "action", void 0);
|
|
37
|
+
__decorate([
|
|
38
|
+
(0, typeorm_1.Column)({
|
|
39
|
+
name: 'resource_type',
|
|
40
|
+
type: 'varchar',
|
|
41
|
+
length: 64,
|
|
42
|
+
nullable: true,
|
|
43
|
+
}),
|
|
44
|
+
__metadata("design:type", Object)
|
|
45
|
+
], AuditLogEntry.prototype, "resourceType", void 0);
|
|
46
|
+
__decorate([
|
|
47
|
+
(0, typeorm_1.Column)({ name: 'resource_id', type: 'varchar', length: 255, nullable: true }),
|
|
48
|
+
__metadata("design:type", Object)
|
|
49
|
+
], AuditLogEntry.prototype, "resourceId", void 0);
|
|
50
|
+
__decorate([
|
|
51
|
+
(0, typeorm_1.Column)({ type: 'inet', nullable: true }),
|
|
52
|
+
__metadata("design:type", Object)
|
|
53
|
+
], AuditLogEntry.prototype, "ip", void 0);
|
|
54
|
+
__decorate([
|
|
55
|
+
(0, typeorm_1.Column)({ name: 'user_agent', type: 'text', nullable: true }),
|
|
56
|
+
__metadata("design:type", Object)
|
|
57
|
+
], AuditLogEntry.prototype, "userAgent", void 0);
|
|
58
|
+
__decorate([
|
|
59
|
+
(0, typeorm_1.Column)({ type: 'int', nullable: true }),
|
|
60
|
+
__metadata("design:type", Object)
|
|
61
|
+
], AuditLogEntry.prototype, "status", void 0);
|
|
62
|
+
__decorate([
|
|
63
|
+
(0, typeorm_1.Column)({ type: 'jsonb', nullable: true }),
|
|
64
|
+
__metadata("design:type", Object)
|
|
65
|
+
], AuditLogEntry.prototype, "metadata", void 0);
|
|
66
|
+
exports.AuditLogEntry = AuditLogEntry = __decorate([
|
|
67
|
+
(0, typeorm_1.Entity)({ name: 'audit_log' }),
|
|
68
|
+
(0, typeorm_1.Index)('ix_audit_log_actor_ts', ['actorId', 'ts']),
|
|
69
|
+
(0, typeorm_1.Index)('ix_audit_log_resource_ts', ['resourceType', 'resourceId', 'ts']),
|
|
70
|
+
(0, typeorm_1.Index)('ix_audit_log_action_ts', ['action', 'ts'])
|
|
71
|
+
], AuditLogEntry);
|
|
72
|
+
//# sourceMappingURL=audit-log.entity.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"audit-log.entity.js","sourceRoot":"","sources":["../../../src/core/audit-log/audit-log.entity.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,qCA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EAAE,CAAC;;6CAClB;AAGtB;IADC,IAAA,gBAAM,EAAC,EAAE,IAAI,EAAE,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;;+CACD;wBArC9B,aAAa;IAJzB,IAAA,gBAAM,EAAC,EAAE,IAAI,EAAE,WAAW,EAAE,CAAC;IAC7B,IAAA,eAAK,EAAC,uBAAuB,EAAE,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;IACjD,IAAA,eAAK,EAAC,0BAA0B,EAAE,CAAC,cAAc,EAAE,YAAY,EAAE,IAAI,CAAC,CAAC;IACvE,IAAA,eAAK,EAAC,wBAAwB,EAAE,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;GACrC,aAAa,CAsCzB"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
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;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.AuditLogModule = void 0;
|
|
10
|
+
const common_1 = require("@nestjs/common");
|
|
11
|
+
const typeorm_1 = require("@nestjs/typeorm");
|
|
12
|
+
const audit_log_entity_1 = require("./audit-log.entity");
|
|
13
|
+
const audit_log_service_1 = require("./audit-log.service");
|
|
14
|
+
let AuditLogModule = class AuditLogModule {
|
|
15
|
+
};
|
|
16
|
+
exports.AuditLogModule = AuditLogModule;
|
|
17
|
+
exports.AuditLogModule = AuditLogModule = __decorate([
|
|
18
|
+
(0, common_1.Global)(),
|
|
19
|
+
(0, common_1.Module)({
|
|
20
|
+
imports: [typeorm_1.TypeOrmModule.forFeature([audit_log_entity_1.AuditLogEntry])],
|
|
21
|
+
providers: [audit_log_service_1.AuditLogService],
|
|
22
|
+
exports: [audit_log_service_1.AuditLogService],
|
|
23
|
+
})
|
|
24
|
+
], AuditLogModule);
|
|
25
|
+
//# sourceMappingURL=audit-log.module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"audit-log.module.js","sourceRoot":"","sources":["../../../src/core/audit-log/audit-log.module.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAAgD;AAChD,6CAAgD;AAChD,yDAAmD;AACnD,2DAAsD;AAQ/C,IAAM,cAAc,GAApB,MAAM,cAAc;CAAG,CAAA;AAAjB,wCAAc;yBAAd,cAAc;IAN1B,IAAA,eAAM,GAAE;IACR,IAAA,eAAM,EAAC;QACN,OAAO,EAAE,CAAC,uBAAa,CAAC,UAAU,CAAC,CAAC,gCAAa,CAAC,CAAC,CAAC;QACpD,SAAS,EAAE,CAAC,mCAAe,CAAC;QAC5B,OAAO,EAAE,CAAC,mCAAe,CAAC;KAC3B,CAAC;GACW,cAAc,CAAG"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Repository } from 'typeorm';
|
|
2
|
+
import { AuditLogEntry } from './audit-log.entity';
|
|
3
|
+
export interface AuditLogEvent {
|
|
4
|
+
action: string;
|
|
5
|
+
actorId?: string | null;
|
|
6
|
+
actorRole?: string | null;
|
|
7
|
+
resourceType?: string | null;
|
|
8
|
+
resourceId?: string | null;
|
|
9
|
+
ip?: string | null;
|
|
10
|
+
userAgent?: string | null;
|
|
11
|
+
status?: number | null;
|
|
12
|
+
metadata?: Record<string, unknown> | null;
|
|
13
|
+
}
|
|
14
|
+
export declare class AuditLogService {
|
|
15
|
+
private readonly repository;
|
|
16
|
+
private readonly logger;
|
|
17
|
+
constructor(repository: Repository<AuditLogEntry>);
|
|
18
|
+
record(event: AuditLogEvent): void;
|
|
19
|
+
private persist;
|
|
20
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
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;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
14
|
+
var AuditLogService_1;
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
exports.AuditLogService = void 0;
|
|
17
|
+
const common_1 = require("@nestjs/common");
|
|
18
|
+
const typeorm_1 = require("@nestjs/typeorm");
|
|
19
|
+
const typeorm_2 = require("typeorm");
|
|
20
|
+
const audit_log_entity_1 = require("./audit-log.entity");
|
|
21
|
+
let AuditLogService = AuditLogService_1 = class AuditLogService {
|
|
22
|
+
constructor(repository) {
|
|
23
|
+
this.repository = repository;
|
|
24
|
+
this.logger = new common_1.Logger(AuditLogService_1.name);
|
|
25
|
+
}
|
|
26
|
+
record(event) {
|
|
27
|
+
void this.persist(event);
|
|
28
|
+
}
|
|
29
|
+
async persist(event) {
|
|
30
|
+
try {
|
|
31
|
+
const entry = this.repository.create({
|
|
32
|
+
action: event.action,
|
|
33
|
+
actorId: event.actorId ?? null,
|
|
34
|
+
actorRole: event.actorRole ?? null,
|
|
35
|
+
resourceType: event.resourceType ?? null,
|
|
36
|
+
resourceId: event.resourceId ?? null,
|
|
37
|
+
ip: event.ip ?? null,
|
|
38
|
+
userAgent: event.userAgent ?? null,
|
|
39
|
+
status: event.status ?? null,
|
|
40
|
+
metadata: event.metadata ?? null,
|
|
41
|
+
});
|
|
42
|
+
await this.repository.save(entry);
|
|
43
|
+
}
|
|
44
|
+
catch (err) {
|
|
45
|
+
this.logger.warn({
|
|
46
|
+
action: event.action,
|
|
47
|
+
actorId: event.actorId,
|
|
48
|
+
error: err instanceof Error ? err.message : String(err),
|
|
49
|
+
}, 'Failed to persist audit log entry');
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
exports.AuditLogService = AuditLogService;
|
|
54
|
+
exports.AuditLogService = AuditLogService = AuditLogService_1 = __decorate([
|
|
55
|
+
(0, common_1.Injectable)(),
|
|
56
|
+
__param(0, (0, typeorm_1.InjectRepository)(audit_log_entity_1.AuditLogEntry)),
|
|
57
|
+
__metadata("design:paramtypes", [typeorm_2.Repository])
|
|
58
|
+
], AuditLogService);
|
|
59
|
+
//# sourceMappingURL=audit-log.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"audit-log.service.js","sourceRoot":"","sources":["../../../src/core/audit-log/audit-log.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAAoD;AACpD,6CAAmD;AACnD,qCAAqC;AACrC,yDAAmD;AAoB5C,IAAM,eAAe,uBAArB,MAAM,eAAe;IAG1B,YAEE,UAAsD;QAArC,eAAU,GAAV,UAAU,CAA2B;QAJvC,WAAM,GAAG,IAAI,eAAM,CAAC,iBAAe,CAAC,IAAI,CAAC,CAAC;IAKxD,CAAC;IAEJ,MAAM,CAAC,KAAoB;QACzB,KAAK,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IAC3B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export { AuditLogService } from './audit-log.service';
|
|
4
|
+
export type { AuditLogEvent } from './audit-log.service';
|
|
5
|
+
export { AuditLogEntry };
|
|
6
|
+
export declare const AUDIT_LOG_ENTITIES: (typeof AuditLogEntry)[];
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AUDIT_LOG_ENTITIES = exports.AuditLogEntry = exports.AuditLogService = exports.AuditLogModule = void 0;
|
|
4
|
+
const audit_log_entity_1 = require("./audit-log.entity");
|
|
5
|
+
Object.defineProperty(exports, "AuditLogEntry", { enumerable: true, get: function () { return audit_log_entity_1.AuditLogEntry; } });
|
|
6
|
+
var audit_log_module_1 = require("./audit-log.module");
|
|
7
|
+
Object.defineProperty(exports, "AuditLogModule", { enumerable: true, get: function () { return audit_log_module_1.AuditLogModule; } });
|
|
8
|
+
var audit_log_service_1 = require("./audit-log.service");
|
|
9
|
+
Object.defineProperty(exports, "AuditLogService", { enumerable: true, get: function () { return audit_log_service_1.AuditLogService; } });
|
|
10
|
+
exports.AUDIT_LOG_ENTITIES = [audit_log_entity_1.AuditLogEntry];
|
|
11
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/core/audit-log/index.ts"],"names":[],"mappings":";;;AAAA,yDAAmD;AAK1C,8FALA,gCAAa,OAKA;AAHtB,uDAAoD;AAA3C,kHAAA,cAAc,OAAA;AACvB,yDAAsD;AAA7C,oHAAA,eAAe,OAAA;AAIX,QAAA,kBAAkB,GAAG,CAAC,gCAAa,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.provider.js","sourceRoot":"","sources":["../../../src/core/auth/auth.provider.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export declare const ROLES_KEY = "roles";
|
|
2
|
+
export declare const Roles: (...roles: string[]) => import("@nestjs/common").CustomDecorator<string>;
|
|
3
|
+
export declare const PUBLIC_KEY = "public";
|
|
4
|
+
export declare const Public: () => import("@nestjs/common").CustomDecorator<string>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Public = exports.PUBLIC_KEY = exports.Roles = exports.ROLES_KEY = void 0;
|
|
4
|
+
const common_1 = require("@nestjs/common");
|
|
5
|
+
exports.ROLES_KEY = 'roles';
|
|
6
|
+
const Roles = (...roles) => (0, common_1.SetMetadata)(exports.ROLES_KEY, roles);
|
|
7
|
+
exports.Roles = Roles;
|
|
8
|
+
exports.PUBLIC_KEY = 'public';
|
|
9
|
+
const Public = () => (0, common_1.SetMetadata)(exports.PUBLIC_KEY, true);
|
|
10
|
+
exports.Public = Public;
|
|
11
|
+
//# sourceMappingURL=decorators.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decorators.js","sourceRoot":"","sources":["../../../src/core/auth/decorators.ts"],"names":[],"mappings":";;;AAAA,2CAA6C;AAEhC,QAAA,SAAS,GAAG,OAAO,CAAC;AAC1B,MAAM,KAAK,GAAG,CAAC,GAAG,KAAe,EAAE,EAAE,CAAC,IAAA,oBAAW,EAAC,iBAAS,EAAE,KAAK,CAAC,CAAC;AAA9D,QAAA,KAAK,SAAyD;AAE9D,QAAA,UAAU,GAAG,QAAQ,CAAC;AAC5B,MAAM,MAAM,GAAG,GAAG,EAAE,CAAC,IAAA,oBAAW,EAAC,kBAAU,EAAE,IAAI,CAAC,CAAC;AAA7C,QAAA,MAAM,UAAuC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./auth.provider"), exports);
|
|
18
|
+
__exportStar(require("./decorators"), exports);
|
|
19
|
+
__exportStar(require("./params"), exports);
|
|
20
|
+
__exportStar(require("./role.can-activate"), exports);
|
|
21
|
+
__exportStar(require("./types"), exports);
|
|
22
|
+
__exportStar(require("./utils"), exports);
|
|
23
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/core/auth/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,kDAAgC;AAChC,+CAA6B;AAC7B,2CAAyB;AACzB,sDAAoC;AACpC,0CAAwB;AACxB,0CAAwB"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.UserEmail = exports.UserId = void 0;
|
|
4
|
+
const common_1 = require("@nestjs/common");
|
|
5
|
+
exports.UserId = (0, common_1.createParamDecorator)((_, ctx) => {
|
|
6
|
+
const request = ctx
|
|
7
|
+
.switchToHttp()
|
|
8
|
+
.getRequest();
|
|
9
|
+
if (!request.user?.sub) {
|
|
10
|
+
throw new common_1.UnauthorizedException('User not authenticated');
|
|
11
|
+
}
|
|
12
|
+
return request.user.sub;
|
|
13
|
+
});
|
|
14
|
+
exports.UserEmail = (0, common_1.createParamDecorator)((_, ctx) => {
|
|
15
|
+
const request = ctx
|
|
16
|
+
.switchToHttp()
|
|
17
|
+
.getRequest();
|
|
18
|
+
if (!request.user?.email) {
|
|
19
|
+
throw new common_1.UnauthorizedException('User not authenticated');
|
|
20
|
+
}
|
|
21
|
+
return request.user.email;
|
|
22
|
+
});
|
|
23
|
+
//# sourceMappingURL=params.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"params.js","sourceRoot":"","sources":["../../../src/core/auth/params.ts"],"names":[],"mappings":";;;AAAA,2CAIwB;AAGX,QAAA,MAAM,GAAG,IAAA,6BAAoB,EACxC,CAAC,CAAU,EAAE,GAAqB,EAAU,EAAE;IAC5C,MAAM,OAAO,GAAG,GAAG;SAChB,YAAY,EAAE;SACd,UAAU,EAAgC,CAAC;IAC9C,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,EAAE,CAAC;QACvB,MAAM,IAAI,8BAAqB,CAAC,wBAAwB,CAAC,CAAC;IAC5D,CAAC;IACD,OAAO,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC;AAC1B,CAAC,CACF,CAAC;AAEW,QAAA,SAAS,GAAG,IAAA,6BAAoB,EAC3C,CAAC,CAAU,EAAE,GAAqB,EAAU,EAAE;IAC5C,MAAM,OAAO,GAAG,GAAG;SAChB,YAAY,EAAE;SACd,UAAU,EAAgC,CAAC;IAC9C,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,KAAK,EAAE,CAAC;QACzB,MAAM,IAAI,8BAAqB,CAAC,wBAAwB,CAAC,CAAC;IAC5D,CAAC;IACD,OAAO,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC;AAC5B,CAAC,CACF,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { CanActivate, ExecutionContext } from '@nestjs/common';
|
|
2
|
+
import { Reflector } from '@nestjs/core';
|
|
3
|
+
import { AuthorizationUser } from './types';
|
|
4
|
+
export declare abstract class RoleCanActivate implements CanActivate {
|
|
5
|
+
private readonly reflector;
|
|
6
|
+
protected constructor(reflector: Reflector);
|
|
7
|
+
canActivate(context: ExecutionContext): Promise<boolean>;
|
|
8
|
+
private resolveUser;
|
|
9
|
+
abstract getUser(token: string): Promise<AuthorizationUser>;
|
|
10
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
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;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.RoleCanActivate = void 0;
|
|
13
|
+
const common_1 = require("@nestjs/common");
|
|
14
|
+
const core_1 = require("@nestjs/core");
|
|
15
|
+
const utils_1 = require("./utils");
|
|
16
|
+
let RoleCanActivate = class RoleCanActivate {
|
|
17
|
+
constructor(reflector) {
|
|
18
|
+
this.reflector = reflector;
|
|
19
|
+
}
|
|
20
|
+
async canActivate(context) {
|
|
21
|
+
if ((0, utils_1.isPublic)(context, this.reflector)) {
|
|
22
|
+
return true;
|
|
23
|
+
}
|
|
24
|
+
const request = context.switchToHttp().getRequest();
|
|
25
|
+
const user = await this.resolveUser(request.headers.authorization);
|
|
26
|
+
request.user = user;
|
|
27
|
+
(0, utils_1.validateRequiredRole)(context, this.reflector, user.role);
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
30
|
+
resolveUser(authHeader) {
|
|
31
|
+
if (!authHeader?.startsWith('Bearer ')) {
|
|
32
|
+
throw new common_1.UnauthorizedException();
|
|
33
|
+
}
|
|
34
|
+
return this.getUser(authHeader.slice('Bearer '.length));
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
exports.RoleCanActivate = RoleCanActivate;
|
|
38
|
+
exports.RoleCanActivate = RoleCanActivate = __decorate([
|
|
39
|
+
(0, common_1.Injectable)(),
|
|
40
|
+
__metadata("design:paramtypes", [core_1.Reflector])
|
|
41
|
+
], RoleCanActivate);
|
|
42
|
+
//# sourceMappingURL=role.can-activate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"role.can-activate.js","sourceRoot":"","sources":["../../../src/core/auth/role.can-activate.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAKwB;AACxB,uCAAyC;AAEzC,mCAAyD;AAQlD,IAAe,eAAe,GAA9B,MAAe,eAAe;IACnC,YAAuC,SAAoB;QAApB,cAAS,GAAT,SAAS,CAAW;IAAG,CAAC;IAE/D,KAAK,CAAC,WAAW,CAAC,OAAyB;QACzC,IAAI,IAAA,gBAAQ,EAAC,OAAO,EAAE,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC;YACtC,OAAO,IAAI,CAAC;QACd,CAAC;QAED,MAAM,OAAO,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC,UAAU,EAG7C,CAAC;QAEL,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC;QACnE,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC;QAEpB,IAAA,4BAAoB,EAAC,OAAO,EAAE,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;QAEzD,OAAO,IAAI,CAAC;IACd,CAAC;IAEO,WAAW,CACjB,UAA8B;QAE9B,IAAI,CAAC,UAAU,EAAE,UAAU,CAAC,SAAS,CAAC,EAAE,CAAC;YACvC,MAAM,IAAI,8BAAqB,EAAE,CAAC;QACpC,CAAC;QACD,OAAO,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,KAAK,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC;IAC1D,CAAC;CAGF,CAAA;AA/BqB,0CAAe;0BAAf,eAAe;IADpC,IAAA,mBAAU,GAAE;qCAEuC,gBAAS;GADvC,eAAe,CA+BpC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/core/auth/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { ExecutionContext } from '@nestjs/common';
|
|
2
|
+
import { Reflector } from '@nestjs/core';
|
|
3
|
+
export declare function isPublic(context: ExecutionContext, reflector: Reflector): boolean;
|
|
4
|
+
export declare function validateRequiredRole(context: ExecutionContext, reflector: Reflector, role: string | undefined): void;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isPublic = isPublic;
|
|
4
|
+
exports.validateRequiredRole = validateRequiredRole;
|
|
5
|
+
const common_1 = require("@nestjs/common");
|
|
6
|
+
const decorators_1 = require("./decorators");
|
|
7
|
+
function isPublic(context, reflector) {
|
|
8
|
+
return reflector.getAllAndOverride(decorators_1.PUBLIC_KEY, [
|
|
9
|
+
context.getHandler(),
|
|
10
|
+
context.getClass(),
|
|
11
|
+
]);
|
|
12
|
+
}
|
|
13
|
+
function validateRequiredRole(context, reflector, role) {
|
|
14
|
+
const requiredRoles = reflector.getAllAndOverride(decorators_1.ROLES_KEY, [
|
|
15
|
+
context.getHandler(),
|
|
16
|
+
context.getClass(),
|
|
17
|
+
]);
|
|
18
|
+
if (requiredRoles && (!role || !requiredRoles.includes(role))) {
|
|
19
|
+
throw new common_1.ForbiddenException('Insufficient role');
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=utils.js.map
|