@swan-io/shared-business 18.4.0 → 18.6.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/BirthdatePicker.d.ts +3 -1
- package/src/components/BirthdatePicker.js +2 -2
- package/src/components/FraudReport/CardDetailsStep.d.ts +7 -0
- package/src/components/FraudReport/CardDetailsStep.js +46 -0
- package/src/components/FraudReport/FraudReportLayout.d.ts +23 -0
- package/src/components/FraudReport/FraudReportLayout.js +35 -0
- package/src/components/FraudReport/FraudsterDetailsStep.d.ts +7 -0
- package/src/components/FraudReport/FraudsterDetailsStep.js +56 -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 +32 -0
- package/src/components/FraudReport/TransactionPicker.d.ts +13 -0
- package/src/components/FraudReport/TransactionPicker.js +213 -0
- package/src/components/FraudReport/TransactionPickerFilters.d.ts +8 -0
- package/src/components/FraudReport/TransactionPickerFilters.js +213 -0
- package/src/components/FraudReport/TransactionRows.d.ts +8 -0
- package/src/components/FraudReport/TransactionRows.js +32 -0
- package/src/components/FraudReport/TransactionsStep.d.ts +16 -0
- package/src/components/FraudReport/TransactionsStep.js +120 -0
- package/src/components/FraudReport/VictimStep.d.ts +11 -0
- package/src/components/FraudReport/VictimStep.js +88 -0
- package/src/components/InlineDatePicker.js +7 -6
- package/src/components/LakeModal.js +1 -1
- 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 +1067 -0
- package/src/hooks/useFraudReportFlow.d.ts +32 -0
- package/src/hooks/useFraudReportFlow.js +265 -0
- package/src/locales/de.json +130 -0
- package/src/locales/en.json +130 -0
- package/src/locales/es.json +130 -0
- package/src/locales/fi.json +130 -0
- package/src/locales/fr.json +130 -0
- package/src/locales/it.json +130 -0
- package/src/locales/nl.json +130 -0
- package/src/locales/pt.json +130 -0
- package/src/utils/__tests__/fraudReport.card.test.d.ts +1 -0
- package/src/utils/__tests__/fraudReport.card.test.js +39 -0
- package/src/utils/__tests__/fraudReport.fakeApi.test.js +42 -13
- package/src/utils/__tests__/fraudReport.fraudster.test.d.ts +1 -0
- package/src/utils/__tests__/fraudReport.fraudster.test.js +35 -0
- package/src/utils/__tests__/fraudReport.messages.test.d.ts +1 -0
- package/src/utils/__tests__/fraudReport.messages.test.js +28 -0
- package/src/utils/__tests__/fraudReport.picker.test.d.ts +1 -0
- package/src/utils/__tests__/fraudReport.picker.test.js +171 -0
- package/src/utils/__tests__/fraudReport.pickerFilters.test.d.ts +1 -0
- package/src/utils/__tests__/fraudReport.pickerFilters.test.js +144 -0
- package/src/utils/__tests__/fraudReport.prefill.test.d.ts +1 -0
- package/src/utils/__tests__/fraudReport.prefill.test.js +151 -0
- package/src/utils/__tests__/fraudReport.rejections.test.d.ts +1 -0
- package/src/utils/__tests__/fraudReport.rejections.test.js +155 -0
- package/src/utils/__tests__/fraudReport.resume.test.d.ts +1 -0
- package/src/utils/__tests__/fraudReport.resume.test.js +81 -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.js +111 -37
- package/src/utils/__tests__/fraudReport.transactions.test.d.ts +1 -0
- package/src/utils/__tests__/fraudReport.transactions.test.js +38 -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 +168 -0
- package/src/utils/__tests__/phone.test.js +60 -5
- package/src/utils/__tests__/validation.test.js +69 -2
- package/src/utils/fraudReport/card.d.ts +11 -0
- package/src/utils/fraudReport/card.js +15 -0
- package/src/utils/fraudReport/fakeApi.d.ts +7 -4
- package/src/utils/fraudReport/fakeApi.js +19 -6
- package/src/utils/fraudReport/fraudster.d.ts +10 -0
- package/src/utils/fraudReport/fraudster.js +11 -0
- package/src/utils/fraudReport/messages.d.ts +4 -0
- package/src/utils/fraudReport/messages.js +7 -0
- package/src/utils/fraudReport/picker.d.ts +18 -0
- package/src/utils/fraudReport/picker.js +49 -0
- package/src/utils/fraudReport/pickerFilters.d.ts +26 -0
- package/src/utils/fraudReport/pickerFilters.js +62 -0
- package/src/utils/fraudReport/prefill.d.ts +3 -0
- package/src/utils/fraudReport/prefill.js +16 -0
- package/src/utils/fraudReport/rejections.d.ts +9 -0
- package/src/utils/fraudReport/rejections.js +49 -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 +14 -3
- package/src/utils/fraudReport/toInput.js +37 -31
- package/src/utils/fraudReport/transactions.d.ts +8 -0
- package/src/utils/fraudReport/transactions.js +11 -0
- package/src/utils/fraudReport/types.d.ts +8 -0
- package/src/utils/fraudReport/validation.d.ts +2 -1
- package/src/utils/fraudReport/validation.js +5 -0
- package/src/utils/fraudReport/victim.d.ts +41 -0
- package/src/utils/fraudReport/victim.js +37 -0
- package/src/utils/phone.d.ts +1 -0
- package/src/utils/phone.js +31 -4
- package/src/utils/validation.d.ts +2 -0
- package/src/utils/validation.js +14 -7
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { describe, expect, test } from "vitest";
|
|
2
|
-
import {
|
|
1
|
+
import { afterEach, beforeEach, describe, expect, test, vi } from "vitest";
|
|
2
|
+
import { t } from "../i18n";
|
|
3
|
+
import { getCompanyTaxNumberHelp, getCompanyTaxNumberPlaceholder, getIndividualTaxNumberHelp, getIndividualTaxNumberPlaceholder, isValidEmail, isValidUsaTaxNumber, sanitizeDecimal, validateAdultBirthdate, validateAdultBirthdateString, validateArrayRequired, validateBirthdate, validateBooleanRequired, validateBooleanTypeRequired, validateCompanyTaxNumber, validateDate, validateIndividualTaxNumber, validateName, validateNullableRequired, validateRequired, } from "../validation";
|
|
3
4
|
describe("isValidEmail", () => {
|
|
4
5
|
test("validates correct email addresses", () => {
|
|
5
6
|
expect(isValidEmail("test@example.com")).toBe(true);
|
|
@@ -370,6 +371,72 @@ describe("validateDate", () => {
|
|
|
370
371
|
expect(validateDate({ day: "31", month: "04", year: "2024" })).toBeDefined(); // April has 30 days
|
|
371
372
|
});
|
|
372
373
|
});
|
|
374
|
+
describe("birth date rules", () => {
|
|
375
|
+
beforeEach(() => {
|
|
376
|
+
vi.useFakeTimers();
|
|
377
|
+
vi.setSystemTime(new Date("2026-11-30T12:00:00.000Z"));
|
|
378
|
+
});
|
|
379
|
+
afterEach(() => {
|
|
380
|
+
vi.useRealTimers();
|
|
381
|
+
});
|
|
382
|
+
describe("validateBirthdate", () => {
|
|
383
|
+
test("accepts a birth date of today", () => {
|
|
384
|
+
expect(validateBirthdate({ day: "30", month: "11", year: "2026" })).toBeUndefined();
|
|
385
|
+
});
|
|
386
|
+
test("accepts a birth date 120 years ago", () => {
|
|
387
|
+
expect(validateBirthdate({ day: "30", month: "11", year: "1906" })).toBeUndefined();
|
|
388
|
+
});
|
|
389
|
+
test("accepts a birth date exactly 150 years ago", () => {
|
|
390
|
+
expect(validateBirthdate({ day: "30", month: "11", year: "1876" })).toBeUndefined();
|
|
391
|
+
});
|
|
392
|
+
test("refuses a birth date more than 150 years ago", () => {
|
|
393
|
+
expect(validateBirthdate({ day: "29", month: "11", year: "1876" })).toBe(t("validation.invalidBirthDate"));
|
|
394
|
+
});
|
|
395
|
+
test("refuses a birth date in the future", () => {
|
|
396
|
+
expect(validateBirthdate({ day: "01", month: "12", year: "2026" })).toBe(t("validation.birthdateCannotBeFuture"));
|
|
397
|
+
});
|
|
398
|
+
test("refuses a missing or malformed date", () => {
|
|
399
|
+
expect(validateBirthdate(undefined)).toBe(t("validation.invalidBirthDate"));
|
|
400
|
+
expect(validateBirthdate({ day: "31", month: "02", year: "1990" })).toBe(t("validation.invalidBirthDate"));
|
|
401
|
+
});
|
|
402
|
+
});
|
|
403
|
+
describe("validateAdultBirthdate", () => {
|
|
404
|
+
test("accepts a person who turns 18 today", () => {
|
|
405
|
+
expect(validateAdultBirthdate({ day: "30", month: "11", year: "2008" })).toBeUndefined();
|
|
406
|
+
});
|
|
407
|
+
test("refuses a person who turns 18 tomorrow", () => {
|
|
408
|
+
expect(validateAdultBirthdate({ day: "01", month: "12", year: "2008" })).toBe(t("validation.birthdateMustBeAdult"));
|
|
409
|
+
});
|
|
410
|
+
test("accepts a person born on February 29th from February 28th of their 18th year", () => {
|
|
411
|
+
vi.setSystemTime(new Date("2026-02-28T12:00:00.000Z"));
|
|
412
|
+
expect(validateAdultBirthdate({ day: "29", month: "02", year: "2008" })).toBeUndefined();
|
|
413
|
+
});
|
|
414
|
+
test("accepts a person over 100 years old", () => {
|
|
415
|
+
expect(validateAdultBirthdate({ day: "30", month: "11", year: "1906" })).toBeUndefined();
|
|
416
|
+
});
|
|
417
|
+
test("refuses a birth date in the future, too old or malformed like the default rule", () => {
|
|
418
|
+
expect(validateAdultBirthdate({ day: "01", month: "12", year: "2026" })).toBe(t("validation.birthdateCannotBeFuture"));
|
|
419
|
+
expect(validateAdultBirthdate({ day: "29", month: "11", year: "1876" })).toBe(t("validation.invalidBirthDate"));
|
|
420
|
+
expect(validateAdultBirthdate({ day: "31", month: "02", year: "1990" })).toBe(t("validation.invalidBirthDate"));
|
|
421
|
+
expect(validateAdultBirthdate(undefined)).toBe(t("validation.invalidBirthDate"));
|
|
422
|
+
});
|
|
423
|
+
});
|
|
424
|
+
describe("validateAdultBirthdateString", () => {
|
|
425
|
+
test("refuses a saved birth date of a person who turns 18 tomorrow", () => {
|
|
426
|
+
expect(validateAdultBirthdateString("2008-12-01")).toBe(t("validation.birthdateMustBeAdult"));
|
|
427
|
+
});
|
|
428
|
+
test("accepts a saved birth date of a person who turns 18 today", () => {
|
|
429
|
+
expect(validateAdultBirthdateString("2008-11-30")).toBeUndefined();
|
|
430
|
+
});
|
|
431
|
+
test("refuses a saved date that is not in the YYYY-MM-DD format", () => {
|
|
432
|
+
expect(validateAdultBirthdateString("30/11/1990")).toBe(t("validation.invalidBirthDate"));
|
|
433
|
+
});
|
|
434
|
+
test("leaves an empty value to the required validator", () => {
|
|
435
|
+
expect(validateAdultBirthdateString(undefined)).toBeUndefined();
|
|
436
|
+
expect(validateAdultBirthdateString("")).toBeUndefined();
|
|
437
|
+
});
|
|
438
|
+
});
|
|
439
|
+
});
|
|
373
440
|
describe("sanitizeDecimal", () => {
|
|
374
441
|
test("removes spaces from decimal input", () => {
|
|
375
442
|
expect(sanitizeDecimal("1 000")).toBe("1000");
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { FraudReportFormValues } from "./toInput";
|
|
2
|
+
export type CardAction = "Merchant" | "Police";
|
|
3
|
+
type CardValues = Pick<FraudReportFormValues, "isLostOrStolen" | "lostOrStolenNoticedAt" | "hasContactedMerchant" | "hasFiledPoliceComplaint">;
|
|
4
|
+
export declare const emptyCardAnswers: Pick<CardValues, "isLostOrStolen" | "lostOrStolenNoticedAt" | "hasContactedMerchant">;
|
|
5
|
+
export declare const getCardActions: ({ hasContactedMerchant, hasFiledPoliceComplaint, }: Pick<CardValues, "hasContactedMerchant" | "hasFiledPoliceComplaint">) => CardAction[];
|
|
6
|
+
export declare const toCardValues: ({ isLostOrStolen, lostOrStolenNoticedAt, actions, }: {
|
|
7
|
+
isLostOrStolen: boolean | undefined;
|
|
8
|
+
lostOrStolenNoticedAt: string | undefined;
|
|
9
|
+
actions: CardAction[];
|
|
10
|
+
}) => CardValues;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export const emptyCardAnswers = {
|
|
2
|
+
isLostOrStolen: undefined,
|
|
3
|
+
lostOrStolenNoticedAt: undefined,
|
|
4
|
+
hasContactedMerchant: undefined,
|
|
5
|
+
};
|
|
6
|
+
export const getCardActions = ({ hasContactedMerchant, hasFiledPoliceComplaint, }) => [
|
|
7
|
+
...(hasContactedMerchant === true ? ["Merchant"] : []),
|
|
8
|
+
...(hasFiledPoliceComplaint === true ? ["Police"] : []),
|
|
9
|
+
];
|
|
10
|
+
export const toCardValues = ({ isLostOrStolen, lostOrStolenNoticedAt, actions, }) => ({
|
|
11
|
+
isLostOrStolen,
|
|
12
|
+
lostOrStolenNoticedAt: isLostOrStolen === true ? lostOrStolenNoticedAt : undefined,
|
|
13
|
+
hasContactedMerchant: actions.includes("Merchant") ? true : undefined,
|
|
14
|
+
hasFiledPoliceComplaint: actions.includes("Police") ? true : undefined,
|
|
15
|
+
});
|
|
@@ -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,6 +1,19 @@
|
|
|
1
1
|
import { Future, Option, Result } from "@bloodyowl/boxed";
|
|
2
2
|
import { match } from "ts-pattern";
|
|
3
|
-
|
|
3
|
+
import { MAX_TRANSACTIONS } from "./transactions";
|
|
4
|
+
const getRail = (type) => match(type)
|
|
5
|
+
.returnType()
|
|
6
|
+
.with("CardOutDebit", () => "Card")
|
|
7
|
+
.with("SepaCreditTransferOut", "SepaInstantCreditTransferOut", "InternationalCreditTransferOut", "InternalCreditTransferOut", () => "Transfer")
|
|
8
|
+
.exhaustive();
|
|
9
|
+
export const createFakeTransaction = (id, type, details = {}) => { var _a, _b, _c; return ({
|
|
10
|
+
id,
|
|
11
|
+
rail: getRail(type),
|
|
12
|
+
type,
|
|
13
|
+
executionDate: (_a = details.executionDate) !== null && _a !== void 0 ? _a : "2026-11-04T10:00:00.000Z",
|
|
14
|
+
counterparty: (_b = details.counterparty) !== null && _b !== void 0 ? _b : `Merchant ${id}`,
|
|
15
|
+
amount: (_c = details.amount) !== null && _c !== void 0 ? _c : { value: "10.00", currency: "EUR" },
|
|
16
|
+
}); };
|
|
4
17
|
const DRAFT_LIFETIME_MS = 30 * 24 * 60 * 60 * 1000;
|
|
5
18
|
const isDefined = (value) => value !== undefined;
|
|
6
19
|
const unique = (values) => [...new Set(values)];
|
|
@@ -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,10 @@
|
|
|
1
|
+
import type { SharedInformationWithFraudster } from "./types";
|
|
2
|
+
export type SharedInformationAnswer = "Yes" | "No";
|
|
3
|
+
export type SharedInformationItem = Exclude<SharedInformationWithFraudster, "None">;
|
|
4
|
+
type SharedInformationChoice = {
|
|
5
|
+
answer: SharedInformationAnswer | undefined;
|
|
6
|
+
items: SharedInformationItem[];
|
|
7
|
+
};
|
|
8
|
+
export declare const getSharedInformationChoice: (shared: SharedInformationWithFraudster[] | undefined) => SharedInformationChoice;
|
|
9
|
+
export declare const toSharedInformation: ({ answer, items, }: SharedInformationChoice) => SharedInformationWithFraudster[] | undefined;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { match, P } from "ts-pattern";
|
|
2
|
+
export const getSharedInformationChoice = (shared) => match(shared)
|
|
3
|
+
.returnType()
|
|
4
|
+
.with(P.nullish, [], () => ({ answer: undefined, items: [] }))
|
|
5
|
+
.with(P.array(P.not("None")), items => ({ answer: "Yes", items }))
|
|
6
|
+
.otherwise(() => ({ answer: "No", items: [] }));
|
|
7
|
+
export const toSharedInformation = ({ answer, items, }) => match(answer)
|
|
8
|
+
.with("No", () => ["None"])
|
|
9
|
+
.with("Yes", () => (items.length > 0 ? items : undefined))
|
|
10
|
+
.with(undefined, () => undefined)
|
|
11
|
+
.exhaustive();
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { t } from "../i18n";
|
|
2
|
+
import { MAX_TRANSACTIONS } from "./transactions";
|
|
3
|
+
// The message for a selection over the limit. With `toRemove`, it also says how many
|
|
4
|
+
// transactions to remove. For the API's rejection, pass its `maxTransactionCount` as `max`.
|
|
5
|
+
export const getTransactionsLimitMessage = ({ max = MAX_TRANSACTIONS, toRemove, } = {}) => toRemove == null || toRemove <= 0
|
|
6
|
+
? t("fraudReport.transactions.limit", { max })
|
|
7
|
+
: t("fraudReport.picker.limitExceeded", { max, count: toRemove });
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { FraudReportTransaction } from "./types";
|
|
2
|
+
export type FraudReportPickerRow = {
|
|
3
|
+
transaction: FraudReportTransaction;
|
|
4
|
+
cardAccountMembershipId: string | null;
|
|
5
|
+
};
|
|
6
|
+
export declare const getPickerTransactions: (rows: FraudReportPickerRow[], victimAccountMembershipId: string | undefined) => FraudReportTransaction[];
|
|
7
|
+
export declare const toggleTransaction: (selected: FraudReportTransaction[], transaction: FraudReportTransaction) => FraudReportTransaction[];
|
|
8
|
+
export declare const getSelectAllValue: (selected: FraudReportTransaction[], listed: FraudReportTransaction[]) => boolean | "mixed";
|
|
9
|
+
export declare const toggleAllTransactions: (selected: FraudReportTransaction[], listed: FraudReportTransaction[]) => FraudReportTransaction[];
|
|
10
|
+
export declare const MAX_PAGES_WITHOUT_ROWS = 3;
|
|
11
|
+
export type PickerPages = {
|
|
12
|
+
rowCount: number;
|
|
13
|
+
listedCount: number;
|
|
14
|
+
withoutRows: number;
|
|
15
|
+
restarted: boolean;
|
|
16
|
+
};
|
|
17
|
+
export declare const restartPickerPages: (pages: PickerPages) => PickerPages;
|
|
18
|
+
export declare const countPagesWithoutRows: (previous: PickerPages, rowCount: number, listedCount: number, loaded?: boolean) => PickerPages;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { match } from "ts-pattern";
|
|
2
|
+
import { removeDuplicateTransactions } from "./transactions";
|
|
3
|
+
export const getPickerTransactions = (rows, victimAccountMembershipId) => removeDuplicateTransactions(rows
|
|
4
|
+
.filter(({ transaction, cardAccountMembershipId }) => match(transaction.rail)
|
|
5
|
+
.with("Card", () => cardAccountMembershipId === victimAccountMembershipId)
|
|
6
|
+
.with("Transfer", () => true)
|
|
7
|
+
.exhaustive())
|
|
8
|
+
.map(({ transaction }) => transaction));
|
|
9
|
+
const isSelected = (selected, { id }) => selected.some(item => item.id === id);
|
|
10
|
+
export const toggleTransaction = (selected, transaction) => isSelected(selected, transaction)
|
|
11
|
+
? selected.filter(({ id }) => id !== transaction.id)
|
|
12
|
+
: [...selected, transaction];
|
|
13
|
+
export const getSelectAllValue = (selected, listed) => {
|
|
14
|
+
const count = listed.filter(item => isSelected(selected, item)).length;
|
|
15
|
+
return count === 0 ? false : count === listed.length ? true : "mixed";
|
|
16
|
+
};
|
|
17
|
+
// Only the listed transactions change: a selected one that isn't listed (not loaded yet) stays.
|
|
18
|
+
export const toggleAllTransactions = (selected, listed) => getSelectAllValue(selected, listed) === true
|
|
19
|
+
? selected.filter(item => !isSelected(listed, item))
|
|
20
|
+
: [...selected, ...listed.filter(item => !isSelected(selected, item))];
|
|
21
|
+
export const MAX_PAGES_WITHOUT_ROWS = 3;
|
|
22
|
+
export const restartPickerPages = (pages) => ({
|
|
23
|
+
...pages,
|
|
24
|
+
withoutRows: 0,
|
|
25
|
+
restarted: true,
|
|
26
|
+
});
|
|
27
|
+
// Counts the pages in a row that added no listed row, so the picker can stop asking for more
|
|
28
|
+
// on its own: the victim filter could otherwise page through the whole account.
|
|
29
|
+
export const countPagesWithoutRows = (previous, rowCount, listedCount,
|
|
30
|
+
// A load just ended. Another list can have as many rows as the one before: only this tells
|
|
31
|
+
// that it arrived. An app that never passes `loading` gets one more page before the pause.
|
|
32
|
+
loaded = false) => {
|
|
33
|
+
if (rowCount === previous.rowCount && !(previous.restarted && loaded)) {
|
|
34
|
+
return previous;
|
|
35
|
+
}
|
|
36
|
+
// No row loaded isn't a page.
|
|
37
|
+
if (rowCount === 0) {
|
|
38
|
+
return { rowCount, listedCount, withoutRows: 0, restarted: false };
|
|
39
|
+
}
|
|
40
|
+
// Another list: its first page is compared with nothing.
|
|
41
|
+
const firstPage = previous.restarted || rowCount < previous.rowCount;
|
|
42
|
+
const added = firstPage ? listedCount > 0 : listedCount > previous.listedCount;
|
|
43
|
+
return {
|
|
44
|
+
rowCount,
|
|
45
|
+
listedCount,
|
|
46
|
+
withoutRows: added ? 0 : firstPage ? 1 : previous.withoutRows + 1,
|
|
47
|
+
restarted: false,
|
|
48
|
+
};
|
|
49
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { FraudReportTransactionType } from "./types";
|
|
2
|
+
export declare const PICKER_DATE_FORMAT = "YYYY-MM-DD";
|
|
3
|
+
export type FraudReportPickerFilters = {
|
|
4
|
+
search?: string;
|
|
5
|
+
fromDate?: string;
|
|
6
|
+
toDate?: string;
|
|
7
|
+
amount?: string;
|
|
8
|
+
types?: FraudReportTransactionType[];
|
|
9
|
+
};
|
|
10
|
+
export declare const pickerFilterTypes: FraudReportTransactionType[];
|
|
11
|
+
export declare const togglePickerFilterType: (types: FraudReportTransactionType[] | undefined, type: FraudReportTransactionType) => FraudReportTransactionType[];
|
|
12
|
+
export declare const setPickerFilters: (filters: FraudReportPickerFilters, patch: FraudReportPickerFilters) => FraudReportPickerFilters;
|
|
13
|
+
export declare const isSamePickerFilters: (a: FraudReportPickerFilters, b: FraudReportPickerFilters) => boolean;
|
|
14
|
+
export declare const hasPickerFilters: (filters: FraudReportPickerFilters) => boolean;
|
|
15
|
+
export declare const parseAmountFilter: (text: string) => {
|
|
16
|
+
amount: string | undefined;
|
|
17
|
+
} | {
|
|
18
|
+
error: "InvalidAmount";
|
|
19
|
+
};
|
|
20
|
+
export type FraudReportDateFilterError = "InvalidDate" | "StartAfterEnd";
|
|
21
|
+
export declare const validateFromDate: (date: string, toDate: string | undefined) => FraudReportDateFilterError | undefined;
|
|
22
|
+
export declare const validateToDate: (date: string, fromDate: string | undefined) => FraudReportDateFilterError | undefined;
|
|
23
|
+
export declare const toExecutionDateBounds: ({ fromDate, toDate, }: FraudReportPickerFilters) => {
|
|
24
|
+
isAfterExecutionDate?: string;
|
|
25
|
+
isBeforeExecutionDate?: string;
|
|
26
|
+
};
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import dayjs from "dayjs";
|
|
2
|
+
export const PICKER_DATE_FORMAT = "YYYY-MM-DD";
|
|
3
|
+
// Every type, in the order the filter lists them. A new type doesn't compile until it is added.
|
|
4
|
+
const typeOrder = {
|
|
5
|
+
CardOutDebit: true,
|
|
6
|
+
SepaCreditTransferOut: true,
|
|
7
|
+
SepaInstantCreditTransferOut: true,
|
|
8
|
+
InternationalCreditTransferOut: true,
|
|
9
|
+
InternalCreditTransferOut: true,
|
|
10
|
+
};
|
|
11
|
+
export const pickerFilterTypes = Object.keys(typeOrder);
|
|
12
|
+
// The result follows the list's order, whatever the order the types were ticked in.
|
|
13
|
+
export const togglePickerFilterType = (types = [], type) => pickerFilterTypes.filter(item => (item === type ? !types.includes(type) : types.includes(item)));
|
|
14
|
+
const isEmpty = (value) => value == null || value.length === 0;
|
|
15
|
+
// `patch` holds the filters that change. One that is cleared comes as `undefined`.
|
|
16
|
+
export const setPickerFilters = (filters, patch) => {
|
|
17
|
+
const { search, fromDate, toDate, amount, types } = { ...filters, ...patch };
|
|
18
|
+
const trimmed = search === null || search === void 0 ? void 0 : search.trim();
|
|
19
|
+
return {
|
|
20
|
+
...(isEmpty(trimmed) ? {} : { search: trimmed }),
|
|
21
|
+
...(isEmpty(fromDate) ? {} : { fromDate }),
|
|
22
|
+
...(isEmpty(toDate) ? {} : { toDate }),
|
|
23
|
+
...(isEmpty(amount) ? {} : { amount }),
|
|
24
|
+
...(isEmpty(types) ? {} : { types }),
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
export const isSamePickerFilters = (a, b) => { var _a, _b; return a.search === b.search &&
|
|
28
|
+
a.fromDate === b.fromDate &&
|
|
29
|
+
a.toDate === b.toDate &&
|
|
30
|
+
a.amount === b.amount &&
|
|
31
|
+
((_a = a.types) !== null && _a !== void 0 ? _a : []).join() === ((_b = b.types) !== null && _b !== void 0 ? _b : []).join(); };
|
|
32
|
+
export const hasPickerFilters = (filters) => Object.keys(filters).length > 0;
|
|
33
|
+
const AMOUNT_REGEX = /^\d+(\.\d{1,2})?$/;
|
|
34
|
+
export const parseAmountFilter = (text) => {
|
|
35
|
+
const amount = text.trim().replace(",", ".");
|
|
36
|
+
if (amount === "") {
|
|
37
|
+
return { amount: undefined };
|
|
38
|
+
}
|
|
39
|
+
return AMOUNT_REGEX.test(amount) ? { amount } : { error: "InvalidAmount" };
|
|
40
|
+
};
|
|
41
|
+
const isValidDate = (date) => dayjs.utc(date, PICKER_DATE_FORMAT, true).isValid();
|
|
42
|
+
// `YYYY-MM-DD` dates sort like the days they stand for.
|
|
43
|
+
export const validateFromDate = (date, toDate) => !isValidDate(date)
|
|
44
|
+
? "InvalidDate"
|
|
45
|
+
: toDate != null && date > toDate
|
|
46
|
+
? "StartAfterEnd"
|
|
47
|
+
: undefined;
|
|
48
|
+
export const validateToDate = (date, fromDate) => !isValidDate(date)
|
|
49
|
+
? "InvalidDate"
|
|
50
|
+
: fromDate != null && date < fromDate
|
|
51
|
+
? "StartAfterEnd"
|
|
52
|
+
: undefined;
|
|
53
|
+
// The dates as `TransactionsFiltersInput` takes them: after is inclusive, before is exclusive.
|
|
54
|
+
// A day is the user's day, like the dates the list shows.
|
|
55
|
+
export const toExecutionDateBounds = ({ fromDate, toDate, }) => ({
|
|
56
|
+
...(fromDate == null
|
|
57
|
+
? {}
|
|
58
|
+
: { isAfterExecutionDate: dayjs(fromDate).startOf("day").toISOString() }),
|
|
59
|
+
...(toDate == null
|
|
60
|
+
? {}
|
|
61
|
+
: { isBeforeExecutionDate: dayjs(toDate).add(1, "day").startOf("day").toISOString() }),
|
|
62
|
+
});
|
|
@@ -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,16 @@
|
|
|
1
|
+
export const toFormValues = ({ transactions, fraudDetails, fraudCardDetails, victimAccountMembershipId, externalReference, }) => { var _a, _b, _c, _d, _e, _f; 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
|
+
hasFiledPoliceComplaint: (_c = fraudDetails === null || fraudDetails === void 0 ? void 0 : fraudDetails.hasFiledPoliceComplaint) !== null && _c !== void 0 ? _c : undefined,
|
|
12
|
+
isLostOrStolen: (_d = fraudCardDetails === null || fraudCardDetails === void 0 ? void 0 : fraudCardDetails.isLostOrStolen) !== null && _d !== void 0 ? _d : undefined,
|
|
13
|
+
lostOrStolenNoticedAt: (_e = fraudCardDetails === null || fraudCardDetails === void 0 ? void 0 : fraudCardDetails.lostOrStolenNoticedAt) !== null && _e !== void 0 ? _e : undefined,
|
|
14
|
+
hasContactedMerchant: (_f = fraudCardDetails === null || fraudCardDetails === void 0 ? void 0 : fraudCardDetails.hasContactedMerchant) !== null && _f !== void 0 ? _f : undefined,
|
|
15
|
+
externalReference: externalReference !== null && externalReference !== void 0 ? externalReference : undefined,
|
|
16
|
+
}); };
|
|
@@ -0,0 +1,9 @@
|
|
|
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
|
+
detailsSteps: readonly FraudReportDetailsStep[];
|
|
7
|
+
};
|
|
8
|
+
export declare const getRejectionStep: (rejection: FraudReportRejection, context: FraudReportRejectionContext) => FraudReportRejectionStep;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,49 @@
|
|
|
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
|
+
// A sub-step missing from the flow is fixed where the choice that adds it is made
|
|
11
|
+
const getDetailsStep = (step, { detailsSteps }) => detailsSteps.includes(step)
|
|
12
|
+
? step
|
|
13
|
+
: match(step)
|
|
14
|
+
.returnType()
|
|
15
|
+
.with("Fraudster", () => "Incident")
|
|
16
|
+
.with("Card", "Transfer", () => "Transactions")
|
|
17
|
+
.exhaustive();
|
|
18
|
+
// Only fields with an input in the form map to a step: going back can't fix the others
|
|
19
|
+
const getFieldStep = ({ path }, context) => match(path)
|
|
20
|
+
.returnType()
|
|
21
|
+
.with(["victimAccountMembershipId"], () => Option.Some("Victim"))
|
|
22
|
+
.with(["transactionIds"], () => Option.Some("Transactions"))
|
|
23
|
+
.with(["fraudDetails", P.union("fraudsterChannels", "sharedInformationWithFraudster")], () => Option.Some(getDetailsStep("Fraudster", context)))
|
|
24
|
+
.with(["fraudDetails"], [
|
|
25
|
+
"fraudDetails",
|
|
26
|
+
P.union("reportedReason", "reportedTypology", "description", "discoveredAt", "discoveryDetails"),
|
|
27
|
+
], () => Option.Some("Incident"))
|
|
28
|
+
.with(["fraudCardDetails"], ["fraudCardDetails", P.union("isLostOrStolen", "lostOrStolenNoticedAt")], () => Option.Some(getDetailsStep("Card", context)))
|
|
29
|
+
.otherwise(() => Option.None());
|
|
30
|
+
const getEarliestStep = (fields, context) => {
|
|
31
|
+
var _a;
|
|
32
|
+
const steps = Array.filterMap(fields, field => getFieldStep(field, context));
|
|
33
|
+
return (_a = fixingSteps.find(step => steps.includes(step))) !== null && _a !== void 0 ? _a : "Rejected";
|
|
34
|
+
};
|
|
35
|
+
export const getRejectionStep = (rejection, context) => match(rejection)
|
|
36
|
+
.returnType()
|
|
37
|
+
.with({ __typename: "AccountMembershipNotFoundRejection" }, () => "Victim")
|
|
38
|
+
.with({
|
|
39
|
+
__typename: P.union("DisputeCaseTransactionsNotFoundRejection", "DisputeCaseTransactionsNotReportableRejection", "DisputeCaseTransactionsLimitExceededRejection", "DisputeCaseMultipleAccountsRejection", "DisputeCaseMultipleCardHoldersRejection",
|
|
40
|
+
// Details that don't apply come from the selection: changing it is the fix
|
|
41
|
+
"DisputeCaseDetailsNotApplicableRejection"),
|
|
42
|
+
}, () => "Transactions")
|
|
43
|
+
.with({ __typename: "DisputeCaseIncompleteRejection" }, ({ missingFields }) => getEarliestStep(missingFields, context))
|
|
44
|
+
// Submitted elsewhere (another tab, an operator): the report reached Swan
|
|
45
|
+
.with({ __typename: "DisputeCaseWrongStatusRejection", currentStatus: "Submitted" }, () => "Submitted")
|
|
46
|
+
.with({
|
|
47
|
+
__typename: P.union("DisputeCaseTransactionsAlreadyReportedRejection", "DisputeCaseTransactionsOutsideReportingWindowRejection", "DisputeCaseWrongStatusRejection", "DisputeCaseNotFoundRejection"),
|
|
48
|
+
}, () => "Rejected")
|
|
49
|
+
.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 || values.hasContactedMerchant != 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 is picked before 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
|
+
};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { Option } from "@bloodyowl/boxed";
|
|
2
|
+
import type { DraftFraudDisputeCaseInput, FraudReason, FraudReportTransaction, FraudsterChannel, FraudTypology, SharedInformationWithFraudster, UpdateDraftFraudDisputeCaseInput } from "./types";
|
|
2
3
|
export type FraudReportFormValues = {
|
|
3
4
|
transactions: FraudReportTransaction[];
|
|
4
5
|
victimAccountMembershipId?: string;
|
|
@@ -9,13 +10,23 @@ export type FraudReportFormValues = {
|
|
|
9
10
|
discoveryDetails?: string;
|
|
10
11
|
fraudsterChannels?: FraudsterChannel[];
|
|
11
12
|
sharedInformationWithFraudster?: SharedInformationWithFraudster[];
|
|
13
|
+
hasFiledPoliceComplaint?: boolean;
|
|
12
14
|
isLostOrStolen?: boolean;
|
|
13
15
|
lostOrStolenNoticedAt?: string;
|
|
16
|
+
hasContactedMerchant?: boolean;
|
|
14
17
|
externalReference?: string;
|
|
15
18
|
};
|
|
19
|
+
export declare const toFilled: (value: string | undefined) => Option<string>;
|
|
20
|
+
export declare const toFilledList: <T>(values: T[] | undefined) => Option<T[]>;
|
|
21
|
+
export declare const toRequiredFraudDetails: (values: FraudReportFormValues) => Option<{
|
|
22
|
+
reportedReason: "Manipulated" | "Unauthorized";
|
|
23
|
+
reportedTypology: "FakeAdvisor" | "FakeSupplierOrInvoice" | "FakeWebsite" | "ImpersonationOrPhishing" | "InvestmentScam" | "Other" | "RomanceScam";
|
|
24
|
+
description: string;
|
|
25
|
+
}>;
|
|
26
|
+
export declare const toTransactionIds: (values: FraudReportFormValues) => string[];
|
|
16
27
|
export declare const toDraftInput: (values: FraudReportFormValues) => DraftFraudDisputeCaseInput;
|
|
17
|
-
export declare const toUpdateInput: ({
|
|
18
|
-
|
|
28
|
+
export declare const toUpdateInput: ({ disputeCaseId, values, savedTransactionIds, }: {
|
|
29
|
+
disputeCaseId: string;
|
|
19
30
|
values: FraudReportFormValues;
|
|
20
31
|
savedTransactionIds: string[];
|
|
21
32
|
}) => UpdateDraftFraudDisputeCaseInput;
|