@swan-io/shared-business 18.3.0 → 18.4.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/utils/__tests__/fraudReport.toInput.test.d.ts +1 -0
- package/src/utils/__tests__/fraudReport.toInput.test.js +529 -0
- package/src/utils/fraudReport/rail.d.ts +5 -0
- package/src/utils/fraudReport/rail.js +14 -0
- package/src/utils/fraudReport/toInput.d.ts +21 -0
- package/src/utils/fraudReport/toInput.js +74 -0
- package/src/utils/fraudReport/validation.d.ts +14 -0
- package/src/utils/fraudReport/validation.js +54 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@swan-io/shared-business",
|
|
3
|
-
"version": "18.
|
|
3
|
+
"version": "18.4.0",
|
|
4
4
|
"engines": {
|
|
5
5
|
"node": ">22.12.0"
|
|
6
6
|
},
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"react": ">=19.0.0",
|
|
29
29
|
"react-dom": ">=19.0.0",
|
|
30
30
|
"react-native-web": ">=0.21.2",
|
|
31
|
-
"@swan-io/lake": "18.
|
|
31
|
+
"@swan-io/lake": "18.4.0"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"@formatjs/intl": "^4.1.16",
|
|
@@ -54,6 +54,6 @@
|
|
|
54
54
|
"react-dom": "^19.2.7",
|
|
55
55
|
"react-native-web": "^0.21.2",
|
|
56
56
|
"type-fest": "^5.8.0",
|
|
57
|
-
"@swan-io/lake": "18.
|
|
57
|
+
"@swan-io/lake": "18.4.0"
|
|
58
58
|
}
|
|
59
59
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,529 @@
|
|
|
1
|
+
import { Option } from "@bloodyowl/boxed";
|
|
2
|
+
import { afterEach, beforeEach, describe, expect, test, vi } from "vitest";
|
|
3
|
+
import { createFakeFraudReportApi } from "../fraudReport/fakeApi";
|
|
4
|
+
import { getCaseRail, getTransactionRail } from "../fraudReport/rail";
|
|
5
|
+
import { toDraftInput, toUpdateInput } from "../fraudReport/toInput";
|
|
6
|
+
import { validateDescription, validateDiscoveryDetails, validateExternalReference, validateNotInFuture, validateSharedInformation, validateTransactionIds, } from "../fraudReport/validation";
|
|
7
|
+
const card1 = { id: "card-1", rail: "Card" };
|
|
8
|
+
const card2 = { id: "card-2", rail: "Card" };
|
|
9
|
+
const transfer1 = { id: "transfer-1", rail: "Transfer" };
|
|
10
|
+
const transfer2 = { id: "transfer-2", rail: "Transfer" };
|
|
11
|
+
const DESCRIPTION_REGEX = /^(?=[\s\S]*\S)[\s\S]{1,2000}$/;
|
|
12
|
+
const DISCOVERY_DETAILS_REGEX = /^(?=[\s\S]*\S)[\s\S]{1,1000}$/;
|
|
13
|
+
const EXTERNAL_REFERENCE_REGEX = /^[\x20-\x7E]{1,255}$/;
|
|
14
|
+
describe("getTransactionRail", () => {
|
|
15
|
+
test("gives the card rail to outgoing card debits", () => {
|
|
16
|
+
expect(getTransactionRail("CardOutDebit")).toEqual(Option.Some("Card"));
|
|
17
|
+
});
|
|
18
|
+
test.each([
|
|
19
|
+
"SepaCreditTransferOut",
|
|
20
|
+
"SepaInstantCreditTransferOut",
|
|
21
|
+
"InternationalCreditTransferOut",
|
|
22
|
+
"InternalCreditTransferOut",
|
|
23
|
+
])("gives the transfer rail to %s", type => {
|
|
24
|
+
expect(getTransactionRail(type)).toEqual(Option.Some("Transfer"));
|
|
25
|
+
});
|
|
26
|
+
test.each([
|
|
27
|
+
"CardOutAuthorization",
|
|
28
|
+
"CardOutDebitReversal",
|
|
29
|
+
"CardOutCredit",
|
|
30
|
+
"CardOutCreditReversal",
|
|
31
|
+
"CardInCredit",
|
|
32
|
+
"CardInChargeback",
|
|
33
|
+
"CardInChargebackReversal",
|
|
34
|
+
"SepaCreditTransferOutReturn",
|
|
35
|
+
"SepaCreditTransferOutRecall",
|
|
36
|
+
"SepaCreditTransferIn",
|
|
37
|
+
"SepaCreditTransferInReturn",
|
|
38
|
+
"SepaCreditTransferInRecall",
|
|
39
|
+
"SepaInstantCreditTransferOutRecall",
|
|
40
|
+
"SepaInstantCreditTransferIn",
|
|
41
|
+
"SepaInstantCreditTransferInRecall",
|
|
42
|
+
"InternationalCreditTransferOutReturn",
|
|
43
|
+
"InternationalCreditTransferIn",
|
|
44
|
+
"InternationalCreditTransferInReturn",
|
|
45
|
+
"InternalCreditTransferOutReturn",
|
|
46
|
+
"InternalCreditTransferOutRecall",
|
|
47
|
+
"InternalCreditTransferIn",
|
|
48
|
+
"InternalCreditTransferInReturn",
|
|
49
|
+
"InternalCreditTransferInRecall",
|
|
50
|
+
"SepaDirectDebitOut",
|
|
51
|
+
"SepaDirectDebitOutReturn",
|
|
52
|
+
"SepaDirectDebitOutReversal",
|
|
53
|
+
"SepaDirectDebitIn",
|
|
54
|
+
"SepaDirectDebitInReturn",
|
|
55
|
+
"SepaDirectDebitInReversal",
|
|
56
|
+
"InternalDirectDebitOut",
|
|
57
|
+
"InternalDirectDebitOutReturn",
|
|
58
|
+
"InternalDirectDebitIn",
|
|
59
|
+
"InternalDirectDebitInReturn",
|
|
60
|
+
"CheckIn",
|
|
61
|
+
"CheckInReturn",
|
|
62
|
+
"FeesOut",
|
|
63
|
+
"FeesIn",
|
|
64
|
+
"",
|
|
65
|
+
])("gives no rail to %s, which can't be reported", type => {
|
|
66
|
+
expect(getTransactionRail(type)).toEqual(Option.None());
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
describe("getCaseRail", () => {
|
|
70
|
+
test("is card-only when every transaction is a card transaction", () => {
|
|
71
|
+
expect(getCaseRail([card1, card2])).toEqual(Option.Some("CardOnly"));
|
|
72
|
+
});
|
|
73
|
+
test("is transfer-only when every transaction is a transfer", () => {
|
|
74
|
+
expect(getCaseRail([transfer1, transfer2])).toEqual(Option.Some("TransferOnly"));
|
|
75
|
+
});
|
|
76
|
+
test("is mixed when the selection holds both rails", () => {
|
|
77
|
+
expect(getCaseRail([transfer1, card1])).toEqual(Option.Some("Mixed"));
|
|
78
|
+
});
|
|
79
|
+
test("has no rail without transactions", () => {
|
|
80
|
+
expect(getCaseRail([])).toEqual(Option.None());
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
describe("validateTransactionIds", () => {
|
|
84
|
+
test("requires at least one transaction", () => {
|
|
85
|
+
expect(validateTransactionIds([])).toBe("Required");
|
|
86
|
+
});
|
|
87
|
+
test("refuses duplicates", () => {
|
|
88
|
+
expect(validateTransactionIds(["card-1", "transfer-1", "card-1"])).toBe("Duplicates");
|
|
89
|
+
});
|
|
90
|
+
test("accepts unique transaction IDs", () => {
|
|
91
|
+
expect(validateTransactionIds(["card-1"])).toBeUndefined();
|
|
92
|
+
expect(validateTransactionIds(["card-1", "transfer-1"])).toBeUndefined();
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
describe("validateNotInFuture", () => {
|
|
96
|
+
beforeEach(() => {
|
|
97
|
+
vi.useFakeTimers();
|
|
98
|
+
vi.setSystemTime(new Date("2026-11-20T10:00:00.000Z"));
|
|
99
|
+
});
|
|
100
|
+
afterEach(() => {
|
|
101
|
+
vi.useRealTimers();
|
|
102
|
+
vi.unstubAllEnvs();
|
|
103
|
+
});
|
|
104
|
+
test("accepts today and past dates", () => {
|
|
105
|
+
expect(validateNotInFuture("2026-11-20")).toBeUndefined();
|
|
106
|
+
expect(validateNotInFuture("2026-11-19")).toBeUndefined();
|
|
107
|
+
expect(validateNotInFuture("2025-01-01")).toBeUndefined();
|
|
108
|
+
});
|
|
109
|
+
test("refuses dates after today", () => {
|
|
110
|
+
expect(validateNotInFuture("2026-11-21")).toBe("DateInFuture");
|
|
111
|
+
expect(validateNotInFuture("2027-01-01")).toBe("DateInFuture");
|
|
112
|
+
});
|
|
113
|
+
test("takes today from UTC, whatever the time of day", () => {
|
|
114
|
+
vi.setSystemTime(new Date("2026-11-20T23:59:59.000Z"));
|
|
115
|
+
expect(validateNotInFuture("2026-11-20")).toBeUndefined();
|
|
116
|
+
expect(validateNotInFuture("2026-11-21")).toBe("DateInFuture");
|
|
117
|
+
vi.setSystemTime(new Date("2026-11-21T00:00:00.000Z"));
|
|
118
|
+
expect(validateNotInFuture("2026-11-21")).toBeUndefined();
|
|
119
|
+
});
|
|
120
|
+
test("refuses tomorrow in UTC, even where it is already tomorrow", () => {
|
|
121
|
+
vi.stubEnv("TZ", "Pacific/Auckland");
|
|
122
|
+
vi.setSystemTime(new Date("2026-11-20T12:30:00.000Z"));
|
|
123
|
+
expect(validateNotInFuture("2026-11-20")).toBeUndefined();
|
|
124
|
+
expect(validateNotInFuture("2026-11-21")).toBe("DateInFuture");
|
|
125
|
+
});
|
|
126
|
+
test("accepts today in UTC, even where it is still yesterday", () => {
|
|
127
|
+
vi.stubEnv("TZ", "America/Los_Angeles");
|
|
128
|
+
vi.setSystemTime(new Date("2026-11-21T02:00:00.000Z"));
|
|
129
|
+
expect(validateNotInFuture("2026-11-21")).toBeUndefined();
|
|
130
|
+
expect(validateNotInFuture("2026-11-22")).toBe("DateInFuture");
|
|
131
|
+
});
|
|
132
|
+
test("refuses anything that isn't a YYYY-MM-DD date", () => {
|
|
133
|
+
expect(validateNotInFuture("20/11/2026")).toBe("InvalidDate");
|
|
134
|
+
expect(validateNotInFuture("2026-13-45")).toBe("InvalidDate");
|
|
135
|
+
expect(validateNotInFuture("2026-11-20T10:00:00.000Z")).toBe("InvalidDate");
|
|
136
|
+
expect(validateNotInFuture("yesterday")).toBe("InvalidDate");
|
|
137
|
+
});
|
|
138
|
+
test("accepts an empty value, as both dates are optional", () => {
|
|
139
|
+
expect(validateNotInFuture(undefined)).toBeUndefined();
|
|
140
|
+
expect(validateNotInFuture("")).toBeUndefined();
|
|
141
|
+
});
|
|
142
|
+
});
|
|
143
|
+
describe("validateSharedInformation", () => {
|
|
144
|
+
test("refuses None with other values", () => {
|
|
145
|
+
expect(validateSharedInformation(["None", "CardDetails"])).toBe("NoneWithOtherValues");
|
|
146
|
+
expect(validateSharedInformation(["SwanPasscode", "Other", "None"])).toBe("NoneWithOtherValues");
|
|
147
|
+
});
|
|
148
|
+
test("accepts None alone", () => {
|
|
149
|
+
expect(validateSharedInformation(["None"])).toBeUndefined();
|
|
150
|
+
});
|
|
151
|
+
test("accepts any other values, or no answer", () => {
|
|
152
|
+
expect(validateSharedInformation(["CardDetails", "BankDetails"])).toBeUndefined();
|
|
153
|
+
expect(validateSharedInformation([])).toBeUndefined();
|
|
154
|
+
expect(validateSharedInformation(undefined)).toBeUndefined();
|
|
155
|
+
});
|
|
156
|
+
});
|
|
157
|
+
describe("validateDescription", () => {
|
|
158
|
+
test("requires text that isn't only whitespace", () => {
|
|
159
|
+
expect(validateDescription(undefined)).toBe("Required");
|
|
160
|
+
expect(validateDescription("")).toBe("Required");
|
|
161
|
+
expect(validateDescription(" \n\t ")).toBe("Required");
|
|
162
|
+
});
|
|
163
|
+
test("refuses more than 2000 characters", () => {
|
|
164
|
+
expect(validateDescription("a".repeat(2001))).toBe("TooLong");
|
|
165
|
+
});
|
|
166
|
+
test("accepts up to 2000 characters, line breaks included", () => {
|
|
167
|
+
expect(validateDescription("a")).toBeUndefined();
|
|
168
|
+
expect(validateDescription("My card was used\nin a shop I never went to.")).toBeUndefined();
|
|
169
|
+
expect(validateDescription("a".repeat(2000))).toBeUndefined();
|
|
170
|
+
});
|
|
171
|
+
test.each(["", " ", "\n", "a", " a ", "é\n\nè", "a".repeat(2000), "a".repeat(2001)])("agrees with the format documented by the API (sample %#)", sample => {
|
|
172
|
+
expect(validateDescription(sample) == null).toBe(DESCRIPTION_REGEX.test(sample));
|
|
173
|
+
});
|
|
174
|
+
});
|
|
175
|
+
describe("validateDiscoveryDetails", () => {
|
|
176
|
+
test("refuses more than 1000 characters", () => {
|
|
177
|
+
expect(validateDiscoveryDetails("a".repeat(1001))).toBe("TooLong");
|
|
178
|
+
});
|
|
179
|
+
test("accepts up to 1000 characters", () => {
|
|
180
|
+
expect(validateDiscoveryDetails("I saw it on my statement.")).toBeUndefined();
|
|
181
|
+
expect(validateDiscoveryDetails("a".repeat(1000))).toBeUndefined();
|
|
182
|
+
});
|
|
183
|
+
test("accepts an empty value, as the field is optional", () => {
|
|
184
|
+
expect(validateDiscoveryDetails(undefined)).toBeUndefined();
|
|
185
|
+
expect(validateDiscoveryDetails("")).toBeUndefined();
|
|
186
|
+
expect(validateDiscoveryDetails(" ")).toBeUndefined();
|
|
187
|
+
});
|
|
188
|
+
test.each(["a", " a ", "é\n\nè", "a".repeat(1000), "a".repeat(1001)])("agrees with the format documented by the API for values that are sent (sample %#)", sample => {
|
|
189
|
+
expect(validateDiscoveryDetails(sample) == null).toBe(DISCOVERY_DETAILS_REGEX.test(sample));
|
|
190
|
+
});
|
|
191
|
+
});
|
|
192
|
+
describe("validateExternalReference", () => {
|
|
193
|
+
test("refuses characters outside printable ASCII", () => {
|
|
194
|
+
expect(validateExternalReference("réf-123")).toBe("InvalidCharacters");
|
|
195
|
+
expect(validateExternalReference("ref\n123")).toBe("InvalidCharacters");
|
|
196
|
+
expect(validateExternalReference("ref\t123")).toBe("InvalidCharacters");
|
|
197
|
+
expect(validateExternalReference("ref\x1F")).toBe("InvalidCharacters");
|
|
198
|
+
expect(validateExternalReference("ref\x7F")).toBe("InvalidCharacters");
|
|
199
|
+
expect(validateExternalReference("ref 🙂")).toBe("InvalidCharacters");
|
|
200
|
+
});
|
|
201
|
+
test("refuses more than 255 characters", () => {
|
|
202
|
+
expect(validateExternalReference("a".repeat(256))).toBe("TooLong");
|
|
203
|
+
});
|
|
204
|
+
test("accepts up to 255 printable ASCII characters", () => {
|
|
205
|
+
expect(validateExternalReference("REF-2026/11 #42 ~ok")).toBeUndefined();
|
|
206
|
+
expect(validateExternalReference("a".repeat(255))).toBeUndefined();
|
|
207
|
+
});
|
|
208
|
+
test("accepts an empty value, as the field is optional", () => {
|
|
209
|
+
expect(validateExternalReference(undefined)).toBeUndefined();
|
|
210
|
+
expect(validateExternalReference("")).toBeUndefined();
|
|
211
|
+
});
|
|
212
|
+
test.each(["a", " ", "REF 1", "réf", "a\nb", "a".repeat(255), "a".repeat(256)])("agrees with the format documented by the API for values that are sent (sample %#)", sample => {
|
|
213
|
+
expect(validateExternalReference(sample) == null).toBe(EXTERNAL_REFERENCE_REGEX.test(sample));
|
|
214
|
+
});
|
|
215
|
+
});
|
|
216
|
+
const incident = {
|
|
217
|
+
reportedReason: "Manipulated",
|
|
218
|
+
reportedTypology: "FakeAdvisor",
|
|
219
|
+
description: "Someone called me pretending to be my bank.",
|
|
220
|
+
};
|
|
221
|
+
const filled = {
|
|
222
|
+
...incident,
|
|
223
|
+
victimAccountMembershipId: "member-1",
|
|
224
|
+
discoveredAt: "2026-11-18",
|
|
225
|
+
discoveryDetails: "I saw it on my statement.",
|
|
226
|
+
fraudsterChannels: ["Phone", "Sms"],
|
|
227
|
+
sharedInformationWithFraudster: ["VerificationCode"],
|
|
228
|
+
isLostOrStolen: true,
|
|
229
|
+
lostOrStolenNoticedAt: "2026-11-17",
|
|
230
|
+
externalReference: "REF-42",
|
|
231
|
+
};
|
|
232
|
+
const fraudDetails = {
|
|
233
|
+
reportedReason: "Manipulated",
|
|
234
|
+
reportedTypology: "FakeAdvisor",
|
|
235
|
+
description: "Someone called me pretending to be my bank.",
|
|
236
|
+
discoveredAt: "2026-11-18",
|
|
237
|
+
discoveryDetails: "I saw it on my statement.",
|
|
238
|
+
fraudsterChannels: ["Phone", "Sms"],
|
|
239
|
+
sharedInformationWithFraudster: ["VerificationCode"],
|
|
240
|
+
hasFiledPoliceComplaint: null,
|
|
241
|
+
};
|
|
242
|
+
const fraudCardDetails = {
|
|
243
|
+
isLostOrStolen: true,
|
|
244
|
+
lostOrStolenNoticedAt: "2026-11-17",
|
|
245
|
+
hasContactedMerchant: null,
|
|
246
|
+
};
|
|
247
|
+
describe("toDraftInput", () => {
|
|
248
|
+
test("sends only the transaction IDs when nothing else is filled", () => {
|
|
249
|
+
expect(toDraftInput({ transactions: [card1, transfer1] })).toStrictEqual({
|
|
250
|
+
transactionIds: ["card-1", "transfer-1"],
|
|
251
|
+
});
|
|
252
|
+
});
|
|
253
|
+
test("sends the card details and no victim on a card-only case", () => {
|
|
254
|
+
expect(toDraftInput({ ...filled, transactions: [card1, card2] })).toStrictEqual({
|
|
255
|
+
transactionIds: ["card-1", "card-2"],
|
|
256
|
+
fraudDetails,
|
|
257
|
+
fraudCardDetails,
|
|
258
|
+
externalReference: "REF-42",
|
|
259
|
+
});
|
|
260
|
+
});
|
|
261
|
+
test("sends the victim and no card details on a transfer-only case", () => {
|
|
262
|
+
expect(toDraftInput({ ...filled, transactions: [transfer1, transfer2] })).toStrictEqual({
|
|
263
|
+
transactionIds: ["transfer-1", "transfer-2"],
|
|
264
|
+
fraudDetails,
|
|
265
|
+
victimAccountMembershipId: "member-1",
|
|
266
|
+
externalReference: "REF-42",
|
|
267
|
+
});
|
|
268
|
+
});
|
|
269
|
+
test("sends the card details and no victim on a mixed case", () => {
|
|
270
|
+
expect(toDraftInput({ ...filled, transactions: [transfer1, card1] })).toStrictEqual({
|
|
271
|
+
transactionIds: ["transfer-1", "card-1"],
|
|
272
|
+
fraudDetails,
|
|
273
|
+
fraudCardDetails,
|
|
274
|
+
externalReference: "REF-42",
|
|
275
|
+
});
|
|
276
|
+
});
|
|
277
|
+
test("never sends transfer details", () => {
|
|
278
|
+
expect(toDraftInput({ ...filled, transactions: [transfer1] })).not.toHaveProperty("fraudTransferDetails");
|
|
279
|
+
expect(toDraftInput({ ...filled, transactions: [transfer1, card1] })).not.toHaveProperty("fraudTransferDetails");
|
|
280
|
+
});
|
|
281
|
+
test("leaves the victim out of a transfer-only case until one is picked", () => {
|
|
282
|
+
expect(toDraftInput({ ...incident, transactions: [transfer1] })).not.toHaveProperty("victimAccountMembershipId");
|
|
283
|
+
});
|
|
284
|
+
test.each([
|
|
285
|
+
["reason", { reportedReason: undefined }],
|
|
286
|
+
["fraud type", { reportedTypology: undefined }],
|
|
287
|
+
["description", { description: undefined }],
|
|
288
|
+
["description", { description: " \n " }],
|
|
289
|
+
])("leaves the fraud details out while the %s is missing", (_, missing) => {
|
|
290
|
+
expect(toDraftInput({ ...filled, ...missing, transactions: [transfer1] })).not.toHaveProperty("fraudDetails");
|
|
291
|
+
});
|
|
292
|
+
test("sends null for the optional fraud details left empty", () => {
|
|
293
|
+
expect(toDraftInput({
|
|
294
|
+
...incident,
|
|
295
|
+
discoveredAt: "",
|
|
296
|
+
discoveryDetails: " ",
|
|
297
|
+
fraudsterChannels: [],
|
|
298
|
+
sharedInformationWithFraudster: [],
|
|
299
|
+
transactions: [card1],
|
|
300
|
+
})).toStrictEqual({
|
|
301
|
+
transactionIds: ["card-1"],
|
|
302
|
+
fraudDetails: {
|
|
303
|
+
...incident,
|
|
304
|
+
discoveredAt: null,
|
|
305
|
+
discoveryDetails: null,
|
|
306
|
+
fraudsterChannels: null,
|
|
307
|
+
sharedInformationWithFraudster: null,
|
|
308
|
+
hasFiledPoliceComplaint: null,
|
|
309
|
+
},
|
|
310
|
+
});
|
|
311
|
+
});
|
|
312
|
+
test("keeps the description as the user typed it", () => {
|
|
313
|
+
var _a;
|
|
314
|
+
const description = " First line\n\nSecond line ";
|
|
315
|
+
expect((_a = toDraftInput({ ...incident, description, transactions: [card1] }).fraudDetails) === null || _a === void 0 ? void 0 : _a.description).toBe(description);
|
|
316
|
+
});
|
|
317
|
+
test("leaves the card details out until one of them is answered", () => {
|
|
318
|
+
expect(toDraftInput({ ...incident, transactions: [card1] })).not.toHaveProperty("fraudCardDetails");
|
|
319
|
+
expect(toDraftInput({ ...incident, lostOrStolenNoticedAt: "", transactions: [card1] })).not.toHaveProperty("fraudCardDetails");
|
|
320
|
+
});
|
|
321
|
+
test("sends null for the card detail left empty", () => {
|
|
322
|
+
expect(toDraftInput({ isLostOrStolen: false, transactions: [card1] }).fraudCardDetails).toStrictEqual({
|
|
323
|
+
isLostOrStolen: false,
|
|
324
|
+
lostOrStolenNoticedAt: null,
|
|
325
|
+
hasContactedMerchant: null,
|
|
326
|
+
});
|
|
327
|
+
expect(toDraftInput({ lostOrStolenNoticedAt: "2026-11-17", transactions: [card1] }).fraudCardDetails).toStrictEqual({
|
|
328
|
+
isLostOrStolen: null,
|
|
329
|
+
lostOrStolenNoticedAt: "2026-11-17",
|
|
330
|
+
hasContactedMerchant: null,
|
|
331
|
+
});
|
|
332
|
+
});
|
|
333
|
+
test("leaves an empty external reference out", () => {
|
|
334
|
+
expect(toDraftInput({ externalReference: "", transactions: [card1] })).toStrictEqual({
|
|
335
|
+
transactionIds: ["card-1"],
|
|
336
|
+
});
|
|
337
|
+
});
|
|
338
|
+
});
|
|
339
|
+
describe("toUpdateInput", () => {
|
|
340
|
+
const savedCase = { id: "case-1", fraudDetails: null, fraudCardDetails: null };
|
|
341
|
+
const disputeCaseId = savedCase.id;
|
|
342
|
+
test("sends the card details and no victim on a card-only case", () => {
|
|
343
|
+
expect(toUpdateInput({
|
|
344
|
+
savedCase,
|
|
345
|
+
values: { ...filled, transactions: [card1, card2] },
|
|
346
|
+
savedTransactionIds: ["card-1"],
|
|
347
|
+
})).toStrictEqual({
|
|
348
|
+
disputeCaseId,
|
|
349
|
+
transactionIds: ["card-1", "card-2"],
|
|
350
|
+
fraudDetails,
|
|
351
|
+
fraudCardDetails,
|
|
352
|
+
externalReference: "REF-42",
|
|
353
|
+
});
|
|
354
|
+
});
|
|
355
|
+
test("sends the victim and no card details on a transfer-only case", () => {
|
|
356
|
+
expect(toUpdateInput({
|
|
357
|
+
savedCase,
|
|
358
|
+
values: { ...filled, transactions: [transfer1] },
|
|
359
|
+
savedTransactionIds: ["transfer-1", "card-1"],
|
|
360
|
+
})).toStrictEqual({
|
|
361
|
+
disputeCaseId,
|
|
362
|
+
transactionIds: ["transfer-1"],
|
|
363
|
+
fraudDetails,
|
|
364
|
+
victimAccountMembershipId: "member-1",
|
|
365
|
+
externalReference: "REF-42",
|
|
366
|
+
});
|
|
367
|
+
});
|
|
368
|
+
test("sends the card details and no victim on a mixed case", () => {
|
|
369
|
+
expect(toUpdateInput({
|
|
370
|
+
savedCase,
|
|
371
|
+
values: { ...filled, transactions: [transfer1, card1] },
|
|
372
|
+
savedTransactionIds: ["transfer-1"],
|
|
373
|
+
})).toStrictEqual({
|
|
374
|
+
disputeCaseId,
|
|
375
|
+
transactionIds: ["transfer-1", "card-1"],
|
|
376
|
+
fraudDetails,
|
|
377
|
+
fraudCardDetails,
|
|
378
|
+
externalReference: "REF-42",
|
|
379
|
+
});
|
|
380
|
+
});
|
|
381
|
+
test("never sends transfer details", () => {
|
|
382
|
+
expect(toUpdateInput({
|
|
383
|
+
savedCase,
|
|
384
|
+
values: { ...filled, transactions: [transfer1] },
|
|
385
|
+
savedTransactionIds: [],
|
|
386
|
+
})).not.toHaveProperty("fraudTransferDetails");
|
|
387
|
+
});
|
|
388
|
+
test("leaves the transaction IDs out when the selection didn't change", () => {
|
|
389
|
+
expect(toUpdateInput({
|
|
390
|
+
savedCase,
|
|
391
|
+
values: { ...incident, transactions: [card1, transfer1] },
|
|
392
|
+
savedTransactionIds: ["transfer-1", "card-1"],
|
|
393
|
+
})).toStrictEqual({ disputeCaseId, fraudDetails: expect.any(Object) });
|
|
394
|
+
});
|
|
395
|
+
test.each([
|
|
396
|
+
["a transaction was added", [card1, card2], ["card-1"]],
|
|
397
|
+
["a transaction was removed", [card1], ["card-1", "card-2"]],
|
|
398
|
+
["a transaction was swapped", [card1, transfer1], ["card-1", "card-2"]],
|
|
399
|
+
["a transaction is there twice", [card1, card1], ["card-1", "card-2"]],
|
|
400
|
+
])("sends the whole selection when %s", (_, transactions, savedTransactionIds) => {
|
|
401
|
+
expect(toUpdateInput({ savedCase, values: { transactions }, savedTransactionIds })).toStrictEqual({ disputeCaseId, transactionIds: transactions.map(({ id }) => id) });
|
|
402
|
+
});
|
|
403
|
+
test("leaves every group out when nothing is filled", () => {
|
|
404
|
+
expect(toUpdateInput({
|
|
405
|
+
savedCase,
|
|
406
|
+
values: { transactions: [card1] },
|
|
407
|
+
savedTransactionIds: ["card-1"],
|
|
408
|
+
})).toStrictEqual({ disputeCaseId });
|
|
409
|
+
});
|
|
410
|
+
test("clears the external reference when it was emptied", () => {
|
|
411
|
+
expect(toUpdateInput({
|
|
412
|
+
savedCase,
|
|
413
|
+
values: { externalReference: "", transactions: [card1] },
|
|
414
|
+
savedTransactionIds: ["card-1"],
|
|
415
|
+
})).toStrictEqual({ disputeCaseId, externalReference: null });
|
|
416
|
+
});
|
|
417
|
+
test("keeps the stored external reference when the form has none", () => {
|
|
418
|
+
expect(toUpdateInput({
|
|
419
|
+
savedCase,
|
|
420
|
+
values: { ...incident, transactions: [card1] },
|
|
421
|
+
savedTransactionIds: ["card-1"],
|
|
422
|
+
})).not.toHaveProperty("externalReference");
|
|
423
|
+
});
|
|
424
|
+
test("holds the card details and the victim back while no transaction is selected", () => {
|
|
425
|
+
expect(toUpdateInput({
|
|
426
|
+
savedCase,
|
|
427
|
+
values: { ...filled, transactions: [] },
|
|
428
|
+
savedTransactionIds: [],
|
|
429
|
+
})).toStrictEqual({ disputeCaseId, fraudDetails, externalReference: "REF-42" });
|
|
430
|
+
});
|
|
431
|
+
test("sends back the actions taken saved on the case, which the form doesn't hold", () => {
|
|
432
|
+
var _a, _b;
|
|
433
|
+
const input = toUpdateInput({
|
|
434
|
+
savedCase: {
|
|
435
|
+
id: "case-1",
|
|
436
|
+
fraudDetails: { ...fraudDetails, hasFiledPoliceComplaint: true },
|
|
437
|
+
fraudCardDetails: { ...fraudCardDetails, hasContactedMerchant: false },
|
|
438
|
+
},
|
|
439
|
+
values: { ...filled, transactions: [card1] },
|
|
440
|
+
savedTransactionIds: ["card-1"],
|
|
441
|
+
});
|
|
442
|
+
expect((_a = input.fraudDetails) === null || _a === void 0 ? void 0 : _a.hasFiledPoliceComplaint).toBe(true);
|
|
443
|
+
expect((_b = input.fraudCardDetails) === null || _b === void 0 ? void 0 : _b.hasContactedMerchant).toBe(false);
|
|
444
|
+
});
|
|
445
|
+
});
|
|
446
|
+
describe("inputs sent to the API", () => {
|
|
447
|
+
const createApi = () => createFakeFraudReportApi({
|
|
448
|
+
transactions: [
|
|
449
|
+
{
|
|
450
|
+
id: "card-1",
|
|
451
|
+
accountId: "account-1",
|
|
452
|
+
rail: "Card",
|
|
453
|
+
cardholderAccountMembershipId: "member-2",
|
|
454
|
+
},
|
|
455
|
+
{ id: "transfer-1", accountId: "account-1", rail: "Transfer" },
|
|
456
|
+
],
|
|
457
|
+
accountMemberships: [
|
|
458
|
+
{ id: "member-1", accountId: "account-1" },
|
|
459
|
+
{ id: "member-2", accountId: "account-1" },
|
|
460
|
+
],
|
|
461
|
+
});
|
|
462
|
+
const getCase = (result) => result.match({
|
|
463
|
+
Ok: value => value,
|
|
464
|
+
Error: error => {
|
|
465
|
+
throw new Error(`The API refused the input: ${JSON.stringify(error)}`);
|
|
466
|
+
},
|
|
467
|
+
});
|
|
468
|
+
test("a card-only draft is accepted, with its card details and the cardholder as victim", async () => {
|
|
469
|
+
const created = getCase(await createApi().draft(toDraftInput({ ...filled, transactions: [card1] })));
|
|
470
|
+
expect(created.fraudCardDetails).toMatchObject({ isLostOrStolen: true });
|
|
471
|
+
expect(created.victimAccountMembershipId).toBe("member-2");
|
|
472
|
+
});
|
|
473
|
+
test("a transfer-only draft is accepted, with the victim picked in the form", async () => {
|
|
474
|
+
const created = getCase(await createApi().draft(toDraftInput({ ...filled, transactions: [transfer1] })));
|
|
475
|
+
expect(created.fraudCardDetails).toBeNull();
|
|
476
|
+
expect(created.victimAccountMembershipId).toBe("member-1");
|
|
477
|
+
});
|
|
478
|
+
test("a mixed draft is accepted, with its card details and the cardholder as victim", async () => {
|
|
479
|
+
const created = getCase(await createApi().draft(toDraftInput({ ...filled, transactions: [transfer1, card1] })));
|
|
480
|
+
expect(created.fraudCardDetails).toMatchObject({ isLostOrStolen: true });
|
|
481
|
+
expect(created.victimAccountMembershipId).toBe("member-2");
|
|
482
|
+
});
|
|
483
|
+
test("an update is accepted when the selection moves from card-only to transfer-only", async () => {
|
|
484
|
+
const api = createApi();
|
|
485
|
+
const savedCase = getCase(await api.draft(toDraftInput({ ...filled, transactions: [card1] })));
|
|
486
|
+
const updated = getCase(await api.update(toUpdateInput({
|
|
487
|
+
savedCase,
|
|
488
|
+
values: { ...filled, transactions: [transfer1] },
|
|
489
|
+
savedTransactionIds: ["card-1"],
|
|
490
|
+
})));
|
|
491
|
+
expect(updated.transactions).toStrictEqual([transfer1]);
|
|
492
|
+
expect(updated.fraudCardDetails).toBeNull();
|
|
493
|
+
expect(updated.victimAccountMembershipId).toBe("member-1");
|
|
494
|
+
});
|
|
495
|
+
test("an update is accepted when the selection moves from transfer-only to card-only", async () => {
|
|
496
|
+
const api = createApi();
|
|
497
|
+
const savedCase = getCase(await api.draft(toDraftInput({ ...filled, transactions: [transfer1] })));
|
|
498
|
+
const updated = getCase(await api.update(toUpdateInput({
|
|
499
|
+
savedCase,
|
|
500
|
+
values: { ...filled, transactions: [card1] },
|
|
501
|
+
savedTransactionIds: ["transfer-1"],
|
|
502
|
+
})));
|
|
503
|
+
expect(updated.transactions).toStrictEqual([card1]);
|
|
504
|
+
expect(updated.fraudCardDetails).toMatchObject({ isLostOrStolen: true });
|
|
505
|
+
expect(updated.victimAccountMembershipId).toBe("member-2");
|
|
506
|
+
});
|
|
507
|
+
test("an update keeps the actions taken that another client stored on the draft", async () => {
|
|
508
|
+
var _a;
|
|
509
|
+
const api = createApi();
|
|
510
|
+
const savedCase = getCase(await api.draft({
|
|
511
|
+
transactionIds: ["card-1", "transfer-1"],
|
|
512
|
+
fraudDetails: { ...incident, hasFiledPoliceComplaint: true },
|
|
513
|
+
fraudCardDetails: { hasContactedMerchant: true },
|
|
514
|
+
fraudTransferDetails: { hasContactedBankOrBeneficiary: true },
|
|
515
|
+
}));
|
|
516
|
+
const updated = getCase(await api.update(toUpdateInput({
|
|
517
|
+
savedCase,
|
|
518
|
+
values: { ...filled, transactions: [card1, transfer1] },
|
|
519
|
+
savedTransactionIds: ["card-1", "transfer-1"],
|
|
520
|
+
})));
|
|
521
|
+
expect((_a = updated.fraudDetails) === null || _a === void 0 ? void 0 : _a.hasFiledPoliceComplaint).toBe(true);
|
|
522
|
+
expect(updated.fraudCardDetails).toStrictEqual({
|
|
523
|
+
isLostOrStolen: true,
|
|
524
|
+
lostOrStolenNoticedAt: "2026-11-17",
|
|
525
|
+
hasContactedMerchant: true,
|
|
526
|
+
});
|
|
527
|
+
expect(updated.fraudTransferDetails).toStrictEqual({ hasContactedBankOrBeneficiary: true });
|
|
528
|
+
});
|
|
529
|
+
});
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { Option } from "@bloodyowl/boxed";
|
|
2
|
+
import type { FraudReportRail, FraudReportTransaction } from "./types";
|
|
3
|
+
export type FraudReportCaseRail = "CardOnly" | "TransferOnly" | "Mixed";
|
|
4
|
+
export declare const getTransactionRail: (transactionType: string) => Option<FraudReportRail>;
|
|
5
|
+
export declare const getCaseRail: (transactions: Pick<FraudReportTransaction, "rail">[]) => Option<FraudReportCaseRail>;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Option } from "@bloodyowl/boxed";
|
|
2
|
+
import { match } from "ts-pattern";
|
|
3
|
+
export const getTransactionRail = (transactionType) => match(transactionType)
|
|
4
|
+
.with("CardOutDebit", () => Option.Some("Card"))
|
|
5
|
+
.with("SepaCreditTransferOut", "SepaInstantCreditTransferOut", "InternationalCreditTransferOut", "InternalCreditTransferOut", () => Option.Some("Transfer"))
|
|
6
|
+
.otherwise(() => Option.None());
|
|
7
|
+
export const getCaseRail = (transactions) => match({
|
|
8
|
+
hasCard: transactions.some(({ rail }) => rail === "Card"),
|
|
9
|
+
hasTransfer: transactions.some(({ rail }) => rail === "Transfer"),
|
|
10
|
+
})
|
|
11
|
+
.with({ hasCard: true, hasTransfer: true }, () => Option.Some("Mixed"))
|
|
12
|
+
.with({ hasCard: true }, () => Option.Some("CardOnly"))
|
|
13
|
+
.with({ hasTransfer: true }, () => Option.Some("TransferOnly"))
|
|
14
|
+
.otherwise(() => Option.None());
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { DraftFraudDisputeCaseInput, FraudReason, FraudReportCase, FraudReportTransaction, FraudsterChannel, FraudTypology, SharedInformationWithFraudster, UpdateDraftFraudDisputeCaseInput } from "./types";
|
|
2
|
+
export type FraudReportFormValues = {
|
|
3
|
+
transactions: FraudReportTransaction[];
|
|
4
|
+
victimAccountMembershipId?: string;
|
|
5
|
+
reportedReason?: FraudReason;
|
|
6
|
+
reportedTypology?: FraudTypology;
|
|
7
|
+
description?: string;
|
|
8
|
+
discoveredAt?: string;
|
|
9
|
+
discoveryDetails?: string;
|
|
10
|
+
fraudsterChannels?: FraudsterChannel[];
|
|
11
|
+
sharedInformationWithFraudster?: SharedInformationWithFraudster[];
|
|
12
|
+
isLostOrStolen?: boolean;
|
|
13
|
+
lostOrStolenNoticedAt?: string;
|
|
14
|
+
externalReference?: string;
|
|
15
|
+
};
|
|
16
|
+
export declare const toDraftInput: (values: FraudReportFormValues) => DraftFraudDisputeCaseInput;
|
|
17
|
+
export declare const toUpdateInput: ({ savedCase, values, savedTransactionIds, }: {
|
|
18
|
+
savedCase: Pick<FraudReportCase, "id" | "fraudDetails" | "fraudCardDetails">;
|
|
19
|
+
values: FraudReportFormValues;
|
|
20
|
+
savedTransactionIds: string[];
|
|
21
|
+
}) => UpdateDraftFraudDisputeCaseInput;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { Option } from "@bloodyowl/boxed";
|
|
2
|
+
import { match, P } from "ts-pattern";
|
|
3
|
+
import { getCaseRail } from "./rail";
|
|
4
|
+
const toFilled = (value) => Option.fromNullable(value).filter(item => item.trim() !== "");
|
|
5
|
+
const toFilledList = (values) => Option.fromNullable(values).filter(items => items.length > 0);
|
|
6
|
+
const toFraudDetails = (values, savedDetails) => Option.allFromDict({
|
|
7
|
+
reportedReason: Option.fromNullable(values.reportedReason),
|
|
8
|
+
reportedTypology: Option.fromNullable(values.reportedTypology),
|
|
9
|
+
description: toFilled(values.description),
|
|
10
|
+
}).map(required => { var _a; var _b; return ({
|
|
11
|
+
...required,
|
|
12
|
+
discoveredAt: toFilled(values.discoveredAt).toNull(),
|
|
13
|
+
discoveryDetails: toFilled(values.discoveryDetails).toNull(),
|
|
14
|
+
fraudsterChannels: toFilledList(values.fraudsterChannels).toNull(),
|
|
15
|
+
sharedInformationWithFraudster: toFilledList(values.sharedInformationWithFraudster).toNull(),
|
|
16
|
+
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,
|
|
17
|
+
}); });
|
|
18
|
+
const toFraudCardDetails = (values, savedDetails) => {
|
|
19
|
+
var _a;
|
|
20
|
+
var _b;
|
|
21
|
+
const isLostOrStolen = Option.fromNullable(values.isLostOrStolen);
|
|
22
|
+
const lostOrStolenNoticedAt = toFilled(values.lostOrStolenNoticedAt);
|
|
23
|
+
return isLostOrStolen.isNone() && lostOrStolenNoticedAt.isNone()
|
|
24
|
+
? Option.None()
|
|
25
|
+
: Option.Some({
|
|
26
|
+
isLostOrStolen: isLostOrStolen.toNull(),
|
|
27
|
+
lostOrStolenNoticedAt: lostOrStolenNoticedAt.toNull(),
|
|
28
|
+
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,
|
|
29
|
+
});
|
|
30
|
+
};
|
|
31
|
+
const toDetails = (values, savedDetails) => {
|
|
32
|
+
const fraudDetails = toFraudDetails(values, savedDetails)
|
|
33
|
+
.map(value => ({ fraudDetails: value }))
|
|
34
|
+
.toUndefined();
|
|
35
|
+
return match(getCaseRail(values.transactions))
|
|
36
|
+
.with(Option.P.Some(P.union("CardOnly", "Mixed")), () => ({
|
|
37
|
+
...fraudDetails,
|
|
38
|
+
...toFraudCardDetails(values, savedDetails)
|
|
39
|
+
.map(value => ({ fraudCardDetails: value }))
|
|
40
|
+
.toUndefined(),
|
|
41
|
+
}))
|
|
42
|
+
.with(Option.P.Some("TransferOnly"), () => ({
|
|
43
|
+
...fraudDetails,
|
|
44
|
+
...toFilled(values.victimAccountMembershipId)
|
|
45
|
+
.map(value => ({ victimAccountMembershipId: value }))
|
|
46
|
+
.toUndefined(),
|
|
47
|
+
}))
|
|
48
|
+
.with(Option.P.None, () => ({ ...fraudDetails }))
|
|
49
|
+
.exhaustive();
|
|
50
|
+
};
|
|
51
|
+
const toTransactionIds = (values) => values.transactions.map(({ id }) => id);
|
|
52
|
+
const isSameSelection = (transactionIds, savedTransactionIds) => {
|
|
53
|
+
const savedIds = new Set(savedTransactionIds);
|
|
54
|
+
return (new Set(transactionIds).size === savedIds.size && transactionIds.every(id => savedIds.has(id)));
|
|
55
|
+
};
|
|
56
|
+
export const toDraftInput = (values) => ({
|
|
57
|
+
transactionIds: toTransactionIds(values),
|
|
58
|
+
...toDetails(values),
|
|
59
|
+
...match(values.externalReference)
|
|
60
|
+
.with(P.union(undefined, ""), () => undefined)
|
|
61
|
+
.otherwise(externalReference => ({ externalReference })),
|
|
62
|
+
});
|
|
63
|
+
export const toUpdateInput = ({ savedCase, values, savedTransactionIds, }) => {
|
|
64
|
+
const transactionIds = toTransactionIds(values);
|
|
65
|
+
return {
|
|
66
|
+
disputeCaseId: savedCase.id,
|
|
67
|
+
...(isSameSelection(transactionIds, savedTransactionIds) ? undefined : { transactionIds }),
|
|
68
|
+
...toDetails(values, savedCase),
|
|
69
|
+
...match(values.externalReference)
|
|
70
|
+
.with(undefined, () => undefined)
|
|
71
|
+
.with("", () => ({ externalReference: null }))
|
|
72
|
+
.otherwise(externalReference => ({ externalReference })),
|
|
73
|
+
};
|
|
74
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Validator } from "@swan-io/use-form";
|
|
2
|
+
import type { SharedInformationWithFraudster } from "./types";
|
|
3
|
+
export type FraudReportValidationError = "Required" | "Duplicates" | "InvalidDate" | "DateInFuture" | "NoneWithOtherValues" | "TooLong" | "InvalidCharacters";
|
|
4
|
+
type FraudReportValidator<Value> = Validator<Value, FraudReportValidationError>;
|
|
5
|
+
export declare const DESCRIPTION_MAX_LENGTH = 2000;
|
|
6
|
+
export declare const DISCOVERY_DETAILS_MAX_LENGTH = 1000;
|
|
7
|
+
export declare const EXTERNAL_REFERENCE_MAX_LENGTH = 255;
|
|
8
|
+
export declare const validateTransactionIds: FraudReportValidator<string[]>;
|
|
9
|
+
export declare const validateNotInFuture: FraudReportValidator<string | undefined>;
|
|
10
|
+
export declare const validateSharedInformation: FraudReportValidator<SharedInformationWithFraudster[] | undefined>;
|
|
11
|
+
export declare const validateDescription: FraudReportValidator<string | undefined>;
|
|
12
|
+
export declare const validateDiscoveryDetails: FraudReportValidator<string | undefined>;
|
|
13
|
+
export declare const validateExternalReference: FraudReportValidator<string | undefined>;
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import dayjs from "dayjs";
|
|
2
|
+
export const DESCRIPTION_MAX_LENGTH = 2000;
|
|
3
|
+
export const DISCOVERY_DETAILS_MAX_LENGTH = 1000;
|
|
4
|
+
export const EXTERNAL_REFERENCE_MAX_LENGTH = 255;
|
|
5
|
+
const PRINTABLE_ASCII_REGEX = /^[\x20-\x7E]*$/;
|
|
6
|
+
export const validateTransactionIds = transactionIds => {
|
|
7
|
+
if (transactionIds.length === 0) {
|
|
8
|
+
return "Required";
|
|
9
|
+
}
|
|
10
|
+
if (new Set(transactionIds).size !== transactionIds.length) {
|
|
11
|
+
return "Duplicates";
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
export const validateNotInFuture = value => {
|
|
15
|
+
if (value == null || value === "") {
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
const date = dayjs.utc(value, "YYYY-MM-DD", true);
|
|
19
|
+
if (!date.isValid()) {
|
|
20
|
+
return "InvalidDate";
|
|
21
|
+
}
|
|
22
|
+
if (date.isAfter(dayjs.utc(), "day")) {
|
|
23
|
+
return "DateInFuture";
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
export const validateSharedInformation = values => {
|
|
27
|
+
if (values != null && values.length > 1 && values.includes("None")) {
|
|
28
|
+
return "NoneWithOtherValues";
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
export const validateDescription = value => {
|
|
32
|
+
if (value == null || value.trim() === "") {
|
|
33
|
+
return "Required";
|
|
34
|
+
}
|
|
35
|
+
if (value.length > DESCRIPTION_MAX_LENGTH) {
|
|
36
|
+
return "TooLong";
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
export const validateDiscoveryDetails = value => {
|
|
40
|
+
if (value != null && value.length > DISCOVERY_DETAILS_MAX_LENGTH) {
|
|
41
|
+
return "TooLong";
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
export const validateExternalReference = value => {
|
|
45
|
+
if (value == null) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
if (!PRINTABLE_ASCII_REGEX.test(value)) {
|
|
49
|
+
return "InvalidCharacters";
|
|
50
|
+
}
|
|
51
|
+
if (value.length > EXTERNAL_REFERENCE_MAX_LENGTH) {
|
|
52
|
+
return "TooLong";
|
|
53
|
+
}
|
|
54
|
+
};
|