subscribe method
Subscribes url to events, after checking the address.
Throws DVWebhookAddressRefusedException for an address a delivery may not go to, and DVWebhookUndeclaredEventException for an event nobody declared.
Implementation
Future<DVWebhookSubscription> subscribe({
required String url,
required Set<String> events,
required String signingSecret,
String? tenant,
String? id,
}) async {
for (final String event in events) {
if (!_events.containsKey(event)) {
throw DVWebhookUndeclaredEventException(event);
}
}
final Uri uri = Uri.parse(url);
await _checkAddress(uri);
final DVWebhookSubscription subscription = DVWebhookSubscription(
id: id ?? _newId('whsub'),
url: uri,
events: Set<String>.unmodifiable(events),
signingSecret: signingSecret,
tenant: tenant,
createdAt: clock(),
);
await _DVWebhookTables.insertSubscription(await _db(), subscription);
return subscription;
}