|
|
|
@ -15,6 +15,8 @@ |
|
|
|
///
|
|
|
|
|
|
|
|
import { DeviceTransportType } from '@shared/models/device.models'; |
|
|
|
import { ValidatorFn } from '@angular/forms'; |
|
|
|
import { isNotEmptyStr } from '@core/utils'; |
|
|
|
|
|
|
|
export const smtpPortPattern: RegExp = /^([0-9]{1,4}|[1-5][0-9]{4}|6[0-4][0-9]{3}|65[0-4][0-9]{2}|655[0-2][0-9]|6553[0-5])$/; |
|
|
|
|
|
|
|
@ -95,6 +97,36 @@ export interface SmsProviderConfiguration extends SmsProviderConfigurations { |
|
|
|
type: SmsProviderType; |
|
|
|
} |
|
|
|
|
|
|
|
export function smsProviderConfigurationValidator(required: boolean): ValidatorFn { |
|
|
|
return control => { |
|
|
|
const configuration: SmsProviderConfiguration = control.value; |
|
|
|
let errors = null; |
|
|
|
if (required) { |
|
|
|
let valid = false; |
|
|
|
if (configuration && configuration.type) { |
|
|
|
switch (configuration.type) { |
|
|
|
case SmsProviderType.AWS_SNS: |
|
|
|
const awsSnsConfiguration: AwsSnsSmsProviderConfiguration = configuration; |
|
|
|
valid = isNotEmptyStr(awsSnsConfiguration.accessKeyId) && isNotEmptyStr(awsSnsConfiguration.secretAccessKey) |
|
|
|
&& isNotEmptyStr(awsSnsConfiguration.region); |
|
|
|
break; |
|
|
|
case SmsProviderType.TWILIO: |
|
|
|
const twilioConfiguration: TwilioSmsProviderConfiguration = configuration; |
|
|
|
valid = isNotEmptyStr(twilioConfiguration.numberFrom) && isNotEmptyStr(twilioConfiguration.accountSid) |
|
|
|
&& isNotEmptyStr(twilioConfiguration.accountToken); |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
if (!valid) { |
|
|
|
errors = { |
|
|
|
invalid: true |
|
|
|
}; |
|
|
|
} |
|
|
|
} |
|
|
|
return errors; |
|
|
|
}; |
|
|
|
} |
|
|
|
|
|
|
|
export interface TestSmsRequest { |
|
|
|
providerConfiguration: SmsProviderConfiguration; |
|
|
|
numberTo: string; |
|
|
|
|