Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: tm monitoring changes for better investigation #2842

Merged
merged 22 commits into from
Dec 7, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions services/workflows-service/jest.config.cjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
testTimeout: 30000,
modulePathIgnorePatterns: ['<rootDir>/dist/'],
testRegex: '(/__tests__/.*|(\\.|/)(unit|e2e|intg)\\.test)\\.ts$',
moduleNameMapper: {
Expand Down
1 change: 1 addition & 0 deletions services/workflows-service/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
"csv-parse": "^5.5.6",
"dayjs": "^1.11.6",
"deep-diff": "^1.0.2",
"deepmerge": "^4.3.0",
"file-type": "^16.5.4",
"helmet": "^6.0.1",
"i18n-iso-countries": "^7.6.0",
Expand Down
2 changes: 1 addition & 1 deletion services/workflows-service/prisma/data-migrations
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
-- AlterTable
ALTER TABLE "Alert" ADD COLUMN "counterpartyBeneficiaryId" TEXT,
ADD COLUMN "counterpartyOriginatorId" TEXT;

-- CreateIndex
CREATE INDEX "Alert_counterpartyOriginatorId_idx" ON "Alert"("counterpartyOriginatorId");

-- CreateIndex
CREATE INDEX "Alert_counterpartyBeneficiaryId_idx" ON "Alert"("counterpartyBeneficiaryId");

-- AddForeignKey
ALTER TABLE "Alert" ADD CONSTRAINT "Alert_counterpartyOriginatorId_fkey" FOREIGN KEY ("counterpartyOriginatorId") REFERENCES "Counterparty"("id") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "Alert" ADD CONSTRAINT "Alert_counterpartyBeneficiaryId_fkey" FOREIGN KEY ("counterpartyBeneficiaryId") REFERENCES "Counterparty"("id") ON DELETE SET NULL ON UPDATE CASCADE;
12 changes: 12 additions & 0 deletions services/workflows-service/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -834,9 +834,15 @@ model Alert {
workflowRuntimeDataId String?
workflowRuntimeData WorkflowRuntimeData? @relation(fields: [workflowRuntimeDataId], references: [id], onUpdate: Cascade, onDelete: NoAction)

// TODO: Remove this field after data migration
counterpartyId String?
counterparty Counterparty? @relation(fields: [counterpartyId], references: [id])

counterpartyOriginatorId String?
counterpartyBeneficiaryId String?
counterpartyOriginator Counterparty? @relation(name: "counterpartyAlertOriginator", fields: [counterpartyOriginatorId], references: [id])
counterpartyBeneficiary Counterparty? @relation(name: "counterpartyAlertBeneficiary", fields: [counterpartyBeneficiaryId], references: [id])

businessId String?
business Business? @relation(fields: [businessId], references: [id])

Expand All @@ -845,6 +851,9 @@ model Alert {
@@index([alertDefinitionId])
@@index([counterpartyId])
@@index([createdAt(sort: Desc)])

@@index([counterpartyOriginatorId])
@@index([counterpartyBeneficiaryId])
}

enum RiskCategory {
Expand Down Expand Up @@ -888,6 +897,9 @@ model Counterparty {
benefitingTransactions TransactionRecord[] @relation("BenefitingCounterparty")
alerts Alert[]

alertsBenefiting Alert[] @relation("counterpartyAlertBeneficiary")
alertsOriginating Alert[] @relation("counterpartyAlertOriginator")

projectId String
project Project @relation(fields: [projectId], references: [id])

Expand Down
81 changes: 55 additions & 26 deletions services/workflows-service/scripts/alerts/generate-alerts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,21 +44,25 @@ export const ALERT_DEFINITIONS = {
inlineRule: {
id: 'PAY_HCA_CC',
fnName: 'evaluateTransactionsAgainstDynamicRules',
subjects: ['counterpartyId'],
fnInvestigationName: 'investigateTransactionsAgainstDynamicRules',
subjects: ['counterpartyBeneficiaryId'],
options: {
havingAggregate: AggregateType.SUM,
groupBy: ['counterpartyBeneficiaryId'],

direction: TransactionDirection.inbound,

excludedCounterparty: {
counterpartyBeneficiaryIds: ['9999999999999999', '999999______9999'],
counterpartyOriginatorIds: [],
},

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

timeAmount: SEVEN_DAYS,
timeUnit: TIME_UNITS.days,
amountThreshold: 1000,
groupBy: ['counterpartyBeneficiaryId'],
},
},
},
Expand All @@ -70,9 +74,11 @@ export const ALERT_DEFINITIONS = {
inlineRule: {
id: 'PAY_HCA_APM',
fnName: 'evaluateTransactionsAgainstDynamicRules',
subjects: ['counterpartyId'],
fnInvestigationName: 'investigateTransactionsAgainstDynamicRules',
subjects: ['counterpartyBeneficiaryId'],
options: {
havingAggregate: AggregateType.SUM,
groupBy: ['counterpartyBeneficiaryId'],

direction: TransactionDirection.inbound,

Expand All @@ -88,8 +94,6 @@ export const ALERT_DEFINITIONS = {
timeUnit: TIME_UNITS.days,

amountThreshold: 1000,

groupBy: ['counterpartyBeneficiaryId'],
},
},
},
Expand All @@ -101,12 +105,14 @@ export const ALERT_DEFINITIONS = {
inlineRule: {
id: 'STRUC_CC',
fnName: 'evaluateTransactionsAgainstDynamicRules',
subjects: ['counterpartyId'],
fnInvestigationName: 'investigateTransactionsAgainstDynamicRules',
subjects: ['counterpartyBeneficiaryId'],
options: {
havingAggregate: AggregateType.COUNT,
groupBy: ['counterpartyBeneficiaryId'],

direction: TransactionDirection.inbound,

excludedCounterparty: {
counterpartyBeneficiaryIds: ['9999999999999999', '999999______9999'],
counterpartyOriginatorIds: [],
Expand All @@ -131,7 +137,8 @@ export const ALERT_DEFINITIONS = {
inlineRule: {
id: 'STRUC_APM',
fnName: 'evaluateTransactionsAgainstDynamicRules',
subjects: ['counterpartyId'],
fnInvestigationName: 'investigateTransactionsAgainstDynamicRules',
subjects: ['counterpartyBeneficiaryId'],
options: {
havingAggregate: AggregateType.COUNT,
groupBy: ['counterpartyBeneficiaryId'],
Expand Down Expand Up @@ -159,12 +166,14 @@ export const ALERT_DEFINITIONS = {
inlineRule: {
id: 'HCAI_CC',
fnName: 'evaluateTransactionsAgainstDynamicRules',
subjects: ['counterpartyId', 'counterpartyOriginatorId'],
fnInvestigationName: 'investigateTransactionsAgainstDynamicRules',
subjects: ['counterpartyBeneficiaryId', 'counterpartyOriginatorId'],
options: {
havingAggregate: AggregateType.SUM,
groupBy: ['counterpartyBeneficiaryId', 'counterpartyOriginatorId'],

direction: TransactionDirection.inbound,

excludedCounterparty: {
counterpartyBeneficiaryIds: ['9999999999999999', '999999______9999'],
counterpartyOriginatorIds: [],
Expand All @@ -188,7 +197,8 @@ export const ALERT_DEFINITIONS = {
inlineRule: {
id: 'HACI_APM',
fnName: 'evaluateTransactionsAgainstDynamicRules',
subjects: ['counterpartyId', 'counterpartyOriginatorId'],
fnInvestigationName: 'investigateTransactionsAgainstDynamicRules',
subjects: ['counterpartyBeneficiaryId', 'counterpartyOriginatorId'],
options: {
havingAggregate: AggregateType.SUM,
groupBy: ['counterpartyBeneficiaryId', 'counterpartyOriginatorId'],
Expand Down Expand Up @@ -217,7 +227,8 @@ export const ALERT_DEFINITIONS = {
inlineRule: {
id: 'HVIC_CC',
fnName: 'evaluateTransactionsAgainstDynamicRules',
subjects: ['counterpartyId', 'counterpartyOriginatorId'],
fnInvestigationName: 'investigateTransactionsAgainstDynamicRules',
subjects: ['counterpartyBeneficiaryId', 'counterpartyOriginatorId'],
options: {
havingAggregate: AggregateType.COUNT,
groupBy: ['counterpartyBeneficiaryId', 'counterpartyOriginatorId'],
Expand Down Expand Up @@ -246,7 +257,8 @@ export const ALERT_DEFINITIONS = {
inlineRule: {
id: 'HVIC_CC',
fnName: 'evaluateTransactionsAgainstDynamicRules',
subjects: ['counterpartyId', 'counterpartyOriginatorId'],
fnInvestigationName: 'investigateTransactionsAgainstDynamicRules',
subjects: ['counterpartyBeneficiaryId', 'counterpartyOriginatorId'],
options: {
havingAggregate: AggregateType.COUNT,
groupBy: ['counterpartyBeneficiaryId', 'counterpartyOriginatorId'],
Expand Down Expand Up @@ -275,7 +287,8 @@ export const ALERT_DEFINITIONS = {
inlineRule: {
id: 'CHVC_C',
fnName: 'evaluateTransactionsAgainstDynamicRules',
subjects: ['counterpartyId'],
fnInvestigationName: 'investigateTransactionsAgainstDynamicRules',
subjects: ['counterpartyOriginatorId'],
options: {
transactionType: [TransactionRecordType.chargeback],
paymentMethods: [PaymentMethod.credit_card],
Expand All @@ -297,7 +310,8 @@ export const ALERT_DEFINITIONS = {
inlineRule: {
id: 'SHCAC_C',
fnName: 'evaluateTransactionsAgainstDynamicRules',
subjects: ['counterpartyId'],
fnInvestigationName: 'investigateTransactionsAgainstDynamicRules',
subjects: ['counterpartyOriginatorId'],
options: {
transactionType: [TransactionRecordType.chargeback],
paymentMethods: [PaymentMethod.credit_card],
Expand All @@ -319,7 +333,8 @@ export const ALERT_DEFINITIONS = {
inlineRule: {
id: 'CHCR_C',
fnName: 'evaluateTransactionsAgainstDynamicRules',
subjects: ['counterpartyId'],
fnInvestigationName: 'investigateTransactionsAgainstDynamicRules',
subjects: ['counterpartyOriginatorId'],
options: {
transactionType: [TransactionRecordType.refund],
paymentMethods: [PaymentMethod.credit_card],
Expand All @@ -341,7 +356,8 @@ export const ALERT_DEFINITIONS = {
inlineRule: {
id: 'SHCAR_C',
fnName: 'evaluateTransactionsAgainstDynamicRules',
subjects: ['counterpartyId'],
fnInvestigationName: 'investigateTransactionsAgainstDynamicRules',
subjects: ['counterpartyOriginatorId'],
options: {
transactionType: [TransactionRecordType.refund],
paymentMethods: [PaymentMethod.credit_card],
Expand All @@ -366,7 +382,8 @@ export const ALERT_DEFINITIONS = {
inlineRule: {
id: 'HPC',
fnName: 'evaluateHighTransactionTypePercentage',
subjects: ['counterpartyId'],
fnInvestigationName: undefined,
subjects: ['counterpartyOriginatorId'],
options: {
transactionType: TransactionRecordType.chargeback,
subjectColumn: 'counterpartyOriginatorId',
Expand All @@ -384,7 +401,7 @@ export const ALERT_DEFINITIONS = {
inlineRule: {
id: 'TLHAICC',
fnName: 'evaluateTransactionAvg',
subjects: ['counterpartyId'],
subjects: ['counterpartyBeneficiaryId'],
options: {
transactionDirection: TransactionDirection.inbound,
minimumCount: 2,
Expand All @@ -407,7 +424,7 @@ export const ALERT_DEFINITIONS = {
inlineRule: {
id: 'TLHAIAPM',
fnName: 'evaluateTransactionAvg',
subjects: ['counterpartyId'],
subjects: ['counterpartyBeneficiaryId'],
options: {
transactionDirection: TransactionDirection.inbound,
minimumCount: 2,
Expand All @@ -430,7 +447,7 @@ export const ALERT_DEFINITIONS = {
inlineRule: {
id: 'PGAICT',
fnName: 'evaluateTransactionAvg',
subjects: ['counterpartyId'],
subjects: ['counterpartyBeneficiaryId'],
options: {
transactionDirection: TransactionDirection.inbound,
minimumCount: 2,
Expand All @@ -454,7 +471,7 @@ export const ALERT_DEFINITIONS = {
inlineRule: {
id: 'PGAIAPM',
fnName: 'evaluateTransactionAvg',
subjects: ['counterpartyId'],
subjects: ['counterpartyBeneficiaryId'],
options: {
transactionDirection: TransactionDirection.inbound,
minimumCount: 2,
Expand Down Expand Up @@ -518,11 +535,11 @@ export const ALERT_DEFINITIONS = {
inlineRule: {
id: 'HVHAI_APM',
fnName: 'evaluateHighVelocityHistoricAverage',
subjects: ['counterpartyId'],
subjects: ['counterpartyBeneficiaryId'],
options: {
transactionDirection: TransactionDirection.inbound,
minimumCount: 3,
transactionFactor: 2,
transactionDirection: TransactionDirection.inbound,
paymentMethod: {
value: PaymentMethod.credit_card,
operator: '!=',
Expand Down Expand Up @@ -622,7 +639,8 @@ export const ALERT_DEFINITIONS = {
inlineRule: {
id: 'DSTA_CC',
fnName: 'evaluateDailySingleTransactionAmount',
subjects: ['counterpartyId'],
fnInvestigationName: 'investigateDailySingleTransactionAmount',
subjects: ['counterpartyBeneficiaryId'],
options: {
ruleType: 'amount',

Expand All @@ -635,6 +653,8 @@ export const ALERT_DEFINITIONS = {

timeAmount: 1,
timeUnit: TIME_UNITS.days,

subjectColumn: 'counterpartyBeneficiaryId',
},
},
},
Expand All @@ -645,7 +665,8 @@ export const ALERT_DEFINITIONS = {
inlineRule: {
id: 'DSTA_APM',
fnName: 'evaluateDailySingleTransactionAmount',
subjects: ['counterpartyId'],
fnInvestigationName: 'investigateDailySingleTransactionAmount',
subjects: ['counterpartyBeneficiaryId'],
options: {
ruleType: 'amount',

Expand All @@ -658,6 +679,8 @@ export const ALERT_DEFINITIONS = {

timeAmount: 1,
timeUnit: TIME_UNITS.days,

subjectColumn: 'counterpartyBeneficiaryId',
},
},
},
Expand All @@ -668,7 +691,8 @@ export const ALERT_DEFINITIONS = {
inlineRule: {
id: 'DMT_CC',
fnName: 'evaluateDailySingleTransactionAmount',
subjects: ['counterpartyId'],
fnInvestigationName: 'investigateDailySingleTransactionAmount',
subjects: ['counterpartyBeneficiaryId'],
options: {
ruleType: 'count',

Expand All @@ -681,6 +705,8 @@ export const ALERT_DEFINITIONS = {

timeAmount: 1,
timeUnit: TIME_UNITS.days,

subjectColumn: 'counterpartyBeneficiaryId',
},
},
},
Expand All @@ -691,7 +717,8 @@ export const ALERT_DEFINITIONS = {
inlineRule: {
id: 'DMT_APM',
fnName: 'evaluateDailySingleTransactionAmount',
subjects: ['counterpartyId'],
fnInvestigationName: 'investigateDailySingleTransactionAmount',
subjects: ['counterpartyBeneficiaryId'],
options: {
ruleType: 'count',

Expand All @@ -704,6 +731,8 @@ export const ALERT_DEFINITIONS = {

timeAmount: 1,
timeUnit: TIME_UNITS.days,

subjectColumn: 'counterpartyBeneficiaryId',
},
},
},
Expand Down
Loading
Loading