@solidxai/core 0.1.21 → 0.1.22-beta.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/CHANGELOG.md +24 -0
- package/dist/controllers/chatter-message.controller.d.ts +4 -0
- package/dist/controllers/chatter-message.controller.d.ts.map +1 -1
- package/dist/controllers/chatter-message.controller.js +13 -0
- package/dist/controllers/chatter-message.controller.js.map +1 -1
- package/dist/decorators/settings-provider.decorator.d.ts +2 -1
- package/dist/decorators/settings-provider.decorator.d.ts.map +1 -1
- package/dist/decorators/settings-provider.decorator.js +3 -2
- package/dist/decorators/settings-provider.decorator.js.map +1 -1
- package/dist/dtos/create-agent-user-memory.dto.d.ts +1 -1
- package/dist/dtos/create-agent-user-memory.dto.d.ts.map +1 -1
- package/dist/dtos/create-agent-user-memory.dto.js +2 -2
- package/dist/dtos/create-agent-user-memory.dto.js.map +1 -1
- package/dist/dtos/import-chatter-from-odoo.dto.d.ts +12 -0
- package/dist/dtos/import-chatter-from-odoo.dto.d.ts.map +1 -0
- package/dist/dtos/import-chatter-from-odoo.dto.js +66 -0
- package/dist/dtos/import-chatter-from-odoo.dto.js.map +1 -0
- package/dist/dtos/update-agent-user-memory.dto.d.ts +1 -1
- package/dist/dtos/update-agent-user-memory.dto.d.ts.map +1 -1
- package/dist/dtos/update-agent-user-memory.dto.js +2 -2
- package/dist/dtos/update-agent-user-memory.dto.js.map +1 -1
- package/dist/entities/agent-user-memory.entity.d.ts +1 -1
- package/dist/entities/agent-user-memory.entity.d.ts.map +1 -1
- package/dist/entities/agent-user-memory.entity.js +2 -2
- package/dist/entities/agent-user-memory.entity.js.map +1 -1
- package/dist/entities/chatter-message.entity.d.ts +1 -0
- package/dist/entities/chatter-message.entity.d.ts.map +1 -1
- package/dist/entities/chatter-message.entity.js +6 -1
- package/dist/entities/chatter-message.entity.js.map +1 -1
- package/dist/helpers/setting-key.helper.d.ts +6 -0
- package/dist/helpers/setting-key.helper.d.ts.map +1 -0
- package/dist/helpers/setting-key.helper.js +28 -0
- package/dist/helpers/setting-key.helper.js.map +1 -0
- package/dist/helpers/setting-key.helper.spec.d.ts +2 -0
- package/dist/helpers/setting-key.helper.spec.d.ts.map +1 -0
- package/dist/helpers/setting-key.helper.spec.js +37 -0
- package/dist/helpers/setting-key.helper.spec.js.map +1 -0
- package/dist/interfaces.d.ts +4 -1
- package/dist/interfaces.d.ts.map +1 -1
- package/dist/interfaces.js.map +1 -1
- package/dist/jobs/rabbitmq/odoo-chatter-import-queue-options.d.ts +18 -0
- package/dist/jobs/rabbitmq/odoo-chatter-import-queue-options.d.ts.map +1 -0
- package/dist/jobs/rabbitmq/odoo-chatter-import-queue-options.js +11 -0
- package/dist/jobs/rabbitmq/odoo-chatter-import-queue-options.js.map +1 -0
- package/dist/jobs/rabbitmq/odoo-chatter-import-queue-publisher.service.d.ts +12 -0
- package/dist/jobs/rabbitmq/odoo-chatter-import-queue-publisher.service.d.ts.map +1 -0
- package/dist/jobs/rabbitmq/odoo-chatter-import-queue-publisher.service.js +39 -0
- package/dist/jobs/rabbitmq/odoo-chatter-import-queue-publisher.service.js.map +1 -0
- package/dist/jobs/rabbitmq/odoo-chatter-import-queue-subscriber.service.d.ts +22 -0
- package/dist/jobs/rabbitmq/odoo-chatter-import-queue-subscriber.service.d.ts.map +1 -0
- package/dist/jobs/rabbitmq/odoo-chatter-import-queue-subscriber.service.js +51 -0
- package/dist/jobs/rabbitmq/odoo-chatter-import-queue-subscriber.service.js.map +1 -0
- package/dist/resources/agent-embed/solid-agent-embed.js +42 -19
- package/dist/seeders/module-metadata-seeder.service.d.ts.map +1 -1
- package/dist/seeders/module-metadata-seeder.service.js +13 -1
- package/dist/seeders/module-metadata-seeder.service.js.map +1 -1
- package/dist/seeders/seed-data/solid-core-metadata.json +2 -180
- package/dist/services/agent-tool-registry.service.js +5 -5
- package/dist/services/agent-tool-registry.service.js.map +1 -1
- package/dist/services/chatter-message.service.d.ts +44 -1
- package/dist/services/chatter-message.service.d.ts.map +1 -1
- package/dist/services/chatter-message.service.js +240 -2
- package/dist/services/chatter-message.service.js.map +1 -1
- package/dist/services/mail/smtp-email.service.d.ts.map +1 -1
- package/dist/services/mail/smtp-email.service.js +2 -6
- package/dist/services/mail/smtp-email.service.js.map +1 -1
- package/dist/services/mediaStorageProviders/file-s3-storage-provider.d.ts +4 -1
- package/dist/services/mediaStorageProviders/file-s3-storage-provider.d.ts.map +1 -1
- package/dist/services/mediaStorageProviders/file-s3-storage-provider.js +4 -2
- package/dist/services/mediaStorageProviders/file-s3-storage-provider.js.map +1 -1
- package/dist/services/mediaStorageProviders/file-storage-provider.d.ts +4 -1
- package/dist/services/mediaStorageProviders/file-storage-provider.d.ts.map +1 -1
- package/dist/services/mediaStorageProviders/file-storage-provider.js +3 -0
- package/dist/services/mediaStorageProviders/file-storage-provider.js.map +1 -1
- package/dist/services/model-metadata.service.d.ts.map +1 -1
- package/dist/services/model-metadata.service.js +4 -2
- package/dist/services/model-metadata.service.js.map +1 -1
- package/dist/services/setting.service.d.ts +1 -1
- package/dist/services/setting.service.d.ts.map +1 -1
- package/dist/services/setting.service.js +25 -8
- package/dist/services/setting.service.js.map +1 -1
- package/dist/services/setting.service.spec.d.ts +2 -0
- package/dist/services/setting.service.spec.d.ts.map +1 -0
- package/dist/services/setting.service.spec.js +110 -0
- package/dist/services/setting.service.spec.js.map +1 -0
- package/dist/services/settings/default-settings-provider.service.d.ts +146 -6
- package/dist/services/settings/default-settings-provider.service.d.ts.map +1 -1
- package/dist/services/settings/default-settings-provider.service.js +81 -4
- package/dist/services/settings/default-settings-provider.service.js.map +1 -1
- package/dist/solid-core.module.d.ts.map +1 -1
- package/dist/solid-core.module.js +4 -0
- package/dist/solid-core.module.js.map +1 -1
- package/dist/subscribers/agent-tool-registry.subscriber.d.ts.map +1 -1
- package/dist/subscribers/agent-tool-registry.subscriber.js +16 -11
- package/dist/subscribers/agent-tool-registry.subscriber.js.map +1 -1
- package/package.json +1 -1
- package/plan.md +480 -0
- package/resources/agent-embed/solid-agent-embed.js +42 -19
- package/src/controllers/chatter-message.controller.ts +7 -0
- package/src/decorators/settings-provider.decorator.ts +6 -3
- package/src/dtos/create-agent-user-memory.dto.ts +1 -1
- package/src/dtos/import-chatter-from-odoo.dto.ts +47 -0
- package/src/dtos/update-agent-user-memory.dto.ts +1 -1
- package/src/entities/agent-user-memory.entity.ts +2 -2
- package/src/entities/chatter-message.entity.ts +12 -0
- package/src/helpers/setting-key.helper.spec.ts +32 -0
- package/src/helpers/setting-key.helper.ts +30 -0
- package/src/interfaces.ts +1 -1
- package/src/jobs/rabbitmq/odoo-chatter-import-queue-options.ts +24 -0
- package/src/jobs/rabbitmq/odoo-chatter-import-queue-publisher.service.ts +23 -0
- package/src/jobs/rabbitmq/odoo-chatter-import-queue-subscriber.service.ts +38 -0
- package/src/seeders/module-metadata-seeder.service.ts +12 -1
- package/src/seeders/seed-data/solid-core-metadata.json +2 -180
- package/src/services/agent-tool-registry.service.ts +5 -5
- package/src/services/chatter-message.service.ts +408 -0
- package/src/services/mail/smtp-email.service.ts +3 -6
- package/src/services/mediaStorageProviders/file-s3-storage-provider.ts +5 -3
- package/src/services/mediaStorageProviders/file-storage-provider.ts +4 -1
- package/src/services/model-metadata.service.ts +5 -2
- package/src/services/setting.service.spec.ts +117 -0
- package/src/services/setting.service.ts +29 -9
- package/src/services/settings/default-settings-provider.service.ts +81 -4
- package/src/solid-core.module.ts +4 -0
- package/src/subscribers/agent-tool-registry.subscriber.ts +16 -9
- package/src/services/1.js +0 -6
|
@@ -3,6 +3,10 @@ import { BadRequestException, ForbiddenException, forwardRef, Inject, Injectable
|
|
|
3
3
|
import { ModuleRef } from "@nestjs/core";
|
|
4
4
|
import { InjectEntityManager } from '@nestjs/typeorm';
|
|
5
5
|
import { Brackets, EntityManager, EntityMetadata, In } from 'typeorm';
|
|
6
|
+
import { HttpService } from '@nestjs/axios';
|
|
7
|
+
import { ClsService } from 'nestjs-cls';
|
|
8
|
+
import { Readable } from 'stream';
|
|
9
|
+
import { v4 as uuidv4 } from 'uuid';
|
|
6
10
|
|
|
7
11
|
import { classify } from '@angular-devkit/core/src/utils/strings';
|
|
8
12
|
import { CHATTER_MESSAGE_STATUS, CHATTER_MESSAGE_SUBTYPE, CHATTER_MESSAGE_TYPE, CHATTER_MESSAGE_USER_FIELDS } from 'src/constants/chatter-message.constants';
|
|
@@ -11,9 +15,12 @@ import { ERROR_MESSAGES } from 'src/constants/error-messages';
|
|
|
11
15
|
import { MediaFieldCrudManager, SolidMediaType } from 'src/helpers/field-crud-managers/MediaFieldCrudManager';
|
|
12
16
|
import { PostChatterMessageDto } from 'src/dtos/post-chatter-message.dto';
|
|
13
17
|
import { UpdateChatterNoteMessageDto } from 'src/dtos/update-chatter-note-message.dto';
|
|
18
|
+
import { ImportChatterFromOdooDto } from 'src/dtos/import-chatter-from-odoo.dto';
|
|
14
19
|
import { ModelMetadataHelperService } from 'src/helpers/model-metadata-helper.service';
|
|
15
20
|
import { lowerFirst } from 'src/helpers/string.helper';
|
|
21
|
+
import { sanitizeStoredMediaFileName } from 'src/services/media-storage.utils';
|
|
16
22
|
import { ChatterMentionNotificationPayload } from 'src/interfaces/chatter-mention-notification.interface';
|
|
23
|
+
import { OdooChatterImportQueuePayload } from 'src/jobs/rabbitmq/odoo-chatter-import-queue-options';
|
|
17
24
|
import { ChatterMessageDetailsRepository } from 'src/repository/chatter-message-details.repository';
|
|
18
25
|
import { ChatterMessageRepository } from 'src/repository/chatter-message.repository';
|
|
19
26
|
import { FieldMetadataRepository } from 'src/repository/field-metadata.repository';
|
|
@@ -31,6 +38,23 @@ import { Logger } from '@nestjs/common';
|
|
|
31
38
|
import { SolidIntrospectService } from './solid-introspect.service';
|
|
32
39
|
import { PublisherFactory } from './queues/publisher-factory.service';
|
|
33
40
|
|
|
41
|
+
/** Shape of a Odoo `mail.message` row, as returned by `search_read` - see ODOO_CHATTER_IMPORT_PLAN.md */
|
|
42
|
+
interface OdooMessage {
|
|
43
|
+
id: number;
|
|
44
|
+
res_id: number;
|
|
45
|
+
date: string;
|
|
46
|
+
author_id?: [number, string];
|
|
47
|
+
body?: string;
|
|
48
|
+
tracking_value_ids?: number[];
|
|
49
|
+
attachment_ids?: number[];
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
interface OdooAttachmentStream {
|
|
53
|
+
stream: Readable;
|
|
54
|
+
mimeType: string;
|
|
55
|
+
originalFileName: string;
|
|
56
|
+
}
|
|
57
|
+
|
|
34
58
|
interface ChatterMention {
|
|
35
59
|
username: string;
|
|
36
60
|
display_name?: string;
|
|
@@ -71,6 +95,8 @@ export class ChatterMessageService extends CRUDService<ChatterMessage> {
|
|
|
71
95
|
readonly requestContextService: RequestContextService,
|
|
72
96
|
private readonly modelMetadataHelperService: ModelMetadataHelperService,
|
|
73
97
|
private readonly publisherFactory: PublisherFactory<ChatterMentionNotificationPayload>,
|
|
98
|
+
private readonly httpService: HttpService,
|
|
99
|
+
private readonly clsService: ClsService,
|
|
74
100
|
) {
|
|
75
101
|
super(entityManager, repo, 'chatterMessage', 'solid-core', moduleRef);
|
|
76
102
|
}
|
|
@@ -505,6 +531,388 @@ export class ChatterMessageService extends CRUDService<ChatterMessage> {
|
|
|
505
531
|
return savedMessage;
|
|
506
532
|
}
|
|
507
533
|
|
|
534
|
+
// ---------------------------------------------------------------------------------------
|
|
535
|
+
// Import chatter history from Odoo - see ODOO_CHATTER_IMPORT_PLAN.md for the full design.
|
|
536
|
+
// ---------------------------------------------------------------------------------------
|
|
537
|
+
|
|
538
|
+
private odooRpcUrl(baseUrl: string, path: string): string {
|
|
539
|
+
return `${baseUrl.replace(/\/+$/, '')}${path}`;
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
/**
|
|
543
|
+
* Logs into Odoo once and returns the `session_id` cookie. The password is used here,
|
|
544
|
+
* synchronously, and never travels any further - only this cookie goes into the queue
|
|
545
|
+
* payload, so a leaked queue message exposes a revocable 7-day session, not the admin
|
|
546
|
+
* password itself.
|
|
547
|
+
*/
|
|
548
|
+
private async odooAuthenticate(baseUrl: string, db: string, login: string, password: string): Promise<string> {
|
|
549
|
+
const response = await this.httpService.axiosRef.post(
|
|
550
|
+
this.odooRpcUrl(baseUrl, '/web/session/authenticate'),
|
|
551
|
+
{ jsonrpc: '2.0', method: 'call', params: { db, login, password } },
|
|
552
|
+
{ headers: { 'Content-Type': 'application/json' } },
|
|
553
|
+
);
|
|
554
|
+
|
|
555
|
+
if (response.data?.error) {
|
|
556
|
+
throw new BadRequestException(`Odoo authentication failed: ${response.data.error.data?.message || response.data.error.message}`);
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
const setCookieHeaders: string[] = response.headers?.['set-cookie'] ?? [];
|
|
560
|
+
const sessionCookie = setCookieHeaders
|
|
561
|
+
.map(cookie => cookie.split(';')[0])
|
|
562
|
+
.find(cookie => cookie.startsWith('session_id='));
|
|
563
|
+
|
|
564
|
+
if (!sessionCookie) {
|
|
565
|
+
throw new BadRequestException('Odoo authentication succeeded but returned no session cookie');
|
|
566
|
+
}
|
|
567
|
+
|
|
568
|
+
return sessionCookie;
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
/** Generic Odoo JSON-RPC read, e.g. `odooCallKw(base, cookie, 'mail.message', 'search_read', [domain, fields], { limit, order })`. */
|
|
572
|
+
private async odooCallKw<T = any>(
|
|
573
|
+
baseUrl: string,
|
|
574
|
+
sessionCookie: string,
|
|
575
|
+
model: string,
|
|
576
|
+
method: string,
|
|
577
|
+
args: any[],
|
|
578
|
+
kwargs: Record<string, any> = {},
|
|
579
|
+
): Promise<T> {
|
|
580
|
+
const response = await this.httpService.axiosRef.post(
|
|
581
|
+
this.odooRpcUrl(baseUrl, '/web/dataset/call_kw'),
|
|
582
|
+
{ jsonrpc: '2.0', method: 'call', params: { model, method, args, kwargs } },
|
|
583
|
+
{ headers: { 'Content-Type': 'application/json', Cookie: sessionCookie } },
|
|
584
|
+
);
|
|
585
|
+
|
|
586
|
+
if (response.data?.error) {
|
|
587
|
+
throw new BadRequestException(`Odoo ${model}.${method} failed: ${response.data.error.data?.message || response.data.error.message}`);
|
|
588
|
+
}
|
|
589
|
+
|
|
590
|
+
return response.data.result;
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
/** Downloads one Odoo attachment via the standard `/web/content/{id}?download=true` convention. */
|
|
594
|
+
private async odooFetchAttachment(baseUrl: string, sessionCookie: string, attachmentId: number): Promise<OdooAttachmentStream> {
|
|
595
|
+
const response = await this.httpService.axiosRef.get(
|
|
596
|
+
this.odooRpcUrl(baseUrl, `/web/content/${attachmentId}?download=true`),
|
|
597
|
+
{ headers: { Cookie: sessionCookie }, responseType: 'stream' },
|
|
598
|
+
);
|
|
599
|
+
|
|
600
|
+
const disposition: string = response.headers?.['content-disposition'] ?? '';
|
|
601
|
+
const fileNameMatch = disposition.match(/filename="?([^";]+)"?/i);
|
|
602
|
+
|
|
603
|
+
return {
|
|
604
|
+
stream: response.data,
|
|
605
|
+
mimeType: response.headers?.['content-type'] || 'application/octet-stream',
|
|
606
|
+
originalFileName: fileNameMatch?.[1] || `odoo-attachment-${attachmentId}`,
|
|
607
|
+
};
|
|
608
|
+
}
|
|
609
|
+
|
|
610
|
+
/**
|
|
611
|
+
* Odoo's `mail.tracking.value.field_id` display name is always suffixed with the owning
|
|
612
|
+
* model's display name, e.g. "Designation (Employees)" - strip that trailing "(...)" since
|
|
613
|
+
* it's redundant noise in a table that's already scoped to one record.
|
|
614
|
+
*/
|
|
615
|
+
private stripOdooModelSuffix(label: string): string {
|
|
616
|
+
return (label || '').replace(/\s*\([^)]*\)\s*$/, '').trim() || label;
|
|
617
|
+
}
|
|
618
|
+
|
|
619
|
+
private escapeHtml(value: any): string {
|
|
620
|
+
if (value === null || value === undefined || value === false || value === '') {
|
|
621
|
+
return '—';
|
|
622
|
+
}
|
|
623
|
+
return String(value).replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>');
|
|
624
|
+
}
|
|
625
|
+
|
|
626
|
+
/** Minimal safety pass over Odoo's own message HTML - strips script tags / inline event handlers, keeps everything else (links, styling) intact. */
|
|
627
|
+
private sanitizeOdooBodyHtml(html: string): string {
|
|
628
|
+
if (!html) {
|
|
629
|
+
return '';
|
|
630
|
+
}
|
|
631
|
+
return html
|
|
632
|
+
.replace(/<script[^>]*>[\s\S]*?<\/script>/gi, '')
|
|
633
|
+
.replace(/\son\w+\s*=\s*"[^"]*"/gi, '')
|
|
634
|
+
.replace(/\son\w+\s*=\s*'[^']*'/gi, '');
|
|
635
|
+
}
|
|
636
|
+
|
|
637
|
+
/** One of `old_value_char|integer|float|text|datetime` is populated on a `mail.tracking.value`, depending on the field's type. */
|
|
638
|
+
private extractOdooTrackingValue(trackingValue: any, prefix: 'old' | 'new'): any {
|
|
639
|
+
for (const key of ['char', 'integer', 'float', 'text', 'datetime']) {
|
|
640
|
+
const value = trackingValue[`${prefix}_value_${key}`];
|
|
641
|
+
if (value !== false && value !== null && value !== undefined && value !== '') {
|
|
642
|
+
return value;
|
|
643
|
+
}
|
|
644
|
+
}
|
|
645
|
+
return null;
|
|
646
|
+
}
|
|
647
|
+
|
|
648
|
+
private formatOdooDate(odooDate: string): Date {
|
|
649
|
+
// Odoo returns naive UTC timestamps as "YYYY-MM-DD HH:mm:ss".
|
|
650
|
+
return new Date(`${odooDate.replace(' ', 'T')}Z`);
|
|
651
|
+
}
|
|
652
|
+
|
|
653
|
+
private buildOdooMessageHtml(message: OdooMessage, trackingValues: any[]): string {
|
|
654
|
+
const hasTracking = trackingValues && trackingValues.length > 0;
|
|
655
|
+
const authorName = this.escapeHtml(message.author_id?.[1] || 'Unknown Odoo user');
|
|
656
|
+
const when = message.date ? this.formatOdooDate(message.date).toLocaleString() : '';
|
|
657
|
+
|
|
658
|
+
const parts: string[] = ['<div class="odoo-import-log">'];
|
|
659
|
+
parts.push(
|
|
660
|
+
`<div class="odoo-import-log__meta"><strong>Imported from Odoo</strong> — ` +
|
|
661
|
+
`${hasTracking ? 'Changed' : 'Posted'} by <strong>${authorName}</strong>` +
|
|
662
|
+
`${when ? ` on <strong>${this.escapeHtml(when)}</strong>` : ''}</div>`,
|
|
663
|
+
);
|
|
664
|
+
|
|
665
|
+
if (hasTracking) {
|
|
666
|
+
const rows = trackingValues.map(trackingValue => {
|
|
667
|
+
const label = this.escapeHtml(this.stripOdooModelSuffix(trackingValue.field_id?.[1] || trackingValue.display_name || 'Field'));
|
|
668
|
+
const oldValue = this.escapeHtml(this.extractOdooTrackingValue(trackingValue, 'old'));
|
|
669
|
+
const newValue = this.escapeHtml(this.extractOdooTrackingValue(trackingValue, 'new'));
|
|
670
|
+
return `<tr><td>${label}</td><td>${oldValue}</td><td>${newValue}</td></tr>`;
|
|
671
|
+
}).join('');
|
|
672
|
+
parts.push(
|
|
673
|
+
`<table class="odoo-import-log__table" border="1" cellpadding="4" cellspacing="0">` +
|
|
674
|
+
`<thead><tr><th>Field</th><th>Previous Value</th><th>Changed Value</th></tr></thead>` +
|
|
675
|
+
`<tbody>${rows}</tbody></table>`,
|
|
676
|
+
);
|
|
677
|
+
}
|
|
678
|
+
|
|
679
|
+
if (message.body && message.body.trim()) {
|
|
680
|
+
parts.push(`<div class="odoo-import-log__note">${this.sanitizeOdooBodyHtml(message.body)}</div>`);
|
|
681
|
+
}
|
|
682
|
+
|
|
683
|
+
parts.push('</div>');
|
|
684
|
+
return parts.join('');
|
|
685
|
+
}
|
|
686
|
+
|
|
687
|
+
/**
|
|
688
|
+
* Fixed system user id attributed as `createdBy`/`updatedBy` on every imported message
|
|
689
|
+
* (the real Odoo author is rendered as text inside the HTML instead - see buildOdooMessageHtml -
|
|
690
|
+
* since that Odoo user will usually not exist as a SolidX `User`). Override via
|
|
691
|
+
* ODOO_IMPORT_SYSTEM_USER_ID if user id 1 isn't the right system/admin account to attribute to.
|
|
692
|
+
*/
|
|
693
|
+
private getOdooImportSystemUserId(): number {
|
|
694
|
+
const envUserId = Number(process.env.ODOO_IMPORT_SYSTEM_USER_ID);
|
|
695
|
+
return Number.isInteger(envUserId) && envUserId > 0 ? envUserId : 1;
|
|
696
|
+
}
|
|
697
|
+
|
|
698
|
+
/**
|
|
699
|
+
* `POST /chatter-message/importFromOdoo` - authenticates against Odoo once (synchronously,
|
|
700
|
+
* so the password never travels through the queue), then hands off the actual import to a
|
|
701
|
+
* RabbitMQ job so the HTTP caller isn't blocked on it.
|
|
702
|
+
*/
|
|
703
|
+
async importFromOdoo(dto: ImportChatterFromOdooDto) {
|
|
704
|
+
const odooSessionCookie = await this.odooAuthenticate(dto.odooBaseUrl, dto.odooDb, dto.odooLogin, dto.odooPassword);
|
|
705
|
+
|
|
706
|
+
const payload: OdooChatterImportQueuePayload = {
|
|
707
|
+
odooModelName: dto.odooModelName,
|
|
708
|
+
odooBaseUrl: dto.odooBaseUrl,
|
|
709
|
+
odooSessionCookie,
|
|
710
|
+
solidxModelName: lowerFirst(dto.solidxModelName),
|
|
711
|
+
odooId: dto.odooId,
|
|
712
|
+
fromDate: dto.fromDate,
|
|
713
|
+
batchSize: dto.batchSize ?? 100,
|
|
714
|
+
};
|
|
715
|
+
|
|
716
|
+
// `publisherFactory` is injected as `PublisherFactory<ChatterMentionNotificationPayload>`
|
|
717
|
+
// above, but NestJS resolves it by class token regardless of the generic parameter (TS
|
|
718
|
+
// generics don't exist at runtime) - it's the same singleton either way, so this cast is
|
|
719
|
+
// safe rather than adding a second constructor dependency for the same provider.
|
|
720
|
+
await this.publisherFactory.publish({ payload } as any, 'OdooChatterImportQueuePublisher');
|
|
721
|
+
|
|
722
|
+
return { message: 'Odoo chatter import started' };
|
|
723
|
+
}
|
|
724
|
+
|
|
725
|
+
/**
|
|
726
|
+
* Fetches one page of SolidX `coModelName` records to import chatter for - either the single
|
|
727
|
+
* record matching `odooId` (throws if it doesn't exist - an explicit single-record request
|
|
728
|
+
* should fail loudly) or a page of every record with a non-null `odooId`.
|
|
729
|
+
*/
|
|
730
|
+
private async fetchSolidxRecordsToImport(
|
|
731
|
+
coModelName: string,
|
|
732
|
+
odooId: number | undefined,
|
|
733
|
+
offset: number,
|
|
734
|
+
limit: number,
|
|
735
|
+
): Promise<{ id: number; odooId: number }[]> {
|
|
736
|
+
const coModelService = this.getCoModelService(coModelName);
|
|
737
|
+
|
|
738
|
+
if (odooId !== undefined && odooId !== null) {
|
|
739
|
+
if (offset > 0) {
|
|
740
|
+
return []; // single-record mode - nothing more after the first page.
|
|
741
|
+
}
|
|
742
|
+
const result = await coModelService.find({ limit: 1, offset: 0, filters: { odooId: { $eq: odooId } } } as any);
|
|
743
|
+
const record = result?.records?.[0];
|
|
744
|
+
if (!record) {
|
|
745
|
+
throw new BadRequestException(`No SolidX "${coModelName}" record found with odooId=${odooId}`);
|
|
746
|
+
}
|
|
747
|
+
return [record];
|
|
748
|
+
}
|
|
749
|
+
|
|
750
|
+
const result = await coModelService.find({ limit, offset, filters: { odooId: { $notNull: true } } } as any);
|
|
751
|
+
return result?.records ?? [];
|
|
752
|
+
}
|
|
753
|
+
|
|
754
|
+
/**
|
|
755
|
+
* The actual worker, invoked from `OdooChatterImportQueueSubscriberRabbitmq`. Runs entirely
|
|
756
|
+
* outside an HTTP request, but `CRUDService.find()` (called by `fetchSolidxRecordsToImport`)
|
|
757
|
+
* unconditionally calls `RequestContextService.setRequestFilter()` -> `ClsService#set`, which
|
|
758
|
+
* throws ("No CLS context available") unless a CLS context has been established first -
|
|
759
|
+
* normally done by a request-scoped middleware/guard, which obviously never runs for a queue
|
|
760
|
+
* job. `clsService.run()` establishes that context manually for the duration of this call.
|
|
761
|
+
*/
|
|
762
|
+
async runOdooChatterImport(payload: OdooChatterImportQueuePayload) {
|
|
763
|
+
return this.clsService.run(() => this.runOdooChatterImportInner(payload));
|
|
764
|
+
}
|
|
765
|
+
|
|
766
|
+
private async runOdooChatterImportInner(payload: OdooChatterImportQueuePayload) {
|
|
767
|
+
const batchSize = payload.batchSize || 100;
|
|
768
|
+
|
|
769
|
+
let messagesImported = 0;
|
|
770
|
+
let messagesSkipped = 0;
|
|
771
|
+
let recordsFailed = 0;
|
|
772
|
+
let recordsProcessed = 0;
|
|
773
|
+
let offset = 0;
|
|
774
|
+
|
|
775
|
+
// eslint-disable-next-line no-constant-condition
|
|
776
|
+
while (true) {
|
|
777
|
+
const records = await this.fetchSolidxRecordsToImport(payload.solidxModelName, payload.odooId, offset, batchSize);
|
|
778
|
+
if (!records.length) {
|
|
779
|
+
break;
|
|
780
|
+
}
|
|
781
|
+
offset += records.length;
|
|
782
|
+
|
|
783
|
+
for (const record of records) {
|
|
784
|
+
recordsProcessed++;
|
|
785
|
+
try {
|
|
786
|
+
const domain: any[] = [['model', '=', payload.odooModelName], ['res_id', '=', record.odooId]];
|
|
787
|
+
if (payload.fromDate) {
|
|
788
|
+
domain.push(['date', '>=', payload.fromDate]);
|
|
789
|
+
}
|
|
790
|
+
|
|
791
|
+
// Odoo's search_read treats limit:0 as "return zero rows", not "no limit" -
|
|
792
|
+
// paginate properly instead, same as the outer SolidX record loop.
|
|
793
|
+
let messageOffset = 0;
|
|
794
|
+
// eslint-disable-next-line no-constant-condition
|
|
795
|
+
while (true) {
|
|
796
|
+
const messages: OdooMessage[] = await this.odooCallKw(
|
|
797
|
+
payload.odooBaseUrl,
|
|
798
|
+
payload.odooSessionCookie,
|
|
799
|
+
'mail.message',
|
|
800
|
+
'search_read',
|
|
801
|
+
[domain, ['id', 'res_id', 'date', 'author_id', 'body', 'tracking_value_ids', 'attachment_ids']],
|
|
802
|
+
{ order: 'id asc', limit: batchSize, offset: messageOffset },
|
|
803
|
+
);
|
|
804
|
+
|
|
805
|
+
if (!messages || messages.length === 0) {
|
|
806
|
+
break;
|
|
807
|
+
}
|
|
808
|
+
messageOffset += messages.length;
|
|
809
|
+
|
|
810
|
+
for (const message of messages) {
|
|
811
|
+
const trackingValues = message.tracking_value_ids?.length
|
|
812
|
+
? await this.odooCallKw(payload.odooBaseUrl, payload.odooSessionCookie, 'mail.tracking.value', 'read', [message.tracking_value_ids])
|
|
813
|
+
: [];
|
|
814
|
+
|
|
815
|
+
const attachments: OdooAttachmentStream[] = [];
|
|
816
|
+
for (const attachmentId of message.attachment_ids ?? []) {
|
|
817
|
+
attachments.push(await this.odooFetchAttachment(payload.odooBaseUrl, payload.odooSessionCookie, attachmentId));
|
|
818
|
+
}
|
|
819
|
+
|
|
820
|
+
const imported = await this.importMessageFromOdoo({
|
|
821
|
+
coModelName: payload.solidxModelName,
|
|
822
|
+
coModelEntityId: record.id,
|
|
823
|
+
odooMessageId: message.id,
|
|
824
|
+
messageBody: this.buildOdooMessageHtml(message, trackingValues),
|
|
825
|
+
createdAt: this.formatOdooDate(message.date),
|
|
826
|
+
attachments,
|
|
827
|
+
});
|
|
828
|
+
|
|
829
|
+
if (imported) {
|
|
830
|
+
messagesImported++;
|
|
831
|
+
} else {
|
|
832
|
+
messagesSkipped++;
|
|
833
|
+
}
|
|
834
|
+
}
|
|
835
|
+
}
|
|
836
|
+
} catch (error: any) {
|
|
837
|
+
recordsFailed++;
|
|
838
|
+
this._logger.error(`Failed importing Odoo chatter for ${payload.solidxModelName} (odooId=${record.odooId}): ${error.message}`, error.stack);
|
|
839
|
+
}
|
|
840
|
+
}
|
|
841
|
+
}
|
|
842
|
+
|
|
843
|
+
return { recordsProcessed, messagesImported, messagesSkipped, recordsFailed };
|
|
844
|
+
}
|
|
845
|
+
|
|
846
|
+
/**
|
|
847
|
+
* Idempotent single-message writer used by the Odoo import job. Unlike `postMessage`, this
|
|
848
|
+
* is a trusted system operation with no active HTTP user, so it does not call
|
|
849
|
+
* `assertRecordAccess` - it relies on `odooMessageId` uniqueness (checked here) instead of
|
|
850
|
+
* a persisted job/checkpoint table for both dedup and resumability; see
|
|
851
|
+
* `runOdooChatterImport`'s cursor derivation for the resume side of that.
|
|
852
|
+
*/
|
|
853
|
+
async importMessageFromOdoo(input: {
|
|
854
|
+
coModelName: string;
|
|
855
|
+
coModelEntityId: number;
|
|
856
|
+
odooMessageId: number;
|
|
857
|
+
messageBody: string;
|
|
858
|
+
createdAt: Date;
|
|
859
|
+
attachments: OdooAttachmentStream[];
|
|
860
|
+
}): Promise<ChatterMessage | null> {
|
|
861
|
+
const existing = await this.repo.findOne({ where: { odooMessageId: input.odooMessageId } });
|
|
862
|
+
if (existing) {
|
|
863
|
+
return null;
|
|
864
|
+
}
|
|
865
|
+
|
|
866
|
+
const chatterMessage = new ChatterMessage();
|
|
867
|
+
chatterMessage.messageType = CHATTER_MESSAGE_TYPE.CUSTOM;
|
|
868
|
+
chatterMessage.messageSubType = CHATTER_MESSAGE_SUBTYPE.NOTE;
|
|
869
|
+
chatterMessage.status = CHATTER_MESSAGE_STATUS.COMPLETED;
|
|
870
|
+
chatterMessage.messageBody = input.messageBody;
|
|
871
|
+
chatterMessage.coModelEntityId = input.coModelEntityId;
|
|
872
|
+
chatterMessage.coModelName = input.coModelName;
|
|
873
|
+
chatterMessage.odooMessageId = input.odooMessageId;
|
|
874
|
+
// Backdate both timestamps to the original Odoo message date, not "now" - this is an
|
|
875
|
+
// import of historical data, so nothing was actually created/updated in SolidX at import
|
|
876
|
+
// time. createdAt alone isn't enough: @UpdateDateColumn defaults to the current time on
|
|
877
|
+
// insert just like @CreateDateColumn would if left unset, so updatedAt must be set too or
|
|
878
|
+
// it silently shows today's date regardless of createdAt being correct.
|
|
879
|
+
chatterMessage.createdAt = input.createdAt;
|
|
880
|
+
chatterMessage.updatedAt = input.createdAt;
|
|
881
|
+
|
|
882
|
+
const model = await this.modelMetadataRepo.findOne({
|
|
883
|
+
where: { singularName: input.coModelName },
|
|
884
|
+
relations: { userKeyField: true, module: true },
|
|
885
|
+
});
|
|
886
|
+
chatterMessage.modelDisplayName = model?.displayName ?? null;
|
|
887
|
+
|
|
888
|
+
this.stampMessageAuditFields(chatterMessage, this.getOdooImportSystemUserId());
|
|
889
|
+
|
|
890
|
+
const savedMessage = await this.repo.save(chatterMessage);
|
|
891
|
+
|
|
892
|
+
if (input.attachments?.length) {
|
|
893
|
+
const chatterModel = await this.modelMetadataService.findOneBySingularName('chatterMessage', {
|
|
894
|
+
fields: { model: true, mediaStorageProvider: true },
|
|
895
|
+
module: true,
|
|
896
|
+
});
|
|
897
|
+
const mediaField = chatterModel?.fields?.find(field => field.type === 'mediaMultiple' && field.name === 'messageAttachments');
|
|
898
|
+
|
|
899
|
+
if (mediaField) {
|
|
900
|
+
const storageProviderType = mediaField.mediaStorageProvider.type as MediaStorageProviderType;
|
|
901
|
+
const storageProvider = await getMediaStorageProvider(this.moduleRef, storageProviderType);
|
|
902
|
+
const streamPairs: [Readable, string, { mimeType?: string; originalFileName?: string }][] = input.attachments.map(attachment => [
|
|
903
|
+
attachment.stream,
|
|
904
|
+
`${uuidv4()}-${sanitizeStoredMediaFileName(attachment.originalFileName)}`,
|
|
905
|
+
{ mimeType: attachment.mimeType, originalFileName: attachment.originalFileName },
|
|
906
|
+
]);
|
|
907
|
+
await storageProvider.storeStreams(streamPairs, savedMessage, mediaField);
|
|
908
|
+
} else {
|
|
909
|
+
this._logger.warn(`Could not resolve "messageAttachments" media field on chatterMessage - skipping ${input.attachments.length} Odoo attachment(s) for message ${input.odooMessageId}`);
|
|
910
|
+
}
|
|
911
|
+
}
|
|
912
|
+
|
|
913
|
+
return savedMessage;
|
|
914
|
+
}
|
|
915
|
+
|
|
508
916
|
async postAuditMessageOnInsert(entity: any, modelName: string, messageQueue: boolean = false, userId?: number | null) {
|
|
509
917
|
if (!entity) {
|
|
510
918
|
return;
|
|
@@ -122,13 +122,10 @@ export class SMTPEMailService implements IMail {
|
|
|
122
122
|
}
|
|
123
123
|
|
|
124
124
|
async sendEmailSynchronously(message: QueueMessage<any>) {
|
|
125
|
-
|
|
126
|
-
const { to, subject, body, attachments = [], cc, bcc } = message.payload;
|
|
125
|
+
const { to, subject, body, attachments = [], cc, bcc, from: payloadFrom } = message.payload;
|
|
127
126
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
from = envFrom;
|
|
131
|
-
}
|
|
127
|
+
// Prefer the from address passed by the caller, fall back to the configured one.
|
|
128
|
+
const from = payloadFrom || this.settingService.getConfigValue<SolidCoreSetting>("smtpMailFrom");
|
|
132
129
|
|
|
133
130
|
// if any of the required fields are missing, throw an error.
|
|
134
131
|
if (!from || !to || !subject || !body) {
|
|
@@ -29,13 +29,13 @@ export class FileS3StorageProvider<T> implements MediaStorageProvider<T> {
|
|
|
29
29
|
private readonly mediaDownloadUrlService: MediaDownloadUrlService,
|
|
30
30
|
) { }
|
|
31
31
|
|
|
32
|
-
async storeStreams(streamPairs: [Readable, string][], entity: T, mediaFieldMetadata: FieldMetadata): Promise<Media[]> {
|
|
32
|
+
async storeStreams(streamPairs: [Readable, string, { mimeType?: string; originalFileName?: string }?][], entity: T, mediaFieldMetadata: FieldMetadata): Promise<Media[]> {
|
|
33
33
|
const entityId = this.getSupportedEntityId(entity);
|
|
34
34
|
const result: Media[] = [];
|
|
35
35
|
const storageProvider = mediaFieldMetadata.mediaStorageProvider;
|
|
36
36
|
const region = getEffectiveS3Region(this.configService, storageProvider.region);
|
|
37
37
|
|
|
38
|
-
for (const [stream, fileName] of streamPairs) {
|
|
38
|
+
for (const [stream, fileName, extraMeta] of streamPairs) {
|
|
39
39
|
const bucketName = storageProvider.bucketName;
|
|
40
40
|
|
|
41
41
|
// Buffer the stream so we can get the byte count and upload in one pass
|
|
@@ -46,12 +46,14 @@ export class FileS3StorageProvider<T> implements MediaStorageProvider<T> {
|
|
|
46
46
|
const fileData = Buffer.concat(chunks);
|
|
47
47
|
const fileSize = fileData.length;
|
|
48
48
|
|
|
49
|
-
await this.s3FileService.write(`${bucketName}:${fileName}`, fileData, { region });
|
|
49
|
+
await this.s3FileService.write(`${bucketName}:${fileName}`, fileData, { region, contentType: extraMeta?.mimeType });
|
|
50
50
|
|
|
51
51
|
const mediaEntity = await this.mediaRepository.createMedia(
|
|
52
52
|
buildMediaRecordCreateInput(entityId, mediaFieldMetadata, storageProvider, {
|
|
53
53
|
relativeUri: fileName,
|
|
54
54
|
fileSize,
|
|
55
|
+
mimeType: extraMeta?.mimeType,
|
|
56
|
+
originalFileName: extraMeta?.originalFileName,
|
|
55
57
|
})
|
|
56
58
|
) as unknown as Media;
|
|
57
59
|
result.push(mediaEntity);
|
|
@@ -72,7 +72,7 @@ export class FileStorageProvider<T> implements MediaStorageProvider<T> {
|
|
|
72
72
|
return result;
|
|
73
73
|
}
|
|
74
74
|
|
|
75
|
-
async storeStreams(streamPairs: [Readable, string][], entity: T, mediaFieldMetadata: FieldMetadata): Promise<Media[]> {
|
|
75
|
+
async storeStreams(streamPairs: [Readable, string, { mimeType?: string; originalFileName?: string }?][], entity: T, mediaFieldMetadata: FieldMetadata): Promise<Media[]> {
|
|
76
76
|
// if (!(entity instanceof CommonEntity)) {
|
|
77
77
|
// throw new Error("Entity must be an instance of CommonEntity"); //FIXME This needs to be handled through generics. e.g T extends CommonEntity
|
|
78
78
|
// }
|
|
@@ -81,6 +81,7 @@ export class FileStorageProvider<T> implements MediaStorageProvider<T> {
|
|
|
81
81
|
for (const pair of streamPairs) {
|
|
82
82
|
const stream = pair[0];
|
|
83
83
|
const fileName = pair[1];
|
|
84
|
+
const extraMeta = pair[2];
|
|
84
85
|
const fullPath = buildDiskMediaPath(fileName, this.settingService, storageProvider);
|
|
85
86
|
await this.fileService.writeStream(fullPath, stream);
|
|
86
87
|
const { size: fileSize } = await fs.promises.stat(fullPath);
|
|
@@ -88,6 +89,8 @@ export class FileStorageProvider<T> implements MediaStorageProvider<T> {
|
|
|
88
89
|
buildMediaRecordCreateInput(this.getEntityId(entity), mediaFieldMetadata, storageProvider, {
|
|
89
90
|
relativeUri: fileName,
|
|
90
91
|
fileSize,
|
|
92
|
+
mimeType: extraMeta?.mimeType,
|
|
93
|
+
originalFileName: extraMeta?.originalFileName,
|
|
91
94
|
})
|
|
92
95
|
) as unknown as Media;
|
|
93
96
|
result.push(mediaEntity);
|
|
@@ -1308,9 +1308,12 @@ export class ModelMetadataService {
|
|
|
1308
1308
|
for (let i = 0; i < model.fields.length; i++) {
|
|
1309
1309
|
const field = model.fields[i];
|
|
1310
1310
|
if (field.isSystem) continue;
|
|
1311
|
-
listViewLayoutFields.push({ type: "field", attrs: { name: `${field.name}` } })
|
|
1312
1311
|
formViewLayoutFields.push({ type: "field", attrs: { name: `${field.name}` } })
|
|
1313
|
-
|
|
1312
|
+
// List and tree layouts already include id as their first column.
|
|
1313
|
+
if (field.name !== "id") {
|
|
1314
|
+
listViewLayoutFields.push({ type: "field", attrs: { name: `${field.name}` } })
|
|
1315
|
+
treeViewLayoutFields.push({ type: "field", attrs: { name: `${field.name}` } })
|
|
1316
|
+
}
|
|
1314
1317
|
}
|
|
1315
1318
|
this.populateVAMConfigInFileInternal(formViewLayoutFields, model, listViewLayoutFields, treeViewLayoutFields, metaData);
|
|
1316
1319
|
// Write the updated object back to the file
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import 'reflect-metadata';
|
|
2
|
+
import { SettingsProvider } from '../decorators/settings-provider.decorator';
|
|
3
|
+
import { SettingLevel } from '../interfaces';
|
|
4
|
+
import { SettingService } from './setting.service';
|
|
5
|
+
|
|
6
|
+
function createServiceWithProviders(providers: Array<{ name: string; metatype: Function; instance: object }>) {
|
|
7
|
+
const registry = {
|
|
8
|
+
getSettingsProviders: () => providers,
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
return new SettingService(
|
|
12
|
+
null as any,
|
|
13
|
+
null as any,
|
|
14
|
+
registry as any,
|
|
15
|
+
null as any,
|
|
16
|
+
null as any,
|
|
17
|
+
null as any,
|
|
18
|
+
null as any,
|
|
19
|
+
);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function setting(moduleName: string, key: string, value: unknown) {
|
|
23
|
+
return {
|
|
24
|
+
moduleName,
|
|
25
|
+
key,
|
|
26
|
+
value,
|
|
27
|
+
level: SettingLevel.SystemAdminEditable,
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
describe('SettingService provider namespaces', () => {
|
|
32
|
+
it('preserves legacy keys and qualifies opt-in provider keys', () => {
|
|
33
|
+
@SettingsProvider()
|
|
34
|
+
class LegacyProvider {
|
|
35
|
+
getSettings() {
|
|
36
|
+
return [setting('solid-core', 'clientID', 'core')];
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
@SettingsProvider('nbf')
|
|
41
|
+
class NbfProvider {
|
|
42
|
+
getSettings() {
|
|
43
|
+
return [setting('nbf', 'clientID', 'nbf')];
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const service = createServiceWithProviders([
|
|
48
|
+
{ name: LegacyProvider.name, metatype: LegacyProvider, instance: new LegacyProvider() },
|
|
49
|
+
{ name: NbfProvider.name, metatype: NbfProvider, instance: new NbfProvider() },
|
|
50
|
+
]);
|
|
51
|
+
|
|
52
|
+
const definitions = (service as any).getAllSettingsFromProviders();
|
|
53
|
+
expect(definitions.map(({ key }: { key: string }) => key)).toEqual([
|
|
54
|
+
'clientID',
|
|
55
|
+
'nbf:clientID',
|
|
56
|
+
]);
|
|
57
|
+
|
|
58
|
+
// Provider-owned objects must not be mutated or double-prefixed on refresh.
|
|
59
|
+
const refreshed = (service as any).getAllSettingsFromProviders();
|
|
60
|
+
expect(refreshed[1].key).toBe('nbf:clientID');
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it('allows providers to share a namespace when their local keys differ', () => {
|
|
64
|
+
@SettingsProvider('nbf')
|
|
65
|
+
class FirstProvider {
|
|
66
|
+
getSettings() {
|
|
67
|
+
return [setting('nbf', 'first', true)];
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
@SettingsProvider('nbf')
|
|
72
|
+
class SecondProvider {
|
|
73
|
+
getSettings() {
|
|
74
|
+
return [setting('nbf', 'second', true)];
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const service = createServiceWithProviders([
|
|
79
|
+
{ name: FirstProvider.name, metatype: FirstProvider, instance: new FirstProvider() },
|
|
80
|
+
{ name: SecondProvider.name, metatype: SecondProvider, instance: new SecondProvider() },
|
|
81
|
+
]);
|
|
82
|
+
|
|
83
|
+
const definitions = (service as any).getAllSettingsFromProviders();
|
|
84
|
+
expect(definitions.map(({ key }: { key: string }) => key)).toEqual([
|
|
85
|
+
'nbf:first',
|
|
86
|
+
'nbf:second',
|
|
87
|
+
]);
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
it('rejects duplicate local keys in one namespace', () => {
|
|
91
|
+
@SettingsProvider('nbf')
|
|
92
|
+
class NbfProvider {
|
|
93
|
+
getSettings() {
|
|
94
|
+
return [
|
|
95
|
+
setting('nbf', 'clientID', 'first'),
|
|
96
|
+
setting('nbf', 'clientID', 'second'),
|
|
97
|
+
];
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const service = createServiceWithProviders([
|
|
102
|
+
{ name: NbfProvider.name, metatype: NbfProvider, instance: new NbfProvider() },
|
|
103
|
+
]);
|
|
104
|
+
|
|
105
|
+
expect(() => (service as any).getAllSettingsFromProviders())
|
|
106
|
+
.toThrow('Duplicate effective setting key "nbf:clientID"');
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
it('reads a canonical key through getConfigValue() with a namespace', () => {
|
|
110
|
+
const service = createServiceWithProviders([]);
|
|
111
|
+
(service as any).settingsByKey = new Map([
|
|
112
|
+
['nbf:clientID', setting('nbf', 'nbf:clientID', 'configured-value')],
|
|
113
|
+
]);
|
|
114
|
+
|
|
115
|
+
expect(service.getConfigValue<string>('clientID', 'nbf')).toBe('configured-value');
|
|
116
|
+
});
|
|
117
|
+
});
|