@swan-io/shared-business 18.3.0 → 18.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +3 -3
- package/src/components/FraudReport/FraudReportLayout.d.ts +23 -0
- package/src/components/FraudReport/FraudReportLayout.js +35 -0
- package/src/components/FraudReport/IncidentStep.d.ts +7 -0
- package/src/components/FraudReport/IncidentStep.js +55 -0
- package/src/components/FraudReport/IntroStep.d.ts +5 -0
- package/src/components/FraudReport/IntroStep.js +28 -0
- package/src/components/FraudReport/TransactionsStep.d.ts +16 -0
- package/src/components/FraudReport/TransactionsStep.js +138 -0
- package/src/components/FraudReport/VictimStep.d.ts +9 -0
- package/src/components/FraudReport/VictimStep.js +55 -0
- package/src/components/InlineDatePicker.js +7 -6
- package/src/constants/__tests__/countries.test.js +32 -1
- package/src/constants/countries.d.ts +2 -1
- package/src/constants/countries.js +36 -2
- package/src/hooks/__tests__/useFraudReportFlow.test.d.ts +1 -0
- package/src/hooks/__tests__/useFraudReportFlow.test.js +979 -0
- package/src/hooks/useFraudReportFlow.d.ts +32 -0
- package/src/hooks/useFraudReportFlow.js +260 -0
- package/src/locales/de.json +76 -0
- package/src/locales/en.json +76 -0
- package/src/locales/es.json +76 -0
- package/src/locales/fi.json +76 -0
- package/src/locales/fr.json +76 -0
- package/src/locales/it.json +76 -0
- package/src/locales/nl.json +76 -0
- package/src/locales/pt.json +76 -0
- package/src/utils/__tests__/fraudReport.fakeApi.test.js +42 -13
- package/src/utils/__tests__/fraudReport.prefill.test.d.ts +1 -0
- package/src/utils/__tests__/fraudReport.prefill.test.js +149 -0
- package/src/utils/__tests__/fraudReport.rejections.test.d.ts +1 -0
- package/src/utils/__tests__/fraudReport.rejections.test.js +163 -0
- package/src/utils/__tests__/fraudReport.resume.test.d.ts +1 -0
- package/src/utils/__tests__/fraudReport.resume.test.js +67 -0
- package/src/utils/__tests__/fraudReport.stepper.test.d.ts +1 -0
- package/src/utils/__tests__/fraudReport.stepper.test.js +102 -0
- package/src/utils/__tests__/fraudReport.toInput.test.d.ts +1 -0
- package/src/utils/__tests__/fraudReport.toInput.test.js +549 -0
- package/src/utils/__tests__/fraudReport.transactions.test.d.ts +1 -0
- package/src/utils/__tests__/fraudReport.transactions.test.js +28 -0
- package/src/utils/__tests__/fraudReport.types.test.d.ts +1 -0
- package/src/utils/__tests__/fraudReport.types.test.js +22 -0
- package/src/utils/__tests__/fraudReport.victim.test.d.ts +1 -0
- package/src/utils/__tests__/fraudReport.victim.test.js +142 -0
- package/src/utils/__tests__/phone.test.js +60 -5
- package/src/utils/fraudReport/fakeApi.d.ts +7 -4
- package/src/utils/fraudReport/fakeApi.js +18 -5
- package/src/utils/fraudReport/prefill.d.ts +3 -0
- package/src/utils/fraudReport/prefill.js +14 -0
- package/src/utils/fraudReport/rail.d.ts +5 -0
- package/src/utils/fraudReport/rail.js +14 -0
- package/src/utils/fraudReport/rejections.d.ts +10 -0
- package/src/utils/fraudReport/rejections.js +53 -0
- package/src/utils/fraudReport/resume.d.ts +4 -0
- package/src/utils/fraudReport/resume.js +26 -0
- package/src/utils/fraudReport/stepper.d.ts +16 -0
- package/src/utils/fraudReport/stepper.js +21 -0
- package/src/utils/fraudReport/toInput.d.ts +30 -0
- package/src/utils/fraudReport/toInput.js +82 -0
- package/src/utils/fraudReport/transactions.d.ts +6 -0
- package/src/utils/fraudReport/transactions.js +7 -0
- package/src/utils/fraudReport/types.d.ts +8 -0
- package/src/utils/fraudReport/validation.d.ts +15 -0
- package/src/utils/fraudReport/validation.js +55 -0
- package/src/utils/fraudReport/victim.d.ts +30 -0
- package/src/utils/fraudReport/victim.js +28 -0
- package/src/utils/phone.d.ts +1 -0
- package/src/utils/phone.js +31 -4
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import { Option } from "@bloodyowl/boxed";
|
|
2
|
+
import { describe, expect, test } from "vitest";
|
|
3
|
+
import { getInitialVictimChoice, getOtherAccountMemberships, getSelectedAccountMembershipId, getVictimAccountMembershipId, } from "../fraudReport/victim";
|
|
4
|
+
const julia = { id: "member-1", name: "Julia Fox" };
|
|
5
|
+
const nicolas = { id: "member-2", name: "Nicolas Saison" };
|
|
6
|
+
const ada = { id: "member-3", name: "Ada Lovelace" };
|
|
7
|
+
const accountMemberships = [julia, nicolas, ada];
|
|
8
|
+
const asMember = Option.Some(julia);
|
|
9
|
+
const asOperator = Option.None();
|
|
10
|
+
const choiceOf = (answer, selectedId) => ({
|
|
11
|
+
answer: Option.fromUndefined(answer),
|
|
12
|
+
selectedId: Option.fromUndefined(selectedId),
|
|
13
|
+
});
|
|
14
|
+
describe("getOtherAccountMemberships", () => {
|
|
15
|
+
test("leaves the current member out of the picker", () => {
|
|
16
|
+
expect(getOtherAccountMemberships({ currentAccountMembership: asMember, accountMemberships })).toEqual([nicolas, ada]);
|
|
17
|
+
});
|
|
18
|
+
test("lists every member for an operator", () => {
|
|
19
|
+
expect(getOtherAccountMemberships({ currentAccountMembership: asOperator, accountMemberships })).toEqual(accountMemberships);
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
describe("getInitialVictimChoice", () => {
|
|
23
|
+
test.each([
|
|
24
|
+
{
|
|
25
|
+
name: "nothing chosen yet",
|
|
26
|
+
victimAccountMembershipId: undefined,
|
|
27
|
+
answer: undefined,
|
|
28
|
+
victim: undefined,
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
name: "the member themselves",
|
|
32
|
+
victimAccountMembershipId: "member-1",
|
|
33
|
+
answer: "Myself",
|
|
34
|
+
victim: "member-1",
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
name: "another member",
|
|
38
|
+
victimAccountMembershipId: "member-2",
|
|
39
|
+
answer: "SomeoneElse",
|
|
40
|
+
victim: "member-2",
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
name: "a member no longer listed",
|
|
44
|
+
victimAccountMembershipId: "member-9",
|
|
45
|
+
answer: "SomeoneElse",
|
|
46
|
+
victim: undefined,
|
|
47
|
+
},
|
|
48
|
+
])("gives back $name when a member comes back", ({ victimAccountMembershipId, answer, victim }) => {
|
|
49
|
+
const choice = getInitialVictimChoice({
|
|
50
|
+
currentAccountMembership: asMember,
|
|
51
|
+
victimAccountMembershipId,
|
|
52
|
+
});
|
|
53
|
+
expect(choice.answer.toUndefined()).toBe(answer);
|
|
54
|
+
expect(getVictimAccountMembershipId({
|
|
55
|
+
currentAccountMembership: asMember,
|
|
56
|
+
accountMemberships,
|
|
57
|
+
choice,
|
|
58
|
+
}).toUndefined()).toBe(victim);
|
|
59
|
+
});
|
|
60
|
+
test.each([
|
|
61
|
+
{ name: "nothing chosen yet", victimAccountMembershipId: undefined, victim: undefined },
|
|
62
|
+
{ name: "a listed member", victimAccountMembershipId: "member-1", victim: "member-1" },
|
|
63
|
+
{ name: "a member no longer listed", victimAccountMembershipId: "member-9", victim: undefined },
|
|
64
|
+
])("gives back $name when an operator comes back, with no answer", ({ victimAccountMembershipId, victim }) => {
|
|
65
|
+
const choice = getInitialVictimChoice({
|
|
66
|
+
currentAccountMembership: asOperator,
|
|
67
|
+
victimAccountMembershipId,
|
|
68
|
+
});
|
|
69
|
+
expect(choice.answer.isNone()).toBe(true);
|
|
70
|
+
expect(getVictimAccountMembershipId({
|
|
71
|
+
currentAccountMembership: asOperator,
|
|
72
|
+
accountMemberships,
|
|
73
|
+
choice,
|
|
74
|
+
}).toUndefined()).toBe(victim);
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
describe("getSelectedAccountMembershipId", () => {
|
|
78
|
+
test.each([
|
|
79
|
+
{ name: "another listed member", selectedId: "member-2", shown: "member-2" },
|
|
80
|
+
{ name: "the member themselves", selectedId: "member-1", shown: undefined },
|
|
81
|
+
])("shows $name in a member's picker", ({ selectedId, shown }) => {
|
|
82
|
+
expect(getSelectedAccountMembershipId({
|
|
83
|
+
currentAccountMembership: asMember,
|
|
84
|
+
accountMemberships,
|
|
85
|
+
choice: choiceOf("SomeoneElse", selectedId),
|
|
86
|
+
}).toUndefined()).toBe(shown);
|
|
87
|
+
});
|
|
88
|
+
test("drops a pick once the member leaves the list", () => {
|
|
89
|
+
const choice = choiceOf("SomeoneElse", "member-2");
|
|
90
|
+
expect(getSelectedAccountMembershipId({
|
|
91
|
+
currentAccountMembership: asMember,
|
|
92
|
+
accountMemberships,
|
|
93
|
+
choice,
|
|
94
|
+
}).toUndefined()).toBe("member-2");
|
|
95
|
+
expect(getSelectedAccountMembershipId({
|
|
96
|
+
currentAccountMembership: asMember,
|
|
97
|
+
accountMemberships: [julia, ada],
|
|
98
|
+
choice,
|
|
99
|
+
}).toUndefined()).toBeUndefined();
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
describe("getVictimAccountMembershipId", () => {
|
|
103
|
+
test.each([
|
|
104
|
+
{ name: "no answer", answer: undefined, selectedId: "member-2", victim: undefined },
|
|
105
|
+
{ name: "Myself", answer: "Myself", selectedId: "member-2", victim: "member-1" },
|
|
106
|
+
{
|
|
107
|
+
name: "SomeoneElse with a member picked",
|
|
108
|
+
answer: "SomeoneElse",
|
|
109
|
+
selectedId: "member-2",
|
|
110
|
+
victim: "member-2",
|
|
111
|
+
},
|
|
112
|
+
{
|
|
113
|
+
name: "SomeoneElse with no member picked",
|
|
114
|
+
answer: "SomeoneElse",
|
|
115
|
+
selectedId: undefined,
|
|
116
|
+
victim: undefined,
|
|
117
|
+
},
|
|
118
|
+
{
|
|
119
|
+
name: "SomeoneElse with a member no longer listed",
|
|
120
|
+
answer: "SomeoneElse",
|
|
121
|
+
selectedId: "member-9",
|
|
122
|
+
victim: undefined,
|
|
123
|
+
},
|
|
124
|
+
])("gives the victim for a member answering $name", ({ answer, selectedId, victim }) => {
|
|
125
|
+
expect(getVictimAccountMembershipId({
|
|
126
|
+
currentAccountMembership: asMember,
|
|
127
|
+
accountMemberships,
|
|
128
|
+
choice: choiceOf(answer, selectedId),
|
|
129
|
+
}).toUndefined()).toBe(victim);
|
|
130
|
+
});
|
|
131
|
+
test.each([
|
|
132
|
+
{ name: "a member picked", selectedId: "member-2", victim: "member-2" },
|
|
133
|
+
{ name: "no member picked", selectedId: undefined, victim: undefined },
|
|
134
|
+
{ name: "a member no longer listed", selectedId: "member-9", victim: undefined },
|
|
135
|
+
])("gives the victim for an operator with $name", ({ selectedId, victim }) => {
|
|
136
|
+
expect(getVictimAccountMembershipId({
|
|
137
|
+
currentAccountMembership: asOperator,
|
|
138
|
+
accountMemberships,
|
|
139
|
+
choice: choiceOf(undefined, selectedId),
|
|
140
|
+
}).toUndefined()).toBe(victim);
|
|
141
|
+
});
|
|
142
|
+
});
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
1
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
2
2
|
import { france, getCountryByCCA2, getCountryByCCA3 } from "../../constants/countries";
|
|
3
|
-
import {
|
|
4
|
-
import { maskPhoneNumber, parsePhoneNumber, prefixPhoneNumber } from "../phone";
|
|
3
|
+
import { getDefaultPhoneCountry, maskPhoneNumber, parsePhoneNumber, prefixPhoneNumber, } from "../phone";
|
|
5
4
|
const gambia = getCountryByCCA2("GM");
|
|
6
5
|
const jamaica = getCountryByCCA2("JM");
|
|
7
6
|
const curacao = getCountryByCCA2("CW");
|
|
@@ -51,8 +50,11 @@ describe("parsePhoneNumber splits an international number into its country and n
|
|
|
51
50
|
});
|
|
52
51
|
});
|
|
53
52
|
});
|
|
54
|
-
describe("parsePhoneNumber falls back to the
|
|
55
|
-
const fallback = { country:
|
|
53
|
+
describe("parsePhoneNumber falls back to the default phone country and an empty national number", () => {
|
|
54
|
+
const fallback = { country: france, nationalNumber: "" };
|
|
55
|
+
beforeEach(() => {
|
|
56
|
+
vi.stubGlobal("navigator", { languages: ["en-GB"] });
|
|
57
|
+
});
|
|
56
58
|
afterEach(() => {
|
|
57
59
|
vi.unstubAllGlobals();
|
|
58
60
|
});
|
|
@@ -88,6 +90,59 @@ describe("parsePhoneNumber falls back to the most likely user country and an emp
|
|
|
88
90
|
});
|
|
89
91
|
});
|
|
90
92
|
});
|
|
93
|
+
describe("getDefaultPhoneCountry picks one of our markets from the browser languages", () => {
|
|
94
|
+
const germany = getCountryByCCA2("DE");
|
|
95
|
+
const belgium = getCountryByCCA2("BE");
|
|
96
|
+
afterEach(() => {
|
|
97
|
+
vi.unstubAllGlobals();
|
|
98
|
+
});
|
|
99
|
+
it.each([[["en"]], [["en-GB"]], [["en-US"]], [["ja-JP"]], [[]]])("falls back to France for %j", languages => {
|
|
100
|
+
expect(getDefaultPhoneCountry(languages)).toEqual(france);
|
|
101
|
+
});
|
|
102
|
+
it.each([
|
|
103
|
+
["fr", "FR"],
|
|
104
|
+
["de", "DE"],
|
|
105
|
+
["es", "ES"],
|
|
106
|
+
["it", "IT"],
|
|
107
|
+
["nl", "NL"],
|
|
108
|
+
["pt", "PT"],
|
|
109
|
+
])("maps the %s language to its country", (language, cca2) => {
|
|
110
|
+
expect(getDefaultPhoneCountry([language])).toEqual(getCountryByCCA2(cca2));
|
|
111
|
+
});
|
|
112
|
+
it.each([
|
|
113
|
+
["nl-BE", "BE"],
|
|
114
|
+
["fr-BE", "BE"],
|
|
115
|
+
["en-BE", "BE"],
|
|
116
|
+
["en-DE", "DE"],
|
|
117
|
+
["es-PT", "PT"],
|
|
118
|
+
])("uses the region of %s when it is one of our markets", (language, cca2) => {
|
|
119
|
+
expect(getDefaultPhoneCountry([language])).toEqual(getCountryByCCA2(cca2));
|
|
120
|
+
});
|
|
121
|
+
it.each([
|
|
122
|
+
["de-AT", "DE"],
|
|
123
|
+
["fr-CA", "FR"],
|
|
124
|
+
["pt-BR", "PT"],
|
|
125
|
+
])("uses the language of %s when its region isn't one of our markets", (language, cca2) => {
|
|
126
|
+
expect(getDefaultPhoneCountry([language])).toEqual(getCountryByCCA2(cca2));
|
|
127
|
+
});
|
|
128
|
+
it("keeps the browser's order of preference", () => {
|
|
129
|
+
expect(getDefaultPhoneCountry(["de-DE", "fr-FR"])).toEqual(germany);
|
|
130
|
+
expect(getDefaultPhoneCountry(["de", "nl-BE"])).toEqual(germany);
|
|
131
|
+
});
|
|
132
|
+
it("skips languages that don't match one of our markets", () => {
|
|
133
|
+
expect(getDefaultPhoneCountry(["en-US", "nl-BE"])).toEqual(belgium);
|
|
134
|
+
});
|
|
135
|
+
it("matches the language and region case-insensitively", () => {
|
|
136
|
+
expect(getDefaultPhoneCountry(["NL-be"])).toEqual(belgium);
|
|
137
|
+
});
|
|
138
|
+
it("skips invalid language tags", () => {
|
|
139
|
+
expect(getDefaultPhoneCountry(["not a tag", "de"])).toEqual(germany);
|
|
140
|
+
});
|
|
141
|
+
it("reads the browser languages by default", () => {
|
|
142
|
+
vi.stubGlobal("navigator", { languages: ["it-IT"] });
|
|
143
|
+
expect(getDefaultPhoneCountry()).toEqual(getCountryByCCA2("IT"));
|
|
144
|
+
});
|
|
145
|
+
});
|
|
91
146
|
describe("prefixPhoneNumber turns a national number into an E.164 number", () => {
|
|
92
147
|
it("prefixes a French national number", () => {
|
|
93
148
|
expect(prefixPhoneNumber(france, "612345678")).toEqual({
|
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
import type { FraudReportApi } from "./api";
|
|
2
|
-
import type { DisputeCaseTransactionNotReportableReason, FraudReportCase } from "./types";
|
|
2
|
+
import type { DisputeCaseTransactionNotReportableReason, FraudReportCase, FraudReportTransaction, FraudReportTransactionType } from "./types";
|
|
3
|
+
type FakeTransactionDetails = Partial<Pick<FraudReportTransaction, "executionDate" | "counterparty" | "amount">>;
|
|
3
4
|
export type FakeTransaction = {
|
|
4
5
|
id: string;
|
|
5
6
|
accountId: string;
|
|
6
7
|
notReportableReason?: DisputeCaseTransactionNotReportableReason;
|
|
7
8
|
reportingWindowEndsAt?: string;
|
|
8
|
-
} & ({
|
|
9
|
-
|
|
9
|
+
} & FakeTransactionDetails & ({
|
|
10
|
+
type: "CardOutDebit";
|
|
10
11
|
cardholderAccountMembershipId: string;
|
|
11
12
|
} | {
|
|
12
|
-
|
|
13
|
+
type: Exclude<FraudReportTransactionType, "CardOutDebit">;
|
|
13
14
|
});
|
|
15
|
+
export declare const createFakeTransaction: (id: string, type: FraudReportTransactionType, details?: FakeTransactionDetails) => FraudReportTransaction;
|
|
14
16
|
export type FakeAccountMembership = {
|
|
15
17
|
id: string;
|
|
16
18
|
accountId: string;
|
|
@@ -27,3 +29,4 @@ export type FakeFraudReportApiConfig = {
|
|
|
27
29
|
now?: () => Date;
|
|
28
30
|
};
|
|
29
31
|
export declare const createFakeFraudReportApi: (config: FakeFraudReportApiConfig) => FraudReportApi;
|
|
32
|
+
export {};
|
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
import { Future, Option, Result } from "@bloodyowl/boxed";
|
|
2
2
|
import { match } from "ts-pattern";
|
|
3
|
+
const getRail = (type) => match(type)
|
|
4
|
+
.returnType()
|
|
5
|
+
.with("CardOutDebit", () => "Card")
|
|
6
|
+
.with("SepaCreditTransferOut", "SepaInstantCreditTransferOut", "InternationalCreditTransferOut", "InternalCreditTransferOut", () => "Transfer")
|
|
7
|
+
.exhaustive();
|
|
8
|
+
export const createFakeTransaction = (id, type, details = {}) => { var _a, _b, _c; return ({
|
|
9
|
+
id,
|
|
10
|
+
rail: getRail(type),
|
|
11
|
+
type,
|
|
12
|
+
executionDate: (_a = details.executionDate) !== null && _a !== void 0 ? _a : "2026-11-04T10:00:00.000Z",
|
|
13
|
+
counterparty: (_b = details.counterparty) !== null && _b !== void 0 ? _b : `Merchant ${id}`,
|
|
14
|
+
amount: (_c = details.amount) !== null && _c !== void 0 ? _c : { value: "10.00", currency: "EUR" },
|
|
15
|
+
}); };
|
|
3
16
|
const MAX_TRANSACTIONS = 100;
|
|
4
17
|
const DRAFT_LIFETIME_MS = 30 * 24 * 60 * 60 * 1000;
|
|
5
18
|
const isDefined = (value) => value !== undefined;
|
|
@@ -45,7 +58,7 @@ export const createFakeFraudReportApi = (config) => {
|
|
|
45
58
|
const findTransaction = (id) => config.transactions.find(item => item.id === id);
|
|
46
59
|
const getTransactions = (ids) => ids.map(findTransaction).filter(isDefined);
|
|
47
60
|
const getIds = (item) => item.transactions.map(({ id }) => id);
|
|
48
|
-
const getCardholder = (ids) => { var _a; var _b; return (_b = (_a = getTransactions(ids).flatMap(item => (item.
|
|
61
|
+
const getCardholder = (ids) => { var _a; var _b; return (_b = (_a = getTransactions(ids).flatMap(item => (item.type === "CardOutDebit" ? [item] : []))[0]) === null || _a === void 0 ? void 0 : _a.cardholderAccountMembershipId) !== null && _b !== void 0 ? _b : null; };
|
|
49
62
|
const cases = new Map(((_c = config.cases) !== null && _c !== void 0 ? _c : []).map(item => [
|
|
50
63
|
item.id,
|
|
51
64
|
{
|
|
@@ -113,7 +126,7 @@ export const createFakeFraudReportApi = (config) => {
|
|
|
113
126
|
: Option.None();
|
|
114
127
|
};
|
|
115
128
|
const checkSingleCardholder = (ids) => {
|
|
116
|
-
const accountMembershipIds = unique(getTransactions(ids).flatMap(item => item.
|
|
129
|
+
const accountMembershipIds = unique(getTransactions(ids).flatMap(item => item.type === "CardOutDebit" ? [item.cardholderAccountMembershipId] : []));
|
|
117
130
|
return accountMembershipIds.length > 1
|
|
118
131
|
? Option.Some({
|
|
119
132
|
__typename: "DisputeCaseMultipleCardHoldersRejection",
|
|
@@ -154,8 +167,8 @@ export const createFakeFraudReportApi = (config) => {
|
|
|
154
167
|
var _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
|
|
155
168
|
const transactionIds = (_b = input.transactionIds) !== null && _b !== void 0 ? _b : (existing != null ? getIds(existing) : []);
|
|
156
169
|
const transactions = getTransactions(transactionIds);
|
|
157
|
-
const hasCard = transactions.some(item => item.
|
|
158
|
-
const hasTransfer = transactions.some(item => item.
|
|
170
|
+
const hasCard = transactions.some(item => getRail(item.type) === "Card");
|
|
171
|
+
const hasTransfer = transactions.some(item => getRail(item.type) === "Transfer");
|
|
159
172
|
const accountId = (_d = (_c = (_a = transactions[0]) === null || _a === void 0 ? void 0 : _a.accountId) !== null && _c !== void 0 ? _c : existing === null || existing === void 0 ? void 0 : existing.accountId) !== null && _d !== void 0 ? _d : "";
|
|
160
173
|
const sentVictim = input.victimAccountMembershipId;
|
|
161
174
|
const checkLimit = () => input.transactionIds != null && input.transactionIds.length > MAX_TRANSACTIONS
|
|
@@ -219,7 +232,7 @@ export const createFakeFraudReportApi = (config) => {
|
|
|
219
232
|
id: (_e = existing === null || existing === void 0 ? void 0 : existing.id) !== null && _e !== void 0 ? _e : crypto.randomUUID(),
|
|
220
233
|
accountId,
|
|
221
234
|
statusInfo: { status: "Draft", expiresAt: new Date(expiresAt).toISOString() },
|
|
222
|
-
transactions: transactions.map(({ id,
|
|
235
|
+
transactions: transactions.map(({ id, type, executionDate, counterparty, amount }) => createFakeTransaction(id, type, { executionDate, counterparty, amount })),
|
|
223
236
|
fraudDetails: input.fraudDetails === undefined
|
|
224
237
|
? ((_f = existing === null || existing === void 0 ? void 0 : existing.fraudDetails) !== null && _f !== void 0 ? _f : null)
|
|
225
238
|
: input.fraudDetails === null
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { FraudReportFormValues } from "./toInput";
|
|
2
|
+
import type { FraudReportCase } from "./types";
|
|
3
|
+
export declare const toFormValues: ({ transactions, fraudDetails, fraudCardDetails, victimAccountMembershipId, externalReference, }: Pick<FraudReportCase, "transactions" | "fraudDetails" | "fraudCardDetails" | "victimAccountMembershipId" | "externalReference">) => FraudReportFormValues;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export const toFormValues = ({ transactions, fraudDetails, fraudCardDetails, victimAccountMembershipId, externalReference, }) => { var _a, _b, _c, _d; return ({
|
|
2
|
+
transactions,
|
|
3
|
+
victimAccountMembershipId: victimAccountMembershipId !== null && victimAccountMembershipId !== void 0 ? victimAccountMembershipId : undefined,
|
|
4
|
+
reportedReason: fraudDetails === null || fraudDetails === void 0 ? void 0 : fraudDetails.reportedReason,
|
|
5
|
+
reportedTypology: fraudDetails === null || fraudDetails === void 0 ? void 0 : fraudDetails.reportedTypology,
|
|
6
|
+
description: fraudDetails === null || fraudDetails === void 0 ? void 0 : fraudDetails.description,
|
|
7
|
+
discoveredAt: (_a = fraudDetails === null || fraudDetails === void 0 ? void 0 : fraudDetails.discoveredAt) !== null && _a !== void 0 ? _a : undefined,
|
|
8
|
+
discoveryDetails: (_b = fraudDetails === null || fraudDetails === void 0 ? void 0 : fraudDetails.discoveryDetails) !== null && _b !== void 0 ? _b : undefined,
|
|
9
|
+
fraudsterChannels: fraudDetails === null || fraudDetails === void 0 ? void 0 : fraudDetails.fraudsterChannels,
|
|
10
|
+
sharedInformationWithFraudster: fraudDetails === null || fraudDetails === void 0 ? void 0 : fraudDetails.sharedInformationWithFraudster,
|
|
11
|
+
isLostOrStolen: (_c = fraudCardDetails === null || fraudCardDetails === void 0 ? void 0 : fraudCardDetails.isLostOrStolen) !== null && _c !== void 0 ? _c : undefined,
|
|
12
|
+
lostOrStolenNoticedAt: (_d = fraudCardDetails === null || fraudCardDetails === void 0 ? void 0 : fraudCardDetails.lostOrStolenNoticedAt) !== null && _d !== void 0 ? _d : undefined,
|
|
13
|
+
externalReference: externalReference !== null && externalReference !== void 0 ? externalReference : undefined,
|
|
14
|
+
}); };
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { Option } from "@bloodyowl/boxed";
|
|
2
|
+
import type { FraudReportRail, FraudReportTransaction } from "./types";
|
|
3
|
+
export type FraudReportCaseRail = "CardOnly" | "TransferOnly" | "Mixed";
|
|
4
|
+
export declare const getTransactionRail: (transactionType: string) => Option<FraudReportRail>;
|
|
5
|
+
export declare const getCaseRail: (transactions: Pick<FraudReportTransaction, "rail">[]) => Option<FraudReportCaseRail>;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Option } from "@bloodyowl/boxed";
|
|
2
|
+
import { match } from "ts-pattern";
|
|
3
|
+
export const getTransactionRail = (transactionType) => match(transactionType)
|
|
4
|
+
.with("CardOutDebit", () => Option.Some("Card"))
|
|
5
|
+
.with("SepaCreditTransferOut", "SepaInstantCreditTransferOut", "InternationalCreditTransferOut", "InternalCreditTransferOut", () => Option.Some("Transfer"))
|
|
6
|
+
.otherwise(() => Option.None());
|
|
7
|
+
export const getCaseRail = (transactions) => match({
|
|
8
|
+
hasCard: transactions.some(({ rail }) => rail === "Card"),
|
|
9
|
+
hasTransfer: transactions.some(({ rail }) => rail === "Transfer"),
|
|
10
|
+
})
|
|
11
|
+
.with({ hasCard: true, hasTransfer: true }, () => Option.Some("Mixed"))
|
|
12
|
+
.with({ hasCard: true }, () => Option.Some("CardOnly"))
|
|
13
|
+
.with({ hasTransfer: true }, () => Option.Some("TransferOnly"))
|
|
14
|
+
.otherwise(() => Option.None());
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { FraudReportLayoutStep } from "./stepper";
|
|
2
|
+
import { type FraudReportDetailsStep, type FraudReportRejection } from "./types";
|
|
3
|
+
type FixingStep = Exclude<FraudReportLayoutStep, "Submitted" | "Documents">;
|
|
4
|
+
export type FraudReportRejectionStep = FixingStep | "Submitted" | "Rejected";
|
|
5
|
+
export type FraudReportRejectionContext = {
|
|
6
|
+
hasDraft: boolean;
|
|
7
|
+
detailsSteps: readonly FraudReportDetailsStep[];
|
|
8
|
+
};
|
|
9
|
+
export declare const getRejectionStep: (rejection: FraudReportRejection, context: FraudReportRejectionContext) => FraudReportRejectionStep;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { Array, Option } from "@bloodyowl/boxed";
|
|
2
|
+
import { match, P } from "ts-pattern";
|
|
3
|
+
import { fraudReportDetailsSteps, } from "./types";
|
|
4
|
+
const fixingSteps = [
|
|
5
|
+
"Victim",
|
|
6
|
+
"Transactions",
|
|
7
|
+
"Incident",
|
|
8
|
+
...fraudReportDetailsSteps,
|
|
9
|
+
];
|
|
10
|
+
// Once the draft exists, the flow keeps the victim: going back to Victim can't fix it
|
|
11
|
+
const getVictimStep = ({ hasDraft }) => hasDraft ? Option.None() : Option.Some("Victim");
|
|
12
|
+
// A sub-step missing from the flow is fixed where the choice that adds it is made
|
|
13
|
+
const getDetailsStep = (step, { detailsSteps }) => detailsSteps.includes(step)
|
|
14
|
+
? step
|
|
15
|
+
: match(step)
|
|
16
|
+
.returnType()
|
|
17
|
+
.with("Fraudster", () => "Incident")
|
|
18
|
+
.with("Card", "Transfer", () => "Transactions")
|
|
19
|
+
.exhaustive();
|
|
20
|
+
// Only fields with an input in the form map to a step: going back can't fix the others
|
|
21
|
+
const getFieldStep = ({ path }, context) => match(path)
|
|
22
|
+
.returnType()
|
|
23
|
+
.with(["victimAccountMembershipId"], () => getVictimStep(context))
|
|
24
|
+
.with(["transactionIds"], () => Option.Some("Transactions"))
|
|
25
|
+
.with(["fraudDetails", P.union("fraudsterChannels", "sharedInformationWithFraudster")], () => Option.Some(getDetailsStep("Fraudster", context)))
|
|
26
|
+
.with(["fraudDetails"], [
|
|
27
|
+
"fraudDetails",
|
|
28
|
+
P.union("reportedReason", "reportedTypology", "description", "discoveredAt", "discoveryDetails"),
|
|
29
|
+
], () => Option.Some("Incident"))
|
|
30
|
+
.with(["fraudCardDetails"], ["fraudCardDetails", P.union("isLostOrStolen", "lostOrStolenNoticedAt")], () => Option.Some(getDetailsStep("Card", context)))
|
|
31
|
+
.otherwise(() => Option.None());
|
|
32
|
+
const getEarliestStep = (fields, context) => {
|
|
33
|
+
var _a;
|
|
34
|
+
const steps = Array.filterMap(fields, field => getFieldStep(field, context));
|
|
35
|
+
return (_a = fixingSteps.find(step => steps.includes(step))) !== null && _a !== void 0 ? _a : "Rejected";
|
|
36
|
+
};
|
|
37
|
+
export const getRejectionStep = (rejection, context) => match(rejection)
|
|
38
|
+
.returnType()
|
|
39
|
+
.with({ __typename: "AccountMembershipNotFoundRejection" }, () => getVictimStep(context)
|
|
40
|
+
.map((step) => step)
|
|
41
|
+
.getOr("Rejected"))
|
|
42
|
+
.with({
|
|
43
|
+
__typename: P.union("DisputeCaseTransactionsNotFoundRejection", "DisputeCaseTransactionsNotReportableRejection", "DisputeCaseTransactionsLimitExceededRejection", "DisputeCaseMultipleAccountsRejection", "DisputeCaseMultipleCardHoldersRejection",
|
|
44
|
+
// Details that don't apply come from the selection: changing it is the fix
|
|
45
|
+
"DisputeCaseDetailsNotApplicableRejection"),
|
|
46
|
+
}, () => "Transactions")
|
|
47
|
+
.with({ __typename: "DisputeCaseIncompleteRejection" }, ({ missingFields }) => getEarliestStep(missingFields, context))
|
|
48
|
+
// Submitted elsewhere (another tab, an operator): the report reached Swan
|
|
49
|
+
.with({ __typename: "DisputeCaseWrongStatusRejection", currentStatus: "Submitted" }, () => "Submitted")
|
|
50
|
+
.with({
|
|
51
|
+
__typename: P.union("DisputeCaseTransactionsAlreadyReportedRejection", "DisputeCaseTransactionsOutsideReportingWindowRejection", "DisputeCaseWrongStatusRejection", "DisputeCaseNotFoundRejection"),
|
|
52
|
+
}, () => "Rejected")
|
|
53
|
+
.exhaustive();
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { FraudReportLayoutStep } from "./stepper";
|
|
2
|
+
import { FraudReportFormValues } from "./toInput";
|
|
3
|
+
export type FraudReportResumeStep = Exclude<FraudReportLayoutStep, "Victim" | "Submitted">;
|
|
4
|
+
export declare const getResumeStep: (values: FraudReportFormValues, startTransactionIds?: string[]) => FraudReportResumeStep;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Array, Option } from "@bloodyowl/boxed";
|
|
2
|
+
import { match } from "ts-pattern";
|
|
3
|
+
import { getDetailsSteps } from "./stepper";
|
|
4
|
+
import { toFilledList, toRequiredFraudDetails, toTransactionIds, } from "./toInput";
|
|
5
|
+
const isDetailsStepAnswered = (step, values) => match(step)
|
|
6
|
+
.with("Card", () => values.isLostOrStolen != null)
|
|
7
|
+
// The transfer sub-step has no form field yet
|
|
8
|
+
.with("Transfer", () => true)
|
|
9
|
+
.with("Fraudster", () => toFilledList(values.fraudsterChannels).isSome() &&
|
|
10
|
+
toFilledList(values.sharedInformationWithFraudster).isSome())
|
|
11
|
+
.exhaustive();
|
|
12
|
+
// The victim can't change once the draft exists, so a resumed report never opens on it
|
|
13
|
+
export const getResumeStep = (values,
|
|
14
|
+
// The transactions the report was opened from
|
|
15
|
+
startTransactionIds = []) => {
|
|
16
|
+
const draftTransactionIds = new Set(toTransactionIds(values));
|
|
17
|
+
// A draft is found from one of the start transactions: the user adds the ones it doesn't hold
|
|
18
|
+
if (draftTransactionIds.size === 0 ||
|
|
19
|
+
startTransactionIds.some(id => !draftTransactionIds.has(id))) {
|
|
20
|
+
return "Transactions";
|
|
21
|
+
}
|
|
22
|
+
if (toRequiredFraudDetails(values).isNone()) {
|
|
23
|
+
return "Incident";
|
|
24
|
+
}
|
|
25
|
+
return Array.findMap(getDetailsSteps(values), step => isDetailsStepAnswered(step, values) ? Option.None() : Option.Some(step)).getOr("Documents");
|
|
26
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { TopLevelStep } from "@swan-io/lake/src/components/LakeStepper";
|
|
2
|
+
import { FraudReason, FraudReportDetailsStep, FraudReportStep, FraudReportTransaction } from "./types";
|
|
3
|
+
export type FraudReportStepperStep = Exclude<FraudReportStep, "Intro">;
|
|
4
|
+
export type FraudReportLayoutStep = Exclude<FraudReportStepperStep, "Details"> | FraudReportDetailsStep;
|
|
5
|
+
export declare const getDetailsSteps: ({ transactions, reportedReason, }: {
|
|
6
|
+
transactions: Pick<FraudReportTransaction, "rail">[];
|
|
7
|
+
reportedReason?: FraudReason;
|
|
8
|
+
}) => ("Card" | "Fraudster" | "Transfer")[];
|
|
9
|
+
export declare const getFraudReportStepper: ({ activeStep, detailsSteps, getLabel, }: {
|
|
10
|
+
activeStep: FraudReportLayoutStep;
|
|
11
|
+
detailsSteps: readonly FraudReportDetailsStep[];
|
|
12
|
+
getLabel: (step: FraudReportStepperStep) => string;
|
|
13
|
+
}) => {
|
|
14
|
+
steps: TopLevelStep[];
|
|
15
|
+
activeStepId: FraudReportLayoutStep;
|
|
16
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { match } from "ts-pattern";
|
|
2
|
+
import { getCaseRail } from "./rail";
|
|
3
|
+
import { fraudReportDetailsSteps, fraudReportSteps, } from "./types";
|
|
4
|
+
const stepperSteps = fraudReportSteps.filter((step) => step !== "Intro");
|
|
5
|
+
export const getDetailsSteps = ({ transactions, reportedReason, }) => {
|
|
6
|
+
const caseRail = getCaseRail(transactions).toUndefined();
|
|
7
|
+
return fraudReportDetailsSteps.filter(step => match(step)
|
|
8
|
+
.with("Card", () => caseRail === "CardOnly" || caseRail === "Mixed")
|
|
9
|
+
.with("Transfer", () => caseRail === "TransferOnly" || caseRail === "Mixed")
|
|
10
|
+
.with("Fraudster", () => reportedReason === "Manipulated")
|
|
11
|
+
.exhaustive());
|
|
12
|
+
};
|
|
13
|
+
export const getFraudReportStepper = ({ activeStep, detailsSteps, getLabel, }) => {
|
|
14
|
+
const subSteps = fraudReportDetailsSteps.filter(step => step === activeStep || detailsSteps.includes(step));
|
|
15
|
+
return {
|
|
16
|
+
steps: stepperSteps.map((step) => step === "Details" && subSteps.length > 0
|
|
17
|
+
? { label: getLabel(step), children: subSteps.map(id => ({ id, label: getLabel(step) })) }
|
|
18
|
+
: { id: step, label: getLabel(step) }),
|
|
19
|
+
activeStepId: activeStep,
|
|
20
|
+
};
|
|
21
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { Option } from "@bloodyowl/boxed";
|
|
2
|
+
import type { DraftFraudDisputeCaseInput, FraudReason, FraudReportCase, FraudReportTransaction, FraudsterChannel, FraudTypology, SharedInformationWithFraudster, UpdateDraftFraudDisputeCaseInput } from "./types";
|
|
3
|
+
export type FraudReportFormValues = {
|
|
4
|
+
transactions: FraudReportTransaction[];
|
|
5
|
+
victimAccountMembershipId?: string;
|
|
6
|
+
reportedReason?: FraudReason;
|
|
7
|
+
reportedTypology?: FraudTypology;
|
|
8
|
+
description?: string;
|
|
9
|
+
discoveredAt?: string;
|
|
10
|
+
discoveryDetails?: string;
|
|
11
|
+
fraudsterChannels?: FraudsterChannel[];
|
|
12
|
+
sharedInformationWithFraudster?: SharedInformationWithFraudster[];
|
|
13
|
+
isLostOrStolen?: boolean;
|
|
14
|
+
lostOrStolenNoticedAt?: string;
|
|
15
|
+
externalReference?: string;
|
|
16
|
+
};
|
|
17
|
+
export declare const toFilled: (value: string | undefined) => Option<string>;
|
|
18
|
+
export declare const toFilledList: <T>(values: T[] | undefined) => Option<T[]>;
|
|
19
|
+
export declare const toRequiredFraudDetails: (values: FraudReportFormValues) => Option<{
|
|
20
|
+
reportedReason: "Manipulated" | "Unauthorized";
|
|
21
|
+
reportedTypology: "FakeAdvisor" | "FakeSupplierOrInvoice" | "FakeWebsite" | "ImpersonationOrPhishing" | "InvestmentScam" | "Other" | "RomanceScam";
|
|
22
|
+
description: string;
|
|
23
|
+
}>;
|
|
24
|
+
export declare const toTransactionIds: (values: FraudReportFormValues) => string[];
|
|
25
|
+
export declare const toDraftInput: (values: FraudReportFormValues) => DraftFraudDisputeCaseInput;
|
|
26
|
+
export declare const toUpdateInput: ({ savedCase, values, savedTransactionIds, }: {
|
|
27
|
+
savedCase: Pick<FraudReportCase, "id" | "fraudDetails" | "fraudCardDetails">;
|
|
28
|
+
values: FraudReportFormValues;
|
|
29
|
+
savedTransactionIds: string[];
|
|
30
|
+
}) => UpdateDraftFraudDisputeCaseInput;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { Option } from "@bloodyowl/boxed";
|
|
2
|
+
import { match, P } from "ts-pattern";
|
|
3
|
+
import { getCaseRail } from "./rail";
|
|
4
|
+
import { getDetailsSteps } from "./stepper";
|
|
5
|
+
export const toFilled = (value) => Option.fromNullable(value).filter(item => item.trim() !== "");
|
|
6
|
+
export const toFilledList = (values) => Option.fromNullable(values).filter(items => items.length > 0);
|
|
7
|
+
// The incident answers `fraudDetails` can't be sent without
|
|
8
|
+
export const toRequiredFraudDetails = (values) => Option.allFromDict({
|
|
9
|
+
reportedReason: Option.fromNullable(values.reportedReason),
|
|
10
|
+
reportedTypology: Option.fromNullable(values.reportedTypology),
|
|
11
|
+
description: toFilled(values.description),
|
|
12
|
+
});
|
|
13
|
+
const toFraudDetails = (values, savedDetails) => {
|
|
14
|
+
const hasFraudster = getDetailsSteps(values).includes("Fraudster");
|
|
15
|
+
return toRequiredFraudDetails(values).map(required => { var _a; var _b; return ({
|
|
16
|
+
...required,
|
|
17
|
+
discoveredAt: toFilled(values.discoveredAt).toNull(),
|
|
18
|
+
discoveryDetails: toFilled(values.discoveryDetails).toNull(),
|
|
19
|
+
fraudsterChannels: hasFraudster ? toFilledList(values.fraudsterChannels).toNull() : null,
|
|
20
|
+
sharedInformationWithFraudster: hasFraudster
|
|
21
|
+
? toFilledList(values.sharedInformationWithFraudster).toNull()
|
|
22
|
+
: null,
|
|
23
|
+
hasFiledPoliceComplaint: (_b = (_a = savedDetails === null || savedDetails === void 0 ? void 0 : savedDetails.fraudDetails) === null || _a === void 0 ? void 0 : _a.hasFiledPoliceComplaint) !== null && _b !== void 0 ? _b : null,
|
|
24
|
+
}); });
|
|
25
|
+
};
|
|
26
|
+
const toFraudCardDetails = (values, savedDetails) => {
|
|
27
|
+
var _a;
|
|
28
|
+
var _b;
|
|
29
|
+
const isLostOrStolen = Option.fromNullable(values.isLostOrStolen);
|
|
30
|
+
const lostOrStolenNoticedAt = toFilled(values.lostOrStolenNoticedAt);
|
|
31
|
+
return isLostOrStolen.isNone() && lostOrStolenNoticedAt.isNone()
|
|
32
|
+
? Option.None()
|
|
33
|
+
: Option.Some({
|
|
34
|
+
isLostOrStolen: isLostOrStolen.toNull(),
|
|
35
|
+
lostOrStolenNoticedAt: lostOrStolenNoticedAt.toNull(),
|
|
36
|
+
hasContactedMerchant: (_b = (_a = savedDetails === null || savedDetails === void 0 ? void 0 : savedDetails.fraudCardDetails) === null || _a === void 0 ? void 0 : _a.hasContactedMerchant) !== null && _b !== void 0 ? _b : null,
|
|
37
|
+
});
|
|
38
|
+
};
|
|
39
|
+
const toDetails = (values, savedDetails) => {
|
|
40
|
+
const fraudDetails = toFraudDetails(values, savedDetails)
|
|
41
|
+
.map(value => ({ fraudDetails: value }))
|
|
42
|
+
.toUndefined();
|
|
43
|
+
return match(getCaseRail(values.transactions))
|
|
44
|
+
.with(Option.P.Some(P.union("CardOnly", "Mixed")), () => ({
|
|
45
|
+
...fraudDetails,
|
|
46
|
+
...toFraudCardDetails(values, savedDetails)
|
|
47
|
+
.map(value => ({ fraudCardDetails: value }))
|
|
48
|
+
.toUndefined(),
|
|
49
|
+
}))
|
|
50
|
+
.with(Option.P.Some("TransferOnly"), () => ({
|
|
51
|
+
...fraudDetails,
|
|
52
|
+
...toFilled(values.victimAccountMembershipId)
|
|
53
|
+
.map(value => ({ victimAccountMembershipId: value }))
|
|
54
|
+
.toUndefined(),
|
|
55
|
+
}))
|
|
56
|
+
.with(Option.P.None, () => ({ ...fraudDetails }))
|
|
57
|
+
.exhaustive();
|
|
58
|
+
};
|
|
59
|
+
export const toTransactionIds = (values) => values.transactions.map(({ id }) => id);
|
|
60
|
+
const isSameSelection = (transactionIds, savedTransactionIds) => {
|
|
61
|
+
const savedIds = new Set(savedTransactionIds);
|
|
62
|
+
return (new Set(transactionIds).size === savedIds.size && transactionIds.every(id => savedIds.has(id)));
|
|
63
|
+
};
|
|
64
|
+
export const toDraftInput = (values) => ({
|
|
65
|
+
transactionIds: toTransactionIds(values),
|
|
66
|
+
...toDetails(values),
|
|
67
|
+
...match(values.externalReference)
|
|
68
|
+
.with(P.union(undefined, ""), () => undefined)
|
|
69
|
+
.otherwise(externalReference => ({ externalReference })),
|
|
70
|
+
});
|
|
71
|
+
export const toUpdateInput = ({ savedCase, values, savedTransactionIds, }) => {
|
|
72
|
+
const transactionIds = toTransactionIds(values);
|
|
73
|
+
return {
|
|
74
|
+
disputeCaseId: savedCase.id,
|
|
75
|
+
...(isSameSelection(transactionIds, savedTransactionIds) ? undefined : { transactionIds }),
|
|
76
|
+
...toDetails(values, savedCase),
|
|
77
|
+
...match(values.externalReference)
|
|
78
|
+
.with(undefined, () => undefined)
|
|
79
|
+
.with("", () => ({ externalReference: null }))
|
|
80
|
+
.otherwise(externalReference => ({ externalReference })),
|
|
81
|
+
};
|
|
82
|
+
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { FraudReportTransaction } from "./types";
|
|
2
|
+
export declare const removeDuplicateTransactions: (transactions: FraudReportTransaction[]) => FraudReportTransaction[];
|
|
3
|
+
export declare const getTransactionsTotal: (transactions: Pick<FraudReportTransaction, "amount">[]) => {
|
|
4
|
+
value: number;
|
|
5
|
+
currency: string;
|
|
6
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export const removeDuplicateTransactions = (transactions) => transactions.filter((transaction, index) => transactions.findIndex(({ id }) => id === transaction.id) === index);
|
|
2
|
+
export const getTransactionsTotal = (transactions) => {
|
|
3
|
+
var _a;
|
|
4
|
+
var _b;
|
|
5
|
+
const cents = transactions.reduce((total, { amount }) => total + Math.round(Number(amount.value) * 100), 0);
|
|
6
|
+
return { value: cents / 100, currency: (_b = (_a = transactions[0]) === null || _a === void 0 ? void 0 : _a.amount.currency) !== null && _b !== void 0 ? _b : "EUR" };
|
|
7
|
+
};
|
|
@@ -79,9 +79,17 @@ export type DisputeCaseStatusInfo = {
|
|
|
79
79
|
submittedAt: string;
|
|
80
80
|
};
|
|
81
81
|
export type FraudReportRail = "Card" | "Transfer";
|
|
82
|
+
export type FraudReportTransactionType = "CardOutDebit" | "SepaCreditTransferOut" | "SepaInstantCreditTransferOut" | "InternationalCreditTransferOut" | "InternalCreditTransferOut";
|
|
82
83
|
export type FraudReportTransaction = {
|
|
83
84
|
id: string;
|
|
84
85
|
rail: FraudReportRail;
|
|
86
|
+
type: FraudReportTransactionType;
|
|
87
|
+
executionDate: string;
|
|
88
|
+
counterparty: string;
|
|
89
|
+
amount: {
|
|
90
|
+
value: string;
|
|
91
|
+
currency: string;
|
|
92
|
+
};
|
|
85
93
|
};
|
|
86
94
|
export type FraudReportCase = {
|
|
87
95
|
id: string;
|