@swan-io/shared-business 18.2.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.fakeApi.test.d.ts +1 -0
- package/src/utils/__tests__/fraudReport.fakeApi.test.js +659 -0
- 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/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/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/types.d.ts +187 -0
- package/src/utils/fraudReport/types.js +13 -0
- package/src/utils/fraudReport/validation.d.ts +14 -0
- package/src/utils/fraudReport/validation.js +54 -0
|
@@ -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"];
|
|
@@ -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
|
+
};
|