aeremmiddleware 1.0.26 → 1.0.28
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/README.md +28 -28
- package/dist/Finance/Ingenico.types.d.ts +5 -4
- package/dist/Finance/ingenicoHtml.js +114 -114
- package/dist/Finance/ingenicoHtml.js.map +1 -1
- package/dist/Finance/novel.types.js +1 -1
- package/dist/Finance/novel.types.js.map +1 -1
- package/dist/Socials/Sms.types.js +1 -1
- package/dist/Socials/Sms.types.js.map +1 -1
- package/dist/Socials/Whatsapp.types.js +1 -1
- package/dist/Socials/Whatsapp.types.js.map +1 -1
- package/package.json +21 -21
- package/src/Finance/Ingenico.types.ts +22 -21
- package/src/Finance/auEncrypt.ts +32 -32
- package/src/Finance/auFinance.ts +115 -115
- package/src/Finance/crimeCheck.ts +212 -212
- package/src/Finance/crimecheck.types.ts +31 -31
- package/src/Finance/encrypt.ts +18 -18
- package/src/Finance/idfy.ts +542 -542
- package/src/Finance/index.ts +16 -16
- package/src/Finance/ingenico.ts +104 -104
- package/src/Finance/ingenicoHtml.ts +119 -119
- package/src/Finance/novel.ts +233 -233
- package/src/Finance/novel.types.ts +30 -30
- package/src/Finance/qbrik.ts +828 -828
- package/src/Finance/qbrik.types.ts +131 -131
- package/src/Finance/setu.ts +560 -560
- package/src/Finance/setu.types.ts +44 -44
- package/src/PushNotification/index.ts +5 -5
- package/src/PushNotification/pushNotificationFCM.ts +37 -37
- package/src/Socials/Sms.types.ts +9 -9
- package/src/Socials/SmsSender.ts +78 -78
- package/src/Socials/Whatsapp.types.ts +95 -95
- package/src/Socials/index.ts +6 -6
- package/src/Socials/whatsApp.ts +188 -188
- package/src/index.ts +9 -9
- package/tsconfig.json +111 -111
package/src/Finance/auFinance.ts
CHANGED
|
@@ -1,115 +1,115 @@
|
|
|
1
|
-
import axios, { AxiosResponse } from "axios";
|
|
2
|
-
import { decrypt, encrypt } from "./auEncrypt";
|
|
3
|
-
|
|
4
|
-
interface PayloadType {
|
|
5
|
-
mbSvcProviderName: string;
|
|
6
|
-
channel: string;
|
|
7
|
-
mbDateFrom: string;
|
|
8
|
-
mbCustMailId: string;
|
|
9
|
-
mbCustFonCellNum: string;
|
|
10
|
-
mbSvcProviderCode: string;
|
|
11
|
-
mbSponserBankCode: string;
|
|
12
|
-
mbFrequencyType: string;
|
|
13
|
-
requestId: string;
|
|
14
|
-
mbCustName: string;
|
|
15
|
-
mbRefNumber: string;
|
|
16
|
-
mbMandateCategory: string;
|
|
17
|
-
mbDRAccountNumber: string;
|
|
18
|
-
mbMandateType: string;
|
|
19
|
-
mbDateTo: string;
|
|
20
|
-
mbRelRefNumber: string;
|
|
21
|
-
mbCustFonLandNum: string;
|
|
22
|
-
mbDRBankCode: string;
|
|
23
|
-
mbAmount: string;
|
|
24
|
-
mbPaymentType: string;
|
|
25
|
-
responseURL: string;
|
|
26
|
-
mbDRAccountType: string;
|
|
27
|
-
mbFrequencyCode: string;
|
|
28
|
-
mbFixedAmount: string;
|
|
29
|
-
referenceCode: string;
|
|
30
|
-
mbCustPAN: string;
|
|
31
|
-
username: string;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
class AuFinanceApiWrapper {
|
|
35
|
-
private isUAT: boolean;
|
|
36
|
-
private enachEndpoint: string | undefined;
|
|
37
|
-
private baseUrl: string;
|
|
38
|
-
private encryptionKey: string;
|
|
39
|
-
private authEndpoint = "/oauth/accesstoken?grant_type=client_credentials";
|
|
40
|
-
private emandateWithUserConfirmationEndpoint =
|
|
41
|
-
"/EmandateUserRegistrationRestService/userconfirmation";
|
|
42
|
-
private emandateWithoutUserConfirmationEndpoint =
|
|
43
|
-
"/EmandateUserRegistrationRestService/withoutUserConfirmation";
|
|
44
|
-
|
|
45
|
-
constructor(isUAT: boolean) {
|
|
46
|
-
this.isUAT = isUAT;
|
|
47
|
-
this.baseUrl = this.isUAT
|
|
48
|
-
? "https://api.aubankuat.in"
|
|
49
|
-
: "https://api.aubank.in";
|
|
50
|
-
this.encryptionKey = this.isUAT
|
|
51
|
-
? "545932040048E8B4FAF59DCC6B20B042AE7B3DD9C282C53B6A0E66599CC01693"
|
|
52
|
-
: "4F773AF556F047DE1D379A122321BF363579FCEB04EAF5E1A47C043754DCAA9C";
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
async getAccessToken({
|
|
56
|
-
clientId,
|
|
57
|
-
clientSecret,
|
|
58
|
-
}: {
|
|
59
|
-
clientId: string;
|
|
60
|
-
clientSecret: string;
|
|
61
|
-
}): Promise<AxiosResponse> {
|
|
62
|
-
try {
|
|
63
|
-
const authString = `${clientId}:${clientSecret}`;
|
|
64
|
-
const base64Auth = Buffer.from(authString).toString("base64");
|
|
65
|
-
|
|
66
|
-
const response = await axios.get(`${this.baseUrl}${this.authEndpoint}`, {
|
|
67
|
-
headers: {
|
|
68
|
-
Authorization: `Basic ${base64Auth}`,
|
|
69
|
-
},
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
return response;
|
|
73
|
-
} catch (error) {
|
|
74
|
-
throw error;
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
async auEmandate({
|
|
79
|
-
requireUserConsent,
|
|
80
|
-
accessToken,
|
|
81
|
-
jsonData,
|
|
82
|
-
}: {
|
|
83
|
-
requireUserConsent: boolean;
|
|
84
|
-
accessToken: string;
|
|
85
|
-
jsonData: PayloadType;
|
|
86
|
-
}): Promise<any> {
|
|
87
|
-
requireUserConsent
|
|
88
|
-
? (this.enachEndpoint = this.emandateWithUserConfirmationEndpoint)
|
|
89
|
-
: (this.enachEndpoint = this.emandateWithoutUserConfirmationEndpoint);
|
|
90
|
-
|
|
91
|
-
let jsonString = JSON.stringify(jsonData);
|
|
92
|
-
const encryptedData = encrypt(this.encryptionKey, jsonString);
|
|
93
|
-
|
|
94
|
-
const headers = {
|
|
95
|
-
Authorization: `Bearer ${accessToken}`,
|
|
96
|
-
"Content-Type": "application/json",
|
|
97
|
-
};
|
|
98
|
-
const body = {
|
|
99
|
-
encvalue: encryptedData,
|
|
100
|
-
};
|
|
101
|
-
try {
|
|
102
|
-
const response = await axios.post(
|
|
103
|
-
`${this.baseUrl}${this.enachEndpoint}`,
|
|
104
|
-
body,
|
|
105
|
-
{ headers: headers }
|
|
106
|
-
);
|
|
107
|
-
const res = response.data;
|
|
108
|
-
const decryptedData = decrypt(this.encryptionKey, res);
|
|
109
|
-
return decryptedData;
|
|
110
|
-
} catch (error: any) {
|
|
111
|
-
throw error;
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
export default AuFinanceApiWrapper;
|
|
1
|
+
import axios, { AxiosResponse } from "axios";
|
|
2
|
+
import { decrypt, encrypt } from "./auEncrypt";
|
|
3
|
+
|
|
4
|
+
interface PayloadType {
|
|
5
|
+
mbSvcProviderName: string;
|
|
6
|
+
channel: string;
|
|
7
|
+
mbDateFrom: string;
|
|
8
|
+
mbCustMailId: string;
|
|
9
|
+
mbCustFonCellNum: string;
|
|
10
|
+
mbSvcProviderCode: string;
|
|
11
|
+
mbSponserBankCode: string;
|
|
12
|
+
mbFrequencyType: string;
|
|
13
|
+
requestId: string;
|
|
14
|
+
mbCustName: string;
|
|
15
|
+
mbRefNumber: string;
|
|
16
|
+
mbMandateCategory: string;
|
|
17
|
+
mbDRAccountNumber: string;
|
|
18
|
+
mbMandateType: string;
|
|
19
|
+
mbDateTo: string;
|
|
20
|
+
mbRelRefNumber: string;
|
|
21
|
+
mbCustFonLandNum: string;
|
|
22
|
+
mbDRBankCode: string;
|
|
23
|
+
mbAmount: string;
|
|
24
|
+
mbPaymentType: string;
|
|
25
|
+
responseURL: string;
|
|
26
|
+
mbDRAccountType: string;
|
|
27
|
+
mbFrequencyCode: string;
|
|
28
|
+
mbFixedAmount: string;
|
|
29
|
+
referenceCode: string;
|
|
30
|
+
mbCustPAN: string;
|
|
31
|
+
username: string;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
class AuFinanceApiWrapper {
|
|
35
|
+
private isUAT: boolean;
|
|
36
|
+
private enachEndpoint: string | undefined;
|
|
37
|
+
private baseUrl: string;
|
|
38
|
+
private encryptionKey: string;
|
|
39
|
+
private authEndpoint = "/oauth/accesstoken?grant_type=client_credentials";
|
|
40
|
+
private emandateWithUserConfirmationEndpoint =
|
|
41
|
+
"/EmandateUserRegistrationRestService/userconfirmation";
|
|
42
|
+
private emandateWithoutUserConfirmationEndpoint =
|
|
43
|
+
"/EmandateUserRegistrationRestService/withoutUserConfirmation";
|
|
44
|
+
|
|
45
|
+
constructor(isUAT: boolean) {
|
|
46
|
+
this.isUAT = isUAT;
|
|
47
|
+
this.baseUrl = this.isUAT
|
|
48
|
+
? "https://api.aubankuat.in"
|
|
49
|
+
: "https://api.aubank.in";
|
|
50
|
+
this.encryptionKey = this.isUAT
|
|
51
|
+
? "545932040048E8B4FAF59DCC6B20B042AE7B3DD9C282C53B6A0E66599CC01693"
|
|
52
|
+
: "4F773AF556F047DE1D379A122321BF363579FCEB04EAF5E1A47C043754DCAA9C";
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
async getAccessToken({
|
|
56
|
+
clientId,
|
|
57
|
+
clientSecret,
|
|
58
|
+
}: {
|
|
59
|
+
clientId: string;
|
|
60
|
+
clientSecret: string;
|
|
61
|
+
}): Promise<AxiosResponse> {
|
|
62
|
+
try {
|
|
63
|
+
const authString = `${clientId}:${clientSecret}`;
|
|
64
|
+
const base64Auth = Buffer.from(authString).toString("base64");
|
|
65
|
+
|
|
66
|
+
const response = await axios.get(`${this.baseUrl}${this.authEndpoint}`, {
|
|
67
|
+
headers: {
|
|
68
|
+
Authorization: `Basic ${base64Auth}`,
|
|
69
|
+
},
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
return response;
|
|
73
|
+
} catch (error) {
|
|
74
|
+
throw error;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
async auEmandate({
|
|
79
|
+
requireUserConsent,
|
|
80
|
+
accessToken,
|
|
81
|
+
jsonData,
|
|
82
|
+
}: {
|
|
83
|
+
requireUserConsent: boolean;
|
|
84
|
+
accessToken: string;
|
|
85
|
+
jsonData: PayloadType;
|
|
86
|
+
}): Promise<any> {
|
|
87
|
+
requireUserConsent
|
|
88
|
+
? (this.enachEndpoint = this.emandateWithUserConfirmationEndpoint)
|
|
89
|
+
: (this.enachEndpoint = this.emandateWithoutUserConfirmationEndpoint);
|
|
90
|
+
|
|
91
|
+
let jsonString = JSON.stringify(jsonData);
|
|
92
|
+
const encryptedData = encrypt(this.encryptionKey, jsonString);
|
|
93
|
+
|
|
94
|
+
const headers = {
|
|
95
|
+
Authorization: `Bearer ${accessToken}`,
|
|
96
|
+
"Content-Type": "application/json",
|
|
97
|
+
};
|
|
98
|
+
const body = {
|
|
99
|
+
encvalue: encryptedData,
|
|
100
|
+
};
|
|
101
|
+
try {
|
|
102
|
+
const response = await axios.post(
|
|
103
|
+
`${this.baseUrl}${this.enachEndpoint}`,
|
|
104
|
+
body,
|
|
105
|
+
{ headers: headers }
|
|
106
|
+
);
|
|
107
|
+
const res = response.data;
|
|
108
|
+
const decryptedData = decrypt(this.encryptionKey, res);
|
|
109
|
+
return decryptedData;
|
|
110
|
+
} catch (error: any) {
|
|
111
|
+
throw error;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
export default AuFinanceApiWrapper;
|
|
@@ -1,212 +1,212 @@
|
|
|
1
|
-
import axios, { AxiosResponse } from "axios";
|
|
2
|
-
import { companyDetails, individualDetails } from "./crimecheck.types";
|
|
3
|
-
import { error } from "console";
|
|
4
|
-
|
|
5
|
-
class CrimeSearchAPIWrapper {
|
|
6
|
-
private apiKey: string;
|
|
7
|
-
private baseUrl: string = "https://crime.getupforchange.com/api/";
|
|
8
|
-
private statusCheckEndpoint = "v3/status";
|
|
9
|
-
private addReportEndpoint = "v3/addReport";
|
|
10
|
-
private downloadAsJsonEndpoint = "v3/downloadJsonReport/";
|
|
11
|
-
private downloadAsPdfEndpoint = "v3/downloadReport/";
|
|
12
|
-
|
|
13
|
-
constructor(apiKey: string) {
|
|
14
|
-
this.apiKey = apiKey;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
async checkApiStatus(): Promise<void> {
|
|
18
|
-
try {
|
|
19
|
-
const response: AxiosResponse = await axios.get(
|
|
20
|
-
this.baseUrl + this.statusCheckEndpoint,
|
|
21
|
-
{
|
|
22
|
-
headers: {
|
|
23
|
-
Authorization: this.apiKey,
|
|
24
|
-
},
|
|
25
|
-
}
|
|
26
|
-
);
|
|
27
|
-
|
|
28
|
-
return response.data;
|
|
29
|
-
} catch (error: any) {
|
|
30
|
-
console.error(error);
|
|
31
|
-
return error.message;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
async addCompanyReport(companyDetails: companyDetails): Promise<void> {
|
|
35
|
-
const bodyFormData = new FormData();
|
|
36
|
-
if (companyDetails) {
|
|
37
|
-
bodyFormData.append("companyName", companyDetails.companyName);
|
|
38
|
-
companyDetails.companyType
|
|
39
|
-
? bodyFormData.append("companyType", companyDetails.companyType)
|
|
40
|
-
: null;
|
|
41
|
-
companyDetails.companyAddress
|
|
42
|
-
? bodyFormData.append("companyAddress", companyDetails.companyAddress)
|
|
43
|
-
: null;
|
|
44
|
-
companyDetails.directors
|
|
45
|
-
? bodyFormData.append("directors", companyDetails.directors)
|
|
46
|
-
: null;
|
|
47
|
-
companyDetails.clientRefNo
|
|
48
|
-
? bodyFormData.append("clientRefNo", companyDetails.clientRefNo)
|
|
49
|
-
: null;
|
|
50
|
-
companyDetails.reportMode
|
|
51
|
-
? bodyFormData.append("reportMode", companyDetails.reportMode)
|
|
52
|
-
: null;
|
|
53
|
-
companyDetails.priority
|
|
54
|
-
? bodyFormData.append("priority", companyDetails.priority)
|
|
55
|
-
: null;
|
|
56
|
-
companyDetails.callbackUrl
|
|
57
|
-
? bodyFormData.append("callbackUrl", companyDetails.callbackUrl)
|
|
58
|
-
: null;
|
|
59
|
-
companyDetails.cinNumber
|
|
60
|
-
? bodyFormData.append("cinNumber", companyDetails.cinNumber)
|
|
61
|
-
: null;
|
|
62
|
-
companyDetails.gstNumber
|
|
63
|
-
? bodyFormData.append("gstNumber", companyDetails.gstNumber)
|
|
64
|
-
: null;
|
|
65
|
-
companyDetails.reqTag
|
|
66
|
-
? bodyFormData.append("reqTag", companyDetails.reqTag)
|
|
67
|
-
: null;
|
|
68
|
-
companyDetails.ticketSize
|
|
69
|
-
? bodyFormData.append("ticketSize", companyDetails.ticketSize)
|
|
70
|
-
: null;
|
|
71
|
-
companyDetails.crimewatch
|
|
72
|
-
? bodyFormData.append("crimewatch", companyDetails.crimewatch)
|
|
73
|
-
: null;
|
|
74
|
-
|
|
75
|
-
try {
|
|
76
|
-
const response: AxiosResponse = await axios.post(
|
|
77
|
-
this.baseUrl + this.addReportEndpoint,
|
|
78
|
-
bodyFormData,
|
|
79
|
-
{
|
|
80
|
-
auth: {
|
|
81
|
-
username: this.apiKey,
|
|
82
|
-
password: "",
|
|
83
|
-
},
|
|
84
|
-
headers: {
|
|
85
|
-
"Content-Type": "application/x-www-form-urlencoded",
|
|
86
|
-
},
|
|
87
|
-
}
|
|
88
|
-
);
|
|
89
|
-
|
|
90
|
-
return response.data;
|
|
91
|
-
} catch (error: any) {
|
|
92
|
-
console.error(error);
|
|
93
|
-
return error.message;
|
|
94
|
-
}
|
|
95
|
-
} else {
|
|
96
|
-
console.log("invalid details entered");
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
async addIndividualReport(
|
|
101
|
-
individualDetails: individualDetails
|
|
102
|
-
): Promise<void> {
|
|
103
|
-
const bodyFormData = new FormData();
|
|
104
|
-
if (individualDetails.name) {
|
|
105
|
-
bodyFormData.append("name", individualDetails.name);
|
|
106
|
-
individualDetails.fatherName
|
|
107
|
-
? bodyFormData.append("fatherName", individualDetails.fatherName)
|
|
108
|
-
: null;
|
|
109
|
-
individualDetails.address
|
|
110
|
-
? bodyFormData.append("address", individualDetails.address)
|
|
111
|
-
: null;
|
|
112
|
-
individualDetails.address2
|
|
113
|
-
? bodyFormData.append("address2", individualDetails.address2)
|
|
114
|
-
: null;
|
|
115
|
-
individualDetails.dob
|
|
116
|
-
? bodyFormData.append("dob", individualDetails.dob)
|
|
117
|
-
: null;
|
|
118
|
-
individualDetails.panNumber
|
|
119
|
-
? bodyFormData.append("panNumber", individualDetails.panNumber)
|
|
120
|
-
: null;
|
|
121
|
-
individualDetails.clientRefNo
|
|
122
|
-
? bodyFormData.append("clientRefNo", individualDetails.clientRefNo)
|
|
123
|
-
: null;
|
|
124
|
-
individualDetails.reportMode
|
|
125
|
-
? bodyFormData.append("reportMode", individualDetails.reportMode)
|
|
126
|
-
: null;
|
|
127
|
-
individualDetails.priority
|
|
128
|
-
? bodyFormData.append("priority", individualDetails.priority)
|
|
129
|
-
: null;
|
|
130
|
-
individualDetails.callbackUrl
|
|
131
|
-
? bodyFormData.append("callbackUrl", individualDetails.callbackUrl)
|
|
132
|
-
: null;
|
|
133
|
-
individualDetails.reqTag
|
|
134
|
-
? bodyFormData.append("reqTag", individualDetails.reqTag)
|
|
135
|
-
: null;
|
|
136
|
-
individualDetails.ticketSize
|
|
137
|
-
? bodyFormData.append("ticketSize", individualDetails.ticketSize)
|
|
138
|
-
: null;
|
|
139
|
-
individualDetails.crimewatch
|
|
140
|
-
? bodyFormData.append("crimewatch", individualDetails.crimewatch)
|
|
141
|
-
: null;
|
|
142
|
-
try {
|
|
143
|
-
const response: AxiosResponse = await axios.post(
|
|
144
|
-
this.baseUrl + this.addReportEndpoint,
|
|
145
|
-
bodyFormData,
|
|
146
|
-
{
|
|
147
|
-
auth: {
|
|
148
|
-
username: this.apiKey,
|
|
149
|
-
password: "",
|
|
150
|
-
},
|
|
151
|
-
headers: {
|
|
152
|
-
"Content-Type": "application/x-www-form-urlencoded",
|
|
153
|
-
},
|
|
154
|
-
}
|
|
155
|
-
);
|
|
156
|
-
|
|
157
|
-
return response.data;
|
|
158
|
-
} catch (error: any) {
|
|
159
|
-
console.error(error);
|
|
160
|
-
return error.message;
|
|
161
|
-
}
|
|
162
|
-
} else {
|
|
163
|
-
console.log("invalid input");
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
async downloadAsJSON(reqId: string): Promise<any> {
|
|
168
|
-
try {
|
|
169
|
-
const response: AxiosResponse = await axios.get(
|
|
170
|
-
this.baseUrl + this.downloadAsJsonEndpoint + `${reqId}/${this.apiKey}`
|
|
171
|
-
);
|
|
172
|
-
|
|
173
|
-
if (response.data) {
|
|
174
|
-
console.log("File downloaded successfully");
|
|
175
|
-
return response.data;
|
|
176
|
-
} else {
|
|
177
|
-
console.error("Failed to download file");
|
|
178
|
-
return error;
|
|
179
|
-
}
|
|
180
|
-
} catch (error: any) {
|
|
181
|
-
console.error("Error:", error.message);
|
|
182
|
-
return error;
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
async downloadAsPDF(reqId: string): Promise<any> {
|
|
187
|
-
try {
|
|
188
|
-
const response: AxiosResponse = await axios.get(
|
|
189
|
-
this.baseUrl + this.downloadAsPdfEndpoint + `${reqId}/${this.apiKey}`,
|
|
190
|
-
{
|
|
191
|
-
responseType: "arraybuffer",
|
|
192
|
-
headers: {
|
|
193
|
-
"Content-Type": "application/pdf",
|
|
194
|
-
},
|
|
195
|
-
}
|
|
196
|
-
);
|
|
197
|
-
|
|
198
|
-
if (response.data) {
|
|
199
|
-
console.log("File downloaded successfully");
|
|
200
|
-
return response.data;
|
|
201
|
-
} else {
|
|
202
|
-
console.error("Failed to download file");
|
|
203
|
-
return error;
|
|
204
|
-
}
|
|
205
|
-
} catch (error: any) {
|
|
206
|
-
console.error("Error:", error.message);
|
|
207
|
-
return error;
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
export default CrimeSearchAPIWrapper;
|
|
1
|
+
import axios, { AxiosResponse } from "axios";
|
|
2
|
+
import { companyDetails, individualDetails } from "./crimecheck.types";
|
|
3
|
+
import { error } from "console";
|
|
4
|
+
|
|
5
|
+
class CrimeSearchAPIWrapper {
|
|
6
|
+
private apiKey: string;
|
|
7
|
+
private baseUrl: string = "https://crime.getupforchange.com/api/";
|
|
8
|
+
private statusCheckEndpoint = "v3/status";
|
|
9
|
+
private addReportEndpoint = "v3/addReport";
|
|
10
|
+
private downloadAsJsonEndpoint = "v3/downloadJsonReport/";
|
|
11
|
+
private downloadAsPdfEndpoint = "v3/downloadReport/";
|
|
12
|
+
|
|
13
|
+
constructor(apiKey: string) {
|
|
14
|
+
this.apiKey = apiKey;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
async checkApiStatus(): Promise<void> {
|
|
18
|
+
try {
|
|
19
|
+
const response: AxiosResponse = await axios.get(
|
|
20
|
+
this.baseUrl + this.statusCheckEndpoint,
|
|
21
|
+
{
|
|
22
|
+
headers: {
|
|
23
|
+
Authorization: this.apiKey,
|
|
24
|
+
},
|
|
25
|
+
}
|
|
26
|
+
);
|
|
27
|
+
|
|
28
|
+
return response.data;
|
|
29
|
+
} catch (error: any) {
|
|
30
|
+
console.error(error);
|
|
31
|
+
return error.message;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
async addCompanyReport(companyDetails: companyDetails): Promise<void> {
|
|
35
|
+
const bodyFormData = new FormData();
|
|
36
|
+
if (companyDetails) {
|
|
37
|
+
bodyFormData.append("companyName", companyDetails.companyName);
|
|
38
|
+
companyDetails.companyType
|
|
39
|
+
? bodyFormData.append("companyType", companyDetails.companyType)
|
|
40
|
+
: null;
|
|
41
|
+
companyDetails.companyAddress
|
|
42
|
+
? bodyFormData.append("companyAddress", companyDetails.companyAddress)
|
|
43
|
+
: null;
|
|
44
|
+
companyDetails.directors
|
|
45
|
+
? bodyFormData.append("directors", companyDetails.directors)
|
|
46
|
+
: null;
|
|
47
|
+
companyDetails.clientRefNo
|
|
48
|
+
? bodyFormData.append("clientRefNo", companyDetails.clientRefNo)
|
|
49
|
+
: null;
|
|
50
|
+
companyDetails.reportMode
|
|
51
|
+
? bodyFormData.append("reportMode", companyDetails.reportMode)
|
|
52
|
+
: null;
|
|
53
|
+
companyDetails.priority
|
|
54
|
+
? bodyFormData.append("priority", companyDetails.priority)
|
|
55
|
+
: null;
|
|
56
|
+
companyDetails.callbackUrl
|
|
57
|
+
? bodyFormData.append("callbackUrl", companyDetails.callbackUrl)
|
|
58
|
+
: null;
|
|
59
|
+
companyDetails.cinNumber
|
|
60
|
+
? bodyFormData.append("cinNumber", companyDetails.cinNumber)
|
|
61
|
+
: null;
|
|
62
|
+
companyDetails.gstNumber
|
|
63
|
+
? bodyFormData.append("gstNumber", companyDetails.gstNumber)
|
|
64
|
+
: null;
|
|
65
|
+
companyDetails.reqTag
|
|
66
|
+
? bodyFormData.append("reqTag", companyDetails.reqTag)
|
|
67
|
+
: null;
|
|
68
|
+
companyDetails.ticketSize
|
|
69
|
+
? bodyFormData.append("ticketSize", companyDetails.ticketSize)
|
|
70
|
+
: null;
|
|
71
|
+
companyDetails.crimewatch
|
|
72
|
+
? bodyFormData.append("crimewatch", companyDetails.crimewatch)
|
|
73
|
+
: null;
|
|
74
|
+
|
|
75
|
+
try {
|
|
76
|
+
const response: AxiosResponse = await axios.post(
|
|
77
|
+
this.baseUrl + this.addReportEndpoint,
|
|
78
|
+
bodyFormData,
|
|
79
|
+
{
|
|
80
|
+
auth: {
|
|
81
|
+
username: this.apiKey,
|
|
82
|
+
password: "",
|
|
83
|
+
},
|
|
84
|
+
headers: {
|
|
85
|
+
"Content-Type": "application/x-www-form-urlencoded",
|
|
86
|
+
},
|
|
87
|
+
}
|
|
88
|
+
);
|
|
89
|
+
|
|
90
|
+
return response.data;
|
|
91
|
+
} catch (error: any) {
|
|
92
|
+
console.error(error);
|
|
93
|
+
return error.message;
|
|
94
|
+
}
|
|
95
|
+
} else {
|
|
96
|
+
console.log("invalid details entered");
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
async addIndividualReport(
|
|
101
|
+
individualDetails: individualDetails
|
|
102
|
+
): Promise<void> {
|
|
103
|
+
const bodyFormData = new FormData();
|
|
104
|
+
if (individualDetails.name) {
|
|
105
|
+
bodyFormData.append("name", individualDetails.name);
|
|
106
|
+
individualDetails.fatherName
|
|
107
|
+
? bodyFormData.append("fatherName", individualDetails.fatherName)
|
|
108
|
+
: null;
|
|
109
|
+
individualDetails.address
|
|
110
|
+
? bodyFormData.append("address", individualDetails.address)
|
|
111
|
+
: null;
|
|
112
|
+
individualDetails.address2
|
|
113
|
+
? bodyFormData.append("address2", individualDetails.address2)
|
|
114
|
+
: null;
|
|
115
|
+
individualDetails.dob
|
|
116
|
+
? bodyFormData.append("dob", individualDetails.dob)
|
|
117
|
+
: null;
|
|
118
|
+
individualDetails.panNumber
|
|
119
|
+
? bodyFormData.append("panNumber", individualDetails.panNumber)
|
|
120
|
+
: null;
|
|
121
|
+
individualDetails.clientRefNo
|
|
122
|
+
? bodyFormData.append("clientRefNo", individualDetails.clientRefNo)
|
|
123
|
+
: null;
|
|
124
|
+
individualDetails.reportMode
|
|
125
|
+
? bodyFormData.append("reportMode", individualDetails.reportMode)
|
|
126
|
+
: null;
|
|
127
|
+
individualDetails.priority
|
|
128
|
+
? bodyFormData.append("priority", individualDetails.priority)
|
|
129
|
+
: null;
|
|
130
|
+
individualDetails.callbackUrl
|
|
131
|
+
? bodyFormData.append("callbackUrl", individualDetails.callbackUrl)
|
|
132
|
+
: null;
|
|
133
|
+
individualDetails.reqTag
|
|
134
|
+
? bodyFormData.append("reqTag", individualDetails.reqTag)
|
|
135
|
+
: null;
|
|
136
|
+
individualDetails.ticketSize
|
|
137
|
+
? bodyFormData.append("ticketSize", individualDetails.ticketSize)
|
|
138
|
+
: null;
|
|
139
|
+
individualDetails.crimewatch
|
|
140
|
+
? bodyFormData.append("crimewatch", individualDetails.crimewatch)
|
|
141
|
+
: null;
|
|
142
|
+
try {
|
|
143
|
+
const response: AxiosResponse = await axios.post(
|
|
144
|
+
this.baseUrl + this.addReportEndpoint,
|
|
145
|
+
bodyFormData,
|
|
146
|
+
{
|
|
147
|
+
auth: {
|
|
148
|
+
username: this.apiKey,
|
|
149
|
+
password: "",
|
|
150
|
+
},
|
|
151
|
+
headers: {
|
|
152
|
+
"Content-Type": "application/x-www-form-urlencoded",
|
|
153
|
+
},
|
|
154
|
+
}
|
|
155
|
+
);
|
|
156
|
+
|
|
157
|
+
return response.data;
|
|
158
|
+
} catch (error: any) {
|
|
159
|
+
console.error(error);
|
|
160
|
+
return error.message;
|
|
161
|
+
}
|
|
162
|
+
} else {
|
|
163
|
+
console.log("invalid input");
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
async downloadAsJSON(reqId: string): Promise<any> {
|
|
168
|
+
try {
|
|
169
|
+
const response: AxiosResponse = await axios.get(
|
|
170
|
+
this.baseUrl + this.downloadAsJsonEndpoint + `${reqId}/${this.apiKey}`
|
|
171
|
+
);
|
|
172
|
+
|
|
173
|
+
if (response.data) {
|
|
174
|
+
console.log("File downloaded successfully");
|
|
175
|
+
return response.data;
|
|
176
|
+
} else {
|
|
177
|
+
console.error("Failed to download file");
|
|
178
|
+
return error;
|
|
179
|
+
}
|
|
180
|
+
} catch (error: any) {
|
|
181
|
+
console.error("Error:", error.message);
|
|
182
|
+
return error;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
async downloadAsPDF(reqId: string): Promise<any> {
|
|
187
|
+
try {
|
|
188
|
+
const response: AxiosResponse = await axios.get(
|
|
189
|
+
this.baseUrl + this.downloadAsPdfEndpoint + `${reqId}/${this.apiKey}`,
|
|
190
|
+
{
|
|
191
|
+
responseType: "arraybuffer",
|
|
192
|
+
headers: {
|
|
193
|
+
"Content-Type": "application/pdf",
|
|
194
|
+
},
|
|
195
|
+
}
|
|
196
|
+
);
|
|
197
|
+
|
|
198
|
+
if (response.data) {
|
|
199
|
+
console.log("File downloaded successfully");
|
|
200
|
+
return response.data;
|
|
201
|
+
} else {
|
|
202
|
+
console.error("Failed to download file");
|
|
203
|
+
return error;
|
|
204
|
+
}
|
|
205
|
+
} catch (error: any) {
|
|
206
|
+
console.error("Error:", error.message);
|
|
207
|
+
return error;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
export default CrimeSearchAPIWrapper;
|