@hed-hog/core 0.0.295 → 0.0.297
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/dist/auth/auth.controller.d.ts +5 -5
- package/dist/auth/auth.service.d.ts +5 -5
- package/dist/challenge/challenge.service.d.ts +2 -2
- package/dist/core.module.d.ts.map +1 -1
- package/dist/core.module.js +4 -1
- package/dist/core.module.js.map +1 -1
- package/dist/dashboard/dashboard-core/dashboard-core.controller.d.ts +1 -1
- package/dist/dashboard/dashboard-core/dashboard-core.service.d.ts +2 -2
- package/dist/index.d.ts +13 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +14 -0
- package/dist/index.js.map +1 -1
- package/dist/integration/index.d.ts +4 -0
- package/dist/integration/index.d.ts.map +1 -0
- package/dist/integration/index.js +20 -0
- package/dist/integration/index.js.map +1 -0
- package/dist/integration/integration-api.validation.d.ts +2 -0
- package/dist/integration/integration-api.validation.d.ts.map +1 -0
- package/dist/integration/integration-api.validation.js +126 -0
- package/dist/integration/integration-api.validation.js.map +1 -0
- package/dist/integration/integration.module.d.ts +3 -0
- package/dist/integration/integration.module.d.ts.map +1 -0
- package/dist/integration/integration.module.js +54 -0
- package/dist/integration/integration.module.js.map +1 -0
- package/dist/integration/services/domain-event.publisher.d.ts +31 -0
- package/dist/integration/services/domain-event.publisher.d.ts.map +1 -0
- package/dist/integration/services/domain-event.publisher.js +79 -0
- package/dist/integration/services/domain-event.publisher.js.map +1 -0
- package/dist/integration/services/event-subscriber.registry.d.ts +37 -0
- package/dist/integration/services/event-subscriber.registry.d.ts.map +1 -0
- package/dist/integration/services/event-subscriber.registry.js +86 -0
- package/dist/integration/services/event-subscriber.registry.js.map +1 -0
- package/dist/integration/services/inbox.service.d.ts +55 -0
- package/dist/integration/services/inbox.service.d.ts.map +1 -0
- package/dist/integration/services/inbox.service.js +173 -0
- package/dist/integration/services/inbox.service.js.map +1 -0
- package/dist/integration/services/index.d.ts +12 -0
- package/dist/integration/services/index.d.ts.map +1 -0
- package/dist/integration/services/index.js +28 -0
- package/dist/integration/services/index.js.map +1 -0
- package/dist/integration/services/integration-developer-api.service.d.ts +30 -0
- package/dist/integration/services/integration-developer-api.service.d.ts.map +1 -0
- package/dist/integration/services/integration-developer-api.service.js +55 -0
- package/dist/integration/services/integration-developer-api.service.js.map +1 -0
- package/dist/integration/services/integration-link.service.d.ts +52 -0
- package/dist/integration/services/integration-link.service.d.ts.map +1 -0
- package/dist/integration/services/integration-link.service.js +128 -0
- package/dist/integration/services/integration-link.service.js.map +1 -0
- package/dist/integration/services/integration-settings.service.d.ts +23 -0
- package/dist/integration/services/integration-settings.service.d.ts.map +1 -0
- package/dist/integration/services/integration-settings.service.js +81 -0
- package/dist/integration/services/integration-settings.service.js.map +1 -0
- package/dist/integration/services/outbox-polling.coordinator.d.ts +45 -0
- package/dist/integration/services/outbox-polling.coordinator.d.ts.map +1 -0
- package/dist/integration/services/outbox-polling.coordinator.js +143 -0
- package/dist/integration/services/outbox-polling.coordinator.js.map +1 -0
- package/dist/integration/services/outbox.notifier.d.ts +30 -0
- package/dist/integration/services/outbox.notifier.d.ts.map +1 -0
- package/dist/integration/services/outbox.notifier.js +57 -0
- package/dist/integration/services/outbox.notifier.js.map +1 -0
- package/dist/integration/services/outbox.processor.d.ts +42 -0
- package/dist/integration/services/outbox.processor.d.ts.map +1 -0
- package/dist/integration/services/outbox.processor.job.d.ts +43 -0
- package/dist/integration/services/outbox.processor.job.d.ts.map +1 -0
- package/dist/integration/services/outbox.processor.job.js +100 -0
- package/dist/integration/services/outbox.processor.job.js.map +1 -0
- package/dist/integration/services/outbox.processor.js +208 -0
- package/dist/integration/services/outbox.processor.js.map +1 -0
- package/dist/integration/services/outbox.service.d.ts +53 -0
- package/dist/integration/services/outbox.service.d.ts.map +1 -0
- package/dist/integration/services/outbox.service.js +149 -0
- package/dist/integration/services/outbox.service.js.map +1 -0
- package/dist/integration/types/event.types.d.ts +88 -0
- package/dist/integration/types/event.types.d.ts.map +1 -0
- package/dist/integration/types/event.types.js +35 -0
- package/dist/integration/types/event.types.js.map +1 -0
- package/dist/integration/types/index.d.ts +3 -0
- package/dist/integration/types/index.d.ts.map +1 -0
- package/dist/integration/types/index.js +19 -0
- package/dist/integration/types/index.js.map +1 -0
- package/dist/integration/types/subscriber.types.d.ts +31 -0
- package/dist/integration/types/subscriber.types.d.ts.map +1 -0
- package/dist/integration/types/subscriber.types.js +3 -0
- package/dist/integration/types/subscriber.types.js.map +1 -0
- package/dist/oauth/oauth.controller.js.map +1 -1
- package/dist/oauth/oauth.service.d.ts +3 -3
- package/dist/oauth/oauth.service.d.ts.map +1 -1
- package/dist/oauth/oauth.service.js.map +1 -1
- package/dist/profile/profile.controller.d.ts +6 -6
- package/dist/profile/profile.service.d.ts +6 -6
- package/dist/session/session.controller.d.ts +2 -2
- package/dist/session/session.service.d.ts +3 -3
- package/dist/setting/setting.controller.d.ts +13 -9
- package/dist/setting/setting.controller.d.ts.map +1 -1
- package/dist/setting/setting.service.d.ts +14 -10
- package/dist/setting/setting.service.d.ts.map +1 -1
- package/dist/setting/setting.service.js +21 -1
- package/dist/setting/setting.service.js.map +1 -1
- package/dist/user/user.controller.d.ts +6 -6
- package/dist/user/user.service.d.ts +12 -12
- package/hedhog/data/dashboard_component_role.yaml +223 -223
- package/hedhog/data/dashboard_role.yaml +18 -18
- package/hedhog/data/route.yaml +2 -0
- package/hedhog/data/setting_group.yaml +955 -470
- package/hedhog/data/setting_subgroup.yaml +303 -0
- package/hedhog/frontend/app/configurations/[slug]/components/setting-field.tsx.ejs +44 -18
- package/hedhog/frontend/app/configurations/[slug]/page.tsx.ejs +134 -27
- package/hedhog/frontend/app/configurations/layout.tsx.ejs +84 -23
- package/hedhog/frontend/app/dashboard/components/widgets/permissions-chart.tsx.ejs +62 -62
- package/hedhog/frontend/app/dashboard/page.tsx.ejs +29 -29
- package/hedhog/frontend/app/preferences/page.tsx.ejs +2 -5
- package/hedhog/table/inbox_event.yaml +40 -0
- package/hedhog/table/integration_link.yaml +33 -0
- package/hedhog/table/outbox_event.yaml +45 -0
- package/hedhog/table/setting.yaml +7 -0
- package/hedhog/table/setting_subgroup.yaml +19 -0
- package/package.json +8 -8
- package/src/ai/ai.service.ts +3 -3
- package/src/auth/auth.controller.ts +11 -11
- package/src/auth/auth.service.ts +8 -8
- package/src/core.module.ts +4 -1
- package/src/index.ts +15 -0
- package/src/integration/README.md +397 -0
- package/src/integration/USAGE_EXAMPLE.md +279 -0
- package/src/integration/index.ts +4 -0
- package/src/integration/integration-api.validation.ts +154 -0
- package/src/integration/integration.module.ts +53 -0
- package/src/integration/services/domain-event.publisher.ts +136 -0
- package/src/integration/services/event-subscriber.registry.ts +89 -0
- package/src/integration/services/inbox.service.ts +218 -0
- package/src/integration/services/index.ts +12 -0
- package/src/integration/services/integration-developer-api.service.ts +96 -0
- package/src/integration/services/integration-link.service.ts +154 -0
- package/src/integration/services/integration-settings.service.ts +128 -0
- package/src/integration/services/outbox-polling.coordinator.ts +146 -0
- package/src/integration/services/outbox.notifier.ts +48 -0
- package/src/integration/services/outbox.processor.job.ts +97 -0
- package/src/integration/services/outbox.processor.ts +266 -0
- package/src/integration/services/outbox.service.ts +209 -0
- package/src/integration/types/event.types.ts +93 -0
- package/src/integration/types/index.ts +3 -0
- package/src/integration/types/subscriber.types.ts +37 -0
- package/src/oauth/oauth.controller.ts +17 -17
- package/src/oauth/oauth.service.ts +20 -20
- package/src/setting/setting.service.ts +27 -2
- package/src/task/task.service.ts +5 -5
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
import { PrismaService } from '@hed-hog/api-prisma';
|
|
2
|
+
import { Injectable } from '@nestjs/common';
|
|
3
|
+
import { OutboxEvent, OutboxEventStatus } from '../types';
|
|
4
|
+
|
|
5
|
+
export interface CreateOutboxEventDto {
|
|
6
|
+
eventName: string;
|
|
7
|
+
sourceModule: string;
|
|
8
|
+
aggregateType: string;
|
|
9
|
+
aggregateId: string;
|
|
10
|
+
payload: Record<string, any>;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface OutboxEventPersistenceClient {
|
|
14
|
+
outbox_event: PrismaService['outbox_event'];
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
interface OutboxEventRecord {
|
|
18
|
+
id: number;
|
|
19
|
+
event_name: string;
|
|
20
|
+
source_module: string;
|
|
21
|
+
aggregate_type: string;
|
|
22
|
+
aggregate_id: string;
|
|
23
|
+
payload: Record<string, any>;
|
|
24
|
+
status: OutboxEventStatus;
|
|
25
|
+
attempt_count: number;
|
|
26
|
+
last_error: string | null;
|
|
27
|
+
available_at: Date;
|
|
28
|
+
processed_at: Date | null;
|
|
29
|
+
created_at: Date;
|
|
30
|
+
updated_at: Date;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
@Injectable()
|
|
34
|
+
export class OutboxService {
|
|
35
|
+
constructor(private readonly prisma: PrismaService) {}
|
|
36
|
+
|
|
37
|
+
private toDomainEvent(record: OutboxEventRecord): OutboxEvent {
|
|
38
|
+
return {
|
|
39
|
+
id: String(record.id),
|
|
40
|
+
eventName: record.event_name,
|
|
41
|
+
sourceModule: record.source_module,
|
|
42
|
+
aggregateType: record.aggregate_type,
|
|
43
|
+
aggregateId: record.aggregate_id,
|
|
44
|
+
payload: record.payload,
|
|
45
|
+
status: record.status,
|
|
46
|
+
attemptCount: record.attempt_count,
|
|
47
|
+
lastError: record.last_error,
|
|
48
|
+
availableAt: record.available_at,
|
|
49
|
+
processedAt: record.processed_at,
|
|
50
|
+
createdAt: record.created_at,
|
|
51
|
+
updatedAt: record.updated_at,
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
private toDatabaseId(eventId: string | number): number {
|
|
56
|
+
return typeof eventId === 'number' ? eventId : Number(eventId);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
private toDatabaseUpdate(
|
|
60
|
+
partialUpdate?: {
|
|
61
|
+
attemptCount?: number;
|
|
62
|
+
lastError?: string | null;
|
|
63
|
+
availableAt?: Date;
|
|
64
|
+
processedAt?: Date | null;
|
|
65
|
+
},
|
|
66
|
+
) {
|
|
67
|
+
if (!partialUpdate) {
|
|
68
|
+
return undefined;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
return {
|
|
72
|
+
attempt_count: partialUpdate.attemptCount,
|
|
73
|
+
last_error: partialUpdate.lastError,
|
|
74
|
+
available_at: partialUpdate.availableAt,
|
|
75
|
+
processed_at: partialUpdate.processedAt,
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Write a new event to the outbox
|
|
81
|
+
*/
|
|
82
|
+
async createEvent(
|
|
83
|
+
dto: CreateOutboxEventDto,
|
|
84
|
+
persistenceClient?: OutboxEventPersistenceClient,
|
|
85
|
+
): Promise<OutboxEvent> {
|
|
86
|
+
const client = persistenceClient ?? this.prisma;
|
|
87
|
+
|
|
88
|
+
const record = await client.outbox_event.create({
|
|
89
|
+
data: {
|
|
90
|
+
event_name: dto.eventName,
|
|
91
|
+
source_module: dto.sourceModule,
|
|
92
|
+
aggregate_type: dto.aggregateType,
|
|
93
|
+
aggregate_id: dto.aggregateId,
|
|
94
|
+
payload: dto.payload,
|
|
95
|
+
status: OutboxEventStatus.PENDING,
|
|
96
|
+
available_at: new Date(),
|
|
97
|
+
attempt_count: 0,
|
|
98
|
+
},
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
return this.toDomainEvent(record as OutboxEventRecord);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Find pending events available for processing, ordered by creation time
|
|
106
|
+
*/
|
|
107
|
+
async findPending(
|
|
108
|
+
limit: number,
|
|
109
|
+
leaseMs: number,
|
|
110
|
+
): Promise<OutboxEvent[]> {
|
|
111
|
+
const now = new Date();
|
|
112
|
+
const leaseThreshold = new Date(now.getTime() - leaseMs);
|
|
113
|
+
|
|
114
|
+
const records = await this.prisma.outbox_event.findMany({
|
|
115
|
+
where: {
|
|
116
|
+
OR: [
|
|
117
|
+
{ status: OutboxEventStatus.PENDING },
|
|
118
|
+
{
|
|
119
|
+
status: OutboxEventStatus.PROCESSING,
|
|
120
|
+
available_at: { lte: leaseThreshold },
|
|
121
|
+
},
|
|
122
|
+
],
|
|
123
|
+
},
|
|
124
|
+
orderBy: { created_at: 'asc' },
|
|
125
|
+
take: limit,
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
return records.map((record) => this.toDomainEvent(record as OutboxEventRecord));
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Update event status and related fields
|
|
133
|
+
*/
|
|
134
|
+
async updateStatus(
|
|
135
|
+
eventId: string | number,
|
|
136
|
+
status: OutboxEventStatus,
|
|
137
|
+
partialUpdate?: {
|
|
138
|
+
attemptCount?: number;
|
|
139
|
+
lastError?: string | null;
|
|
140
|
+
availableAt?: Date;
|
|
141
|
+
processedAt?: Date | null;
|
|
142
|
+
},
|
|
143
|
+
): Promise<OutboxEvent> {
|
|
144
|
+
const record = await this.prisma.outbox_event.update({
|
|
145
|
+
where: { id: this.toDatabaseId(eventId) },
|
|
146
|
+
data: {
|
|
147
|
+
status,
|
|
148
|
+
...this.toDatabaseUpdate(partialUpdate),
|
|
149
|
+
},
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
return this.toDomainEvent(record as OutboxEventRecord);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Mark event as processing and set lease time
|
|
157
|
+
*/
|
|
158
|
+
async markProcessing(
|
|
159
|
+
eventId: string | number,
|
|
160
|
+
leaseMs: number,
|
|
161
|
+
): Promise<OutboxEvent> {
|
|
162
|
+
const leaseUntil = new Date(Date.now() + leaseMs);
|
|
163
|
+
return this.updateStatus(eventId, OutboxEventStatus.PROCESSING, {
|
|
164
|
+
availableAt: leaseUntil,
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* Increment attempt count and optionally update error
|
|
170
|
+
*/
|
|
171
|
+
async incrementAttempt(
|
|
172
|
+
eventId: string | number,
|
|
173
|
+
error?: string,
|
|
174
|
+
): Promise<OutboxEvent> {
|
|
175
|
+
const record = await this.prisma.outbox_event.findUnique({
|
|
176
|
+
where: { id: this.toDatabaseId(eventId) },
|
|
177
|
+
});
|
|
178
|
+
if (!record) {
|
|
179
|
+
throw new Error(`Event ${eventId} not found`);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
const event = this.toDomainEvent(record as OutboxEventRecord);
|
|
183
|
+
|
|
184
|
+
return this.updateStatus(eventId, event.status, {
|
|
185
|
+
attemptCount: event.attemptCount + 1,
|
|
186
|
+
lastError: error || null,
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* Get event by ID
|
|
192
|
+
*/
|
|
193
|
+
async getById(eventId: string | number): Promise<OutboxEvent | null> {
|
|
194
|
+
const record = await this.prisma.outbox_event.findUnique({
|
|
195
|
+
where: { id: this.toDatabaseId(eventId) },
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
return record ? this.toDomainEvent(record as OutboxEventRecord) : null;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* Count events by status
|
|
203
|
+
*/
|
|
204
|
+
async countByStatus(status: OutboxEventStatus): Promise<number> {
|
|
205
|
+
return this.prisma.outbox_event.count({
|
|
206
|
+
where: { status },
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Event status throughout the integration lifecycle
|
|
3
|
+
*/
|
|
4
|
+
export enum OutboxEventStatus {
|
|
5
|
+
PENDING = 'pending',
|
|
6
|
+
PROCESSING = 'processing',
|
|
7
|
+
PROCESSED = 'processed',
|
|
8
|
+
FAILED = 'failed',
|
|
9
|
+
DEAD_LETTER = 'dead_letter',
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Inbox event processing status per consumer
|
|
14
|
+
*/
|
|
15
|
+
export enum InboxEventStatus {
|
|
16
|
+
RECEIVED = 'received',
|
|
17
|
+
PROCESSING = 'processing',
|
|
18
|
+
PROCESSED = 'processed',
|
|
19
|
+
FAILED = 'failed',
|
|
20
|
+
SKIPPED = 'skipped',
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Type of link between entities from different modules
|
|
25
|
+
*/
|
|
26
|
+
export enum LinkType {
|
|
27
|
+
REFERENCE = 'reference',
|
|
28
|
+
CASCADE = 'cascade',
|
|
29
|
+
AGGREGATE_ROOT = 'aggregate_root',
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Domain event interface that is published and processed
|
|
34
|
+
*/
|
|
35
|
+
export interface DomainEvent {
|
|
36
|
+
eventName: string;
|
|
37
|
+
sourceModule: string;
|
|
38
|
+
aggregateType: string;
|
|
39
|
+
aggregateId: string;
|
|
40
|
+
payload: Record<string, any>;
|
|
41
|
+
timestamp: Date;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Outbox event record from database
|
|
46
|
+
*/
|
|
47
|
+
export interface OutboxEvent {
|
|
48
|
+
id: string;
|
|
49
|
+
eventName: string;
|
|
50
|
+
sourceModule: string;
|
|
51
|
+
aggregateType: string;
|
|
52
|
+
aggregateId: string;
|
|
53
|
+
payload: Record<string, any>;
|
|
54
|
+
status: OutboxEventStatus;
|
|
55
|
+
attemptCount: number;
|
|
56
|
+
lastError: string | null;
|
|
57
|
+
availableAt: Date;
|
|
58
|
+
processedAt: Date | null;
|
|
59
|
+
createdAt: Date;
|
|
60
|
+
updatedAt: Date;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Inbox event record from database for idempotency tracking
|
|
65
|
+
*/
|
|
66
|
+
export interface InboxEvent {
|
|
67
|
+
id: string;
|
|
68
|
+
outboxEventId: string;
|
|
69
|
+
consumerName: string;
|
|
70
|
+
status: InboxEventStatus;
|
|
71
|
+
attemptCount: number;
|
|
72
|
+
lastError: string | null;
|
|
73
|
+
processedAt: Date | null;
|
|
74
|
+
createdAt: Date;
|
|
75
|
+
updatedAt: Date;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Integration link between entities across modules
|
|
80
|
+
*/
|
|
81
|
+
export interface IntegrationLink {
|
|
82
|
+
id: string;
|
|
83
|
+
sourceModule: string;
|
|
84
|
+
sourceEntityType: string;
|
|
85
|
+
sourceEntityId: string;
|
|
86
|
+
targetModule: string;
|
|
87
|
+
targetEntityType: string;
|
|
88
|
+
targetEntityId: string;
|
|
89
|
+
linkType: LinkType;
|
|
90
|
+
metadata: Record<string, any> | null;
|
|
91
|
+
createdAt: Date;
|
|
92
|
+
updatedAt: Date;
|
|
93
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { Logger } from '@nestjs/common';
|
|
2
|
+
import { DomainEvent } from './event.types';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Context passed to event handlers
|
|
6
|
+
*/
|
|
7
|
+
export interface SubscriberContext {
|
|
8
|
+
logger: Logger;
|
|
9
|
+
inboxService: any; // To be injected at runtime
|
|
10
|
+
linkService: any; // To be injected at runtime
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Event handler function signature
|
|
15
|
+
*/
|
|
16
|
+
export type EventHandler = (
|
|
17
|
+
event: DomainEvent,
|
|
18
|
+
context: SubscriberContext,
|
|
19
|
+
) => Promise<void>;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Event subscriber definition
|
|
23
|
+
*/
|
|
24
|
+
export interface SubscriberDefinition {
|
|
25
|
+
eventName: string;
|
|
26
|
+
consumerName: string;
|
|
27
|
+
priority?: number;
|
|
28
|
+
handler: EventHandler;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Subscription registry entry
|
|
33
|
+
*/
|
|
34
|
+
export interface SubscriptionEntry {
|
|
35
|
+
definition: SubscriberDefinition;
|
|
36
|
+
handler: EventHandler;
|
|
37
|
+
}
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
|
|
2
2
|
import { Public, User } from '@hed-hog/api';
|
|
3
3
|
import { Locale } from '@hed-hog/api-locale';
|
|
4
|
-
import {
|
|
4
|
+
import { user_account_provider_52222e2ecb_enum } from '@hed-hog/api-prisma';
|
|
5
5
|
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
6
|
+
Body,
|
|
7
|
+
Controller,
|
|
8
|
+
Delete,
|
|
9
|
+
Get,
|
|
10
|
+
Headers,
|
|
11
|
+
Ip,
|
|
12
|
+
Param,
|
|
13
|
+
Query,
|
|
14
|
+
Res,
|
|
15
15
|
} from '@nestjs/common';
|
|
16
16
|
import { SettingService } from '../setting/setting.service';
|
|
17
17
|
import { OAuthService } from './oauth.service';
|
|
@@ -37,7 +37,7 @@ export class OAuthController {
|
|
|
37
37
|
@Get(':provider/login')
|
|
38
38
|
async login(@Param('provider') provider: string, @Res() res) {
|
|
39
39
|
const url = await this.service.getAuthUrl(
|
|
40
|
-
provider as
|
|
40
|
+
provider as user_account_provider_52222e2ecb_enum,
|
|
41
41
|
`/callback/${provider}/login`,
|
|
42
42
|
);
|
|
43
43
|
return res.redirect(url);
|
|
@@ -48,7 +48,7 @@ export class OAuthController {
|
|
|
48
48
|
@Get(':provider/register')
|
|
49
49
|
async register(@Param('provider') provider: string, @Res() res) {
|
|
50
50
|
const url = await this.service.getAuthUrl(
|
|
51
|
-
provider as
|
|
51
|
+
provider as user_account_provider_52222e2ecb_enum,
|
|
52
52
|
`/callback/${provider}/register`,
|
|
53
53
|
);
|
|
54
54
|
return res.redirect(url);
|
|
@@ -59,7 +59,7 @@ export class OAuthController {
|
|
|
59
59
|
@Get(':provider/connect')
|
|
60
60
|
async connect(@Param('provider') provider: string, @Res() res) {
|
|
61
61
|
const url = this.service.getAuthUrl(
|
|
62
|
-
provider as
|
|
62
|
+
provider as user_account_provider_52222e2ecb_enum,
|
|
63
63
|
`/callback/${provider}/connect`,
|
|
64
64
|
);
|
|
65
65
|
return res.redirect(url);
|
|
@@ -76,7 +76,7 @@ export class OAuthController {
|
|
|
76
76
|
@Query('code') code: string,
|
|
77
77
|
@Res({ passthrough: true }) res,
|
|
78
78
|
) {
|
|
79
|
-
return this.service.handleCallback({ res, locale, ipAddress, userAgent, provider: provider as
|
|
79
|
+
return this.service.handleCallback({ res, locale, ipAddress, userAgent, provider: provider as user_account_provider_52222e2ecb_enum, code, type: 'login' });
|
|
80
80
|
}
|
|
81
81
|
|
|
82
82
|
|
|
@@ -90,7 +90,7 @@ export class OAuthController {
|
|
|
90
90
|
@Query('code') code: string,
|
|
91
91
|
@Res({ passthrough: true }) res,
|
|
92
92
|
) {
|
|
93
|
-
return this.service.handleCallback({ res, locale, ipAddress, userAgent, provider: provider as
|
|
93
|
+
return this.service.handleCallback({ res, locale, ipAddress, userAgent, provider: provider as user_account_provider_52222e2ecb_enum, code, type: 'register' });
|
|
94
94
|
}
|
|
95
95
|
|
|
96
96
|
|
|
@@ -104,7 +104,7 @@ export class OAuthController {
|
|
|
104
104
|
@Query('code') code: string,
|
|
105
105
|
@Res({ passthrough: true }) res,
|
|
106
106
|
) {
|
|
107
|
-
return this.service.handleCallback({ res, locale, ipAddress, userAgent, provider: provider as
|
|
107
|
+
return this.service.handleCallback({ res, locale, ipAddress, userAgent, provider: provider as user_account_provider_52222e2ecb_enum, code, type: 'connect', userId: id });
|
|
108
108
|
}
|
|
109
109
|
|
|
110
110
|
|
|
@@ -117,6 +117,6 @@ export class OAuthController {
|
|
|
117
117
|
@Body('email') email: string,
|
|
118
118
|
@Res({ passthrough: true }) res,
|
|
119
119
|
) {
|
|
120
|
-
return this.service.handleCallback({ res, locale, ipAddress, userAgent, provider: provider as
|
|
120
|
+
return this.service.handleCallback({ res, locale, ipAddress, userAgent, provider: provider as user_account_provider_52222e2ecb_enum, email, type: 'disconnect' });
|
|
121
121
|
}
|
|
122
122
|
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { PrismaService,
|
|
1
|
+
import { PrismaService, user_account_provider_52222e2ecb_enum } from '@hed-hog/api-prisma';
|
|
2
2
|
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
3
|
+
BadRequestException,
|
|
4
|
+
ConflictException,
|
|
5
|
+
Inject,
|
|
6
|
+
Injectable,
|
|
7
|
+
NotFoundException,
|
|
8
|
+
forwardRef
|
|
9
9
|
} from '@nestjs/common';
|
|
10
10
|
import { AuthService } from '../auth/auth.service';
|
|
11
11
|
import { FileService } from '../file/file.service';
|
|
@@ -26,7 +26,7 @@ type HandleCallbackProps = {
|
|
|
26
26
|
ipAddress: string;
|
|
27
27
|
userAgent: string;
|
|
28
28
|
res: Response;
|
|
29
|
-
provider:
|
|
29
|
+
provider: user_account_provider_52222e2ecb_enum;
|
|
30
30
|
code?: string;
|
|
31
31
|
type: 'login' | 'register' | 'connect' | 'disconnect';
|
|
32
32
|
userId?: number;
|
|
@@ -61,7 +61,7 @@ export class OAuthService {
|
|
|
61
61
|
this.providers.set(microsoftEntraId.getProviderType(), microsoftEntraId);
|
|
62
62
|
}
|
|
63
63
|
|
|
64
|
-
getAuthUrl(provider:
|
|
64
|
+
getAuthUrl(provider: user_account_provider_52222e2ecb_enum, callbackPath: string) {
|
|
65
65
|
return this.getProvider(provider).getAuthUrl(callbackPath);
|
|
66
66
|
}
|
|
67
67
|
|
|
@@ -96,14 +96,14 @@ export class OAuthService {
|
|
|
96
96
|
}
|
|
97
97
|
}
|
|
98
98
|
|
|
99
|
-
private getProvider(provider:
|
|
99
|
+
private getProvider(provider: user_account_provider_52222e2ecb_enum) {
|
|
100
100
|
const prov = this.providers.get(String(provider).toUpperCase());
|
|
101
101
|
if (!prov)
|
|
102
102
|
throw new BadRequestException(`Provider ${provider} não suportado`);
|
|
103
103
|
return prov;
|
|
104
104
|
}
|
|
105
105
|
|
|
106
|
-
private async getProviderScopes(provider:
|
|
106
|
+
private async getProviderScopes(provider: user_account_provider_52222e2ecb_enum) {
|
|
107
107
|
const settingKey = `${String(provider).toLowerCase().replace(/-/g, '_')}_scopes`;
|
|
108
108
|
|
|
109
109
|
const settings = await this.setting.getSettingValues([
|
|
@@ -118,13 +118,13 @@ export class OAuthService {
|
|
|
118
118
|
return settings[settingKey].join(',') || '';
|
|
119
119
|
}
|
|
120
120
|
|
|
121
|
-
private async handleLogin(res: Response, locale: string, ipAddress: string, userAgent: string, provider:
|
|
121
|
+
private async handleLogin(res: Response, locale: string, ipAddress: string, userAgent: string, provider: user_account_provider_52222e2ecb_enum, profile: any) {
|
|
122
122
|
|
|
123
123
|
console.log('[OAuthService] Handling login for provider:', provider);
|
|
124
124
|
|
|
125
125
|
const userAccount = await this.prisma.user_account.findFirst({
|
|
126
126
|
where: {
|
|
127
|
-
provider: String(provider).toLowerCase().replace(/-/g, '_') as
|
|
127
|
+
provider: String(provider).toLowerCase().replace(/-/g, '_') as user_account_provider_52222e2ecb_enum,
|
|
128
128
|
email: profile.email,
|
|
129
129
|
},
|
|
130
130
|
include: {
|
|
@@ -177,7 +177,7 @@ export class OAuthService {
|
|
|
177
177
|
}
|
|
178
178
|
}
|
|
179
179
|
|
|
180
|
-
private async handleRegister(res: Response, locale: string, ipAddress: string, userAgent: string, provider:
|
|
180
|
+
private async handleRegister(res: Response, locale: string, ipAddress: string, userAgent: string, provider: user_account_provider_52222e2ecb_enum, profile: any) {
|
|
181
181
|
const existingUser = await this.prisma.user_identifier.findFirst({
|
|
182
182
|
where: {
|
|
183
183
|
type: 'email',
|
|
@@ -223,7 +223,7 @@ export class OAuthService {
|
|
|
223
223
|
},
|
|
224
224
|
user_account: {
|
|
225
225
|
create: {
|
|
226
|
-
provider: String(provider).toLowerCase().replace(/-/g, '_') as
|
|
226
|
+
provider: String(provider).toLowerCase().replace(/-/g, '_') as user_account_provider_52222e2ecb_enum,
|
|
227
227
|
provider_user_id: profile.id,
|
|
228
228
|
email: profile.email,
|
|
229
229
|
refresh_token: encryptedRefreshToken ? Buffer.from(encryptedRefreshToken) : null,
|
|
@@ -272,14 +272,14 @@ export class OAuthService {
|
|
|
272
272
|
locale: string,
|
|
273
273
|
ipAddress: string,
|
|
274
274
|
userAgent: string,
|
|
275
|
-
provider:
|
|
275
|
+
provider: user_account_provider_52222e2ecb_enum,
|
|
276
276
|
profile: any,
|
|
277
277
|
userId: number,
|
|
278
278
|
) {
|
|
279
279
|
const existingAccount = await this.prisma.user_account.findFirst({
|
|
280
280
|
where: {
|
|
281
281
|
user_id: userId,
|
|
282
|
-
provider: String(provider).toLowerCase().replace(/-/g, '_') as
|
|
282
|
+
provider: String(provider).toLowerCase().replace(/-/g, '_') as user_account_provider_52222e2ecb_enum,
|
|
283
283
|
},
|
|
284
284
|
});
|
|
285
285
|
|
|
@@ -292,7 +292,7 @@ export class OAuthService {
|
|
|
292
292
|
await this.prisma.user_account.create({
|
|
293
293
|
data: {
|
|
294
294
|
user_id: userId,
|
|
295
|
-
provider: String(provider).toLowerCase().replace(/-/g, '_') as
|
|
295
|
+
provider: String(provider).toLowerCase().replace(/-/g, '_') as user_account_provider_52222e2ecb_enum,
|
|
296
296
|
provider_user_id: profile.id,
|
|
297
297
|
email: profile.email,
|
|
298
298
|
refresh_token: Buffer.from(encryptedRefreshToken),
|
|
@@ -334,11 +334,11 @@ export class OAuthService {
|
|
|
334
334
|
return { accessToken };
|
|
335
335
|
}
|
|
336
336
|
|
|
337
|
-
private async handleDisconnect(res: Response, locale: string, ipAddress: string, userAgent: string, provider:
|
|
337
|
+
private async handleDisconnect(res: Response, locale: string, ipAddress: string, userAgent: string, provider: user_account_provider_52222e2ecb_enum, email: string) {
|
|
338
338
|
const userAccount = await this.prisma.user_account.findFirst({
|
|
339
339
|
where: {
|
|
340
340
|
email,
|
|
341
|
-
provider: String(provider).toLowerCase().replace(/-/g, '_') as
|
|
341
|
+
provider: String(provider).toLowerCase().replace(/-/g, '_') as user_account_provider_52222e2ecb_enum,
|
|
342
342
|
},
|
|
343
343
|
include: { user: true }
|
|
344
344
|
});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { itemTranslations } from '@hed-hog/api';
|
|
2
2
|
import { getLocaleText, LocaleService } from '@hed-hog/api-locale';
|
|
3
3
|
import { PaginationDTO, PaginationService } from '@hed-hog/api-pagination';
|
|
4
|
-
import { PrismaService,
|
|
4
|
+
import { PrismaService, setting_type_0f055cd5ea_enum } from '@hed-hog/api-prisma';
|
|
5
5
|
import {
|
|
6
6
|
BadRequestException,
|
|
7
7
|
forwardRef,
|
|
@@ -36,7 +36,7 @@ export class SettingService {
|
|
|
36
36
|
where: {
|
|
37
37
|
...( !includeSecrets ? {
|
|
38
38
|
NOT: [
|
|
39
|
-
{ type:
|
|
39
|
+
{ type: setting_type_0f055cd5ea_enum.secret },
|
|
40
40
|
],
|
|
41
41
|
} : {}),
|
|
42
42
|
},
|
|
@@ -294,6 +294,21 @@ export class SettingService {
|
|
|
294
294
|
},
|
|
295
295
|
},
|
|
296
296
|
},
|
|
297
|
+
setting_subgroup: {
|
|
298
|
+
include: {
|
|
299
|
+
setting_subgroup_locale: {
|
|
300
|
+
where: {
|
|
301
|
+
locale: {
|
|
302
|
+
code: locale,
|
|
303
|
+
},
|
|
304
|
+
},
|
|
305
|
+
select: {
|
|
306
|
+
name: true,
|
|
307
|
+
description: true,
|
|
308
|
+
},
|
|
309
|
+
},
|
|
310
|
+
},
|
|
311
|
+
},
|
|
297
312
|
setting_locale: {
|
|
298
313
|
where: {
|
|
299
314
|
locale: {
|
|
@@ -334,6 +349,16 @@ export class SettingService {
|
|
|
334
349
|
'setting_group_locale',
|
|
335
350
|
setting.setting_group,
|
|
336
351
|
);
|
|
352
|
+
|
|
353
|
+
if (setting.setting_subgroup) {
|
|
354
|
+
setting.setting_subgroup = itemTranslations(
|
|
355
|
+
'setting_subgroup_locale',
|
|
356
|
+
setting.setting_subgroup,
|
|
357
|
+
);
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
setting.subgroupId ??= setting.subgroup_id ?? setting.setting_subgroup?.id ?? null;
|
|
361
|
+
|
|
337
362
|
return setting;
|
|
338
363
|
});
|
|
339
364
|
|
package/src/task/task.service.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { Prisma, PrismaService } from '@hed-hog/api-prisma';
|
|
2
|
-
import { Injectable, Logger } from '@nestjs/common';
|
|
3
|
-
import { Cron, CronExpression } from '@nestjs/schedule';
|
|
4
|
-
import { SettingService } from '../setting/setting.service';
|
|
1
|
+
import { Prisma, PrismaService } from '@hed-hog/api-prisma';
|
|
2
|
+
import { Injectable, Logger } from '@nestjs/common';
|
|
3
|
+
import { Cron, CronExpression } from '@nestjs/schedule';
|
|
4
|
+
import { SettingService } from '../setting/setting.service';
|
|
5
5
|
|
|
6
6
|
@Injectable()
|
|
7
7
|
export class TasksService {
|
|
@@ -225,4 +225,4 @@ export class TasksService {
|
|
|
225
225
|
`Unverified MFA with expired challenges cleaned up in ${Date.now() - startAt}ms`,
|
|
226
226
|
);
|
|
227
227
|
}
|
|
228
|
-
}
|
|
228
|
+
}
|