@swan-io/shared-business 18.2.0 → 18.3.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.fakeApi.test.d.ts +1 -0
- package/src/utils/__tests__/fraudReport.fakeApi.test.js +659 -0
- package/src/utils/fraudReport/api.d.ts +34 -0
- package/src/utils/fraudReport/api.js +1 -0
- package/src/utils/fraudReport/fakeApi.d.ts +29 -0
- package/src/utils/fraudReport/fakeApi.js +366 -0
- package/src/utils/fraudReport/types.d.ts +187 -0
- package/src/utils/fraudReport/types.js +13 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@swan-io/shared-business",
|
|
3
|
-
"version": "18.
|
|
3
|
+
"version": "18.3.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.3.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.3.0"
|
|
58
58
|
}
|
|
59
59
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,659 @@
|
|
|
1
|
+
import { Option } from "@bloodyowl/boxed";
|
|
2
|
+
import { describe, expect, expectTypeOf, test } from "vitest";
|
|
3
|
+
import { createFakeFraudReportApi, } from "../fraudReport/fakeApi";
|
|
4
|
+
const NOW = new Date("2026-11-20T10:00:00.000Z");
|
|
5
|
+
const card1 = {
|
|
6
|
+
id: "card-1",
|
|
7
|
+
accountId: "account-1",
|
|
8
|
+
rail: "Card",
|
|
9
|
+
cardholderAccountMembershipId: "member-1",
|
|
10
|
+
};
|
|
11
|
+
const card2 = { ...card1, id: "card-2" };
|
|
12
|
+
const cardOtherHolder = {
|
|
13
|
+
...card1,
|
|
14
|
+
id: "card-3",
|
|
15
|
+
cardholderAccountMembershipId: "member-2",
|
|
16
|
+
};
|
|
17
|
+
const transfer1 = { id: "transfer-1", accountId: "account-1", rail: "Transfer" };
|
|
18
|
+
const transferOtherAccount = {
|
|
19
|
+
...transfer1,
|
|
20
|
+
id: "transfer-2",
|
|
21
|
+
accountId: "account-2",
|
|
22
|
+
};
|
|
23
|
+
const notReportable = {
|
|
24
|
+
...transfer1,
|
|
25
|
+
id: "transfer-3",
|
|
26
|
+
notReportableReason: "TransactionStatusNotReportable",
|
|
27
|
+
};
|
|
28
|
+
const outsideWindow = {
|
|
29
|
+
...transfer1,
|
|
30
|
+
id: "transfer-4",
|
|
31
|
+
reportingWindowEndsAt: "2026-10-01T00:00:00.000Z",
|
|
32
|
+
};
|
|
33
|
+
const fraudDetails = {
|
|
34
|
+
reportedReason: "Manipulated",
|
|
35
|
+
reportedTypology: "FakeAdvisor",
|
|
36
|
+
description: "A fake advisor called me",
|
|
37
|
+
};
|
|
38
|
+
const createApi = (config = {}) => createFakeFraudReportApi({
|
|
39
|
+
transactions: [
|
|
40
|
+
card1,
|
|
41
|
+
card2,
|
|
42
|
+
cardOtherHolder,
|
|
43
|
+
transfer1,
|
|
44
|
+
transferOtherAccount,
|
|
45
|
+
notReportable,
|
|
46
|
+
outsideWindow,
|
|
47
|
+
],
|
|
48
|
+
accountMemberships: [
|
|
49
|
+
{ id: "member-1", accountId: "account-1" },
|
|
50
|
+
{ id: "member-2", accountId: "account-1" },
|
|
51
|
+
{ id: "member-other", accountId: "account-2" },
|
|
52
|
+
],
|
|
53
|
+
now: () => NOW,
|
|
54
|
+
...config,
|
|
55
|
+
});
|
|
56
|
+
const getRejection = (result) => result.match({
|
|
57
|
+
Ok: () => undefined,
|
|
58
|
+
Error: error => (error.kind === "rejection" ? error.rejection : undefined),
|
|
59
|
+
});
|
|
60
|
+
const getOk = (result) => result.match({
|
|
61
|
+
Ok: value => value,
|
|
62
|
+
Error: error => {
|
|
63
|
+
throw new Error(`Expected Ok, got ${JSON.stringify(error)}`);
|
|
64
|
+
},
|
|
65
|
+
});
|
|
66
|
+
const draft = async (api, input) => getOk(await api.draft(input));
|
|
67
|
+
describe("contract types", () => {
|
|
68
|
+
test("the fake adapter implements FraudReportApi", () => {
|
|
69
|
+
expectTypeOf(createApi()).toExtend();
|
|
70
|
+
});
|
|
71
|
+
test("update: leaving a field out keeps it, null clears it, transactionIds can't be null", () => {
|
|
72
|
+
expectTypeOf().toExtend();
|
|
73
|
+
expectTypeOf().toExtend();
|
|
74
|
+
expectTypeOf().not.toExtend();
|
|
75
|
+
});
|
|
76
|
+
test("draft requires transactionIds only", () => {
|
|
77
|
+
expectTypeOf().toExtend();
|
|
78
|
+
expectTypeOf().not.toExtend();
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
describe("happy path", () => {
|
|
82
|
+
test("draft → update → submit", async () => {
|
|
83
|
+
var _a, _b;
|
|
84
|
+
const api = createApi();
|
|
85
|
+
const created = await draft(api, { transactionIds: ["transfer-1"] });
|
|
86
|
+
expect(created.statusInfo).toEqual({ status: "Draft", expiresAt: "2026-12-20T10:00:00.000Z" });
|
|
87
|
+
expect(created.accountId).toBe("account-1");
|
|
88
|
+
expect(created.hasVictim).toBe(false);
|
|
89
|
+
expect(created.supportingDocumentCollection.status).toBe("WaitingForDocument");
|
|
90
|
+
const updated = getOk(await api.update({
|
|
91
|
+
disputeCaseId: created.id,
|
|
92
|
+
fraudDetails,
|
|
93
|
+
fraudTransferDetails: { hasContactedBankOrBeneficiary: true },
|
|
94
|
+
victimAccountMembershipId: "member-2",
|
|
95
|
+
}));
|
|
96
|
+
expect((_a = updated.fraudDetails) === null || _a === void 0 ? void 0 : _a.description).toBe("A fake advisor called me");
|
|
97
|
+
expect((_b = updated.fraudDetails) === null || _b === void 0 ? void 0 : _b.fraudsterChannels).toEqual([]);
|
|
98
|
+
expect(updated.victimAccountMembershipId).toBe("member-2");
|
|
99
|
+
expect(updated.hasVictim).toBe(true);
|
|
100
|
+
const submitted = getOk(await api.submit({ disputeCaseId: created.id }));
|
|
101
|
+
expect(submitted.statusInfo).toEqual({ status: "Submitted", submittedAt: NOW.toISOString() });
|
|
102
|
+
expect(submitted.supportingDocumentCollection.status).toBe("PendingReview");
|
|
103
|
+
});
|
|
104
|
+
test("the victim of a case with card transactions is the cardholder", async () => {
|
|
105
|
+
const created = await draft(createApi(), { transactionIds: ["card-1", "transfer-1"] });
|
|
106
|
+
expect(created.victimAccountMembershipId).toBe("member-1");
|
|
107
|
+
expect(created.hasVictim).toBe(true);
|
|
108
|
+
});
|
|
109
|
+
test("update: left-out fields are kept, null clears", async () => {
|
|
110
|
+
var _a;
|
|
111
|
+
const api = createApi();
|
|
112
|
+
const created = await draft(api, {
|
|
113
|
+
transactionIds: ["transfer-1"],
|
|
114
|
+
fraudDetails,
|
|
115
|
+
externalReference: "ref-1",
|
|
116
|
+
});
|
|
117
|
+
const kept = getOk(await api.update({ disputeCaseId: created.id, externalReference: "ref-2" }));
|
|
118
|
+
expect((_a = kept.fraudDetails) === null || _a === void 0 ? void 0 : _a.reportedTypology).toBe("FakeAdvisor");
|
|
119
|
+
expect(kept.externalReference).toBe("ref-2");
|
|
120
|
+
const cleared = getOk(await api.update({ disputeCaseId: created.id, fraudDetails: null }));
|
|
121
|
+
expect(cleared.fraudDetails).toBeNull();
|
|
122
|
+
expect(cleared.externalReference).toBe("ref-2");
|
|
123
|
+
});
|
|
124
|
+
test("changing transactions removes details and victim that no longer apply", async () => {
|
|
125
|
+
const api = createApi();
|
|
126
|
+
const created = await draft(api, {
|
|
127
|
+
transactionIds: ["transfer-1"],
|
|
128
|
+
fraudTransferDetails: { hasContactedBankOrBeneficiary: false },
|
|
129
|
+
victimAccountMembershipId: "member-2",
|
|
130
|
+
});
|
|
131
|
+
const updated = getOk(await api.update({ disputeCaseId: created.id, transactionIds: ["card-1"] }));
|
|
132
|
+
expect(updated.fraudTransferDetails).toBeNull();
|
|
133
|
+
expect(updated.victimAccountMembershipId).toBe("member-1");
|
|
134
|
+
});
|
|
135
|
+
test("submitting twice returns the submitted case", async () => {
|
|
136
|
+
const api = createApi();
|
|
137
|
+
const created = await draft(api, { transactionIds: ["card-1"], fraudDetails });
|
|
138
|
+
const first = getOk(await api.submit({ disputeCaseId: created.id }));
|
|
139
|
+
const second = getOk(await api.submit({ disputeCaseId: created.id }));
|
|
140
|
+
expect(second).toEqual(first);
|
|
141
|
+
});
|
|
142
|
+
test("cancel, getCase and findDrafts", async () => {
|
|
143
|
+
const api = createApi();
|
|
144
|
+
const a = await draft(api, { transactionIds: ["card-1"] });
|
|
145
|
+
const b = await draft(api, { transactionIds: ["card-1", "card-2"] });
|
|
146
|
+
await draft(api, { transactionIds: ["transfer-2"] });
|
|
147
|
+
const drafts = getOk(await api.findDrafts({ accountId: "account-1", transactionIds: ["card-1"] }));
|
|
148
|
+
expect(drafts.map(item => item.id)).toEqual([b.id, a.id]);
|
|
149
|
+
const canceled = getOk(await api.cancel({ disputeCaseId: a.id }));
|
|
150
|
+
expect(canceled.statusInfo).toEqual({ status: "Canceled", canceledAt: NOW.toISOString() });
|
|
151
|
+
expect(getOk(await api.cancel({ disputeCaseId: a.id }))).toEqual(canceled);
|
|
152
|
+
const remaining = getOk(await api.findDrafts({ accountId: "account-1", transactionIds: ["card-1"] }));
|
|
153
|
+
expect(remaining.map(item => item.id)).toEqual([b.id]);
|
|
154
|
+
expect(getOk(await api.getCase({ disputeCaseId: b.id }))).toEqual(Option.Some(b));
|
|
155
|
+
expect(getOk(await api.getCase({ disputeCaseId: "unknown" }))).toEqual(Option.None());
|
|
156
|
+
});
|
|
157
|
+
test("starts from seeded cases", async () => {
|
|
158
|
+
const seeded = await draft(createApi(), { transactionIds: ["card-1"] });
|
|
159
|
+
const api = createApi({ cases: [seeded] });
|
|
160
|
+
expect(getOk(await api.getCase({ disputeCaseId: seeded.id }))).toEqual(Option.Some(seeded));
|
|
161
|
+
});
|
|
162
|
+
test("uploads resolve", async () => {
|
|
163
|
+
const api = createApi();
|
|
164
|
+
const upload = getOk(await api.generateUpload({
|
|
165
|
+
supportingDocumentCollectionId: "collection-1",
|
|
166
|
+
fileName: "police-report.pdf",
|
|
167
|
+
purpose: "PoliceReport",
|
|
168
|
+
}));
|
|
169
|
+
expect(upload.id).toEqual(expect.any(String));
|
|
170
|
+
expect((await api.removeFile({
|
|
171
|
+
id: upload.id,
|
|
172
|
+
name: "police-report.pdf",
|
|
173
|
+
statusInfo: { status: "Uploaded" },
|
|
174
|
+
})).isOk()).toBe(true);
|
|
175
|
+
});
|
|
176
|
+
});
|
|
177
|
+
describe("draft and update rejections", () => {
|
|
178
|
+
test("malformed transactionIds are errors, not rejections", async () => {
|
|
179
|
+
const api = createApi();
|
|
180
|
+
for (const transactionIds of [[], ["card-1", "card-1"]]) {
|
|
181
|
+
const result = await api.draft({ transactionIds });
|
|
182
|
+
expect(result.match({ Ok: () => undefined, Error: error => error.kind })).toBe("error");
|
|
183
|
+
}
|
|
184
|
+
});
|
|
185
|
+
test("DisputeCaseNotFoundRejection", async () => {
|
|
186
|
+
const result = await createApi().update({ disputeCaseId: "unknown", fraudDetails });
|
|
187
|
+
expect(getRejection(result)).toMatchObject({
|
|
188
|
+
__typename: "DisputeCaseNotFoundRejection",
|
|
189
|
+
disputeCaseId: "unknown",
|
|
190
|
+
});
|
|
191
|
+
});
|
|
192
|
+
test("DisputeCaseWrongStatusRejection", async () => {
|
|
193
|
+
const api = createApi();
|
|
194
|
+
const created = await draft(api, { transactionIds: ["card-1"] });
|
|
195
|
+
await api.cancel({ disputeCaseId: created.id });
|
|
196
|
+
expect(getRejection(await api.update({ disputeCaseId: created.id, fraudDetails }))).toMatchObject({
|
|
197
|
+
__typename: "DisputeCaseWrongStatusRejection",
|
|
198
|
+
currentStatus: "Canceled",
|
|
199
|
+
expectedStatuses: ["Draft"],
|
|
200
|
+
});
|
|
201
|
+
});
|
|
202
|
+
test("DisputeCaseTransactionsLimitExceededRejection", async () => {
|
|
203
|
+
const transactions = Array.from({ length: 101 }, (_, index) => ({
|
|
204
|
+
...card1,
|
|
205
|
+
id: `card-${index}`,
|
|
206
|
+
}));
|
|
207
|
+
const result = await createApi({ transactions }).draft({
|
|
208
|
+
transactionIds: transactions.map(item => item.id),
|
|
209
|
+
});
|
|
210
|
+
expect(getRejection(result)).toMatchObject({
|
|
211
|
+
__typename: "DisputeCaseTransactionsLimitExceededRejection",
|
|
212
|
+
transactionCount: 101,
|
|
213
|
+
maxTransactionCount: 100,
|
|
214
|
+
});
|
|
215
|
+
});
|
|
216
|
+
test("DisputeCaseTransactionsNotFoundRejection", async () => {
|
|
217
|
+
const result = await createApi().draft({ transactionIds: ["card-1", "unknown"] });
|
|
218
|
+
expect(getRejection(result)).toMatchObject({
|
|
219
|
+
__typename: "DisputeCaseTransactionsNotFoundRejection",
|
|
220
|
+
transactionIds: ["unknown"],
|
|
221
|
+
});
|
|
222
|
+
});
|
|
223
|
+
test("DisputeCaseTransactionsNotReportableRejection", async () => {
|
|
224
|
+
const result = await createApi().draft({ transactionIds: ["transfer-3"] });
|
|
225
|
+
expect(getRejection(result)).toMatchObject({
|
|
226
|
+
__typename: "DisputeCaseTransactionsNotReportableRejection",
|
|
227
|
+
transactions: [{ transactionId: "transfer-3", reason: "TransactionStatusNotReportable" }],
|
|
228
|
+
});
|
|
229
|
+
});
|
|
230
|
+
test("DisputeCaseMultipleAccountsRejection", async () => {
|
|
231
|
+
const result = await createApi().draft({ transactionIds: ["transfer-1", "transfer-2"] });
|
|
232
|
+
expect(getRejection(result)).toMatchObject({
|
|
233
|
+
__typename: "DisputeCaseMultipleAccountsRejection",
|
|
234
|
+
accountIds: ["account-1", "account-2"],
|
|
235
|
+
});
|
|
236
|
+
});
|
|
237
|
+
test("DisputeCaseMultipleCardHoldersRejection", async () => {
|
|
238
|
+
const result = await createApi().draft({ transactionIds: ["card-1", "card-3"] });
|
|
239
|
+
expect(getRejection(result)).toMatchObject({
|
|
240
|
+
__typename: "DisputeCaseMultipleCardHoldersRejection",
|
|
241
|
+
accountMembershipIds: ["member-1", "member-2"],
|
|
242
|
+
});
|
|
243
|
+
});
|
|
244
|
+
test("DisputeCaseTransactionsOutsideReportingWindowRejection", async () => {
|
|
245
|
+
const result = await createApi().draft({ transactionIds: ["transfer-4"] });
|
|
246
|
+
expect(getRejection(result)).toMatchObject({
|
|
247
|
+
__typename: "DisputeCaseTransactionsOutsideReportingWindowRejection",
|
|
248
|
+
transactions: [
|
|
249
|
+
{ transactionId: "transfer-4", reportingWindowEndedAt: "2026-10-01T00:00:00.000Z" },
|
|
250
|
+
],
|
|
251
|
+
});
|
|
252
|
+
});
|
|
253
|
+
test("DisputeCaseDetailsNotApplicableRejection", async () => {
|
|
254
|
+
const api = createApi();
|
|
255
|
+
expect(getRejection(await api.draft({
|
|
256
|
+
transactionIds: ["card-1"],
|
|
257
|
+
fraudTransferDetails: { hasContactedBankOrBeneficiary: true },
|
|
258
|
+
}))).toMatchObject({
|
|
259
|
+
__typename: "DisputeCaseDetailsNotApplicableRejection",
|
|
260
|
+
fields: [{ path: ["fraudTransferDetails"] }],
|
|
261
|
+
});
|
|
262
|
+
expect(getRejection(await api.draft({
|
|
263
|
+
transactionIds: ["transfer-1"],
|
|
264
|
+
fraudCardDetails: { isLostOrStolen: true },
|
|
265
|
+
}))).toMatchObject({ fields: [{ path: ["fraudCardDetails"] }] });
|
|
266
|
+
expect(getRejection(await api.draft({ transactionIds: ["card-1"], victimAccountMembershipId: "member-1" }))).toMatchObject({ fields: [{ path: ["victimAccountMembershipId"] }] });
|
|
267
|
+
});
|
|
268
|
+
test("AccountMembershipNotFoundRejection", async () => {
|
|
269
|
+
const result = await createApi().draft({
|
|
270
|
+
transactionIds: ["transfer-1"],
|
|
271
|
+
victimAccountMembershipId: "member-other",
|
|
272
|
+
});
|
|
273
|
+
expect(getRejection(result)).toMatchObject({
|
|
274
|
+
__typename: "AccountMembershipNotFoundRejection",
|
|
275
|
+
id: "member-other",
|
|
276
|
+
});
|
|
277
|
+
});
|
|
278
|
+
test("a rejected call changes nothing", async () => {
|
|
279
|
+
const api = createApi();
|
|
280
|
+
const created = await draft(api, { transactionIds: ["transfer-1"], fraudDetails });
|
|
281
|
+
await api.update({
|
|
282
|
+
disputeCaseId: created.id,
|
|
283
|
+
fraudDetails: null,
|
|
284
|
+
transactionIds: ["unknown"],
|
|
285
|
+
});
|
|
286
|
+
expect(getOk(await api.getCase({ disputeCaseId: created.id }))).toEqual(Option.Some(created));
|
|
287
|
+
});
|
|
288
|
+
});
|
|
289
|
+
describe("submit and cancel rejections", () => {
|
|
290
|
+
test("DisputeCaseIncompleteRejection: fraud details", async () => {
|
|
291
|
+
const api = createApi();
|
|
292
|
+
const created = await draft(api, { transactionIds: ["card-1"] });
|
|
293
|
+
expect(getRejection(await api.submit({ disputeCaseId: created.id }))).toMatchObject({
|
|
294
|
+
__typename: "DisputeCaseIncompleteRejection",
|
|
295
|
+
missingFields: [{ path: ["fraudDetails"] }],
|
|
296
|
+
});
|
|
297
|
+
});
|
|
298
|
+
test("DisputeCaseIncompleteRejection: victim on a transfer-only case", async () => {
|
|
299
|
+
const api = createApi();
|
|
300
|
+
const created = await draft(api, { transactionIds: ["transfer-1"], fraudDetails });
|
|
301
|
+
expect(getRejection(await api.submit({ disputeCaseId: created.id }))).toMatchObject({
|
|
302
|
+
__typename: "DisputeCaseIncompleteRejection",
|
|
303
|
+
missingFields: [{ path: ["victimAccountMembershipId"] }],
|
|
304
|
+
});
|
|
305
|
+
});
|
|
306
|
+
test("DisputeCaseTransactionsAlreadyReportedRejection", async () => {
|
|
307
|
+
const api = createApi({ alreadyReported: [{ transactionId: "card-2", disputeCaseId: null }] });
|
|
308
|
+
const first = await draft(api, { transactionIds: ["card-1"], fraudDetails });
|
|
309
|
+
const second = await draft(api, { transactionIds: ["card-1", "card-2"], fraudDetails });
|
|
310
|
+
getOk(await api.submit({ disputeCaseId: first.id }));
|
|
311
|
+
expect(getRejection(await api.submit({ disputeCaseId: second.id }))).toMatchObject({
|
|
312
|
+
__typename: "DisputeCaseTransactionsAlreadyReportedRejection",
|
|
313
|
+
transactions: [
|
|
314
|
+
{ transactionId: "card-1", disputeCaseId: first.id },
|
|
315
|
+
{ transactionId: "card-2", disputeCaseId: null },
|
|
316
|
+
],
|
|
317
|
+
});
|
|
318
|
+
});
|
|
319
|
+
test("DisputeCaseTransactionsNotReportableRejection and OutsideReportingWindow on seeded drafts", async () => {
|
|
320
|
+
const seeded = await draft(createApi(), { transactionIds: ["transfer-1"], fraudDetails });
|
|
321
|
+
const notReportableCase = {
|
|
322
|
+
...seeded,
|
|
323
|
+
id: "case-1",
|
|
324
|
+
transactions: [{ id: "transfer-3", rail: "Transfer" }],
|
|
325
|
+
};
|
|
326
|
+
const outsideCase = {
|
|
327
|
+
...seeded,
|
|
328
|
+
id: "case-2",
|
|
329
|
+
transactions: [{ id: "transfer-4", rail: "Transfer" }],
|
|
330
|
+
};
|
|
331
|
+
const api = createApi({ cases: [notReportableCase, outsideCase] });
|
|
332
|
+
expect(getRejection(await api.submit({ disputeCaseId: "case-1" }))).toMatchObject({
|
|
333
|
+
__typename: "DisputeCaseTransactionsNotReportableRejection",
|
|
334
|
+
});
|
|
335
|
+
expect(getRejection(await api.submit({ disputeCaseId: "case-2" }))).toMatchObject({
|
|
336
|
+
__typename: "DisputeCaseTransactionsOutsideReportingWindowRejection",
|
|
337
|
+
});
|
|
338
|
+
});
|
|
339
|
+
test("DisputeCaseNotFoundRejection and DisputeCaseWrongStatusRejection", async () => {
|
|
340
|
+
const api = createApi();
|
|
341
|
+
expect(getRejection(await api.submit({ disputeCaseId: "unknown" }))).toMatchObject({
|
|
342
|
+
__typename: "DisputeCaseNotFoundRejection",
|
|
343
|
+
});
|
|
344
|
+
expect(getRejection(await api.cancel({ disputeCaseId: "unknown" }))).toMatchObject({
|
|
345
|
+
__typename: "DisputeCaseNotFoundRejection",
|
|
346
|
+
});
|
|
347
|
+
const created = await draft(api, { transactionIds: ["card-1"] });
|
|
348
|
+
await api.cancel({ disputeCaseId: created.id });
|
|
349
|
+
expect(getRejection(await api.submit({ disputeCaseId: created.id }))).toMatchObject({
|
|
350
|
+
__typename: "DisputeCaseWrongStatusRejection",
|
|
351
|
+
currentStatus: "Canceled",
|
|
352
|
+
});
|
|
353
|
+
const submittedCase = await draft(api, { transactionIds: ["card-2"], fraudDetails });
|
|
354
|
+
await api.submit({ disputeCaseId: submittedCase.id });
|
|
355
|
+
expect(getRejection(await api.cancel({ disputeCaseId: submittedCase.id }))).toMatchObject({
|
|
356
|
+
__typename: "DisputeCaseWrongStatusRejection",
|
|
357
|
+
currentStatus: "Submitted",
|
|
358
|
+
expectedStatuses: ["Draft"],
|
|
359
|
+
});
|
|
360
|
+
});
|
|
361
|
+
});
|
|
362
|
+
describe("check order", () => {
|
|
363
|
+
const precedence = [
|
|
364
|
+
[
|
|
365
|
+
"limit before not found",
|
|
366
|
+
{},
|
|
367
|
+
{ transactionIds: Array.from({ length: 101 }, (_, index) => `unknown-${index}`) },
|
|
368
|
+
"DisputeCaseTransactionsLimitExceededRejection",
|
|
369
|
+
],
|
|
370
|
+
[
|
|
371
|
+
"not found before not reportable",
|
|
372
|
+
{},
|
|
373
|
+
{ transactionIds: ["unknown", "transfer-3"] },
|
|
374
|
+
"DisputeCaseTransactionsNotFoundRejection",
|
|
375
|
+
],
|
|
376
|
+
[
|
|
377
|
+
"not reportable before multiple accounts",
|
|
378
|
+
{},
|
|
379
|
+
{ transactionIds: ["transfer-3", "transfer-2"] },
|
|
380
|
+
"DisputeCaseTransactionsNotReportableRejection",
|
|
381
|
+
],
|
|
382
|
+
[
|
|
383
|
+
"multiple cardholders before outside reporting window",
|
|
384
|
+
{},
|
|
385
|
+
{ transactionIds: ["card-1", "card-3", "transfer-4"] },
|
|
386
|
+
"DisputeCaseMultipleCardHoldersRejection",
|
|
387
|
+
],
|
|
388
|
+
[
|
|
389
|
+
"outside reporting window before details not applicable",
|
|
390
|
+
{},
|
|
391
|
+
{ transactionIds: ["transfer-4"], fraudCardDetails: { isLostOrStolen: true } },
|
|
392
|
+
"DisputeCaseTransactionsOutsideReportingWindowRejection",
|
|
393
|
+
],
|
|
394
|
+
[
|
|
395
|
+
"details not applicable before account membership not found",
|
|
396
|
+
{},
|
|
397
|
+
{
|
|
398
|
+
transactionIds: ["transfer-1"],
|
|
399
|
+
fraudCardDetails: { isLostOrStolen: true },
|
|
400
|
+
victimAccountMembershipId: "member-other",
|
|
401
|
+
},
|
|
402
|
+
"DisputeCaseDetailsNotApplicableRejection",
|
|
403
|
+
],
|
|
404
|
+
];
|
|
405
|
+
test.each(precedence)("draft: %s", async (_, config, input, expected) => {
|
|
406
|
+
var _a;
|
|
407
|
+
expect((_a = getRejection(await createApi(config).draft(input))) === null || _a === void 0 ? void 0 : _a.__typename).toBe(expected);
|
|
408
|
+
});
|
|
409
|
+
test("update: malformed input before case not found", async () => {
|
|
410
|
+
const result = await createApi().update({ disputeCaseId: "unknown", transactionIds: [] });
|
|
411
|
+
expect(result.match({ Ok: () => undefined, Error: error => error.kind })).toBe("error");
|
|
412
|
+
});
|
|
413
|
+
test("submit: outside reporting window before already reported, already reported before incomplete", async () => {
|
|
414
|
+
var _a, _b;
|
|
415
|
+
const seeded = await draft(createApi(), { transactionIds: ["transfer-1"] });
|
|
416
|
+
const outsideAndReported = {
|
|
417
|
+
...seeded,
|
|
418
|
+
id: "case-1",
|
|
419
|
+
transactions: [{ id: "transfer-4", rail: "Transfer" }],
|
|
420
|
+
};
|
|
421
|
+
const api = createApi({
|
|
422
|
+
cases: [outsideAndReported, { ...seeded, id: "case-2" }],
|
|
423
|
+
alreadyReported: [
|
|
424
|
+
{ transactionId: "transfer-4", disputeCaseId: null },
|
|
425
|
+
{ transactionId: "transfer-1", disputeCaseId: null },
|
|
426
|
+
],
|
|
427
|
+
});
|
|
428
|
+
expect((_a = getRejection(await api.submit({ disputeCaseId: "case-1" }))) === null || _a === void 0 ? void 0 : _a.__typename).toBe("DisputeCaseTransactionsOutsideReportingWindowRejection");
|
|
429
|
+
expect((_b = getRejection(await api.submit({ disputeCaseId: "case-2" }))) === null || _b === void 0 ? void 0 : _b.__typename).toBe("DisputeCaseTransactionsAlreadyReportedRejection");
|
|
430
|
+
});
|
|
431
|
+
test("submit: DisputeCaseTransactionsNotFoundRejection when a transaction can no longer be reported", async () => {
|
|
432
|
+
const seeded = await draft(createApi(), { transactionIds: ["transfer-1"], fraudDetails });
|
|
433
|
+
const api = createApi({
|
|
434
|
+
cases: [{ ...seeded, transactions: [{ id: "gone", rail: "Transfer" }] }],
|
|
435
|
+
});
|
|
436
|
+
expect(getRejection(await api.submit({ disputeCaseId: seeded.id }))).toMatchObject({
|
|
437
|
+
__typename: "DisputeCaseTransactionsNotFoundRejection",
|
|
438
|
+
transactionIds: ["gone"],
|
|
439
|
+
});
|
|
440
|
+
});
|
|
441
|
+
});
|
|
442
|
+
describe("details and victim after a transaction change", () => {
|
|
443
|
+
test("transfer → card → transfer doesn't bring the victim back", async () => {
|
|
444
|
+
const api = createApi();
|
|
445
|
+
const created = await draft(api, {
|
|
446
|
+
transactionIds: ["transfer-1"],
|
|
447
|
+
victimAccountMembershipId: "member-2",
|
|
448
|
+
});
|
|
449
|
+
await api.update({ disputeCaseId: created.id, transactionIds: ["card-1"] });
|
|
450
|
+
const back = getOk(await api.update({ disputeCaseId: created.id, transactionIds: ["transfer-1"] }));
|
|
451
|
+
expect(back.hasVictim).toBe(false);
|
|
452
|
+
expect(back.victimAccountMembershipId).toBeNull();
|
|
453
|
+
});
|
|
454
|
+
test("moving to another account removes the victim", async () => {
|
|
455
|
+
const api = createApi({
|
|
456
|
+
transactions: [transfer1, { ...transfer1, id: "transfer-5", accountId: "account-2" }],
|
|
457
|
+
});
|
|
458
|
+
const created = await draft(api, {
|
|
459
|
+
transactionIds: ["transfer-1"],
|
|
460
|
+
victimAccountMembershipId: "member-2",
|
|
461
|
+
});
|
|
462
|
+
const moved = getOk(await api.update({ disputeCaseId: created.id, transactionIds: ["transfer-5"] }));
|
|
463
|
+
expect(moved.hasVictim).toBe(false);
|
|
464
|
+
});
|
|
465
|
+
test("a victim sent with new transactions is kept", async () => {
|
|
466
|
+
const api = createApi({
|
|
467
|
+
transactions: [transfer1, { ...transfer1, id: "transfer-5", accountId: "account-2" }],
|
|
468
|
+
});
|
|
469
|
+
const created = await draft(api, {
|
|
470
|
+
transactionIds: ["transfer-1"],
|
|
471
|
+
victimAccountMembershipId: "member-2",
|
|
472
|
+
});
|
|
473
|
+
const moved = getOk(await api.update({
|
|
474
|
+
disputeCaseId: created.id,
|
|
475
|
+
transactionIds: ["transfer-5"],
|
|
476
|
+
victimAccountMembershipId: "member-other",
|
|
477
|
+
}));
|
|
478
|
+
expect(moved.victimAccountMembershipId).toBe("member-other");
|
|
479
|
+
});
|
|
480
|
+
test("removing card transactions removes card details", async () => {
|
|
481
|
+
const api = createApi();
|
|
482
|
+
const created = await draft(api, {
|
|
483
|
+
transactionIds: ["card-1", "transfer-1"],
|
|
484
|
+
fraudCardDetails: { isLostOrStolen: true },
|
|
485
|
+
});
|
|
486
|
+
expect(created.transactions).toEqual([
|
|
487
|
+
{ id: "card-1", rail: "Card" },
|
|
488
|
+
{ id: "transfer-1", rail: "Transfer" },
|
|
489
|
+
]);
|
|
490
|
+
const updated = getOk(await api.update({ disputeCaseId: created.id, transactionIds: ["transfer-1"] }));
|
|
491
|
+
expect(updated.fraudCardDetails).toBeNull();
|
|
492
|
+
});
|
|
493
|
+
});
|
|
494
|
+
describe("expiry", () => {
|
|
495
|
+
test("a draft expires at the end of its oldest transaction's reporting window", async () => {
|
|
496
|
+
let now = NOW;
|
|
497
|
+
const api = createApi({
|
|
498
|
+
transactions: [{ ...transfer1, reportingWindowEndsAt: "2026-12-01T00:00:00.000Z" }],
|
|
499
|
+
now: () => now,
|
|
500
|
+
});
|
|
501
|
+
const created = await draft(api, { transactionIds: ["transfer-1"] });
|
|
502
|
+
expect(created.statusInfo).toEqual({ status: "Draft", expiresAt: "2026-12-01T00:00:00.000Z" });
|
|
503
|
+
now = new Date("2026-12-02T00:00:00.000Z");
|
|
504
|
+
const expired = getOk(await api.getCase({ disputeCaseId: created.id })).toUndefined();
|
|
505
|
+
expect(expired === null || expired === void 0 ? void 0 : expired.statusInfo).toEqual({
|
|
506
|
+
status: "Expired",
|
|
507
|
+
expiredAt: "2026-12-01T00:00:00.000Z",
|
|
508
|
+
});
|
|
509
|
+
expect(getRejection(await api.update({ disputeCaseId: created.id, fraudDetails }))).toMatchObject({
|
|
510
|
+
__typename: "DisputeCaseWrongStatusRejection",
|
|
511
|
+
currentStatus: "Expired",
|
|
512
|
+
});
|
|
513
|
+
});
|
|
514
|
+
});
|
|
515
|
+
describe("more precedence", () => {
|
|
516
|
+
test("draft: multiple accounts before multiple cardholders", async () => {
|
|
517
|
+
var _a;
|
|
518
|
+
const api = createApi({
|
|
519
|
+
transactions: [
|
|
520
|
+
card1,
|
|
521
|
+
{
|
|
522
|
+
...card1,
|
|
523
|
+
id: "card-9",
|
|
524
|
+
accountId: "account-2",
|
|
525
|
+
cardholderAccountMembershipId: "member-other",
|
|
526
|
+
},
|
|
527
|
+
],
|
|
528
|
+
});
|
|
529
|
+
expect((_a = getRejection(await api.draft({ transactionIds: ["card-1", "card-9"] }))) === null || _a === void 0 ? void 0 : _a.__typename).toBe("DisputeCaseMultipleAccountsRejection");
|
|
530
|
+
});
|
|
531
|
+
test("update: case not found and wrong status before transaction checks", async () => {
|
|
532
|
+
var _a, _b;
|
|
533
|
+
const api = createApi();
|
|
534
|
+
expect((_a = getRejection(await api.update({ disputeCaseId: "unknown", transactionIds: ["unknown"] }))) === null || _a === void 0 ? void 0 : _a.__typename).toBe("DisputeCaseNotFoundRejection");
|
|
535
|
+
const created = await draft(api, { transactionIds: ["card-1"] });
|
|
536
|
+
await api.cancel({ disputeCaseId: created.id });
|
|
537
|
+
expect((_b = getRejection(await api.update({ disputeCaseId: created.id, transactionIds: ["unknown"] }))) === null || _b === void 0 ? void 0 : _b.__typename).toBe("DisputeCaseWrongStatusRejection");
|
|
538
|
+
});
|
|
539
|
+
test("submit: not found before not reportable, not reportable before outside reporting window", async () => {
|
|
540
|
+
var _a, _b;
|
|
541
|
+
const seeded = await draft(createApi(), { transactionIds: ["transfer-1"], fraudDetails });
|
|
542
|
+
const api = createApi({
|
|
543
|
+
cases: [
|
|
544
|
+
{
|
|
545
|
+
...seeded,
|
|
546
|
+
id: "case-1",
|
|
547
|
+
transactions: [
|
|
548
|
+
{ id: "gone", rail: "Transfer" },
|
|
549
|
+
{ id: "transfer-3", rail: "Transfer" },
|
|
550
|
+
],
|
|
551
|
+
},
|
|
552
|
+
{
|
|
553
|
+
...seeded,
|
|
554
|
+
id: "case-2",
|
|
555
|
+
transactions: [
|
|
556
|
+
{ id: "transfer-3", rail: "Transfer" },
|
|
557
|
+
{ id: "transfer-4", rail: "Transfer" },
|
|
558
|
+
],
|
|
559
|
+
},
|
|
560
|
+
],
|
|
561
|
+
});
|
|
562
|
+
expect((_a = getRejection(await api.submit({ disputeCaseId: "case-1" }))) === null || _a === void 0 ? void 0 : _a.__typename).toBe("DisputeCaseTransactionsNotFoundRejection");
|
|
563
|
+
expect((_b = getRejection(await api.submit({ disputeCaseId: "case-2" }))) === null || _b === void 0 ? void 0 : _b.__typename).toBe("DisputeCaseTransactionsNotReportableRejection");
|
|
564
|
+
});
|
|
565
|
+
});
|
|
566
|
+
describe("left-out fields are kept", () => {
|
|
567
|
+
const transfer6 = { ...transfer1, id: "transfer-6" };
|
|
568
|
+
test("adding a transfer keeps the victim and transfer details", async () => {
|
|
569
|
+
const api = createApi({ transactions: [transfer1, transfer6] });
|
|
570
|
+
const created = await draft(api, {
|
|
571
|
+
transactionIds: ["transfer-1"],
|
|
572
|
+
victimAccountMembershipId: "member-2",
|
|
573
|
+
fraudTransferDetails: { hasContactedBankOrBeneficiary: true },
|
|
574
|
+
});
|
|
575
|
+
const updated = getOk(await api.update({ disputeCaseId: created.id, transactionIds: ["transfer-1", "transfer-6"] }));
|
|
576
|
+
expect(updated.victimAccountMembershipId).toBe("member-2");
|
|
577
|
+
expect(updated.fraudTransferDetails).toEqual({ hasContactedBankOrBeneficiary: true });
|
|
578
|
+
const referenced = getOk(await api.update({ disputeCaseId: created.id, externalReference: "ref" }));
|
|
579
|
+
expect(referenced.hasVictim).toBe(true);
|
|
580
|
+
});
|
|
581
|
+
test("adding a card transaction keeps card details", async () => {
|
|
582
|
+
const api = createApi();
|
|
583
|
+
const created = await draft(api, {
|
|
584
|
+
transactionIds: ["card-1"],
|
|
585
|
+
fraudCardDetails: { hasContactedMerchant: true },
|
|
586
|
+
});
|
|
587
|
+
const updated = getOk(await api.update({ disputeCaseId: created.id, transactionIds: ["card-1", "card-2"] }));
|
|
588
|
+
expect(updated.fraudCardDetails).toEqual({
|
|
589
|
+
isLostOrStolen: null,
|
|
590
|
+
lostOrStolenNoticedAt: null,
|
|
591
|
+
hasContactedMerchant: true,
|
|
592
|
+
});
|
|
593
|
+
});
|
|
594
|
+
test("a victim the caller can't see stays on the case", async () => {
|
|
595
|
+
const seeded = await draft(createApi(), {
|
|
596
|
+
transactionIds: ["transfer-1"],
|
|
597
|
+
victimAccountMembershipId: "member-2",
|
|
598
|
+
});
|
|
599
|
+
const api = createApi({ cases: [{ ...seeded, victimAccountMembershipId: null }] });
|
|
600
|
+
const updated = getOk(await api.update({ disputeCaseId: seeded.id, externalReference: "ref" }));
|
|
601
|
+
expect(updated.hasVictim).toBe(true);
|
|
602
|
+
expect(updated.victimAccountMembershipId).toBeNull();
|
|
603
|
+
});
|
|
604
|
+
});
|
|
605
|
+
test("findDrafts returns the newest draft first", async () => {
|
|
606
|
+
const seeded = await draft(createApi(), { transactionIds: ["card-1"] });
|
|
607
|
+
const newer = { ...seeded, id: "newer", createdAt: "2026-11-19T00:00:00.000Z" };
|
|
608
|
+
const older = { ...seeded, id: "older", createdAt: "2026-11-01T00:00:00.000Z" };
|
|
609
|
+
const api = createApi({ cases: [newer, older] });
|
|
610
|
+
const drafts = getOk(await api.findDrafts({ accountId: "account-1", transactionIds: ["card-1"] }));
|
|
611
|
+
expect(drafts.map(item => item.id)).toEqual(["newer", "older"]);
|
|
612
|
+
});
|
|
613
|
+
describe("dates", () => {
|
|
614
|
+
const later = (days) => new Date(NOW.getTime() + days * 24 * 60 * 60 * 1000);
|
|
615
|
+
test("submitting or canceling again doesn't change the case", async () => {
|
|
616
|
+
let now = NOW;
|
|
617
|
+
const api = createApi({ now: () => now });
|
|
618
|
+
const toSubmit = await draft(api, { transactionIds: ["card-1"], fraudDetails });
|
|
619
|
+
const toCancel = await draft(api, { transactionIds: ["card-2"] });
|
|
620
|
+
const submitted = getOk(await api.submit({ disputeCaseId: toSubmit.id }));
|
|
621
|
+
const canceled = getOk(await api.cancel({ disputeCaseId: toCancel.id }));
|
|
622
|
+
now = later(1);
|
|
623
|
+
expect(getOk(await api.submit({ disputeCaseId: toSubmit.id }))).toEqual(submitted);
|
|
624
|
+
expect(getOk(await api.cancel({ disputeCaseId: toCancel.id }))).toEqual(canceled);
|
|
625
|
+
});
|
|
626
|
+
test("a draft expires 30 days after its last update", async () => {
|
|
627
|
+
var _a;
|
|
628
|
+
let now = NOW;
|
|
629
|
+
const api = createApi({ now: () => now });
|
|
630
|
+
const created = await draft(api, { transactionIds: ["transfer-1"] });
|
|
631
|
+
now = later(10);
|
|
632
|
+
const updated = getOk(await api.update({ disputeCaseId: created.id, fraudDetails }));
|
|
633
|
+
expect(updated.statusInfo).toEqual({ status: "Draft", expiresAt: later(40).toISOString() });
|
|
634
|
+
now = later(40);
|
|
635
|
+
expect((_a = getOk(await api.getCase({ disputeCaseId: created.id })).toUndefined()) === null || _a === void 0 ? void 0 : _a.statusInfo).toEqual({
|
|
636
|
+
status: "Expired",
|
|
637
|
+
expiredAt: later(40).toISOString(),
|
|
638
|
+
});
|
|
639
|
+
expect(getOk(await api.findDrafts({ accountId: "account-1", transactionIds: ["transfer-1"] }))).toEqual([]);
|
|
640
|
+
expect(getRejection(await api.update({ disputeCaseId: created.id, fraudDetails }))).toMatchObject({
|
|
641
|
+
__typename: "DisputeCaseWrongStatusRejection",
|
|
642
|
+
currentStatus: "Expired",
|
|
643
|
+
});
|
|
644
|
+
});
|
|
645
|
+
});
|
|
646
|
+
test("null clears the victim", async () => {
|
|
647
|
+
const api = createApi();
|
|
648
|
+
const created = await draft(api, {
|
|
649
|
+
transactionIds: ["transfer-1"],
|
|
650
|
+
fraudDetails,
|
|
651
|
+
victimAccountMembershipId: "member-2",
|
|
652
|
+
});
|
|
653
|
+
const cleared = getOk(await api.update({ disputeCaseId: created.id, victimAccountMembershipId: null }));
|
|
654
|
+
expect(cleared.hasVictim).toBe(false);
|
|
655
|
+
expect(getRejection(await api.submit({ disputeCaseId: created.id }))).toMatchObject({
|
|
656
|
+
__typename: "DisputeCaseIncompleteRejection",
|
|
657
|
+
missingFields: [{ path: ["victimAccountMembershipId"] }],
|
|
658
|
+
});
|
|
659
|
+
});
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { Future, Option, Result } from "@bloodyowl/boxed";
|
|
2
|
+
import type { NetworkError, Response, TimeoutError } from "@bloodyowl/request";
|
|
3
|
+
import type { UploadOutput } from "../../components/SupportingDocumentCollection";
|
|
4
|
+
import type { UploadFileInput, UploadOutputWithId } from "../../hooks/useFilesUploader";
|
|
5
|
+
import type { SwanFile } from "../SwanFile";
|
|
6
|
+
import type { CancelDisputeCaseInput, CancelDisputeCaseRejection, DraftFraudDisputeCaseInput, DraftFraudDisputeCaseRejection, FraudReportCase, FraudReportDocumentPurpose, SubmitDisputeCaseInput, SubmitDisputeCaseRejection, UpdateDraftFraudDisputeCaseInput, UpdateDraftFraudDisputeCaseRejection } from "./types";
|
|
7
|
+
export type FraudReportApiError<Rejection> = {
|
|
8
|
+
kind: "rejection";
|
|
9
|
+
rejection: Rejection;
|
|
10
|
+
} | {
|
|
11
|
+
kind: "error";
|
|
12
|
+
error: unknown;
|
|
13
|
+
};
|
|
14
|
+
export type FraudReportApiResult<Value, Rejection = never> = Future<Result<Value, FraudReportApiError<Rejection>>>;
|
|
15
|
+
export type FraudReportApi = {
|
|
16
|
+
draft: (input: DraftFraudDisputeCaseInput) => FraudReportApiResult<FraudReportCase, DraftFraudDisputeCaseRejection>;
|
|
17
|
+
update: (input: UpdateDraftFraudDisputeCaseInput) => FraudReportApiResult<FraudReportCase, UpdateDraftFraudDisputeCaseRejection>;
|
|
18
|
+
submit: (input: SubmitDisputeCaseInput) => FraudReportApiResult<FraudReportCase, SubmitDisputeCaseRejection>;
|
|
19
|
+
cancel: (input: CancelDisputeCaseInput) => FraudReportApiResult<FraudReportCase, CancelDisputeCaseRejection>;
|
|
20
|
+
getCase: (input: {
|
|
21
|
+
disputeCaseId: string;
|
|
22
|
+
}) => FraudReportApiResult<Option<FraudReportCase>>;
|
|
23
|
+
findDrafts: (input: {
|
|
24
|
+
accountId: string;
|
|
25
|
+
transactionIds: string[];
|
|
26
|
+
}) => FraudReportApiResult<FraudReportCase[]>;
|
|
27
|
+
generateUpload: (input: {
|
|
28
|
+
supportingDocumentCollectionId: string;
|
|
29
|
+
fileName: string;
|
|
30
|
+
purpose: FraudReportDocumentPurpose;
|
|
31
|
+
}) => Future<Result<UploadOutputWithId<UploadOutput>, unknown>>;
|
|
32
|
+
uploadFile?: (config: UploadFileInput<UploadOutput>) => Future<Result<Response<string>, NetworkError | TimeoutError>>;
|
|
33
|
+
removeFile: (file: SwanFile) => Future<Result<unknown, unknown>>;
|
|
34
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { FraudReportApi } from "./api";
|
|
2
|
+
import type { DisputeCaseTransactionNotReportableReason, FraudReportCase } from "./types";
|
|
3
|
+
export type FakeTransaction = {
|
|
4
|
+
id: string;
|
|
5
|
+
accountId: string;
|
|
6
|
+
notReportableReason?: DisputeCaseTransactionNotReportableReason;
|
|
7
|
+
reportingWindowEndsAt?: string;
|
|
8
|
+
} & ({
|
|
9
|
+
rail: "Card";
|
|
10
|
+
cardholderAccountMembershipId: string;
|
|
11
|
+
} | {
|
|
12
|
+
rail: "Transfer";
|
|
13
|
+
});
|
|
14
|
+
export type FakeAccountMembership = {
|
|
15
|
+
id: string;
|
|
16
|
+
accountId: string;
|
|
17
|
+
};
|
|
18
|
+
export type FakeFraudReportApiConfig = {
|
|
19
|
+
transactions: FakeTransaction[];
|
|
20
|
+
accountMemberships: FakeAccountMembership[];
|
|
21
|
+
cases?: FraudReportCase[];
|
|
22
|
+
alreadyReported?: {
|
|
23
|
+
transactionId: string;
|
|
24
|
+
disputeCaseId: string | null;
|
|
25
|
+
}[];
|
|
26
|
+
delay?: number;
|
|
27
|
+
now?: () => Date;
|
|
28
|
+
};
|
|
29
|
+
export declare const createFakeFraudReportApi: (config: FakeFraudReportApiConfig) => FraudReportApi;
|
|
@@ -0,0 +1,366 @@
|
|
|
1
|
+
import { Future, Option, Result } from "@bloodyowl/boxed";
|
|
2
|
+
import { match } from "ts-pattern";
|
|
3
|
+
const MAX_TRANSACTIONS = 100;
|
|
4
|
+
const DRAFT_LIFETIME_MS = 30 * 24 * 60 * 60 * 1000;
|
|
5
|
+
const isDefined = (value) => value !== undefined;
|
|
6
|
+
const unique = (values) => [...new Set(values)];
|
|
7
|
+
const firstOf = (...checks) => {
|
|
8
|
+
for (const check of checks) {
|
|
9
|
+
const result = check();
|
|
10
|
+
if (result.isSome()) {
|
|
11
|
+
return result;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
return Option.None();
|
|
15
|
+
};
|
|
16
|
+
const toFraudDetails = (input) => { var _a, _b, _c, _d, _e; return ({
|
|
17
|
+
reportedReason: input.reportedReason,
|
|
18
|
+
reportedTypology: input.reportedTypology,
|
|
19
|
+
description: input.description,
|
|
20
|
+
discoveredAt: (_a = input.discoveredAt) !== null && _a !== void 0 ? _a : null,
|
|
21
|
+
discoveryDetails: (_b = input.discoveryDetails) !== null && _b !== void 0 ? _b : null,
|
|
22
|
+
fraudsterChannels: (_c = input.fraudsterChannels) !== null && _c !== void 0 ? _c : [],
|
|
23
|
+
sharedInformationWithFraudster: (_d = input.sharedInformationWithFraudster) !== null && _d !== void 0 ? _d : [],
|
|
24
|
+
hasFiledPoliceComplaint: (_e = input.hasFiledPoliceComplaint) !== null && _e !== void 0 ? _e : null,
|
|
25
|
+
}); };
|
|
26
|
+
const toPublicCase = ({ sentVictim: _, ...rest }) => rest;
|
|
27
|
+
const rejection = (value) => ({
|
|
28
|
+
kind: "rejection",
|
|
29
|
+
rejection: value,
|
|
30
|
+
});
|
|
31
|
+
const badUserInput = (message) => ({
|
|
32
|
+
kind: "error",
|
|
33
|
+
error: new Error(`BAD_USER_INPUT: ${message}`),
|
|
34
|
+
});
|
|
35
|
+
export const createFakeFraudReportApi = (config) => {
|
|
36
|
+
var _a, _b, _c;
|
|
37
|
+
const now = (_a = config.now) !== null && _a !== void 0 ? _a : (() => new Date());
|
|
38
|
+
const delay = (_b = config.delay) !== null && _b !== void 0 ? _b : 0;
|
|
39
|
+
const respond = (result) => delay > 0
|
|
40
|
+
? Future.make(resolve => {
|
|
41
|
+
const timeout = setTimeout(() => resolve(result), delay);
|
|
42
|
+
return () => clearTimeout(timeout);
|
|
43
|
+
})
|
|
44
|
+
: Future.value(result);
|
|
45
|
+
const findTransaction = (id) => config.transactions.find(item => item.id === id);
|
|
46
|
+
const getTransactions = (ids) => ids.map(findTransaction).filter(isDefined);
|
|
47
|
+
const getIds = (item) => item.transactions.map(({ id }) => id);
|
|
48
|
+
const getCardholder = (ids) => { var _a; var _b; return (_b = (_a = getTransactions(ids).flatMap(item => (item.rail === "Card" ? [item] : []))[0]) === null || _a === void 0 ? void 0 : _a.cardholderAccountMembershipId) !== null && _b !== void 0 ? _b : null; };
|
|
49
|
+
const cases = new Map(((_c = config.cases) !== null && _c !== void 0 ? _c : []).map(item => [
|
|
50
|
+
item.id,
|
|
51
|
+
{
|
|
52
|
+
...item,
|
|
53
|
+
sentVictim: item.hasVictim && !item.transactions.some(({ rail }) => rail === "Card")
|
|
54
|
+
? { id: item.victimAccountMembershipId }
|
|
55
|
+
: null,
|
|
56
|
+
},
|
|
57
|
+
]));
|
|
58
|
+
// A draft past its expiry date reads as expired, as the API does.
|
|
59
|
+
const getStoredCase = (id) => Option.fromUndefined(cases.get(id)).map(item => item.statusInfo.status === "Draft" && now().getTime() >= Date.parse(item.statusInfo.expiresAt)
|
|
60
|
+
? {
|
|
61
|
+
...item,
|
|
62
|
+
statusInfo: { status: "Expired", expiredAt: item.statusInfo.expiresAt },
|
|
63
|
+
supportingDocumentCollection: {
|
|
64
|
+
...item.supportingDocumentCollection,
|
|
65
|
+
status: "Canceled",
|
|
66
|
+
},
|
|
67
|
+
}
|
|
68
|
+
: item);
|
|
69
|
+
const save = (item) => {
|
|
70
|
+
cases.set(item.id, item);
|
|
71
|
+
return toPublicCase(item);
|
|
72
|
+
};
|
|
73
|
+
const notFound = (disputeCaseId) => rejection({
|
|
74
|
+
__typename: "DisputeCaseNotFoundRejection",
|
|
75
|
+
message: "Dispute case not found",
|
|
76
|
+
disputeCaseId,
|
|
77
|
+
});
|
|
78
|
+
const wrongStatus = (item, expectedStatuses) => rejection({
|
|
79
|
+
__typename: "DisputeCaseWrongStatusRejection",
|
|
80
|
+
message: "Dispute case has the wrong status",
|
|
81
|
+
disputeCaseId: item.id,
|
|
82
|
+
currentStatus: item.statusInfo.status,
|
|
83
|
+
expectedStatuses,
|
|
84
|
+
});
|
|
85
|
+
const checkTransactionsFound = (ids) => {
|
|
86
|
+
const missing = ids.filter(id => findTransaction(id) == null);
|
|
87
|
+
return missing.length > 0
|
|
88
|
+
? Option.Some({
|
|
89
|
+
__typename: "DisputeCaseTransactionsNotFoundRejection",
|
|
90
|
+
message: "Some transactions were not found",
|
|
91
|
+
transactionIds: missing,
|
|
92
|
+
})
|
|
93
|
+
: Option.None();
|
|
94
|
+
};
|
|
95
|
+
const checkReportable = (ids) => {
|
|
96
|
+
const transactions = getTransactions(ids).flatMap(({ id, notReportableReason }) => notReportableReason == null ? [] : [{ transactionId: id, reason: notReportableReason }]);
|
|
97
|
+
return transactions.length > 0
|
|
98
|
+
? Option.Some({
|
|
99
|
+
__typename: "DisputeCaseTransactionsNotReportableRejection",
|
|
100
|
+
message: "Some transactions can't be reported",
|
|
101
|
+
transactions,
|
|
102
|
+
})
|
|
103
|
+
: Option.None();
|
|
104
|
+
};
|
|
105
|
+
const checkSingleAccount = (ids) => {
|
|
106
|
+
const accountIds = unique(getTransactions(ids).map(item => item.accountId));
|
|
107
|
+
return accountIds.length > 1
|
|
108
|
+
? Option.Some({
|
|
109
|
+
__typename: "DisputeCaseMultipleAccountsRejection",
|
|
110
|
+
message: "Transactions belong to several accounts",
|
|
111
|
+
accountIds,
|
|
112
|
+
})
|
|
113
|
+
: Option.None();
|
|
114
|
+
};
|
|
115
|
+
const checkSingleCardholder = (ids) => {
|
|
116
|
+
const accountMembershipIds = unique(getTransactions(ids).flatMap(item => item.rail === "Card" ? [item.cardholderAccountMembershipId] : []));
|
|
117
|
+
return accountMembershipIds.length > 1
|
|
118
|
+
? Option.Some({
|
|
119
|
+
__typename: "DisputeCaseMultipleCardHoldersRejection",
|
|
120
|
+
message: "Card transactions belong to several cardholders",
|
|
121
|
+
accountMembershipIds,
|
|
122
|
+
})
|
|
123
|
+
: Option.None();
|
|
124
|
+
};
|
|
125
|
+
const checkReportingWindow = (ids) => {
|
|
126
|
+
const transactions = getTransactions(ids).flatMap(({ id, reportingWindowEndsAt }) => reportingWindowEndsAt != null && now().getTime() >= Date.parse(reportingWindowEndsAt)
|
|
127
|
+
? [{ transactionId: id, reportingWindowEndedAt: reportingWindowEndsAt }]
|
|
128
|
+
: []);
|
|
129
|
+
return transactions.length > 0
|
|
130
|
+
? Option.Some({
|
|
131
|
+
__typename: "DisputeCaseTransactionsOutsideReportingWindowRejection",
|
|
132
|
+
message: "Some transactions are outside the reporting window",
|
|
133
|
+
transactions,
|
|
134
|
+
})
|
|
135
|
+
: Option.None();
|
|
136
|
+
};
|
|
137
|
+
const checkInputFormat = (input) => {
|
|
138
|
+
const { transactionIds } = input;
|
|
139
|
+
if (transactionIds == null) {
|
|
140
|
+
return Option.None();
|
|
141
|
+
}
|
|
142
|
+
if (transactionIds.length === 0) {
|
|
143
|
+
return Option.Some(badUserInput("transactionIds must not be empty"));
|
|
144
|
+
}
|
|
145
|
+
if (unique(transactionIds).length !== transactionIds.length) {
|
|
146
|
+
return Option.Some(badUserInput("transactionIds must not contain duplicates"));
|
|
147
|
+
}
|
|
148
|
+
return Option.None();
|
|
149
|
+
};
|
|
150
|
+
// Draft and update checks, from the transaction limit on, run on the case as it would stand
|
|
151
|
+
// after the call.
|
|
152
|
+
const write = (existing, input) => {
|
|
153
|
+
var _a;
|
|
154
|
+
var _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
|
|
155
|
+
const transactionIds = (_b = input.transactionIds) !== null && _b !== void 0 ? _b : (existing != null ? getIds(existing) : []);
|
|
156
|
+
const transactions = getTransactions(transactionIds);
|
|
157
|
+
const hasCard = transactions.some(item => item.rail === "Card");
|
|
158
|
+
const hasTransfer = transactions.some(item => item.rail === "Transfer");
|
|
159
|
+
const accountId = (_d = (_c = (_a = transactions[0]) === null || _a === void 0 ? void 0 : _a.accountId) !== null && _c !== void 0 ? _c : existing === null || existing === void 0 ? void 0 : existing.accountId) !== null && _d !== void 0 ? _d : "";
|
|
160
|
+
const sentVictim = input.victimAccountMembershipId;
|
|
161
|
+
const checkLimit = () => input.transactionIds != null && input.transactionIds.length > MAX_TRANSACTIONS
|
|
162
|
+
? Option.Some({
|
|
163
|
+
__typename: "DisputeCaseTransactionsLimitExceededRejection",
|
|
164
|
+
message: "Too many transactions",
|
|
165
|
+
transactionCount: input.transactionIds.length,
|
|
166
|
+
maxTransactionCount: MAX_TRANSACTIONS,
|
|
167
|
+
})
|
|
168
|
+
: Option.None();
|
|
169
|
+
const checkDetailsApplicable = () => {
|
|
170
|
+
const fields = [
|
|
171
|
+
input.fraudCardDetails != null && !hasCard ? ["fraudCardDetails"] : undefined,
|
|
172
|
+
input.fraudTransferDetails != null && !hasTransfer ? ["fraudTransferDetails"] : undefined,
|
|
173
|
+
sentVictim != null && hasCard ? ["victimAccountMembershipId"] : undefined,
|
|
174
|
+
]
|
|
175
|
+
.filter(isDefined)
|
|
176
|
+
.map(path => ({ path }));
|
|
177
|
+
return fields.length > 0
|
|
178
|
+
? Option.Some({
|
|
179
|
+
__typename: "DisputeCaseDetailsNotApplicableRejection",
|
|
180
|
+
message: "Some details don't apply to this case",
|
|
181
|
+
fields,
|
|
182
|
+
})
|
|
183
|
+
: Option.None();
|
|
184
|
+
};
|
|
185
|
+
const checkVictim = () => sentVictim != null &&
|
|
186
|
+
!config.accountMemberships.some(item => item.id === sentVictim && item.accountId === accountId)
|
|
187
|
+
? Option.Some({
|
|
188
|
+
__typename: "AccountMembershipNotFoundRejection",
|
|
189
|
+
message: "Account membership not found",
|
|
190
|
+
id: sentVictim,
|
|
191
|
+
})
|
|
192
|
+
: Option.None();
|
|
193
|
+
const failure = firstOf(checkLimit, () => checkTransactionsFound(transactionIds), () => checkReportable(transactionIds), () => checkSingleAccount(transactionIds), () => checkSingleCardholder(transactionIds), () => checkReportingWindow(transactionIds), checkDetailsApplicable, checkVictim);
|
|
194
|
+
if (failure.isSome()) {
|
|
195
|
+
return Result.Error(rejection(failure.get()));
|
|
196
|
+
}
|
|
197
|
+
// A stored victim is dropped when the case gets card transactions or moves to another
|
|
198
|
+
// account, unless one is sent in this call.
|
|
199
|
+
const victim = hasCard
|
|
200
|
+
? null
|
|
201
|
+
: sentVictim !== undefined
|
|
202
|
+
? sentVictim === null
|
|
203
|
+
? null
|
|
204
|
+
: { id: sentVictim }
|
|
205
|
+
: (existing === null || existing === void 0 ? void 0 : existing.accountId) === accountId
|
|
206
|
+
? existing.sentVictim
|
|
207
|
+
: null;
|
|
208
|
+
const cardholder = getCardholder(transactionIds);
|
|
209
|
+
const keep = (key) => { var _a; return (input[key] === undefined ? ((_a = existing === null || existing === void 0 ? void 0 : existing[key]) !== null && _a !== void 0 ? _a : null) : input[key]); };
|
|
210
|
+
const fraudCardDetails = hasCard ? keep("fraudCardDetails") : null;
|
|
211
|
+
const fraudTransferDetails = hasTransfer ? keep("fraudTransferDetails") : null;
|
|
212
|
+
const date = now();
|
|
213
|
+
const windowEnds = transactions
|
|
214
|
+
.map(item => item.reportingWindowEndsAt)
|
|
215
|
+
.filter(isDefined)
|
|
216
|
+
.map(value => Date.parse(value));
|
|
217
|
+
const expiresAt = Math.min(date.getTime() + DRAFT_LIFETIME_MS, ...windowEnds);
|
|
218
|
+
return Result.Ok({
|
|
219
|
+
id: (_e = existing === null || existing === void 0 ? void 0 : existing.id) !== null && _e !== void 0 ? _e : crypto.randomUUID(),
|
|
220
|
+
accountId,
|
|
221
|
+
statusInfo: { status: "Draft", expiresAt: new Date(expiresAt).toISOString() },
|
|
222
|
+
transactions: transactions.map(({ id, rail }) => ({ id, rail })),
|
|
223
|
+
fraudDetails: input.fraudDetails === undefined
|
|
224
|
+
? ((_f = existing === null || existing === void 0 ? void 0 : existing.fraudDetails) !== null && _f !== void 0 ? _f : null)
|
|
225
|
+
: input.fraudDetails === null
|
|
226
|
+
? null
|
|
227
|
+
: toFraudDetails(input.fraudDetails),
|
|
228
|
+
fraudCardDetails: fraudCardDetails == null
|
|
229
|
+
? null
|
|
230
|
+
: {
|
|
231
|
+
isLostOrStolen: (_g = fraudCardDetails.isLostOrStolen) !== null && _g !== void 0 ? _g : null,
|
|
232
|
+
lostOrStolenNoticedAt: (_h = fraudCardDetails.lostOrStolenNoticedAt) !== null && _h !== void 0 ? _h : null,
|
|
233
|
+
hasContactedMerchant: (_j = fraudCardDetails.hasContactedMerchant) !== null && _j !== void 0 ? _j : null,
|
|
234
|
+
},
|
|
235
|
+
fraudTransferDetails: fraudTransferDetails == null
|
|
236
|
+
? null
|
|
237
|
+
: {
|
|
238
|
+
hasContactedBankOrBeneficiary: (_k = fraudTransferDetails.hasContactedBankOrBeneficiary) !== null && _k !== void 0 ? _k : null,
|
|
239
|
+
},
|
|
240
|
+
victimAccountMembershipId: hasCard ? cardholder : ((_l = victim === null || victim === void 0 ? void 0 : victim.id) !== null && _l !== void 0 ? _l : null),
|
|
241
|
+
hasVictim: hasCard ? cardholder != null : victim != null,
|
|
242
|
+
sentVictim: victim,
|
|
243
|
+
externalReference: keep("externalReference"),
|
|
244
|
+
supportingDocumentCollection: (_m = existing === null || existing === void 0 ? void 0 : existing.supportingDocumentCollection) !== null && _m !== void 0 ? _m : {
|
|
245
|
+
id: crypto.randomUUID(),
|
|
246
|
+
status: "WaitingForDocument",
|
|
247
|
+
},
|
|
248
|
+
createdAt: (_o = existing === null || existing === void 0 ? void 0 : existing.createdAt) !== null && _o !== void 0 ? _o : date.toISOString(),
|
|
249
|
+
updatedAt: date.toISOString(),
|
|
250
|
+
});
|
|
251
|
+
};
|
|
252
|
+
const checkNotAlreadyReported = (item) => {
|
|
253
|
+
const transactions = getIds(item).flatMap(transactionId => {
|
|
254
|
+
var _a;
|
|
255
|
+
const external = (_a = config.alreadyReported) === null || _a === void 0 ? void 0 : _a.find(entry => entry.transactionId === transactionId);
|
|
256
|
+
if (external != null) {
|
|
257
|
+
return [external];
|
|
258
|
+
}
|
|
259
|
+
const submitted = [...cases.values()].find(other => other.id !== item.id &&
|
|
260
|
+
other.statusInfo.status === "Submitted" &&
|
|
261
|
+
getIds(other).includes(transactionId));
|
|
262
|
+
return submitted == null ? [] : [{ transactionId, disputeCaseId: submitted.id }];
|
|
263
|
+
});
|
|
264
|
+
return transactions.length > 0
|
|
265
|
+
? Option.Some({
|
|
266
|
+
__typename: "DisputeCaseTransactionsAlreadyReportedRejection",
|
|
267
|
+
message: "Some transactions are already reported",
|
|
268
|
+
transactions,
|
|
269
|
+
})
|
|
270
|
+
: Option.None();
|
|
271
|
+
};
|
|
272
|
+
const checkComplete = (item) => {
|
|
273
|
+
const isTransferOnly = item.transactions.every(({ rail }) => rail === "Transfer");
|
|
274
|
+
const missingFields = [
|
|
275
|
+
item.fraudDetails == null ? ["fraudDetails"] : undefined,
|
|
276
|
+
isTransferOnly && !item.hasVictim ? ["victimAccountMembershipId"] : undefined,
|
|
277
|
+
]
|
|
278
|
+
.filter(isDefined)
|
|
279
|
+
.map(path => ({ path }));
|
|
280
|
+
return missingFields.length > 0
|
|
281
|
+
? Option.Some({
|
|
282
|
+
__typename: "DisputeCaseIncompleteRejection",
|
|
283
|
+
message: "The case is incomplete",
|
|
284
|
+
missingFields,
|
|
285
|
+
})
|
|
286
|
+
: Option.None();
|
|
287
|
+
};
|
|
288
|
+
const submitDraft = (item) => {
|
|
289
|
+
const ids = getIds(item);
|
|
290
|
+
const failure = firstOf(() => checkTransactionsFound(ids), () => checkReportable(ids), () => checkReportingWindow(ids), () => checkNotAlreadyReported(item), () => checkComplete(item));
|
|
291
|
+
if (failure.isSome()) {
|
|
292
|
+
return Result.Error(rejection(failure.get()));
|
|
293
|
+
}
|
|
294
|
+
const date = now().toISOString();
|
|
295
|
+
return Result.Ok(save({
|
|
296
|
+
...item,
|
|
297
|
+
statusInfo: { status: "Submitted", submittedAt: date },
|
|
298
|
+
supportingDocumentCollection: {
|
|
299
|
+
...item.supportingDocumentCollection,
|
|
300
|
+
status: "PendingReview",
|
|
301
|
+
},
|
|
302
|
+
updatedAt: date,
|
|
303
|
+
}));
|
|
304
|
+
};
|
|
305
|
+
const cancelDraft = (item) => {
|
|
306
|
+
const date = now().toISOString();
|
|
307
|
+
return save({
|
|
308
|
+
...item,
|
|
309
|
+
statusInfo: { status: "Canceled", canceledAt: date },
|
|
310
|
+
supportingDocumentCollection: { ...item.supportingDocumentCollection, status: "Canceled" },
|
|
311
|
+
updatedAt: date,
|
|
312
|
+
});
|
|
313
|
+
};
|
|
314
|
+
return {
|
|
315
|
+
draft: input => respond(checkInputFormat(input).match({
|
|
316
|
+
Some: error => Result.Error(error),
|
|
317
|
+
None: () => write(undefined, input).map(save),
|
|
318
|
+
})),
|
|
319
|
+
update: ({ disputeCaseId, ...input }) => respond(checkInputFormat(input).match({
|
|
320
|
+
Some: error => Result.Error(error),
|
|
321
|
+
None: () => getStoredCase(disputeCaseId)
|
|
322
|
+
.toResult(notFound(disputeCaseId))
|
|
323
|
+
.flatMap((existing) => existing.statusInfo.status === "Draft"
|
|
324
|
+
? write(existing, input)
|
|
325
|
+
: Result.Error(wrongStatus(existing, ["Draft"])))
|
|
326
|
+
.map(save),
|
|
327
|
+
})),
|
|
328
|
+
submit: ({ disputeCaseId }) => respond(getStoredCase(disputeCaseId)
|
|
329
|
+
.toResult(notFound(disputeCaseId))
|
|
330
|
+
.flatMap(item => match(item.statusInfo.status)
|
|
331
|
+
.with("Submitted", () => Result.Ok(toPublicCase(item)))
|
|
332
|
+
.with("Draft", () => submitDraft(item))
|
|
333
|
+
.with("Expired", "Canceled", () => Result.Error(wrongStatus(item, ["Draft"])))
|
|
334
|
+
.exhaustive())),
|
|
335
|
+
cancel: ({ disputeCaseId }) => respond(getStoredCase(disputeCaseId)
|
|
336
|
+
.toResult(notFound(disputeCaseId))
|
|
337
|
+
.flatMap(item => match(item.statusInfo.status)
|
|
338
|
+
.with("Canceled", () => Result.Ok(toPublicCase(item)))
|
|
339
|
+
.with("Draft", () => Result.Ok(cancelDraft(item)))
|
|
340
|
+
.with("Submitted", "Expired", () => Result.Error(wrongStatus(item, ["Draft"])))
|
|
341
|
+
.exhaustive())),
|
|
342
|
+
getCase: ({ disputeCaseId }) => respond(Result.Ok(getStoredCase(disputeCaseId).map(toPublicCase))),
|
|
343
|
+
findDrafts: ({ accountId, transactionIds }) => respond(Result.Ok([...cases.keys()]
|
|
344
|
+
// Insertion order breaks createdAt ties.
|
|
345
|
+
.reverse()
|
|
346
|
+
.map(id => getStoredCase(id).toUndefined())
|
|
347
|
+
.filter(isDefined)
|
|
348
|
+
.filter(item => item.statusInfo.status === "Draft" &&
|
|
349
|
+
item.accountId === accountId &&
|
|
350
|
+
getIds(item).some(id => transactionIds.includes(id)))
|
|
351
|
+
.sort((a, b) => Date.parse(b.createdAt) - Date.parse(a.createdAt))
|
|
352
|
+
.map(toPublicCase))),
|
|
353
|
+
generateUpload: () => respond(Result.Ok({
|
|
354
|
+
id: crypto.randomUUID(),
|
|
355
|
+
upload: { url: "https://example.org/upload", fields: [] },
|
|
356
|
+
})),
|
|
357
|
+
uploadFile: () => respond(Result.Ok({
|
|
358
|
+
headers: new Headers(),
|
|
359
|
+
status: 200,
|
|
360
|
+
ok: true,
|
|
361
|
+
url: "https://example.org/upload",
|
|
362
|
+
response: Option.None(),
|
|
363
|
+
})),
|
|
364
|
+
removeFile: () => respond(Result.Ok(undefined)),
|
|
365
|
+
};
|
|
366
|
+
};
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
export type FraudReason = "Unauthorized" | "Manipulated";
|
|
2
|
+
export type FraudTypology = "FakeAdvisor" | "ImpersonationOrPhishing" | "FakeWebsite" | "FakeSupplierOrInvoice" | "InvestmentScam" | "RomanceScam" | "Other";
|
|
3
|
+
export type FraudsterChannel = "Email" | "Sms" | "Phone" | "Website" | "Application" | "Other";
|
|
4
|
+
export type SharedInformationWithFraudster = "SwanPasscode" | "PartnerPassword" | "VerificationCode" | "PersonalInformation" | "CardDetails" | "BankDetails" | "Other" | "None";
|
|
5
|
+
export type DisputeCaseStatus = "Draft" | "Expired" | "Canceled" | "Submitted";
|
|
6
|
+
export type DisputeCaseTransactionNotReportableReason = "TransactionTypeNotReportable" | "TransactionStatusNotReportable";
|
|
7
|
+
export type FraudReportDocumentPurpose = "PoliceReport" | "FraudEvidence" | "DisputeCorrespondence" | "CardFraudDeclaration" | "Other";
|
|
8
|
+
export type SupportingDocumentCollectionStatus = "WaitingForDocument" | "PendingReview" | "Approved" | "Canceled" | "Rejected";
|
|
9
|
+
export type FraudDetailsInput = {
|
|
10
|
+
reportedReason: FraudReason;
|
|
11
|
+
reportedTypology: FraudTypology;
|
|
12
|
+
description: string;
|
|
13
|
+
discoveredAt?: string | null;
|
|
14
|
+
discoveryDetails?: string | null;
|
|
15
|
+
fraudsterChannels?: FraudsterChannel[] | null;
|
|
16
|
+
sharedInformationWithFraudster?: SharedInformationWithFraudster[] | null;
|
|
17
|
+
hasFiledPoliceComplaint?: boolean | null;
|
|
18
|
+
};
|
|
19
|
+
export type FraudCardDetailsInput = {
|
|
20
|
+
isLostOrStolen?: boolean | null;
|
|
21
|
+
lostOrStolenNoticedAt?: string | null;
|
|
22
|
+
hasContactedMerchant?: boolean | null;
|
|
23
|
+
};
|
|
24
|
+
export type FraudTransferDetailsInput = {
|
|
25
|
+
hasContactedBankOrBeneficiary?: boolean | null;
|
|
26
|
+
};
|
|
27
|
+
export type DraftFraudDisputeCaseInput = {
|
|
28
|
+
transactionIds: string[];
|
|
29
|
+
fraudDetails?: FraudDetailsInput | null;
|
|
30
|
+
fraudCardDetails?: FraudCardDetailsInput | null;
|
|
31
|
+
fraudTransferDetails?: FraudTransferDetailsInput | null;
|
|
32
|
+
victimAccountMembershipId?: string | null;
|
|
33
|
+
externalReference?: string | null;
|
|
34
|
+
};
|
|
35
|
+
export type UpdateDraftFraudDisputeCaseInput = {
|
|
36
|
+
disputeCaseId: string;
|
|
37
|
+
transactionIds?: string[];
|
|
38
|
+
fraudDetails?: FraudDetailsInput | null;
|
|
39
|
+
fraudCardDetails?: FraudCardDetailsInput | null;
|
|
40
|
+
fraudTransferDetails?: FraudTransferDetailsInput | null;
|
|
41
|
+
victimAccountMembershipId?: string | null;
|
|
42
|
+
externalReference?: string | null;
|
|
43
|
+
};
|
|
44
|
+
export type SubmitDisputeCaseInput = {
|
|
45
|
+
disputeCaseId: string;
|
|
46
|
+
};
|
|
47
|
+
export type CancelDisputeCaseInput = {
|
|
48
|
+
disputeCaseId: string;
|
|
49
|
+
};
|
|
50
|
+
export type FraudDetails = {
|
|
51
|
+
reportedReason: FraudReason;
|
|
52
|
+
reportedTypology: FraudTypology;
|
|
53
|
+
description: string;
|
|
54
|
+
discoveredAt: string | null;
|
|
55
|
+
discoveryDetails: string | null;
|
|
56
|
+
fraudsterChannels: FraudsterChannel[];
|
|
57
|
+
sharedInformationWithFraudster: SharedInformationWithFraudster[];
|
|
58
|
+
hasFiledPoliceComplaint: boolean | null;
|
|
59
|
+
};
|
|
60
|
+
export type FraudCardDetails = {
|
|
61
|
+
isLostOrStolen: boolean | null;
|
|
62
|
+
lostOrStolenNoticedAt: string | null;
|
|
63
|
+
hasContactedMerchant: boolean | null;
|
|
64
|
+
};
|
|
65
|
+
export type FraudTransferDetails = {
|
|
66
|
+
hasContactedBankOrBeneficiary: boolean | null;
|
|
67
|
+
};
|
|
68
|
+
export type DisputeCaseStatusInfo = {
|
|
69
|
+
status: "Draft";
|
|
70
|
+
expiresAt: string;
|
|
71
|
+
} | {
|
|
72
|
+
status: "Expired";
|
|
73
|
+
expiredAt: string;
|
|
74
|
+
} | {
|
|
75
|
+
status: "Canceled";
|
|
76
|
+
canceledAt: string;
|
|
77
|
+
} | {
|
|
78
|
+
status: "Submitted";
|
|
79
|
+
submittedAt: string;
|
|
80
|
+
};
|
|
81
|
+
export type FraudReportRail = "Card" | "Transfer";
|
|
82
|
+
export type FraudReportTransaction = {
|
|
83
|
+
id: string;
|
|
84
|
+
rail: FraudReportRail;
|
|
85
|
+
};
|
|
86
|
+
export type FraudReportCase = {
|
|
87
|
+
id: string;
|
|
88
|
+
accountId: string;
|
|
89
|
+
statusInfo: DisputeCaseStatusInfo;
|
|
90
|
+
transactions: FraudReportTransaction[];
|
|
91
|
+
fraudDetails: FraudDetails | null;
|
|
92
|
+
fraudCardDetails: FraudCardDetails | null;
|
|
93
|
+
fraudTransferDetails: FraudTransferDetails | null;
|
|
94
|
+
victimAccountMembershipId: string | null;
|
|
95
|
+
hasVictim: boolean;
|
|
96
|
+
externalReference: string | null;
|
|
97
|
+
supportingDocumentCollection: {
|
|
98
|
+
id: string;
|
|
99
|
+
status: SupportingDocumentCollectionStatus;
|
|
100
|
+
};
|
|
101
|
+
createdAt: string;
|
|
102
|
+
updatedAt: string;
|
|
103
|
+
};
|
|
104
|
+
export type DisputeCaseFieldPath = {
|
|
105
|
+
path: string[];
|
|
106
|
+
};
|
|
107
|
+
export type DisputeCaseNotFoundRejection = {
|
|
108
|
+
__typename: "DisputeCaseNotFoundRejection";
|
|
109
|
+
message: string;
|
|
110
|
+
disputeCaseId: string;
|
|
111
|
+
};
|
|
112
|
+
export type DisputeCaseWrongStatusRejection = {
|
|
113
|
+
__typename: "DisputeCaseWrongStatusRejection";
|
|
114
|
+
message: string;
|
|
115
|
+
disputeCaseId: string;
|
|
116
|
+
currentStatus: DisputeCaseStatus;
|
|
117
|
+
expectedStatuses: DisputeCaseStatus[];
|
|
118
|
+
};
|
|
119
|
+
export type DisputeCaseTransactionsNotFoundRejection = {
|
|
120
|
+
__typename: "DisputeCaseTransactionsNotFoundRejection";
|
|
121
|
+
message: string;
|
|
122
|
+
transactionIds: string[];
|
|
123
|
+
};
|
|
124
|
+
export type DisputeCaseTransactionsLimitExceededRejection = {
|
|
125
|
+
__typename: "DisputeCaseTransactionsLimitExceededRejection";
|
|
126
|
+
message: string;
|
|
127
|
+
transactionCount: number;
|
|
128
|
+
maxTransactionCount: number;
|
|
129
|
+
};
|
|
130
|
+
export type DisputeCaseMultipleAccountsRejection = {
|
|
131
|
+
__typename: "DisputeCaseMultipleAccountsRejection";
|
|
132
|
+
message: string;
|
|
133
|
+
accountIds: string[];
|
|
134
|
+
};
|
|
135
|
+
export type DisputeCaseMultipleCardHoldersRejection = {
|
|
136
|
+
__typename: "DisputeCaseMultipleCardHoldersRejection";
|
|
137
|
+
message: string;
|
|
138
|
+
accountMembershipIds: string[];
|
|
139
|
+
};
|
|
140
|
+
export type DisputeCaseTransactionsNotReportableRejection = {
|
|
141
|
+
__typename: "DisputeCaseTransactionsNotReportableRejection";
|
|
142
|
+
message: string;
|
|
143
|
+
transactions: {
|
|
144
|
+
transactionId: string;
|
|
145
|
+
reason: DisputeCaseTransactionNotReportableReason;
|
|
146
|
+
}[];
|
|
147
|
+
};
|
|
148
|
+
export type DisputeCaseTransactionsOutsideReportingWindowRejection = {
|
|
149
|
+
__typename: "DisputeCaseTransactionsOutsideReportingWindowRejection";
|
|
150
|
+
message: string;
|
|
151
|
+
transactions: {
|
|
152
|
+
transactionId: string;
|
|
153
|
+
reportingWindowEndedAt: string;
|
|
154
|
+
}[];
|
|
155
|
+
};
|
|
156
|
+
export type DisputeCaseDetailsNotApplicableRejection = {
|
|
157
|
+
__typename: "DisputeCaseDetailsNotApplicableRejection";
|
|
158
|
+
message: string;
|
|
159
|
+
fields: DisputeCaseFieldPath[];
|
|
160
|
+
};
|
|
161
|
+
export type AccountMembershipNotFoundRejection = {
|
|
162
|
+
__typename: "AccountMembershipNotFoundRejection";
|
|
163
|
+
message: string;
|
|
164
|
+
id: string;
|
|
165
|
+
};
|
|
166
|
+
export type DisputeCaseIncompleteRejection = {
|
|
167
|
+
__typename: "DisputeCaseIncompleteRejection";
|
|
168
|
+
message: string;
|
|
169
|
+
missingFields: DisputeCaseFieldPath[];
|
|
170
|
+
};
|
|
171
|
+
export type DisputeCaseTransactionsAlreadyReportedRejection = {
|
|
172
|
+
__typename: "DisputeCaseTransactionsAlreadyReportedRejection";
|
|
173
|
+
message: string;
|
|
174
|
+
transactions: {
|
|
175
|
+
transactionId: string;
|
|
176
|
+
disputeCaseId: string | null;
|
|
177
|
+
}[];
|
|
178
|
+
};
|
|
179
|
+
export type DraftFraudDisputeCaseRejection = DisputeCaseTransactionsNotFoundRejection | DisputeCaseTransactionsLimitExceededRejection | DisputeCaseMultipleAccountsRejection | DisputeCaseMultipleCardHoldersRejection | DisputeCaseTransactionsNotReportableRejection | DisputeCaseTransactionsOutsideReportingWindowRejection | DisputeCaseDetailsNotApplicableRejection | AccountMembershipNotFoundRejection;
|
|
180
|
+
export type UpdateDraftFraudDisputeCaseRejection = DisputeCaseNotFoundRejection | DisputeCaseWrongStatusRejection | DraftFraudDisputeCaseRejection;
|
|
181
|
+
export type SubmitDisputeCaseRejection = DisputeCaseNotFoundRejection | DisputeCaseIncompleteRejection | DisputeCaseTransactionsAlreadyReportedRejection | DisputeCaseTransactionsNotFoundRejection | DisputeCaseTransactionsNotReportableRejection | DisputeCaseTransactionsOutsideReportingWindowRejection | DisputeCaseWrongStatusRejection;
|
|
182
|
+
export type CancelDisputeCaseRejection = DisputeCaseNotFoundRejection | DisputeCaseWrongStatusRejection;
|
|
183
|
+
export type FraudReportRejection = UpdateDraftFraudDisputeCaseRejection | SubmitDisputeCaseRejection | CancelDisputeCaseRejection;
|
|
184
|
+
export declare const fraudReportSteps: readonly ["Intro", "Victim", "Transactions", "Incident", "Details", "Documents", "Submitted"];
|
|
185
|
+
export type FraudReportStep = (typeof fraudReportSteps)[number];
|
|
186
|
+
export declare const fraudReportDetailsSteps: readonly ["Card", "Transfer", "Fraudster"];
|
|
187
|
+
export type FraudReportDetailsStep = (typeof fraudReportDetailsSteps)[number];
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// Structural types for the fraud report and its step list. The API types mirror the Swan
|
|
2
|
+
// partner GraphQL schema (dispute cases), so each app maps its generated types onto them.
|
|
3
|
+
// Steps in display order. "Details" groups the sub-steps that depend on the selection.
|
|
4
|
+
export const fraudReportSteps = [
|
|
5
|
+
"Intro",
|
|
6
|
+
"Victim",
|
|
7
|
+
"Transactions",
|
|
8
|
+
"Incident",
|
|
9
|
+
"Details",
|
|
10
|
+
"Documents",
|
|
11
|
+
"Submitted",
|
|
12
|
+
];
|
|
13
|
+
export const fraudReportDetailsSteps = ["Card", "Transfer", "Fraudster"];
|