feat(sms): Transport recipient PhoneNumber + SmsConfig round-trip (S10)
This commit is contained in:
@@ -138,11 +138,17 @@ public sealed class EntitySerializer
|
||||
NotificationLists: aggregate.NotificationLists.Select(nl => new NotificationListDto(
|
||||
Name: nl.Name,
|
||||
Type: nl.Type,
|
||||
// S10: carry BOTH contacts. Keep any recipient that has at least
|
||||
// one contact (email OR phone) — SMS-only recipients have a null
|
||||
// EmailAddress and would have been dropped by the old email-only
|
||||
// filter. EmailAddress/PhoneNumber are nullable on the DTO so a
|
||||
// recipient round-trips exactly the contact(s) it holds.
|
||||
Recipients: nl.Recipients
|
||||
.Where(r => r.EmailAddress is not null)
|
||||
.Where(r => r.EmailAddress is not null || r.PhoneNumber is not null)
|
||||
.Select(r => new NotificationRecipientDto(
|
||||
Name: r.Name,
|
||||
EmailAddress: r.EmailAddress!)).ToList())).ToList(),
|
||||
EmailAddress: r.EmailAddress,
|
||||
PhoneNumber: r.PhoneNumber)).ToList())).ToList(),
|
||||
SmtpConfigs: aggregate.SmtpConfigurations.Select(smtp =>
|
||||
{
|
||||
SecretsBlock? secrets = null;
|
||||
@@ -212,6 +218,32 @@ public sealed class EntitySerializer
|
||||
FailoverRetryCount: c.FailoverRetryCount,
|
||||
Secrets: secretValues.Count > 0 ? new SecretsBlock(secretValues) : null);
|
||||
}).ToList(),
|
||||
// SMS (S10): mirror the SMTP secret handling exactly — the provider
|
||||
// auth token (never a public field) rides inside the SecretsBlock, so a
|
||||
// "share without secrets" export can drop it as a unit. Omit the secret
|
||||
// entirely when the token is null/empty so the importer's TryGetValue
|
||||
// cleanly yields "no value".
|
||||
SmsConfigs = aggregate.SmsConfigurations.Select(sms =>
|
||||
{
|
||||
SecretsBlock? secrets = null;
|
||||
if (!string.IsNullOrEmpty(sms.AuthToken))
|
||||
{
|
||||
secrets = new SecretsBlock(new Dictionary<string, string>(StringComparer.Ordinal)
|
||||
{
|
||||
["AuthToken"] = sms.AuthToken,
|
||||
});
|
||||
}
|
||||
|
||||
return new SmsConfigDto(
|
||||
AccountSid: sms.AccountSid,
|
||||
FromNumber: sms.FromNumber,
|
||||
MessagingServiceSid: sms.MessagingServiceSid,
|
||||
ApiBaseUrl: sms.ApiBaseUrl,
|
||||
ConnectionTimeoutSeconds: sms.ConnectionTimeoutSeconds,
|
||||
MaxRetries: sms.MaxRetries,
|
||||
RetryDelay: sms.RetryDelay,
|
||||
Secrets: secrets);
|
||||
}).ToList(),
|
||||
Instances = aggregate.Instances.Select(inst => new InstanceDto(
|
||||
UniqueName: inst.UniqueName,
|
||||
TemplateName: templateNameById.TryGetValue(inst.TemplateId, out var tn) ? tn : string.Empty,
|
||||
@@ -392,10 +424,16 @@ public sealed class EntitySerializer
|
||||
var list = new NotificationList(dto.Name) { Id = ix + 1, Type = dto.Type };
|
||||
foreach (var r in dto.Recipients)
|
||||
{
|
||||
list.Recipients.Add(new NotificationRecipient(r.Name, r.EmailAddress)
|
||||
{
|
||||
NotificationListId = list.Id,
|
||||
});
|
||||
// S10: reconstruct whichever contact(s) the bundle carries.
|
||||
// Email-present recipients use the email ctor (unchanged
|
||||
// historical path) and additively restore the phone number;
|
||||
// phone-only recipients (null email) take the SMS factory so we
|
||||
// never pass null to the non-null email ctor.
|
||||
var recipient = r.EmailAddress is not null
|
||||
? new NotificationRecipient(r.Name, r.EmailAddress) { PhoneNumber = r.PhoneNumber }
|
||||
: NotificationRecipient.ForSms(r.Name, r.PhoneNumber ?? string.Empty);
|
||||
recipient.NotificationListId = list.Id;
|
||||
list.Recipients.Add(recipient);
|
||||
}
|
||||
return list;
|
||||
})
|
||||
@@ -415,6 +453,22 @@ public sealed class EntitySerializer
|
||||
})
|
||||
.ToList();
|
||||
|
||||
// SMS (S10): mirror the SMTP path — restore AccountSid/FromNumber and decrypt
|
||||
// the auth token back out of the SecretsBlock (null when the key was omitted
|
||||
// because the source token was null/empty).
|
||||
var smsConfigurations = content.SmsConfigs
|
||||
.Select((dto, ix) => new SmsConfiguration(dto.AccountSid, dto.FromNumber)
|
||||
{
|
||||
Id = ix + 1,
|
||||
AuthToken = dto.Secrets?.Values.TryGetValue("AuthToken", out var token) == true ? token : null,
|
||||
MessagingServiceSid = dto.MessagingServiceSid,
|
||||
ApiBaseUrl = dto.ApiBaseUrl,
|
||||
ConnectionTimeoutSeconds = dto.ConnectionTimeoutSeconds,
|
||||
MaxRetries = dto.MaxRetries,
|
||||
RetryDelay = dto.RetryDelay,
|
||||
})
|
||||
.ToList();
|
||||
|
||||
// Inbound API keys are not transported (re-arch C4) — content.ApiKeys is a
|
||||
// legacy field only present on pre-C4 bundles; it is ignored here. The
|
||||
// BundleImporter is responsible for counting and reporting any such keys.
|
||||
@@ -538,6 +592,7 @@ public sealed class EntitySerializer
|
||||
Sites = sites,
|
||||
DataConnections = dataConnections,
|
||||
Instances = instances,
|
||||
SmsConfigurations = smsConfigurations,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user