diff --git a/backend/src/Notifo.Domain.Integrations.Abstractions/Notifo.Domain.Integrations.Abstractions.csproj b/backend/src/Notifo.Domain.Integrations.Abstractions/Notifo.Domain.Integrations.Abstractions.csproj index a623775f..acd1847d 100644 --- a/backend/src/Notifo.Domain.Integrations.Abstractions/Notifo.Domain.Integrations.Abstractions.csproj +++ b/backend/src/Notifo.Domain.Integrations.Abstractions/Notifo.Domain.Integrations.Abstractions.csproj @@ -10,7 +10,7 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/backend/src/Notifo.Domain.Integrations/AmazonSES/IntegratedAmazonSESIntegration.cs b/backend/src/Notifo.Domain.Integrations/AmazonSES/IntegratedAmazonSESIntegration.cs index e1305d2d..27c9b83f 100644 --- a/backend/src/Notifo.Domain.Integrations/AmazonSES/IntegratedAmazonSESIntegration.cs +++ b/backend/src/Notifo.Domain.Integrations/AmazonSES/IntegratedAmazonSESIntegration.cs @@ -55,13 +55,12 @@ public sealed class IntegratedAmazonSESIntegration : IIntegration, IInitializabl "AmazonSES", Texts.AmazonSES_Name, "", - new List - { + [ FromEmailProperty, FromNameProperty, AdditionalFromEmails - }, - new List(), + ], + [], new HashSet { Providers.Email diff --git a/backend/src/Notifo.Domain.Integrations/Discord/DiscordBotClientPool.cs b/backend/src/Notifo.Domain.Integrations/Discord/DiscordBotClientPool.cs index b78d59ab..d194b713 100644 --- a/backend/src/Notifo.Domain.Integrations/Discord/DiscordBotClientPool.cs +++ b/backend/src/Notifo.Domain.Integrations/Discord/DiscordBotClientPool.cs @@ -17,7 +17,7 @@ public DiscordBotClientPool(IMemoryCache memoryCache) { } - public async Task GetDiscordClient(string botToken, CancellationToken ct) + public async Task GetDiscordClient(string botToken) { var cacheKey = $"{nameof(IDiscordClient)}_{botToken}"; diff --git a/backend/src/Notifo.Domain.Integrations/Discord/DiscordIntegration.Messaging.cs b/backend/src/Notifo.Domain.Integrations/Discord/DiscordIntegration.Messaging.cs index 9203e9bd..46a38032 100644 --- a/backend/src/Notifo.Domain.Integrations/Discord/DiscordIntegration.Messaging.cs +++ b/backend/src/Notifo.Domain.Integrations/Discord/DiscordIntegration.Messaging.cs @@ -45,19 +45,20 @@ private async Task SendMessageAsync(IntegrationContext context, { try { - var client = await discordBotClientPool.GetDiscordClient(botToken, ct); - var requestOptions = new RequestOptions { CancelToken = ct }; + var client = await discordBotClientPool.GetDiscordClient(botToken); + + var requestOptions = new RequestOptions + { + CancelToken = ct + }; if (!ulong.TryParse(chatId, out var chatIdParsed)) { throw new InvalidOperationException("Invalid Discord DM chat ID."); } - var user = await client.GetUserAsync(chatIdParsed, CacheMode.AllowDownload, requestOptions); - if (user is null) - { - throw new InvalidOperationException("User not found."); - } + var user = await client.GetUserAsync(chatIdParsed, CacheMode.AllowDownload, requestOptions) + ?? throw new InvalidOperationException("User not found."); EmbedBuilder builder = new EmbedBuilder(); diff --git a/backend/src/Notifo.Domain.Integrations/Discord/DiscordIntegration.cs b/backend/src/Notifo.Domain.Integrations/Discord/DiscordIntegration.cs index 09736b4d..01a69d5c 100644 --- a/backend/src/Notifo.Domain.Integrations/Discord/DiscordIntegration.cs +++ b/backend/src/Notifo.Domain.Integrations/Discord/DiscordIntegration.cs @@ -33,14 +33,12 @@ public sealed partial class DiscordIntegration : IIntegration "Discord", Texts.Discord_Name, "", - new List - { + [ BotToken - }, - new List - { + ], + [ UserId - }, + ], new HashSet { Providers.Messaging, diff --git a/backend/src/Notifo.Domain.Integrations/Firebase/FirebaseIntegration.cs b/backend/src/Notifo.Domain.Integrations/Firebase/FirebaseIntegration.cs index 002b1474..9865910b 100644 --- a/backend/src/Notifo.Domain.Integrations/Firebase/FirebaseIntegration.cs +++ b/backend/src/Notifo.Domain.Integrations/Firebase/FirebaseIntegration.cs @@ -53,14 +53,13 @@ public sealed partial class FirebaseIntegration : IIntegration "Firebase", Texts.Firebase_Name, "", - new List - { + [ ProjectIdProperty, SilentAndroidProperty, SilentIOSProperty, CredentialsProperty - }, - new List(), + ], + [], new HashSet { Providers.MobilePush diff --git a/backend/src/Notifo.Domain.Integrations/Http/HttpIntegration.cs b/backend/src/Notifo.Domain.Integrations/Http/HttpIntegration.cs index ae00b6c8..78790411 100644 --- a/backend/src/Notifo.Domain.Integrations/Http/HttpIntegration.cs +++ b/backend/src/Notifo.Domain.Integrations/Http/HttpIntegration.cs @@ -50,13 +50,12 @@ public sealed partial class HttpIntegration : IIntegration "Webhook", "Webhook", "", - new List - { + [ HttpUrlProperty, HttpMethodProperty, SendConfirmProperty - }, - new List(), + ], + [], new HashSet { Providers.Webhook diff --git a/backend/src/Notifo.Domain.Integrations/Mailchimp/MailchimpIntegration.cs b/backend/src/Notifo.Domain.Integrations/Mailchimp/MailchimpIntegration.cs index b3eaaafb..8639ceb4 100644 --- a/backend/src/Notifo.Domain.Integrations/Mailchimp/MailchimpIntegration.cs +++ b/backend/src/Notifo.Domain.Integrations/Mailchimp/MailchimpIntegration.cs @@ -41,13 +41,12 @@ public sealed partial class MailchimpIntegration : IIntegration "Mailchimp", Texts.Mailchimp_Name, "", - new List - { + [ ApiKeyProperty, FromEmailProperty, FromNameProperty - }, - new List(), + ], + [], new HashSet { Providers.Email diff --git a/backend/src/Notifo.Domain.Integrations/Mailjet/MailjetIntegration.cs b/backend/src/Notifo.Domain.Integrations/Mailjet/MailjetIntegration.cs index 4acedf38..28593841 100644 --- a/backend/src/Notifo.Domain.Integrations/Mailjet/MailjetIntegration.cs +++ b/backend/src/Notifo.Domain.Integrations/Mailjet/MailjetIntegration.cs @@ -48,14 +48,13 @@ public sealed partial class MailjetIntegration : IIntegration "Mailjet", Texts.Mailjet_Name, "", - new List - { + [ ApiKeyProperty, ApiSecretProperty, FromEmailProperty, FromNameProperty - }, - new List(), + ], + [], new HashSet { Providers.Email diff --git a/backend/src/Notifo.Domain.Integrations/MessageBird/IntegratedMessageBirdIntegration.cs b/backend/src/Notifo.Domain.Integrations/MessageBird/IntegratedMessageBirdIntegration.cs index ef5b4439..d8ca6dbb 100644 --- a/backend/src/Notifo.Domain.Integrations/MessageBird/IntegratedMessageBirdIntegration.cs +++ b/backend/src/Notifo.Domain.Integrations/MessageBird/IntegratedMessageBirdIntegration.cs @@ -24,8 +24,8 @@ public sealed class IntegratedMessageBirdIntegration : IIntegration, ISmsSender, "MessageBirdIntegrated", Texts.MessageBirdIntegrated_Name, "", - new List(), - new List(), + [], + [], new HashSet { Providers.Sms diff --git a/backend/src/Notifo.Domain.Integrations/MessageBird/MessageBirdSmsIntegration.cs b/backend/src/Notifo.Domain.Integrations/MessageBird/MessageBirdSmsIntegration.cs index 44640966..53c7129c 100644 --- a/backend/src/Notifo.Domain.Integrations/MessageBird/MessageBirdSmsIntegration.cs +++ b/backend/src/Notifo.Domain.Integrations/MessageBird/MessageBirdSmsIntegration.cs @@ -73,16 +73,15 @@ public sealed partial class MessageBirdSmsIntegration : IIntegration "MessageBird", Texts.MessageBird_Name, "", - new List - { + [ AccessKeyProperty, PhoneNumberProperty, PhoneNumbersProperty, WhatsAppChannelIdProperty, WhatsAppTemplateNamespaceProperty, WhatsAppTemplateNameProperty - }, - new List(), + ], + [], new HashSet { Providers.Sms diff --git a/backend/src/Notifo.Domain.Integrations/MessageBird/MessageBirdWhatsAppIntegration.cs b/backend/src/Notifo.Domain.Integrations/MessageBird/MessageBirdWhatsAppIntegration.cs index 4c7910aa..26293e3d 100644 --- a/backend/src/Notifo.Domain.Integrations/MessageBird/MessageBirdWhatsAppIntegration.cs +++ b/backend/src/Notifo.Domain.Integrations/MessageBird/MessageBirdWhatsAppIntegration.cs @@ -65,16 +65,15 @@ public sealed partial class MessageBirdWhatsAppIntegration : IIntegration "MessageBirdWhatsApp", Texts.MessageBirdWhatsApp_Name, "", - new List - { + [ AccessKeyProperty, PhoneNumberProperty, PhoneNumbersProperty, WhatsAppChannelIdProperty, WhatsAppTemplateNamespaceProperty, WhatsAppTemplateNameProperty - }, - new List(), + ], + [], new HashSet { Providers.Messaging diff --git a/backend/src/Notifo.Domain.Integrations/Notifo.Domain.Integrations.csproj b/backend/src/Notifo.Domain.Integrations/Notifo.Domain.Integrations.csproj index 935684a3..e50419d7 100644 --- a/backend/src/Notifo.Domain.Integrations/Notifo.Domain.Integrations.csproj +++ b/backend/src/Notifo.Domain.Integrations/Notifo.Domain.Integrations.csproj @@ -9,23 +9,23 @@ - - + + - - - - + + + + - - + + all runtime; build; native; contentfiles; analyzers; buildtransitive - + @@ -33,7 +33,7 @@ - + diff --git a/backend/src/Notifo.Domain.Integrations/OpenNotifications/OpenNotificationsIntegrationBase.cs b/backend/src/Notifo.Domain.Integrations/OpenNotifications/OpenNotificationsIntegrationBase.cs index 9e132a88..9a0f8238 100644 --- a/backend/src/Notifo.Domain.Integrations/OpenNotifications/OpenNotificationsIntegrationBase.cs +++ b/backend/src/Notifo.Domain.Integrations/OpenNotifications/OpenNotificationsIntegrationBase.cs @@ -100,7 +100,7 @@ bool MakeSummary(PropertyInfoDto property) Summary = MakeSummary(property) }; }).ToList(), - new List(), + [], capabilities) { Description = providerInfo.Description.Values.FirstOrDefault(), diff --git a/backend/src/Notifo.Domain.Integrations/Smtp/SmtpIntegration.cs b/backend/src/Notifo.Domain.Integrations/Smtp/SmtpIntegration.cs index 33a9611c..b40735d3 100644 --- a/backend/src/Notifo.Domain.Integrations/Smtp/SmtpIntegration.cs +++ b/backend/src/Notifo.Domain.Integrations/Smtp/SmtpIntegration.cs @@ -61,16 +61,15 @@ public sealed partial class SmtpIntegration : IIntegration "SMTP", Texts.SMTP_Name, "", - new List - { + [ HostProperty, HostPortProperty, UsernameProperty, PasswordProperty, FromEmailProperty, FromNameProperty - }, - new List(), + ], + [], new HashSet { Providers.Email diff --git a/backend/src/Notifo.Domain.Integrations/Telegram/TelegramIntegration.cs b/backend/src/Notifo.Domain.Integrations/Telegram/TelegramIntegration.cs index 52f16ff7..370d1823 100644 --- a/backend/src/Notifo.Domain.Integrations/Telegram/TelegramIntegration.cs +++ b/backend/src/Notifo.Domain.Integrations/Telegram/TelegramIntegration.cs @@ -38,15 +38,13 @@ public sealed partial class TelegramIntegration : IIntegration "Telegram", Texts.Telegram_Name, "", - new List - { + [ AccessToken - }, - new List - { + ], + [ UserUsername, UserChatId - }, + ], new HashSet { Providers.Messaging diff --git a/backend/src/Notifo.Domain.Integrations/Telekom/TelekomSmsIntegration.cs b/backend/src/Notifo.Domain.Integrations/Telekom/TelekomSmsIntegration.cs index c2a9b038..b6cdfac5 100644 --- a/backend/src/Notifo.Domain.Integrations/Telekom/TelekomSmsIntegration.cs +++ b/backend/src/Notifo.Domain.Integrations/Telekom/TelekomSmsIntegration.cs @@ -41,13 +41,12 @@ public sealed partial class TelekomSmsIntegration : IIntegration "Telekom", Texts.Telekom_Name, "", - new List - { + [ ApiKeyProperty, PhoneNumberProperty, PhoneNumbersProperty - }, - new List(), + ], + [], new HashSet { Providers.Messaging diff --git a/backend/src/Notifo.Domain.Integrations/Threema/ThreemaSimpleIntegration.cs b/backend/src/Notifo.Domain.Integrations/Threema/ThreemaSimpleIntegration.cs index 1c1b8e67..c1991e05 100644 --- a/backend/src/Notifo.Domain.Integrations/Threema/ThreemaSimpleIntegration.cs +++ b/backend/src/Notifo.Domain.Integrations/Threema/ThreemaSimpleIntegration.cs @@ -33,12 +33,11 @@ public sealed partial class ThreemaSimpleIntegration : IIntegration "ThreemaSimple", Texts.ThreemaSimple_Name, "", - new List - { + [ ApiIdentity, ApiSecret - }, - new List(), + ], + [], new HashSet { Providers.Messaging diff --git a/backend/src/Notifo.Domain.Integrations/Twilio/TwilioSmsIntegration.cs b/backend/src/Notifo.Domain.Integrations/Twilio/TwilioSmsIntegration.cs index 697d7602..20062283 100644 --- a/backend/src/Notifo.Domain.Integrations/Twilio/TwilioSmsIntegration.cs +++ b/backend/src/Notifo.Domain.Integrations/Twilio/TwilioSmsIntegration.cs @@ -44,13 +44,12 @@ public sealed partial class TwilioSmsIntegration : IIntegration "Twilio", Texts.Twilio_Name, "\r\n", - new List - { + [ AccountSidProperty, AuthTokenProperty, PhoneNumberProperty - }, - new List(), + ], + [], new HashSet { Providers.Sms diff --git a/backend/src/Notifo.Domain/Integrations/ConditionParser.cs b/backend/src/Notifo.Domain/Integrations/ConditionParser.cs index 65992eb7..71806d85 100644 --- a/backend/src/Notifo.Domain/Integrations/ConditionParser.cs +++ b/backend/src/Notifo.Domain/Integrations/ConditionParser.cs @@ -5,20 +5,27 @@ // All rights reserved. Licensed under the MIT license. // ========================================================================== -using Esprima; using Esprima.Ast; +using Jint; using Microsoft.Extensions.Caching.Memory; -using Microsoft.Extensions.Options; +using Options = Microsoft.Extensions.Options.Options; namespace Notifo.Domain.Integrations; internal static class ConditionParser { - private static readonly JavaScriptParser Parser = new JavaScriptParser(new ParserOptions { Tolerant = true }); + private static readonly ScriptPreparationOptions PreparationOptions = new ScriptPreparationOptions + { + ParsingOptions = new ScriptParsingOptions + { + Tolerant = true + } + }; + private static readonly TimeSpan CacheDuration = TimeSpan.FromMinutes(10); private static readonly IMemoryCache Cache = new MemoryCache(Options.Create(new MemoryCacheOptions())); - public static Script Parse(string script) + public static Prepared