Skip to content

Commit

Permalink
Merge branch 'master' into localization-configs
Browse files Browse the repository at this point in the history
  • Loading branch information
nitrosx authored Jan 31, 2025
2 parents 63086ff + 67d1627 commit a46a35a
Show file tree
Hide file tree
Showing 11 changed files with 396 additions and 109 deletions.
8 changes: 6 additions & 2 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,14 @@ REGISTER_METADATA_URI="https://mds.test.datacite.org/metadata"
DOI_USERNAME="username"
DOI_PASSWORD="password"
SITE=<SITE>
EMAIL_TYPE=<"smtp"|"ms365">
EMAIL_FROM=<MESSAGE_FROM>
SMTP_HOST=<SMTP_HOST>
SMTP_MESSAGE_FROM=<SMTP_MESSAGE_FROM>
SMTP_PORT=<SMTP_PORT>
SMTP_SECURE=<SMTP_SECURE>
SMTP_SECURE=<"yes"|"no">
MS365_TENANT_ID=<tenantId>
MS365_CLIENT_ID=<clientId>
MS365_CLIENT_SECRET=<clientSecret>

DATASET_CREATION_VALIDATION_ENABLED=true
DATASET_CREATION_VALIDATION_REGEX="^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$"
Expand Down
11 changes: 8 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,15 @@ Valid environment variables for the .env file. See [.env.example](/.env.example)
| `REGISTER_DOI_URI` | string | | URI to the organization that registers the facility's DOIs. | |
| `REGISTER_METADATA_URI` | string | | URI to the organization that registers the facility's published data metadata. | |
| `SITE` | string | | The name of your site. | |
| `EMAIL_TYPE` | string | Yes | The type of your email provider. Options are "smtp" or "ms365". | "smtp" |
| `EMAIL_FROM` | string | Yes | Email address that emails should be sent from. | |
| `SMTP_HOST` | string | Yes | Host of SMTP server. | |
| `SMTP_MESSAGE_FROM` | string | Yes | Email address that emails should be sent from. | |
| `SMTP_PORT` | string | Yes | Port of SMTP server. | |
| `SMTP_SECURE` | string | Yes | Secure of SMTP server. | |
| `SMTP_MESSAGE_FROM` | string | Yes | (Deprecated) Alternate spelling of EMAIL_FROM.| |
| `SMTP_PORT` | number | Yes | Port of SMTP server. | 587 |
| `SMTP_SECURE` | bool | Yes | Use encrypted SMTPS. | "no" |
| `MS365_TENANT_ID` | string | Yes | Tenant ID for sending emails over Microsoft Graph API. | |
| `MS365_CLIENT_ID` | string | Yes | Client ID for sending emails over Microsoft Graph API | |
| `MS365_CLIENT_SECRET` | string | Yes | Client Secret for sending emails over Microsoft Graph API | |
| `POLICY_PUBLICATION_SHIFT` | integer | Yes | Embargo period expressed in years. | 3 years |
| `POLICY_RETENTION_SHIFT` | integer | Yes | Retention period (how long the facility will hold on to data) expressed in years. | -1 (indefinitely) |
| `ELASTICSEARCH_ENABLED` | string | | Flag to enable/disable the Elasticsearch endpoints. Values "yes" or "no". | "no" |
Expand Down
165 changes: 89 additions & 76 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

57 changes: 47 additions & 10 deletions src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ import { EventEmitterModule } from "@nestjs/event-emitter";
import { AdminModule } from "./admin/admin.module";
import { HealthModule } from "./health/health.module";
import { LoggerModule } from "./loggers/logger.module";
import { HttpModule, HttpService } from "@nestjs/axios";
import { MSGraphMailTransport } from "./common/graph-mail";
import { TransportType } from "@nestjs-modules/mailer/dist/interfaces/mailer-options.interface";
import { MetricsModule } from "./metrics/metrics.module";

@Module({
Expand Down Expand Up @@ -61,17 +64,51 @@ import { MetricsModule } from "./metrics/metrics.module";
LogbooksModule,
EventEmitterModule.forRoot(),
MailerModule.forRootAsync({
useFactory: async (configService: ConfigService) => {
const port = configService.get<string>("smtp.port");
imports: [ConfigModule, HttpModule],
useFactory: async (
configService: ConfigService,
httpService: HttpService,
) => {
let transport: TransportType;
const transportType = configService
.get<string>("email.type")
?.toLowerCase();
if (transportType === "smtp") {
transport = {
host: configService.get<string>("email.smtp.host"),
port: configService.get<number>("email.smtp.port"),
secure: configService.get<boolean>("email.smtp.secure"),
};
} else if (transportType === "ms365") {
const tenantId = configService.get<string>("email.ms365.tenantId"),
clientId = configService.get<string>("email.ms365.clientId"),
clientSecret = configService.get<string>(
"email.ms365.clientSecret",
);
if (tenantId === undefined) {
throw new Error("Missing MS365_TENANT_ID");
}
if (clientId === undefined) {
throw new Error("Missing MS365_CLIENT_ID");
}
if (clientSecret === undefined) {
throw new Error("Missing MS365_CLIENT_SECRET");
}
transport = new MSGraphMailTransport(httpService, {
tenantId,
clientId,
clientSecret,
});
} else {
throw new Error(
`Invalid EMAIL_TYPE: ${transportType}. Expect on of "smtp" or "ms365"`,
);
}

return {
transport: {
host: configService.get<string>("smtp.host"),
port: port ? parseInt(port) : undefined,
secure:
configService.get<string>("smtp.secure") === "yes" ? true : false,
},
transport: transport,
defaults: {
from: configService.get<string>("smtp.messageFrom"),
from: configService.get<string>("email.from"),
},
template: {
dir: join(__dirname, "./common/email-templates"),
Expand All @@ -86,7 +123,7 @@ import { MetricsModule } from "./metrics/metrics.module";
},
};
},
inject: [ConfigService],
inject: [ConfigService, HttpService],
}),
MongooseModule.forRootAsync({
useFactory: async (configService: ConfigService) => ({
Expand Down
Loading

0 comments on commit a46a35a

Please sign in to comment.