@swan-io/shared-business 18.5.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.
Files changed (70) hide show
  1. package/package.json +3 -3
  2. package/src/components/BirthdatePicker.d.ts +3 -1
  3. package/src/components/BirthdatePicker.js +2 -2
  4. package/src/components/FraudReport/CardDetailsStep.d.ts +7 -0
  5. package/src/components/FraudReport/CardDetailsStep.js +46 -0
  6. package/src/components/FraudReport/FraudsterDetailsStep.d.ts +7 -0
  7. package/src/components/FraudReport/FraudsterDetailsStep.js +56 -0
  8. package/src/components/FraudReport/IntroStep.js +5 -1
  9. package/src/components/FraudReport/TransactionPicker.d.ts +13 -0
  10. package/src/components/FraudReport/TransactionPicker.js +213 -0
  11. package/src/components/FraudReport/TransactionPickerFilters.d.ts +8 -0
  12. package/src/components/FraudReport/TransactionPickerFilters.js +213 -0
  13. package/src/components/FraudReport/TransactionRows.d.ts +8 -0
  14. package/src/components/FraudReport/TransactionRows.js +32 -0
  15. package/src/components/FraudReport/TransactionsStep.js +9 -27
  16. package/src/components/FraudReport/VictimStep.d.ts +3 -1
  17. package/src/components/FraudReport/VictimStep.js +38 -5
  18. package/src/components/LakeModal.js +1 -1
  19. package/src/hooks/__tests__/useFraudReportFlow.test.js +108 -20
  20. package/src/hooks/useFraudReportFlow.js +12 -7
  21. package/src/locales/de.json +62 -8
  22. package/src/locales/en.json +55 -1
  23. package/src/locales/es.json +55 -1
  24. package/src/locales/fi.json +55 -1
  25. package/src/locales/fr.json +55 -1
  26. package/src/locales/it.json +55 -1
  27. package/src/locales/nl.json +55 -1
  28. package/src/locales/pt.json +55 -1
  29. package/src/utils/__tests__/fraudReport.card.test.d.ts +1 -0
  30. package/src/utils/__tests__/fraudReport.card.test.js +39 -0
  31. package/src/utils/__tests__/fraudReport.fraudster.test.d.ts +1 -0
  32. package/src/utils/__tests__/fraudReport.fraudster.test.js +35 -0
  33. package/src/utils/__tests__/fraudReport.messages.test.d.ts +1 -0
  34. package/src/utils/__tests__/fraudReport.messages.test.js +28 -0
  35. package/src/utils/__tests__/fraudReport.picker.test.d.ts +1 -0
  36. package/src/utils/__tests__/fraudReport.picker.test.js +171 -0
  37. package/src/utils/__tests__/fraudReport.pickerFilters.test.d.ts +1 -0
  38. package/src/utils/__tests__/fraudReport.pickerFilters.test.js +144 -0
  39. package/src/utils/__tests__/fraudReport.prefill.test.js +3 -1
  40. package/src/utils/__tests__/fraudReport.rejections.test.js +11 -19
  41. package/src/utils/__tests__/fraudReport.resume.test.js +17 -3
  42. package/src/utils/__tests__/fraudReport.toInput.test.js +84 -30
  43. package/src/utils/__tests__/fraudReport.transactions.test.js +11 -1
  44. package/src/utils/__tests__/fraudReport.victim.test.js +27 -1
  45. package/src/utils/__tests__/validation.test.js +69 -2
  46. package/src/utils/fraudReport/card.d.ts +11 -0
  47. package/src/utils/fraudReport/card.js +15 -0
  48. package/src/utils/fraudReport/fakeApi.js +1 -1
  49. package/src/utils/fraudReport/fraudster.d.ts +10 -0
  50. package/src/utils/fraudReport/fraudster.js +11 -0
  51. package/src/utils/fraudReport/messages.d.ts +4 -0
  52. package/src/utils/fraudReport/messages.js +7 -0
  53. package/src/utils/fraudReport/picker.d.ts +18 -0
  54. package/src/utils/fraudReport/picker.js +49 -0
  55. package/src/utils/fraudReport/pickerFilters.d.ts +26 -0
  56. package/src/utils/fraudReport/pickerFilters.js +62 -0
  57. package/src/utils/fraudReport/prefill.js +5 -3
  58. package/src/utils/fraudReport/rejections.d.ts +0 -1
  59. package/src/utils/fraudReport/rejections.js +2 -6
  60. package/src/utils/fraudReport/resume.js +3 -3
  61. package/src/utils/fraudReport/toInput.d.ts +5 -3
  62. package/src/utils/fraudReport/toInput.js +20 -22
  63. package/src/utils/fraudReport/transactions.d.ts +2 -0
  64. package/src/utils/fraudReport/transactions.js +4 -0
  65. package/src/utils/fraudReport/validation.d.ts +1 -1
  66. package/src/utils/fraudReport/validation.js +4 -0
  67. package/src/utils/fraudReport/victim.d.ts +11 -0
  68. package/src/utils/fraudReport/victim.js +9 -0
  69. package/src/utils/validation.d.ts +2 -0
  70. package/src/utils/validation.js +14 -7
@@ -1,5 +1,6 @@
1
- import { describe, expect, test } from "vitest";
2
- import { getCompanyTaxNumberHelp, getCompanyTaxNumberPlaceholder, getIndividualTaxNumberHelp, getIndividualTaxNumberPlaceholder, isValidEmail, isValidUsaTaxNumber, sanitizeDecimal, validateArrayRequired, validateBooleanRequired, validateBooleanTypeRequired, validateCompanyTaxNumber, validateDate, validateIndividualTaxNumber, validateName, validateNullableRequired, validateRequired, } from "../validation";
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,5 +1,6 @@
1
1
  import { Future, Option, Result } from "@bloodyowl/boxed";
2
2
  import { match } from "ts-pattern";
3
+ import { MAX_TRANSACTIONS } from "./transactions";
3
4
  const getRail = (type) => match(type)
4
5
  .returnType()
5
6
  .with("CardOutDebit", () => "Card")
@@ -13,7 +14,6 @@ export const createFakeTransaction = (id, type, details = {}) => { var _a, _b, _
13
14
  counterparty: (_b = details.counterparty) !== null && _b !== void 0 ? _b : `Merchant ${id}`,
14
15
  amount: (_c = details.amount) !== null && _c !== void 0 ? _c : { value: "10.00", currency: "EUR" },
15
16
  }); };
16
- const MAX_TRANSACTIONS = 100;
17
17
  const DRAFT_LIFETIME_MS = 30 * 24 * 60 * 60 * 1000;
18
18
  const isDefined = (value) => value !== undefined;
19
19
  const unique = (values) => [...new Set(values)];
@@ -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,4 @@
1
+ export declare const getTransactionsLimitMessage: ({ max, toRemove, }?: {
2
+ max?: number;
3
+ toRemove?: number;
4
+ }) => string;
@@ -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
+ });
@@ -1,4 +1,4 @@
1
- export const toFormValues = ({ transactions, fraudDetails, fraudCardDetails, victimAccountMembershipId, externalReference, }) => { var _a, _b, _c, _d; return ({
1
+ export const toFormValues = ({ transactions, fraudDetails, fraudCardDetails, victimAccountMembershipId, externalReference, }) => { var _a, _b, _c, _d, _e, _f; return ({
2
2
  transactions,
3
3
  victimAccountMembershipId: victimAccountMembershipId !== null && victimAccountMembershipId !== void 0 ? victimAccountMembershipId : undefined,
4
4
  reportedReason: fraudDetails === null || fraudDetails === void 0 ? void 0 : fraudDetails.reportedReason,
@@ -8,7 +8,9 @@ export const toFormValues = ({ transactions, fraudDetails, fraudCardDetails, vic
8
8
  discoveryDetails: (_b = fraudDetails === null || fraudDetails === void 0 ? void 0 : fraudDetails.discoveryDetails) !== null && _b !== void 0 ? _b : undefined,
9
9
  fraudsterChannels: fraudDetails === null || fraudDetails === void 0 ? void 0 : fraudDetails.fraudsterChannels,
10
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,
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,
13
15
  externalReference: externalReference !== null && externalReference !== void 0 ? externalReference : undefined,
14
16
  }); };
@@ -3,7 +3,6 @@ import { type FraudReportDetailsStep, type FraudReportRejection } from "./types"
3
3
  type FixingStep = Exclude<FraudReportLayoutStep, "Submitted" | "Documents">;
4
4
  export type FraudReportRejectionStep = FixingStep | "Submitted" | "Rejected";
5
5
  export type FraudReportRejectionContext = {
6
- hasDraft: boolean;
7
6
  detailsSteps: readonly FraudReportDetailsStep[];
8
7
  };
9
8
  export declare const getRejectionStep: (rejection: FraudReportRejection, context: FraudReportRejectionContext) => FraudReportRejectionStep;
@@ -7,8 +7,6 @@ const fixingSteps = [
7
7
  "Incident",
8
8
  ...fraudReportDetailsSteps,
9
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
10
  // A sub-step missing from the flow is fixed where the choice that adds it is made
13
11
  const getDetailsStep = (step, { detailsSteps }) => detailsSteps.includes(step)
14
12
  ? step
@@ -20,7 +18,7 @@ const getDetailsStep = (step, { detailsSteps }) => detailsSteps.includes(step)
20
18
  // Only fields with an input in the form map to a step: going back can't fix the others
21
19
  const getFieldStep = ({ path }, context) => match(path)
22
20
  .returnType()
23
- .with(["victimAccountMembershipId"], () => getVictimStep(context))
21
+ .with(["victimAccountMembershipId"], () => Option.Some("Victim"))
24
22
  .with(["transactionIds"], () => Option.Some("Transactions"))
25
23
  .with(["fraudDetails", P.union("fraudsterChannels", "sharedInformationWithFraudster")], () => Option.Some(getDetailsStep("Fraudster", context)))
26
24
  .with(["fraudDetails"], [
@@ -36,9 +34,7 @@ const getEarliestStep = (fields, context) => {
36
34
  };
37
35
  export const getRejectionStep = (rejection, context) => match(rejection)
38
36
  .returnType()
39
- .with({ __typename: "AccountMembershipNotFoundRejection" }, () => getVictimStep(context)
40
- .map((step) => step)
41
- .getOr("Rejected"))
37
+ .with({ __typename: "AccountMembershipNotFoundRejection" }, () => "Victim")
42
38
  .with({
43
39
  __typename: P.union("DisputeCaseTransactionsNotFoundRejection", "DisputeCaseTransactionsNotReportableRejection", "DisputeCaseTransactionsLimitExceededRejection", "DisputeCaseMultipleAccountsRejection", "DisputeCaseMultipleCardHoldersRejection",
44
40
  // Details that don't apply come from the selection: changing it is the fix
@@ -3,13 +3,13 @@ import { match } from "ts-pattern";
3
3
  import { getDetailsSteps } from "./stepper";
4
4
  import { toFilledList, toRequiredFraudDetails, toTransactionIds, } from "./toInput";
5
5
  const isDetailsStepAnswered = (step, values) => match(step)
6
- .with("Card", () => values.isLostOrStolen != null)
6
+ .with("Card", () => values.isLostOrStolen != null || values.hasContactedMerchant != null)
7
7
  // The transfer sub-step has no form field yet
8
8
  .with("Transfer", () => true)
9
- .with("Fraudster", () => toFilledList(values.fraudsterChannels).isSome() &&
9
+ .with("Fraudster", () => toFilledList(values.fraudsterChannels).isSome() ||
10
10
  toFilledList(values.sharedInformationWithFraudster).isSome())
11
11
  .exhaustive();
12
- // The victim can't change once the draft exists, so a resumed report never opens on it
12
+ // The victim is picked before the draft exists, so a resumed report never opens on it
13
13
  export const getResumeStep = (values,
14
14
  // The transactions the report was opened from
15
15
  startTransactionIds = []) => {
@@ -1,5 +1,5 @@
1
1
  import { Option } from "@bloodyowl/boxed";
2
- import type { DraftFraudDisputeCaseInput, FraudReason, FraudReportCase, FraudReportTransaction, FraudsterChannel, FraudTypology, SharedInformationWithFraudster, UpdateDraftFraudDisputeCaseInput } from "./types";
2
+ import type { DraftFraudDisputeCaseInput, FraudReason, FraudReportTransaction, FraudsterChannel, FraudTypology, SharedInformationWithFraudster, UpdateDraftFraudDisputeCaseInput } from "./types";
3
3
  export type FraudReportFormValues = {
4
4
  transactions: FraudReportTransaction[];
5
5
  victimAccountMembershipId?: string;
@@ -10,8 +10,10 @@ export type FraudReportFormValues = {
10
10
  discoveryDetails?: string;
11
11
  fraudsterChannels?: FraudsterChannel[];
12
12
  sharedInformationWithFraudster?: SharedInformationWithFraudster[];
13
+ hasFiledPoliceComplaint?: boolean;
13
14
  isLostOrStolen?: boolean;
14
15
  lostOrStolenNoticedAt?: string;
16
+ hasContactedMerchant?: boolean;
15
17
  externalReference?: string;
16
18
  };
17
19
  export declare const toFilled: (value: string | undefined) => Option<string>;
@@ -23,8 +25,8 @@ export declare const toRequiredFraudDetails: (values: FraudReportFormValues) =>
23
25
  }>;
24
26
  export declare const toTransactionIds: (values: FraudReportFormValues) => string[];
25
27
  export declare const toDraftInput: (values: FraudReportFormValues) => DraftFraudDisputeCaseInput;
26
- export declare const toUpdateInput: ({ savedCase, values, savedTransactionIds, }: {
27
- savedCase: Pick<FraudReportCase, "id" | "fraudDetails" | "fraudCardDetails">;
28
+ export declare const toUpdateInput: ({ disputeCaseId, values, savedTransactionIds, }: {
29
+ disputeCaseId: string;
28
30
  values: FraudReportFormValues;
29
31
  savedTransactionIds: string[];
30
32
  }) => UpdateDraftFraudDisputeCaseInput;
@@ -10,9 +10,9 @@ export const toRequiredFraudDetails = (values) => Option.allFromDict({
10
10
  reportedTypology: Option.fromNullable(values.reportedTypology),
11
11
  description: toFilled(values.description),
12
12
  });
13
- const toFraudDetails = (values, savedDetails) => {
13
+ const toFraudDetails = (values) => {
14
14
  const hasFraudster = getDetailsSteps(values).includes("Fraudster");
15
- return toRequiredFraudDetails(values).map(required => { var _a; var _b; return ({
15
+ return toRequiredFraudDetails(values).map(required => { var _a; return ({
16
16
  ...required,
17
17
  discoveredAt: toFilled(values.discoveredAt).toNull(),
18
18
  discoveryDetails: toFilled(values.discoveryDetails).toNull(),
@@ -20,30 +20,28 @@ const toFraudDetails = (values, savedDetails) => {
20
20
  sharedInformationWithFraudster: hasFraudster
21
21
  ? toFilledList(values.sharedInformationWithFraudster).toNull()
22
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,
23
+ hasFiledPoliceComplaint: (_a = values.hasFiledPoliceComplaint) !== null && _a !== void 0 ? _a : null,
24
24
  }); });
25
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
- });
26
+ const toFraudCardDetails = (values, { sendEmpty }) => {
27
+ var _a, _b;
28
+ const details = {
29
+ isLostOrStolen: (_a = values.isLostOrStolen) !== null && _a !== void 0 ? _a : null,
30
+ lostOrStolenNoticedAt: toFilled(values.lostOrStolenNoticedAt).toNull(),
31
+ hasContactedMerchant: (_b = values.hasContactedMerchant) !== null && _b !== void 0 ? _b : null,
32
+ };
33
+ return sendEmpty || Object.values(details).some(value => value !== null)
34
+ ? Option.Some(details)
35
+ : Option.None();
38
36
  };
39
- const toDetails = (values, savedDetails) => {
40
- const fraudDetails = toFraudDetails(values, savedDetails)
37
+ const toDetails = (values, { isUpdate }) => {
38
+ const fraudDetails = toFraudDetails(values)
41
39
  .map(value => ({ fraudDetails: value }))
42
40
  .toUndefined();
43
41
  return match(getCaseRail(values.transactions))
44
42
  .with(Option.P.Some(P.union("CardOnly", "Mixed")), () => ({
45
43
  ...fraudDetails,
46
- ...toFraudCardDetails(values, savedDetails)
44
+ ...toFraudCardDetails(values, { sendEmpty: isUpdate })
47
45
  .map(value => ({ fraudCardDetails: value }))
48
46
  .toUndefined(),
49
47
  }))
@@ -63,17 +61,17 @@ const isSameSelection = (transactionIds, savedTransactionIds) => {
63
61
  };
64
62
  export const toDraftInput = (values) => ({
65
63
  transactionIds: toTransactionIds(values),
66
- ...toDetails(values),
64
+ ...toDetails(values, { isUpdate: false }),
67
65
  ...match(values.externalReference)
68
66
  .with(P.union(undefined, ""), () => undefined)
69
67
  .otherwise(externalReference => ({ externalReference })),
70
68
  });
71
- export const toUpdateInput = ({ savedCase, values, savedTransactionIds, }) => {
69
+ export const toUpdateInput = ({ disputeCaseId, values, savedTransactionIds, }) => {
72
70
  const transactionIds = toTransactionIds(values);
73
71
  return {
74
- disputeCaseId: savedCase.id,
72
+ disputeCaseId,
75
73
  ...(isSameSelection(transactionIds, savedTransactionIds) ? undefined : { transactionIds }),
76
- ...toDetails(values, savedCase),
74
+ ...toDetails(values, { isUpdate: true }),
77
75
  ...match(values.externalReference)
78
76
  .with(undefined, () => undefined)
79
77
  .with("", () => ({ externalReference: null }))
@@ -1,4 +1,6 @@
1
1
  import type { FraudReportTransaction } from "./types";
2
+ export declare const MAX_TRANSACTIONS = 100;
3
+ export declare const getTransactionsOverLimit: (count: number) => number;
2
4
  export declare const removeDuplicateTransactions: (transactions: FraudReportTransaction[]) => FraudReportTransaction[];
3
5
  export declare const getTransactionsTotal: (transactions: Pick<FraudReportTransaction, "amount">[]) => {
4
6
  value: number;
@@ -1,3 +1,7 @@
1
+ // The most transactions a dispute case takes (`DisputeCaseTransactionsLimitExceededRejection`).
2
+ export const MAX_TRANSACTIONS = 100;
3
+ // How many transactions a selection has to lose to fit in one report.
4
+ export const getTransactionsOverLimit = (count) => Math.max(0, count - MAX_TRANSACTIONS);
1
5
  export const removeDuplicateTransactions = (transactions) => transactions.filter((transaction, index) => transactions.findIndex(({ id }) => id === transaction.id) === index);
2
6
  export const getTransactionsTotal = (transactions) => {
3
7
  var _a;
@@ -1,6 +1,6 @@
1
1
  import type { Validator } from "@swan-io/use-form";
2
2
  import type { SharedInformationWithFraudster } from "./types";
3
- export type FraudReportValidationError = "Required" | "Duplicates" | "InvalidDate" | "DateInFuture" | "NoneWithOtherValues" | "TooLong" | "InvalidCharacters";
3
+ export type FraudReportValidationError = "Required" | "Duplicates" | "TooMany" | "InvalidDate" | "DateInFuture" | "NoneWithOtherValues" | "TooLong" | "InvalidCharacters";
4
4
  type FraudReportValidator<Value> = Validator<Value, FraudReportValidationError>;
5
5
  export declare const DESCRIPTION_MAX_LENGTH = 2000;
6
6
  export declare const DISCOVERY_DETAILS_MAX_LENGTH = 1000;
@@ -1,4 +1,5 @@
1
1
  import dayjs from "dayjs";
2
+ import { MAX_TRANSACTIONS } from "./transactions";
2
3
  export const DESCRIPTION_MAX_LENGTH = 2000;
3
4
  export const DISCOVERY_DETAILS_MAX_LENGTH = 1000;
4
5
  export const EXTERNAL_REFERENCE_MAX_LENGTH = 255;
@@ -10,6 +11,9 @@ export const validateTransactionIds = transactionIds => {
10
11
  if (new Set(transactionIds).size !== transactionIds.length) {
11
12
  return "Duplicates";
12
13
  }
14
+ if (transactionIds.length > MAX_TRANSACTIONS) {
15
+ return "TooMany";
16
+ }
13
17
  };
14
18
  export const validateSelected = (value) => (value == null ? "Required" : undefined);
15
19
  export const validateNotInFuture = value => {
@@ -1,7 +1,9 @@
1
1
  import { Option } from "@bloodyowl/boxed";
2
+ import type { FraudReportTransaction } from "./types";
2
3
  export type FraudReportAccountMembership = {
3
4
  id: string;
4
5
  name: string;
6
+ phoneNumber?: string;
5
7
  };
6
8
  export type VictimAnswer = "Myself" | "SomeoneElse";
7
9
  type VictimChoice = {
@@ -27,4 +29,13 @@ export declare const getVictimAccountMembershipId: ({ currentAccountMembership,
27
29
  accountMemberships: FraudReportAccountMembership[];
28
30
  choice: VictimChoice;
29
31
  }) => Option<string>;
32
+ export declare const getVictimChange: ({ transactions, previousVictimAccountMembershipId, victimAccountMembershipId, }: {
33
+ transactions: FraudReportTransaction[];
34
+ previousVictimAccountMembershipId: string | undefined;
35
+ victimAccountMembershipId: string | undefined;
36
+ }) => {
37
+ changed: boolean;
38
+ removed: FraudReportTransaction[];
39
+ kept: FraudReportTransaction[];
40
+ };
30
41
  export {};
@@ -26,3 +26,12 @@ export const getVictimAccountMembershipId = ({ currentAccountMembership, account
26
26
  .exhaustive()),
27
27
  });
28
28
  };
29
+ export const getVictimChange = ({ transactions, previousVictimAccountMembershipId, victimAccountMembershipId, }) => {
30
+ const changed = victimAccountMembershipId != null &&
31
+ previousVictimAccountMembershipId !== victimAccountMembershipId;
32
+ return {
33
+ changed,
34
+ removed: changed ? transactions.filter(({ rail }) => rail === "Card") : [],
35
+ kept: changed ? transactions.filter(({ rail }) => rail !== "Card") : transactions,
36
+ };
37
+ };
@@ -20,6 +20,8 @@ export { printFormat as printIbanFormat } from "iban";
20
20
  export declare const validateIban: (iban: string) => string | undefined;
21
21
  export declare const validateDate: (value: ExtractedDate | undefined) => string | undefined;
22
22
  export declare const validateBirthdate: (value: ExtractedDate | undefined) => string | undefined;
23
+ export declare const validateAdultBirthdate: (value: ExtractedDate | undefined) => string | undefined;
24
+ export declare const validateAdultBirthdateString: (value: string | undefined) => string | undefined;
23
25
  export declare const getTaxNumberLabel: (isCompany: boolean, country: CompanyCountryCCA3) => string;
24
26
  export declare const getIndividualTaxNumberPlaceholder: (country: IndividualCountryCCA3 | CompanyCountryCCA3) => string | undefined;
25
27
  export declare const getCompanyTaxNumberPlaceholder: (country: IndividualCountryCCA3 | CompanyCountryCCA3) => string | undefined;