Skip to content

Commit

Permalink
Merge pull request #74 from mayorJAY/feat-new-configurations
Browse files Browse the repository at this point in the history
Add new configurations and make logging configurable
  • Loading branch information
Cliftonz authored May 1, 2024
2 parents d4172c1 + 18bc55b commit fe1b33a
Show file tree
Hide file tree
Showing 22 changed files with 115 additions and 110 deletions.
9 changes: 7 additions & 2 deletions src/main/kotlin/Novu.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,19 @@ import co.novu.api.TenantsApi
import co.novu.api.TopicsApi
import co.novu.api.WorkflowsApi
import co.novu.helpers.RetrofitHelper
import okhttp3.logging.HttpLoggingInterceptor

data class NovuConfig(
var apiKey: String = "",
var backendUrl: String = "https://api.novu.co/v1/",
var apiKey: String = ""
var euBackendUrl: String = "https://eu.api.novu.co/v1/",
var enableEuVersion: Boolean = false,
var enableLogging: Boolean = true,
var apiLogLevel: HttpLoggingInterceptor.Level = HttpLoggingInterceptor.Level.BASIC
)

class Novu(
config: NovuConfig
val config: NovuConfig
) {

constructor(apiKey: String) : this(NovuConfig(apiKey = apiKey))
Expand Down
4 changes: 2 additions & 2 deletions src/main/kotlin/extensions/BlueprintsExtensions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ private val logger = KotlinLogging.logger {}

suspend fun Novu.getBlueprintsByCategory(): ResponseWrapper<BlueprintsResponse>? {
val response = blueprintsApi.getBlueprintsByCategory()
return response.extractResponse(logger)
return response.extractResponse(logger, config.enableLogging)
}

suspend fun Novu.getBlueprint(templateId: String): Blueprint? {
val response = blueprintsApi.getBlueprint(templateId)
return response.extractResponse(logger)
return response.extractResponse(logger, config.enableLogging)
}
8 changes: 4 additions & 4 deletions src/main/kotlin/extensions/ChangesExtentions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,20 @@ private val logger = KotlinLogging.logger {}

suspend fun Novu.changes(page: BigInteger? = null, limit: BigInteger? = null, promoted: String? = null): PaginatedResponseWrapper<ChangesResponse>? {
val response = changesApi.getChanges(page, limit, promoted)
return response.extractResponse(logger)
return response.extractResponse(logger, config.enableLogging)
}

suspend fun Novu.changesCount(): ResponseWrapper<BigInteger>? {
val response = changesApi.getChangesCount()
return response.extractResponse(logger)
return response.extractResponse(logger, config.enableLogging)
}

suspend fun Novu.applyBulkChanges(request: ChangesRequest): ResponseWrapper<List<ChangesResponse>>? {
val response = changesApi.applyBulkChanges(request)
return response.extractResponse(logger)
return response.extractResponse(logger, config.enableLogging)
}

suspend fun Novu.applyChange(changeId: String): ResponseWrapper<List<ChangesResponse>>? {
val response = changesApi.applyChange(changedId = changeId)
return response.extractResponse(logger)
return response.extractResponse(logger, config.enableLogging)
}
14 changes: 7 additions & 7 deletions src/main/kotlin/extensions/EnvironmentsExtentions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,35 +14,35 @@ private val logger = KotlinLogging.logger {}

suspend fun Novu.currentEnvironment(): ResponseWrapper<GetEnvironmentResponse>? {
val response = environmentsApi.getCurrentEnvironment()
return response.extractResponse(logger)
return response.extractResponse(logger, config.enableLogging)
}

suspend fun Novu.createEnvironment(request: CreateEnvironmentRequest): ResponseWrapper<GetEnvironmentResponse>? {
val response = environmentsApi.createEnvironment(request)
return response.extractResponse(logger)
return response.extractResponse(logger, config.enableLogging)
}

suspend fun Novu.environments(): ResponseWrapper<List<GetEnvironmentResponse>>? {
val response = environmentsApi.getEnvironments()
return response.extractResponse(logger)
return response.extractResponse(logger, config.enableLogging)
}

suspend fun Novu.updateEnvironment(environmentId: String, request: UpdateEnvironmentRequest): ResponseWrapper<GetEnvironmentResponse>? {
val response = environmentsApi.updateEnvironment(environmentId, request)
return response.extractResponse(logger)
return response.extractResponse(logger, config.enableLogging)
}

suspend fun Novu.apiKeys(): ResponseWrapper<List<ApiKeys>>? {
val response = environmentsApi.getApiKeys()
return response.extractResponse(logger)
return response.extractResponse(logger, config.enableLogging)
}

suspend fun Novu.regenrateApiKey(): ResponseWrapper<List<ApiKeys>>? {
val response = environmentsApi.regenerateApiKey()
return response.extractResponse(logger)
return response.extractResponse(logger, config.enableLogging)
}

suspend fun Novu.updateWidgetSettings(request: Widget): ResponseWrapper<GetEnvironmentResponse>? {
val response = environmentsApi.updateWidgetSettings(request)
return response.extractResponse(logger)
return response.extractResponse(logger, config.enableLogging)
}
8 changes: 4 additions & 4 deletions src/main/kotlin/extensions/EventsExtensions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,20 @@ private val logger = KotlinLogging.logger {}

suspend fun Novu.trigger(body: TriggerEventRequest): ResponseWrapper<TriggerResponse>? {
val response = eventsApi.triggerEvent(body)
return response.extractResponse(logger)
return response.extractResponse(logger, config.enableLogging)
}

suspend fun Novu.bulkTrigger(body: BulkTriggerEventRequest): ResponseWrapper<List<TriggerResponse>>? {
val response = eventsApi.bulkTriggerEvent(body)
return response.extractResponse(logger)
return response.extractResponse(logger, config.enableLogging)
}

suspend fun Novu.broadcast(body: BroadcastEventRequest): ResponseWrapper<TriggerResponse>? {
val response = eventsApi.broadcastEvent(body)
return response.extractResponse(logger)
return response.extractResponse(logger, config.enableLogging)
}

suspend fun Novu.cancelTriggerEvent(transactionId: String): ResponseWrapper<Boolean>? {
val response = eventsApi.cancelTriggerEvent(transactionId)
return response.extractResponse(logger)
return response.extractResponse(logger, config.enableLogging)
}
2 changes: 1 addition & 1 deletion src/main/kotlin/extensions/ExecutionDetailsExtentions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ private val logger = KotlinLogging.logger {}

suspend fun Novu.executionDetails(notificationId: String, subscriberId: String): ResponseWrapper<List<ExecutionDetails>>? {
val response = executionDetailsApi.getExecutionDetails(notificationId, subscriberId)
return response.extractResponse(logger)
return response.extractResponse(logger, config.enableLogging)
}
6 changes: 3 additions & 3 deletions src/main/kotlin/extensions/FeedsExtentions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ private val logger = KotlinLogging.logger {}

suspend fun Novu.createFeed(body: CreateByNameRequest): ResponseWrapper<FeedResponse>? {
val response = feedsApi.createFeed(body)
return response.extractResponse(logger)
return response.extractResponse(logger, config.enableLogging)
}

suspend fun Novu.feeds(): ResponseWrapper<List<FeedResponse>>? {
val response = feedsApi.getFeeds()
return response.extractResponse(logger)
return response.extractResponse(logger, config.enableLogging)
}

suspend fun Novu.deleteFeed(feedId: String): ResponseWrapper<FeedResponse>? {
val response = feedsApi.deleteFeed(feedId)
return response.extractResponse(logger)
return response.extractResponse(logger, config.enableLogging)
}
2 changes: 1 addition & 1 deletion src/main/kotlin/extensions/InboundParseExtentions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ private val logger = KotlinLogging.logger {}

suspend fun Novu.validateMxRecordSetupForInboundParse(): ValidateMxRecordSetupForInboundParseResponse? {
val response = inboundParseApi.validateMxRecordSetupForInboundParse()
return response.extractResponse(logger)
return response.extractResponse(logger, config.enableLogging)
}
14 changes: 7 additions & 7 deletions src/main/kotlin/extensions/IntegrationsExtentions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,35 +11,35 @@ private val logger = KotlinLogging.logger {}

suspend fun Novu.integrations(): ResponseWrapper<List<IntegrationResponse>>? {
val response = integrationsApi.getIntegrations()
return response.extractResponse(logger)
return response.extractResponse(logger, config.enableLogging)
}

suspend fun Novu.createIntegration(request: IntegrationRequest): ResponseWrapper<IntegrationResponse>? {
val response = integrationsApi.createIntegration(request)
return response.extractResponse(logger)
return response.extractResponse(logger, config.enableLogging)
}

suspend fun Novu.activeIntegrations(): ResponseWrapper<List<IntegrationResponse>>? {
val response = integrationsApi.getActiveIntegrations()
return response.extractResponse(logger)
return response.extractResponse(logger, config.enableLogging)
}

suspend fun Novu.providerWebhook(providerId: String): ResponseWrapper<Boolean>? {
val response = integrationsApi.getProviderWebhook(providerId)
return response.extractResponse(logger)
return response.extractResponse(logger, config.enableLogging)
}

suspend fun Novu.updateIntegration(integrationId: String, request: IntegrationRequest): ResponseWrapper<IntegrationResponse>? {
val response = integrationsApi.updateIntegration(integrationId, request)
return response.extractResponse(logger)
return response.extractResponse(logger, config.enableLogging)
}

suspend fun Novu.deleteIntegration(integrationId: String): ResponseWrapper<List<IntegrationResponse>>? {
val response = integrationsApi.deleteIntegration(integrationId)
return response.extractResponse(logger)
return response.extractResponse(logger, config.enableLogging)
}

suspend fun Novu.setIntegrationAsPrimary(integrationId: String): ResponseWrapper<IntegrationResponse>? {
val response = integrationsApi.setPrimaryIntegration(integrationId)
return response.extractResponse(logger)
return response.extractResponse(logger, config.enableLogging)
}
12 changes: 6 additions & 6 deletions src/main/kotlin/extensions/LayoutsExtentions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,30 +16,30 @@ private val logger = KotlinLogging.logger {}

suspend fun Novu.filterLayouts(page: BigInteger, pageSize: BigInteger, orderBy: BigInteger, sortBy: String): PaginatedResponseWrapper<GetLayoutsResponse>? {
val response = layoutsApi.filterLayouts(page, pageSize, sortBy, orderBy)
return response.extractResponse(logger)
return response.extractResponse(logger, config.enableLogging)
}

suspend fun Novu.createLayout(request: CreateLayoutRequest): ResponseWrapper<CreateLayoutResponse>? {
val response = layoutsApi.createLayout(request)
return response.extractResponse(logger)
return response.extractResponse(logger, config.enableLogging)
}

suspend fun Novu.layout(layoutId: String): ResponseWrapper<GetLayoutsResponse>? {
val response = layoutsApi.getLayout(layoutId)
return response.extractResponse(logger)
return response.extractResponse(logger, config.enableLogging)
}

suspend fun Novu.deleteLayout(layoutId: String): DeleteLayoutResponse {
val response = layoutsApi.deleteLayout(layoutId)
return response.extractResponse(logger, DeleteLayoutResponse())
return response.extractResponse(logger, config.enableLogging, DeleteLayoutResponse())
}

suspend fun Novu.updateLayout(layoutId: String, request: CreateLayoutRequest): ResponseWrapper<GetLayoutsResponse>? {
val response = layoutsApi.updateLayout(layoutId, request)
return response.extractResponse(logger)
return response.extractResponse(logger, config.enableLogging)
}

suspend fun Novu.setDefaultLayout(layoutId: String): SetDefaultLayoutResponse {
val response = layoutsApi.setDefaultLayout(layoutId)
return response.extractResponse(logger, SetDefaultLayoutResponse())
return response.extractResponse(logger, config.enableLogging, SetDefaultLayoutResponse())
}
4 changes: 2 additions & 2 deletions src/main/kotlin/extensions/MessagesExtentions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ suspend fun Novu.messages(
transactionId: String? = null
): PaginatedResponseWrapper<Message>? {
val response = messagesApi.getMessages(channel, subscriberId, limit, page, transactionId)
return response.extractResponse(logger)
return response.extractResponse(logger, config.enableLogging)
}

suspend fun Novu.deleteMessage(messageId: String): ResponseWrapper<TriggerResponse>? {
val response = messagesApi.deleteMessage(messageId)
return response.extractResponse(logger)
return response.extractResponse(logger, config.enableLogging)
}
10 changes: 5 additions & 5 deletions src/main/kotlin/extensions/NotificationGroupsExtentions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,25 @@ private val logger = KotlinLogging.logger {}

suspend fun Novu.getWorkflowGroups(): ResponseWrapper<List<NotificationGroupsResponse>>? {
val response = notificationGroupsApi.getNotificationGroups()
return response.extractResponse(logger)
return response.extractResponse(logger, config.enableLogging)
}

suspend fun Novu.createWorkflowGroup(request: CreateByNameRequest): ResponseWrapper<NotificationGroupsResponse>? {
val response = notificationGroupsApi.createNotificationGroup(request)
return response.extractResponse(logger)
return response.extractResponse(logger, config.enableLogging)
}

suspend fun Novu.getWorkflowGroup(id: String): ResponseWrapper<NotificationGroupsResponse>? {
val response = notificationGroupsApi.getWorkflowGroup(id)
return response.extractResponse(logger)
return response.extractResponse(logger, config.enableLogging)
}

suspend fun Novu.updateWorkflowGroup(id: String, request: CreateByNameRequest): ResponseWrapper<NotificationGroupsResponse>? {
val response = notificationGroupsApi.updateWorkflowGroup(id, request)
return response.extractResponse(logger)
return response.extractResponse(logger, config.enableLogging)
}

suspend fun Novu.deleteWorkflowGroup(id: String): ResponseWrapper<DeleteWorkflowGroupResponse>? {
val response = notificationGroupsApi.deleteWorkflowGroup(id)
return response.extractResponse(logger)
return response.extractResponse(logger, config.enableLogging)
}
12 changes: 6 additions & 6 deletions src/main/kotlin/extensions/NotificationTemplatesExtentions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,35 +14,35 @@ private val logger = KotlinLogging.logger {}
@Deprecated("Use getWorkflows(): this will be removed in a future release")
suspend fun Novu.notificationTemplates(page: BigInteger, limit: BigInteger): PaginatedResponseWrapper<NotificationTemplates>? {
val response = notificationTemplatesApi.getNotificationTemplates(page, limit)
return response.extractResponse(logger)
return response.extractResponse(logger, config.enableLogging)
}

@Deprecated("Use createWorkflow(): this will be removed in a future release")
suspend fun Novu.createNotificationTemplates(request: NotificationTemplates): ResponseWrapper<NotificationTemplates>? {
val response = notificationTemplatesApi.createNotificationTemplates(request)
return response.extractResponse(logger)
return response.extractResponse(logger, config.enableLogging)
}

@Deprecated("Use updateWorkflow(): this will be removed in a future release")
suspend fun Novu.updateNotificationTemplates(templateId: String, request: NotificationTemplates): ResponseWrapper<NotificationTemplates>? {
val response = notificationTemplatesApi.updateNotificationTemplates(templateId, request)
return response.extractResponse(logger)
return response.extractResponse(logger, config.enableLogging)
}

@Deprecated("Use deleteWorkflow(): this will be removed in a future release")
suspend fun Novu.deleteNotificationTemplate(templateId: String): ResponseWrapper<Boolean>? {
val response = notificationTemplatesApi.deleteNotificationTemplate(templateId)
return response.extractResponse(logger)
return response.extractResponse(logger, config.enableLogging)
}

@Deprecated("Use getWorkflow(): this will be removed in a future release")
suspend fun Novu.notificationTemplate(templateId: String): ResponseWrapper<NotificationTemplates>? {
val response = notificationTemplatesApi.getNotificationTemplate(templateId)
return response.extractResponse(logger)
return response.extractResponse(logger, config.enableLogging)
}

@Deprecated("Use updateWorkflowStatus(): this will be removed in a future release")
suspend fun Novu.updateNotificationTemplateStatus(templateId: String, request: UpdateNotificationTemplateStatusRequest): ResponseWrapper<NotificationTemplates>? {
val response = notificationTemplatesApi.updateNotificationTemplateStatus(templateId, request)
return response.extractResponse(logger)
return response.extractResponse(logger, config.enableLogging)
}
8 changes: 4 additions & 4 deletions src/main/kotlin/extensions/NotificationsExtentions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,20 @@ suspend fun Novu.notifications(notificationRequest: NotificationRequest): Pagina
page = notificationRequest.page,
transactionId = notificationRequest.transactionId
)
return response.extractResponse(logger)
return response.extractResponse(logger, config.enableLogging)
}

suspend fun Novu.notificationsStats(): ResponseWrapper<NotificationStatsResponse>? {
val response = notificationsApi.getNotificationsStats()
return response.extractResponse(logger)
return response.extractResponse(logger, config.enableLogging)
}

suspend fun Novu.notificationGraphStats(): ResponseWrapper<List<NotificationGraphStatsResponse>>? {
val response = notificationsApi.getNotificationGraphStats()
return response.extractResponse(logger)
return response.extractResponse(logger, config.enableLogging)
}

suspend fun Novu.notification(notificationId: String): ResponseWrapper<Notification>? {
val response = notificationsApi.getNotification(notificationId)
return response.extractResponse(logger)
return response.extractResponse(logger, config.enableLogging)
}
Loading

0 comments on commit fe1b33a

Please sign in to comment.