Skip to content

Commit

Permalink
TM Alert rules - STRUC_CC & STRUC_APM (#2306)
Browse files Browse the repository at this point in the history
* chore: infra

* chore: infra

* fix: pr comments

* fix: structuring rules

* fix: severities

* fix: revert enabling broken rules
  • Loading branch information
MatanYadaev committed Apr 21, 2024
1 parent e7e812f commit 89e49fd
Show file tree
Hide file tree
Showing 4 changed files with 452 additions and 151 deletions.
104 changes: 75 additions & 29 deletions services/workflows-service/scripts/alerts/generate-alerts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
Prisma,
PrismaClient,
Project,
TransactionDirection,
TransactionRecordType,
} from '@prisma/client';
import { faker } from '@faker-js/faker';
Expand Down Expand Up @@ -43,7 +44,7 @@ export const ALERT_DEFINITIONS = {
options: {
havingAggregate: AggregateType.SUM,

direction: 'inbound',
direction: TransactionDirection.inbound,

excludedCounterparty: {
counterpartyBeneficiaryIds: ['9999999999999999', '999999______9999'],
Expand Down Expand Up @@ -74,7 +75,7 @@ export const ALERT_DEFINITIONS = {
options: {
havingAggregate: AggregateType.SUM,

direction: 'inbound',
direction: TransactionDirection.inbound,

excludedCounterparty: {
counterpartyBeneficiaryIds: ['9999999999999999', '999999______9999'],
Expand All @@ -95,19 +96,23 @@ export const ALERT_DEFINITIONS = {
},

STRUC_CC: {
defaultSeverity: AlertSeverity.medium,
enabled: true,
defaultSeverity: AlertSeverity.high,
description:
'Structuring - Significant number of low value incoming transactions just below a threshold of credit card',
inlineRule: {
id: 'STRUC_CC',
fnName: 'evaluateTransactionsAgainstDynamicRules',
subjects: ['businessId'],
subjects: ['counterpartyId'],
options: {
havingAggregate: AggregateType.COUNT,
groupBy: ['counterpartyBeneficiaryId'],

direction: 'inbound',
// TODO: add excludedCounterparty
// excludedCounterparty: ['9999999999999999', '999999******9999'],
direction: TransactionDirection.inbound,
excludedCounterparty: {
counterpartyBeneficiaryIds: ['9999999999999999', '999999______9999'],
counterpartyOriginatorIds: [],
},

paymentMethods: [PaymentMethod.credit_card],
excludePaymentMethods: false,
Expand All @@ -116,32 +121,36 @@ export const ALERT_DEFINITIONS = {
timeUnit: TIME_UNITS.days,

amountThreshold: 5,
amountBetween: { min: 500, max: 1000 },
amountBetween: { min: 500, max: 999 },
},
},
},
STRUC_APM: {
defaultSeverity: AlertSeverity.medium,
enabled: true,
defaultSeverity: AlertSeverity.high,
description:
'Structuring - Significant number of low value incoming transactions just below a threshold of APM',
inlineRule: {
id: 'STRUC_APM',
fnName: 'evaluateTransactionsAgainstDynamicRules',
subjects: ['businessId'],
subjects: ['counterpartyId'],
options: {
havingAggregate: AggregateType.COUNT,
groupBy: ['counterpartyBeneficiaryId'],

direction: 'inbound',
// TODO: add excludedCounterparty
// excludedCounterparty: ['9999999999999999', '999999******9999'],
direction: TransactionDirection.inbound,
excludedCounterparty: {
counterpartyBeneficiaryIds: ['9999999999999999', '999999______9999'],
counterpartyOriginatorIds: [],
},

paymentMethods: [PaymentMethod.credit_card],
excludePaymentMethods: false,
excludePaymentMethods: true,

timeAmount: 7,
timeUnit: TIME_UNITS.days,

amountBetween: { min: 500, max: 1000 },
amountBetween: { min: 500, max: 999 },

amountThreshold: 5,
},
Expand All @@ -154,13 +163,16 @@ export const ALERT_DEFINITIONS = {
inlineRule: {
id: 'HCAI_CC',
fnName: 'evaluateTransactionsAgainstDynamicRules',
subjects: ['businessId', 'counterpartyOriginatorId'],
subjects: ['counterpartyId', 'counterpartyOriginatorId'],
options: {
havingAggregate: AggregateType.SUM,
groupBy: ['counterpartyBeneficiaryId', 'counterpartyOriginatorId'],

direction: 'inbound',
// TODO: add excludedCounterparty
// excludedCounterparty: ['9999999999999999', '999999******9999'],
direction: TransactionDirection.inbound,
excludedCounterparty: {
counterpartyBeneficiaryIds: ['9999999999999999', '999999______9999'],
counterpartyOriginatorIds: [],
},

paymentMethods: [PaymentMethod.credit_card],
excludePaymentMethods: false,
Expand All @@ -179,13 +191,16 @@ export const ALERT_DEFINITIONS = {
inlineRule: {
id: 'HACI_APM',
fnName: 'evaluateTransactionsAgainstDynamicRules',
subjects: ['businessId', 'counterpartyOriginatorId'],
subjects: ['counterpartyId', 'counterpartyOriginatorId'],
options: {
havingAggregate: AggregateType.SUM,
groupBy: ['counterpartyBeneficiaryId', 'counterpartyOriginatorId'],

direction: 'inbound',
// TODO: add excludedCounterparty
// excludedCounterparty: ['9999999999999999', '999999******9999'],
direction: TransactionDirection.inbound,
excludedCounterparty: {
counterpartyBeneficiaryIds: ['9999999999999999', '999999______9999'],
counterpartyOriginatorIds: [],
},

paymentMethods: [PaymentMethod.credit_card],
excludePaymentMethods: true,
Expand All @@ -204,13 +219,16 @@ export const ALERT_DEFINITIONS = {
inlineRule: {
id: 'HVIC_CC',
fnName: 'evaluateTransactionsAgainstDynamicRules',
subjects: ['businessId', 'counterpartyOriginatorId'],
subjects: ['counterpartyId', 'counterpartyOriginatorId'],
options: {
havingAggregate: AggregateType.COUNT,
groupBy: ['counterpartyBeneficiaryId', 'counterpartyOriginatorId'],

direction: 'inbound',
// TODO: add excludedCounterparty
// excludedCounterparty: ['9999999999999999', '999999******9999'],
direction: TransactionDirection.inbound,
excludedCounterparty: {
counterpartyBeneficiaryIds: ['9999999999999999', '999999______9999'],
counterpartyOriginatorIds: [],
},

paymentMethods: [PaymentMethod.credit_card],
excludePaymentMethods: false,
Expand All @@ -222,6 +240,34 @@ export const ALERT_DEFINITIONS = {
},
},
},
HVIC_APM: {
defaultSeverity: AlertSeverity.medium,
description:
'High Velocity - High number of inbound non-traditional payment transactions received from a Counterparty over a set period of time',
inlineRule: {
id: 'HVIC_CC',
fnName: 'evaluateTransactionsAgainstDynamicRules',
subjects: ['counterpartyId', 'counterpartyOriginatorId'],
options: {
havingAggregate: AggregateType.COUNT,
groupBy: ['counterpartyBeneficiaryId', 'counterpartyOriginatorId'],

direction: TransactionDirection.inbound,
excludedCounterparty: {
counterpartyBeneficiaryIds: ['9999999999999999', '999999______9999'],
counterpartyOriginatorIds: [],
},

paymentMethods: [PaymentMethod.credit_card],
excludePaymentMethods: true,

timeAmount: 7,
timeUnit: TIME_UNITS.days,

amountThreshold: 2,
},
},
},
CHVC_C: {
enabled: true,
defaultSeverity: AlertSeverity.medium,
Expand All @@ -244,7 +290,7 @@ export const ALERT_DEFINITIONS = {
},
SHCAC_C: {
enabled: true,
defaultSeverity: AlertSeverity.medium,
defaultSeverity: AlertSeverity.high,
description:
'High Cumulative Amount - Chargeback - High sum of chargebacks over a set period of time',
inlineRule: {
Expand Down Expand Up @@ -283,7 +329,7 @@ export const ALERT_DEFINITIONS = {
},
SHCAR_C: {
enabled: true,
defaultSeverity: AlertSeverity.medium,
defaultSeverity: AlertSeverity.high,
description: 'High Cumulative Amount - Refund - High sum of refunds over a set period of time',
inlineRule: {
id: 'SHCAR_C',
Expand Down
Loading

0 comments on commit 89e49fd

Please sign in to comment.