@swan-io/shared-business 18.5.0 → 18.7.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 (97) 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/FileInput.js +25 -10
  5. package/src/components/FileTile.d.ts +4 -3
  6. package/src/components/FileTile.js +14 -7
  7. package/src/components/FilesUploader.js +12 -4
  8. package/src/components/FraudReport/CardDetailsStep.d.ts +7 -0
  9. package/src/components/FraudReport/CardDetailsStep.js +46 -0
  10. package/src/components/FraudReport/DocumentsStep.d.ts +13 -0
  11. package/src/components/FraudReport/DocumentsStep.js +49 -0
  12. package/src/components/FraudReport/FraudReportLayout.d.ts +2 -1
  13. package/src/components/FraudReport/FraudReportLayout.js +2 -2
  14. package/src/components/FraudReport/FraudsterDetailsStep.d.ts +7 -0
  15. package/src/components/FraudReport/FraudsterDetailsStep.js +56 -0
  16. package/src/components/FraudReport/IntroStep.js +5 -1
  17. package/src/components/FraudReport/TransactionPicker.d.ts +13 -0
  18. package/src/components/FraudReport/TransactionPicker.js +213 -0
  19. package/src/components/FraudReport/TransactionPickerFilters.d.ts +8 -0
  20. package/src/components/FraudReport/TransactionPickerFilters.js +213 -0
  21. package/src/components/FraudReport/TransactionRows.d.ts +8 -0
  22. package/src/components/FraudReport/TransactionRows.js +32 -0
  23. package/src/components/FraudReport/TransactionsStep.js +9 -27
  24. package/src/components/FraudReport/TransferDetailsStep.d.ts +7 -0
  25. package/src/components/FraudReport/TransferDetailsStep.js +25 -0
  26. package/src/components/FraudReport/VictimStep.d.ts +3 -1
  27. package/src/components/FraudReport/VictimStep.js +38 -5
  28. package/src/components/LakeModal.js +1 -1
  29. package/src/components/SupportingDocumentCollection.d.ts +1 -0
  30. package/src/components/SupportingDocumentCollection.js +13 -14
  31. package/src/hooks/__tests__/useFilesUploader.test.d.ts +1 -0
  32. package/src/hooks/__tests__/useFilesUploader.test.js +101 -0
  33. package/src/hooks/__tests__/useFraudReportFlow.test.js +108 -20
  34. package/src/hooks/useFilesUploader.d.ts +2 -1
  35. package/src/hooks/useFilesUploader.js +28 -9
  36. package/src/hooks/useFraudReportFlow.js +12 -7
  37. package/src/locales/de.json +84 -8
  38. package/src/locales/en.json +77 -1
  39. package/src/locales/es.json +77 -1
  40. package/src/locales/fi.json +77 -1
  41. package/src/locales/fr.json +77 -1
  42. package/src/locales/it.json +77 -1
  43. package/src/locales/nl.json +77 -1
  44. package/src/locales/pt.json +77 -1
  45. package/src/utils/SwanFile.d.ts +2 -0
  46. package/src/utils/__tests__/fraudReport.card.test.d.ts +1 -0
  47. package/src/utils/__tests__/fraudReport.card.test.js +39 -0
  48. package/src/utils/__tests__/fraudReport.documents.test.d.ts +1 -0
  49. package/src/utils/__tests__/fraudReport.documents.test.js +61 -0
  50. package/src/utils/__tests__/fraudReport.fraudster.test.d.ts +1 -0
  51. package/src/utils/__tests__/fraudReport.fraudster.test.js +35 -0
  52. package/src/utils/__tests__/fraudReport.messages.test.d.ts +1 -0
  53. package/src/utils/__tests__/fraudReport.messages.test.js +28 -0
  54. package/src/utils/__tests__/fraudReport.picker.test.d.ts +1 -0
  55. package/src/utils/__tests__/fraudReport.picker.test.js +186 -0
  56. package/src/utils/__tests__/fraudReport.pickerFilters.test.d.ts +1 -0
  57. package/src/utils/__tests__/fraudReport.pickerFilters.test.js +144 -0
  58. package/src/utils/__tests__/fraudReport.prefill.test.js +7 -1
  59. package/src/utils/__tests__/fraudReport.rejections.test.js +11 -19
  60. package/src/utils/__tests__/fraudReport.resume.test.js +19 -4
  61. package/src/utils/__tests__/fraudReport.toInput.test.js +160 -40
  62. package/src/utils/__tests__/fraudReport.transactions.test.js +11 -1
  63. package/src/utils/__tests__/fraudReport.transfer.test.d.ts +1 -0
  64. package/src/utils/__tests__/fraudReport.transfer.test.js +31 -0
  65. package/src/utils/__tests__/fraudReport.victim.test.js +27 -1
  66. package/src/utils/__tests__/validation.test.js +81 -7
  67. package/src/utils/fraudReport/card.d.ts +11 -0
  68. package/src/utils/fraudReport/card.js +15 -0
  69. package/src/utils/fraudReport/documents.d.ts +9 -0
  70. package/src/utils/fraudReport/documents.js +18 -0
  71. package/src/utils/fraudReport/fakeApi.js +1 -1
  72. package/src/utils/fraudReport/fraudster.d.ts +10 -0
  73. package/src/utils/fraudReport/fraudster.js +11 -0
  74. package/src/utils/fraudReport/messages.d.ts +4 -0
  75. package/src/utils/fraudReport/messages.js +7 -0
  76. package/src/utils/fraudReport/picker.d.ts +19 -0
  77. package/src/utils/fraudReport/picker.js +50 -0
  78. package/src/utils/fraudReport/pickerFilters.d.ts +26 -0
  79. package/src/utils/fraudReport/pickerFilters.js +62 -0
  80. package/src/utils/fraudReport/prefill.d.ts +1 -1
  81. package/src/utils/fraudReport/prefill.js +6 -3
  82. package/src/utils/fraudReport/rejections.d.ts +0 -1
  83. package/src/utils/fraudReport/rejections.js +2 -6
  84. package/src/utils/fraudReport/resume.js +4 -4
  85. package/src/utils/fraudReport/toInput.d.ts +6 -3
  86. package/src/utils/fraudReport/toInput.js +41 -24
  87. package/src/utils/fraudReport/transactions.d.ts +2 -0
  88. package/src/utils/fraudReport/transactions.js +4 -0
  89. package/src/utils/fraudReport/transfer.d.ts +6 -0
  90. package/src/utils/fraudReport/transfer.js +8 -0
  91. package/src/utils/fraudReport/types.d.ts +1 -1
  92. package/src/utils/fraudReport/validation.d.ts +1 -1
  93. package/src/utils/fraudReport/validation.js +4 -0
  94. package/src/utils/fraudReport/victim.d.ts +11 -0
  95. package/src/utils/fraudReport/victim.js +9 -0
  96. package/src/utils/validation.d.ts +2 -0
  97. package/src/utils/validation.js +15 -8
@@ -1,6 +1,6 @@
1
1
  import { describe, expect, test } from "vitest";
2
2
  import { createFakeTransaction } from "../fraudReport/fakeApi";
3
- import { getTransactionsTotal, removeDuplicateTransactions } from "../fraudReport/transactions";
3
+ import { getTransactionsOverLimit, getTransactionsTotal, MAX_TRANSACTIONS, removeDuplicateTransactions, } from "../fraudReport/transactions";
4
4
  const withAmount = (value, currency = "EUR") => createFakeTransaction(`card-${value}`, "CardOutDebit", { amount: { value, currency } });
5
5
  describe("getTransactionsTotal", () => {
6
6
  test("adds the amounts without rounding drift", () => {
@@ -26,3 +26,13 @@ describe("removeDuplicateTransactions", () => {
26
26
  expect(removeDuplicateTransactions([card, transfer, { ...card, counterparty: "Lidl" }])).toEqual([card, transfer]);
27
27
  });
28
28
  });
29
+ describe("getTransactionsOverLimit", () => {
30
+ test("is 0 up to the limit", () => {
31
+ expect(getTransactionsOverLimit(0)).toBe(0);
32
+ expect(getTransactionsOverLimit(MAX_TRANSACTIONS)).toBe(0);
33
+ });
34
+ test("is the number of transactions to remove over the limit", () => {
35
+ expect(getTransactionsOverLimit(MAX_TRANSACTIONS + 1)).toBe(1);
36
+ expect(getTransactionsOverLimit(MAX_TRANSACTIONS + 2)).toBe(2);
37
+ });
38
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,31 @@
1
+ import { describe, expect, test } from "vitest";
2
+ import { getTransferActions, toTransferValues } from "../fraudReport/transfer";
3
+ describe("getTransferActions", () => {
4
+ test("selects the actions answered yes", () => {
5
+ expect(getTransferActions({ hasContactedBankOrBeneficiary: true, hasFiledPoliceComplaint: true })).toEqual(["BankOrBeneficiary", "Police"]);
6
+ });
7
+ test("selects nothing for actions answered no or not answered", () => {
8
+ expect(getTransferActions({
9
+ hasContactedBankOrBeneficiary: false,
10
+ hasFiledPoliceComplaint: undefined,
11
+ })).toEqual([]);
12
+ });
13
+ });
14
+ describe("toTransferValues", () => {
15
+ test("sends the selected actions as yes", () => {
16
+ expect(toTransferValues(["BankOrBeneficiary", "Police"])).toEqual({
17
+ hasContactedBankOrBeneficiary: true,
18
+ hasFiledPoliceComplaint: true,
19
+ });
20
+ });
21
+ test("leaves an unselected action empty instead of sending false", () => {
22
+ expect(toTransferValues(["Police"])).toEqual({
23
+ hasContactedBankOrBeneficiary: undefined,
24
+ hasFiledPoliceComplaint: true,
25
+ });
26
+ expect(toTransferValues([])).toEqual({
27
+ hasContactedBankOrBeneficiary: undefined,
28
+ hasFiledPoliceComplaint: undefined,
29
+ });
30
+ });
31
+ });
@@ -1,6 +1,7 @@
1
1
  import { Option } from "@bloodyowl/boxed";
2
2
  import { describe, expect, test } from "vitest";
3
- import { getInitialVictimChoice, getOtherAccountMemberships, getSelectedAccountMembershipId, getVictimAccountMembershipId, } from "../fraudReport/victim";
3
+ import { createFakeTransaction } from "../fraudReport/fakeApi";
4
+ import { getInitialVictimChoice, getOtherAccountMemberships, getSelectedAccountMembershipId, getVictimAccountMembershipId, getVictimChange, } from "../fraudReport/victim";
4
5
  const julia = { id: "member-1", name: "Julia Fox" };
5
6
  const nicolas = { id: "member-2", name: "Nicolas Saison" };
6
7
  const ada = { id: "member-3", name: "Ada Lovelace" };
@@ -140,3 +141,28 @@ describe("getVictimAccountMembershipId", () => {
140
141
  }).toUndefined()).toBe(victim);
141
142
  });
142
143
  });
144
+ describe("getVictimChange", () => {
145
+ const card = createFakeTransaction("card-1", "CardOutDebit");
146
+ const transfer = createFakeTransaction("transfer-1", "SepaCreditTransferOut");
147
+ test("removes the card transactions when the victim changes", () => {
148
+ expect(getVictimChange({
149
+ transactions: [card, transfer],
150
+ previousVictimAccountMembershipId: "member-1",
151
+ victimAccountMembershipId: "member-2",
152
+ })).toEqual({ changed: true, removed: [card], kept: [transfer] });
153
+ });
154
+ test("removes nothing when the victim stays the same", () => {
155
+ expect(getVictimChange({
156
+ transactions: [card, transfer],
157
+ previousVictimAccountMembershipId: "member-1",
158
+ victimAccountMembershipId: "member-1",
159
+ })).toEqual({ changed: false, removed: [], kept: [card, transfer] });
160
+ });
161
+ test("removes the card transactions when the previous victim isn't known", () => {
162
+ expect(getVictimChange({
163
+ transactions: [card, transfer],
164
+ previousVictimAccountMembershipId: undefined,
165
+ victimAccountMembershipId: "member-2",
166
+ })).toEqual({ changed: true, removed: [card], kept: [transfer] });
167
+ });
168
+ });
@@ -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);
@@ -131,13 +132,20 @@ describe("validateIndividualTaxNumber", () => {
131
132
  });
132
133
  describe("FIN (Finland)", () => {
133
134
  const validator = validateIndividualTaxNumber("FIN");
134
- test("accepts valid 11-character tax numbers", () => {
135
- expect(validator("12345678901")).toBeUndefined();
136
- expect(validator("A234567890B")).toBeUndefined();
135
+ test("accepts personal identity codes with their separator", () => {
136
+ expect(validator("131052-308T")).toBeUndefined();
137
+ expect(validator("131052+308T")).toBeUndefined();
138
+ expect(validator("131052A308T")).toBeUndefined();
139
+ expect(validator("010594Y9032")).toBeUndefined();
140
+ expect(validator("131052-308t")).toBeUndefined();
137
141
  });
138
142
  test("rejects invalid formats", () => {
139
- expect(validator("1234567890")).toBeDefined(); // 10 characters
140
- expect(validator("123456789012")).toBeDefined(); // 12 characters
143
+ expect(validator("131052308T")).toBeDefined();
144
+ expect(validator("12345678901")).toBeDefined();
145
+ expect(validator("131052G308T")).toBeDefined();
146
+ expect(validator("131052-308G")).toBeDefined();
147
+ expect(validator("131052-3089T")).toBeDefined();
148
+ expect(validator("3368725-9")).toBeDefined();
141
149
  });
142
150
  });
143
151
  describe("FRA (France)", () => {
@@ -370,6 +378,72 @@ describe("validateDate", () => {
370
378
  expect(validateDate({ day: "31", month: "04", year: "2024" })).toBeDefined(); // April has 30 days
371
379
  });
372
380
  });
381
+ describe("birth date rules", () => {
382
+ beforeEach(() => {
383
+ vi.useFakeTimers();
384
+ vi.setSystemTime(new Date("2026-11-30T12:00:00.000Z"));
385
+ });
386
+ afterEach(() => {
387
+ vi.useRealTimers();
388
+ });
389
+ describe("validateBirthdate", () => {
390
+ test("accepts a birth date of today", () => {
391
+ expect(validateBirthdate({ day: "30", month: "11", year: "2026" })).toBeUndefined();
392
+ });
393
+ test("accepts a birth date 120 years ago", () => {
394
+ expect(validateBirthdate({ day: "30", month: "11", year: "1906" })).toBeUndefined();
395
+ });
396
+ test("accepts a birth date exactly 150 years ago", () => {
397
+ expect(validateBirthdate({ day: "30", month: "11", year: "1876" })).toBeUndefined();
398
+ });
399
+ test("refuses a birth date more than 150 years ago", () => {
400
+ expect(validateBirthdate({ day: "29", month: "11", year: "1876" })).toBe(t("validation.invalidBirthDate"));
401
+ });
402
+ test("refuses a birth date in the future", () => {
403
+ expect(validateBirthdate({ day: "01", month: "12", year: "2026" })).toBe(t("validation.birthdateCannotBeFuture"));
404
+ });
405
+ test("refuses a missing or malformed date", () => {
406
+ expect(validateBirthdate(undefined)).toBe(t("validation.invalidBirthDate"));
407
+ expect(validateBirthdate({ day: "31", month: "02", year: "1990" })).toBe(t("validation.invalidBirthDate"));
408
+ });
409
+ });
410
+ describe("validateAdultBirthdate", () => {
411
+ test("accepts a person who turns 18 today", () => {
412
+ expect(validateAdultBirthdate({ day: "30", month: "11", year: "2008" })).toBeUndefined();
413
+ });
414
+ test("refuses a person who turns 18 tomorrow", () => {
415
+ expect(validateAdultBirthdate({ day: "01", month: "12", year: "2008" })).toBe(t("validation.birthdateMustBeAdult"));
416
+ });
417
+ test("accepts a person born on February 29th from February 28th of their 18th year", () => {
418
+ vi.setSystemTime(new Date("2026-02-28T12:00:00.000Z"));
419
+ expect(validateAdultBirthdate({ day: "29", month: "02", year: "2008" })).toBeUndefined();
420
+ });
421
+ test("accepts a person over 100 years old", () => {
422
+ expect(validateAdultBirthdate({ day: "30", month: "11", year: "1906" })).toBeUndefined();
423
+ });
424
+ test("refuses a birth date in the future, too old or malformed like the default rule", () => {
425
+ expect(validateAdultBirthdate({ day: "01", month: "12", year: "2026" })).toBe(t("validation.birthdateCannotBeFuture"));
426
+ expect(validateAdultBirthdate({ day: "29", month: "11", year: "1876" })).toBe(t("validation.invalidBirthDate"));
427
+ expect(validateAdultBirthdate({ day: "31", month: "02", year: "1990" })).toBe(t("validation.invalidBirthDate"));
428
+ expect(validateAdultBirthdate(undefined)).toBe(t("validation.invalidBirthDate"));
429
+ });
430
+ });
431
+ describe("validateAdultBirthdateString", () => {
432
+ test("refuses a saved birth date of a person who turns 18 tomorrow", () => {
433
+ expect(validateAdultBirthdateString("2008-12-01")).toBe(t("validation.birthdateMustBeAdult"));
434
+ });
435
+ test("accepts a saved birth date of a person who turns 18 today", () => {
436
+ expect(validateAdultBirthdateString("2008-11-30")).toBeUndefined();
437
+ });
438
+ test("refuses a saved date that is not in the YYYY-MM-DD format", () => {
439
+ expect(validateAdultBirthdateString("30/11/1990")).toBe(t("validation.invalidBirthDate"));
440
+ });
441
+ test("leaves an empty value to the required validator", () => {
442
+ expect(validateAdultBirthdateString(undefined)).toBeUndefined();
443
+ expect(validateAdultBirthdateString("")).toBeUndefined();
444
+ });
445
+ });
446
+ });
373
447
  describe("sanitizeDecimal", () => {
374
448
  test("removes spaces from decimal input", () => {
375
449
  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
+ });
@@ -0,0 +1,9 @@
1
+ import type { Document } from "../../components/SupportingDocumentCollection";
2
+ import type { SwanFile } from "../SwanFile";
3
+ import type { FraudReportDocumentPurpose } from "./types";
4
+ export type FraudReportDocument = Document<FraudReportDocumentPurpose>;
5
+ export type FraudReportDocumentGroup = "PoliceReport" | "OtherDocuments";
6
+ export declare const fraudReportDocumentGroups: FraudReportDocumentGroup[];
7
+ export declare const getUploadPurpose: (group: FraudReportDocumentGroup) => FraudReportDocumentPurpose;
8
+ export declare const getGroupFiles: (documents: FraudReportDocument[], group: FraudReportDocumentGroup) => SwanFile[];
9
+ export declare const setGroupFiles: (documents: FraudReportDocument[], group: FraudReportDocumentGroup, files: SwanFile[]) => FraudReportDocument[];
@@ -0,0 +1,18 @@
1
+ export const fraudReportDocumentGroups = [
2
+ "PoliceReport",
3
+ "OtherDocuments",
4
+ ];
5
+ const uploadPurposes = {
6
+ PoliceReport: "PoliceReport",
7
+ OtherDocuments: "FraudEvidence",
8
+ };
9
+ export const getUploadPurpose = (group) => uploadPurposes[group];
10
+ const getGroup = (purpose) => purpose === "PoliceReport" ? "PoliceReport" : "OtherDocuments";
11
+ export const getGroupFiles = (documents, group) => documents.filter(({ purpose }) => getGroup(purpose) === group).map(({ file }) => file);
12
+ export const setGroupFiles = (documents, group, files) => [
13
+ ...documents.filter(({ purpose }) => getGroup(purpose) !== group),
14
+ ...files.map(file => { var _a; var _b; return ({
15
+ file,
16
+ purpose: (_b = (_a = documents.find(document => document.file.id === file.id)) === null || _a === void 0 ? void 0 : _a.purpose) !== null && _b !== void 0 ? _b : uploadPurposes[group],
17
+ }); }),
18
+ ];
@@ -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,19 @@
1
+ import type { FraudReportTransaction } from "./types";
2
+ export type FraudReportPickerRow = {
3
+ transaction: FraudReportTransaction;
4
+ cardAccountMembershipId: string | null;
5
+ alreadyReported: boolean;
6
+ };
7
+ export declare const getPickerTransactions: (rows: FraudReportPickerRow[], victimAccountMembershipId: string | undefined) => FraudReportTransaction[];
8
+ export declare const toggleTransaction: (selected: FraudReportTransaction[], transaction: FraudReportTransaction) => FraudReportTransaction[];
9
+ export declare const getSelectAllValue: (selected: FraudReportTransaction[], listed: FraudReportTransaction[]) => boolean | "mixed";
10
+ export declare const toggleAllTransactions: (selected: FraudReportTransaction[], listed: FraudReportTransaction[]) => FraudReportTransaction[];
11
+ export declare const MAX_PAGES_WITHOUT_ROWS = 3;
12
+ export type PickerPages = {
13
+ rowCount: number;
14
+ listedCount: number;
15
+ withoutRows: number;
16
+ restarted: boolean;
17
+ };
18
+ export declare const restartPickerPages: (pages: PickerPages) => PickerPages;
19
+ export declare const countPagesWithoutRows: (previous: PickerPages, rowCount: number, listedCount: number, loaded?: boolean) => PickerPages;
@@ -0,0 +1,50 @@
1
+ import { match } from "ts-pattern";
2
+ import { removeDuplicateTransactions } from "./transactions";
3
+ export const getPickerTransactions = (rows, victimAccountMembershipId) => removeDuplicateTransactions(rows
4
+ .filter(({ transaction, cardAccountMembershipId, alreadyReported }) => !alreadyReported &&
5
+ match(transaction.rail)
6
+ .with("Card", () => cardAccountMembershipId === victimAccountMembershipId)
7
+ .with("Transfer", () => true)
8
+ .exhaustive())
9
+ .map(({ transaction }) => transaction));
10
+ const isSelected = (selected, { id }) => selected.some(item => item.id === id);
11
+ export const toggleTransaction = (selected, transaction) => isSelected(selected, transaction)
12
+ ? selected.filter(({ id }) => id !== transaction.id)
13
+ : [...selected, transaction];
14
+ export const getSelectAllValue = (selected, listed) => {
15
+ const count = listed.filter(item => isSelected(selected, item)).length;
16
+ return count === 0 ? false : count === listed.length ? true : "mixed";
17
+ };
18
+ // Only the listed transactions change: a selected one that isn't listed (not loaded yet) stays.
19
+ export const toggleAllTransactions = (selected, listed) => getSelectAllValue(selected, listed) === true
20
+ ? selected.filter(item => !isSelected(listed, item))
21
+ : [...selected, ...listed.filter(item => !isSelected(selected, item))];
22
+ export const MAX_PAGES_WITHOUT_ROWS = 3;
23
+ export const restartPickerPages = (pages) => ({
24
+ ...pages,
25
+ withoutRows: 0,
26
+ restarted: true,
27
+ });
28
+ // Counts the pages in a row that added no listed row, so the picker can stop asking for more
29
+ // on its own: the victim filter could otherwise page through the whole account.
30
+ export const countPagesWithoutRows = (previous, rowCount, listedCount,
31
+ // A load just ended. Another list can have as many rows as the one before: only this tells
32
+ // that it arrived. An app that never passes `loading` gets one more page before the pause.
33
+ loaded = false) => {
34
+ if (rowCount === previous.rowCount && !(previous.restarted && loaded)) {
35
+ return previous;
36
+ }
37
+ // No row loaded isn't a page.
38
+ if (rowCount === 0) {
39
+ return { rowCount, listedCount, withoutRows: 0, restarted: false };
40
+ }
41
+ // Another list: its first page is compared with nothing.
42
+ const firstPage = previous.restarted || rowCount < previous.rowCount;
43
+ const added = firstPage ? listedCount > 0 : listedCount > previous.listedCount;
44
+ return {
45
+ rowCount,
46
+ listedCount,
47
+ withoutRows: added ? 0 : firstPage ? 1 : previous.withoutRows + 1,
48
+ restarted: false,
49
+ };
50
+ };
@@ -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,3 +1,3 @@
1
1
  import type { FraudReportFormValues } from "./toInput";
2
2
  import type { FraudReportCase } from "./types";
3
- export declare const toFormValues: ({ transactions, fraudDetails, fraudCardDetails, victimAccountMembershipId, externalReference, }: Pick<FraudReportCase, "transactions" | "fraudDetails" | "fraudCardDetails" | "victimAccountMembershipId" | "externalReference">) => FraudReportFormValues;
3
+ export declare const toFormValues: ({ transactions, fraudDetails, fraudCardDetails, fraudTransferDetails, victimAccountMembershipId, externalReference, }: Pick<FraudReportCase, "transactions" | "fraudDetails" | "fraudCardDetails" | "fraudTransferDetails" | "victimAccountMembershipId" | "externalReference">) => FraudReportFormValues;
@@ -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, fraudTransferDetails, victimAccountMembershipId, externalReference, }) => { var _a, _b, _c, _d, _e, _f, _g; 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,10 @@ 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,
15
+ hasContactedBankOrBeneficiary: (_g = fraudTransferDetails === null || fraudTransferDetails === void 0 ? void 0 : fraudTransferDetails.hasContactedBankOrBeneficiary) !== null && _g !== void 0 ? _g : undefined,
13
16
  externalReference: externalReference !== null && externalReference !== void 0 ? externalReference : undefined,
14
17
  }); };
@@ -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)
7
- // The transfer sub-step has no form field yet
6
+ .with("Card", () => values.isLostOrStolen != null || values.hasContactedMerchant != null)
7
+ // Its only answer has no "No", so an empty one can't tell skipped from seen
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,11 @@ 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;
17
+ hasContactedBankOrBeneficiary?: boolean;
15
18
  externalReference?: string;
16
19
  };
17
20
  export declare const toFilled: (value: string | undefined) => Option<string>;
@@ -23,8 +26,8 @@ export declare const toRequiredFraudDetails: (values: FraudReportFormValues) =>
23
26
  }>;
24
27
  export declare const toTransactionIds: (values: FraudReportFormValues) => string[];
25
28
  export declare const toDraftInput: (values: FraudReportFormValues) => DraftFraudDisputeCaseInput;
26
- export declare const toUpdateInput: ({ savedCase, values, savedTransactionIds, }: {
27
- savedCase: Pick<FraudReportCase, "id" | "fraudDetails" | "fraudCardDetails">;
29
+ export declare const toUpdateInput: ({ disputeCaseId, values, savedTransactionIds, }: {
30
+ disputeCaseId: string;
28
31
  values: FraudReportFormValues;
29
32
  savedTransactionIds: string[];
30
33
  }) => UpdateDraftFraudDisputeCaseInput;