aeremmiddleware 1.0.2 → 1.0.3

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.
@@ -1,205 +1,292 @@
1
- import axios, { AxiosRequestConfig, AxiosResponse } from "axios";
2
-
3
-
4
- export default class IdfyAPIWrapper {
5
-
6
- private bodyTaskIdGroupId = {
7
- task_id: '74f4c926-250c-43ca-9c53-453e87ceacd1',
8
- group_id: '8e16424a-58fc-4ba4-ab20-5bc8e7c3c41e',
9
- }
10
- private defaultHeaderIdfyApi = {
11
- "account-id": "e0d2add9d3c1/86e1d197-adb5-4f8f-af82-2728599a3615",
12
- "api-key": "7fad350f-5519-4ec7-b977-d8c8b131b8e4"
13
- }
14
- private baseUrl: string = "https://eve.idfy.com/";
15
- private gstVerificationEndPoint = 'v3/tasks/sync/verify_with_source/ind_gst_certificate'
16
- private panIndividualVerificationEndPoint = 'v3/tasks/async/verify_with_source/ind_pan'
17
- private cinCompanyVerificationEndPoint = 'v3/tasks/async/verify_with_source/ind_mca'
18
- private taskUrl = 'v3/tasks?request_id='
19
- private syncIndividualAadharScanInfoEndpoint = 'v3/tasks/sync/extract/ind_aadhaar_plus'
20
- private syncIndividualPANScanInfoEndpoint = 'v3/tasks/sync/extract/ind_pan'
21
- private syncIndividualLiveFaceLivenessEndpoint = 'v3/tasks/sync/check_photo_liveness/face'
22
-
23
-
24
-
25
-
26
- constructor() { }
27
-
28
- private async makeRequest<T>(
29
- method: string,
30
- endpoint: string,
31
- data?: any
32
- ): Promise<T> {
33
- const requestConfig: AxiosRequestConfig = {
34
- method,
35
- url: this.baseUrl + endpoint,
36
- headers: this.defaultHeaderIdfyApi,
37
- data,
38
- };
39
-
40
- try {
41
- const response: AxiosResponse<T> = await axios(requestConfig);
42
- return response.data;
43
- } catch (error) {
44
- console.error("Error while making Idfy Axios API request:", error);
45
- throw error;
46
- }
47
- }
48
-
49
- private async getTask(requestId: string): Promise<any> {
50
- try {
51
- // const data = {}
52
- const urlEndPoint = this.taskUrl + requestId
53
- const response = await this.makeRequest<any>("get", urlEndPoint);
54
- return response;
55
- } catch (error) {
56
- console.error("Error while fetching Idfy getTask API data:", error);
57
- throw error;
58
- }
59
- }
60
-
61
- private async pingTaskUntilSuccess(requestId: string): Promise<any> {
62
- try {
63
-
64
- let res: any = null
65
- const checkTaskAfter1sec = (requestId:string) => {
66
- return new Promise<any>((resolve, reject) => {
67
- try{
68
- setTimeout(async () => {
69
- const data = await this.getTask(requestId)
70
- if(res?.[0].status == 'failed'){
71
- reject(res)
72
- }
73
- resolve(data)
74
- }, 1000)
75
-
76
- }catch(e){
77
- reject(e)
78
- }
79
- })
80
- }
81
- do {
82
- res = await checkTaskAfter1sec(requestId)
83
-
84
- console.log( "### res ",res) ;
85
- } while (res?.[0].status !== 'completed')
86
-
87
- return res;
88
-
89
- } catch (error) {
90
- console.error("Error while fetching Idfy getTask API data:", error);
91
- throw error;
92
- }
93
- }
94
- async getCompanyGstInfo({ gstNo }: { gstNo: string }): Promise<any> {
95
- try {
96
- const data = {
97
- ...(this.bodyTaskIdGroupId),
98
- data: {
99
- gstin: gstNo,
100
- }
101
- }
102
- const response = await this.makeRequest<any>("post", this.gstVerificationEndPoint, data);
103
- return response;
104
- } catch (error) {
105
- console.error("Error while fetching Idfy API data:", error);
106
- throw error;
107
- }
108
- }
109
- async getCompanyCINInfo({ cinNo }: { cinNo: string }): Promise<any> {
110
- try {
111
- const data = {
112
- ...(this.bodyTaskIdGroupId),
113
- data: {
114
- "cin": cinNo,
115
- }
116
- }
117
- const response = await this.makeRequest<any>("post", this.cinCompanyVerificationEndPoint, data);
118
- const successData = await this.pingTaskUntilSuccess(response.request_id)
119
-
120
- return successData?.[0]?.result?.source_output;
121
- } catch (error) {
122
- console.error("Error while fetching Idfy CIN API data:", error);
123
- throw error;
124
- }
125
- }
126
- async getIndividualPANInfo({ panNo }: { panNo: string }): Promise<any> {
127
- try {
128
- const data = {
129
- ...(this.bodyTaskIdGroupId),
130
- data: {
131
- "id_number": panNo,
132
- }
133
- }
134
- const response = await this.makeRequest<any>("post", this.panIndividualVerificationEndPoint, data);
135
- const successData = await this.pingTaskUntilSuccess(response.request_id)
136
-
137
- return successData?.[0]?.result?.source_output;
138
- } catch (error) {
139
- console.error("Error while fetching Idfy PAN API data:", error);
140
- throw error;
141
- }
142
- }
143
-
144
- async getSyncIndividualAadharScanInfo({ frontScanBase64,backScanBase64 }: { frontScanBase64: string,backScanBase64:string }): Promise<any> {
145
- try {
146
- const data = {
147
- ...(this.bodyTaskIdGroupId),
148
- data: {
149
- "document1":frontScanBase64,
150
- "document2":backScanBase64,
151
- "consent":"yes",
152
- "advanced_details": {
153
- "extract_qr_info": true,
154
- "extract_last_4_digit":false
155
- }
156
- }
157
- }
158
- const response = await this.makeRequest<any>("post", this.syncIndividualAadharScanInfoEndpoint, data);
159
-
160
- return response?.result;
161
- } catch (error) {
162
- console.error("Error while fetching Idfy PAN API data:", error);
163
- throw error;
164
- }
165
- }
166
-
167
- async getSyncIndividualPANScanInfo({ frontScanBase64 }: { frontScanBase64: string }): Promise<any> {
168
- try {
169
- const data = {
170
- ...(this.bodyTaskIdGroupId),
171
- data: {
172
- "document1":frontScanBase64,
173
- "consent":"yes",
174
- }
175
- }
176
- const response = await this.makeRequest<any>("post", this.syncIndividualPANScanInfoEndpoint, data);
177
-
178
- return response?.result;
179
- } catch (error) {
180
- console.error("Error while fetching Idfy PAN API data:", error);
181
- throw error;
182
- }
183
- }
184
-
185
- async getSyncIndividualLivenessSelfyScanInfo({ faceScanBase64 }: { faceScanBase64: string }): Promise<any> {
186
- try {
187
- const data = {
188
- ...(this.bodyTaskIdGroupId),
189
- data: {
190
- "document1":faceScanBase64,
191
- "consent":"yes",
192
- }
193
- }
194
- const response = await this.makeRequest<any>("post", this.syncIndividualLiveFaceLivenessEndpoint, data);
195
-
196
- return response?.result;
197
- } catch (error) {
198
- console.error("Error while fetching Idfy PAN API data:", error);
199
- throw error;
200
- }
201
- }
202
-
203
-
204
-
1
+ import axios, { AxiosRequestConfig, AxiosResponse } from "axios";
2
+
3
+
4
+ export default class IdfyAPIWrapper {
5
+
6
+ private bodyTaskIdGroupId = {
7
+ task_id: '74f4c926-250c-43ca-9c53-453e87ceacd1',
8
+ group_id: '8e16424a-58fc-4ba4-ab20-5bc8e7c3c41e',
9
+ }
10
+ private defaultHeaderIdfyApi = {
11
+ "account-id": "e0d2add9d3c1/86e1d197-adb5-4f8f-af82-2728599a3615",
12
+ "api-key": "7fad350f-5519-4ec7-b977-d8c8b131b8e4"
13
+ }
14
+ private standardErrorThrowFormat = {
15
+ statusCode: 400,
16
+ message: ["bad request"]
17
+ }
18
+ private baseUrl: string = "https://eve.idfy.com/";
19
+ private gstVerificationEndPoint = 'v3/tasks/sync/verify_with_source/ind_gst_certificate'
20
+ private panIndividualVerificationEndPoint = 'v3/tasks/async/verify_with_source/ind_pan_plus'
21
+ private cinCompanyVerificationEndPoint = 'v3/tasks/async/verify_with_source/ind_mca'
22
+ private taskUrl = 'v3/tasks?request_id='
23
+ private asyncIndividualAadhaarLiteInfoEndPoint='v3/tasks/async/verify_with_source/aadhaar_lite'
24
+ private syncIndividualAadharScanInfoEndpoint = 'v3/tasks/sync/extract/ind_aadhaar_plus'
25
+ private syncIndividualPANScanInfoEndpoint = 'v3/tasks/sync/extract/ind_pan'
26
+ private syncIndividualGSTScanInfoEndpoint = 'v3/tasks/sync/extract/ind_gst_certificate'
27
+ private syncIndividualLiveFaceLivenessEndpoint = 'v3/tasks/sync/check_photo_liveness/face'
28
+
29
+ private idfyError = {
30
+ "INVALID_IMAGE":{
31
+ idfyErrorCode :"IDFY_ERR_100" ,
32
+ message:"Please scan correct document"
33
+ },
34
+ "INSUFFICIENT_CREDITS":{
35
+ idfyErrorCode :"IDFY_ERR_101" ,
36
+ message:"Please renew credit"
37
+ }
38
+ }
39
+
40
+
41
+
42
+
43
+ constructor() { }
44
+
45
+ private async makeRequest<T>(
46
+ method: string,
47
+ endpoint: string,
48
+ data?: any
49
+ ): Promise<T> {
50
+ const requestConfig: AxiosRequestConfig = {
51
+ method,
52
+ url: this.baseUrl + endpoint,
53
+ headers: this.defaultHeaderIdfyApi,
54
+ data,
55
+ };
56
+
57
+ try {
58
+ const response: AxiosResponse<T> = await axios(requestConfig);
59
+ return response.data;
60
+ } catch (error) {
61
+ console.error("Error while making Idfy Axios API request:", error);
62
+ throw error;
63
+ }
64
+ }
65
+
66
+ private async getTask(requestId: string): Promise<any> {
67
+ try {
68
+ // const data = {}
69
+ const urlEndPoint = this.taskUrl + requestId
70
+ const response = await this.makeRequest<any>("get", urlEndPoint);
71
+ return response;
72
+ } catch (error) {
73
+ console.error("Error while fetching Idfy getTask API data:", error);
74
+ throw error;
75
+ }
76
+ }
77
+
78
+ private async pingTaskUntilSuccess(requestId: string): Promise<any> {
79
+ try {
80
+
81
+ let res: any = null
82
+ const checkTaskAfter1sec = (requestId:string) => {
83
+ return new Promise<any>((resolve, reject) => {
84
+ try{
85
+ setTimeout(async () => {
86
+ const data = await this.getTask(requestId)
87
+ if(res?.[0].status == 'failed'){
88
+ reject(res)
89
+ }
90
+ resolve(data)
91
+ }, 1000)
92
+
93
+ }catch(e){
94
+ reject(e)
95
+ }
96
+ })
97
+ }
98
+ do {
99
+ res = await checkTaskAfter1sec(requestId)
100
+
101
+ console.log( "### res ",res) ;
102
+ } while (res?.[0].status !== 'completed')
103
+
104
+ return res;
105
+
106
+ } catch (error) {
107
+ console.error("Error while fetching Idfy getTask API data:", error);
108
+ throw error;
109
+ }
110
+ }
111
+ async getCompanyGstInfo({ gstNo }: { gstNo: string }): Promise<any> {
112
+ try {
113
+ const data = {
114
+ ...(this.bodyTaskIdGroupId),
115
+ data: {
116
+ gstin: gstNo,
117
+ }
118
+ }
119
+ const response = await this.makeRequest<any>("post", this.gstVerificationEndPoint, data);
120
+ return response;
121
+ } catch (error) {
122
+
123
+ // if(error?.response?.data?.error){
124
+ // const errorObj = this.idfyError[error?.response?.data?.error]
125
+ // if(errorObj)
126
+ // throw ({ ...this.standardErrorThrowFormat, message: [errorObj.message] })
127
+ // }
128
+
129
+ throw error;
130
+ }
131
+ }
132
+ async getCompanyCINInfo({ cinNo }: { cinNo: string }): Promise<any> {
133
+ try {
134
+ const data = {
135
+ ...(this.bodyTaskIdGroupId),
136
+ data: {
137
+ "cin": cinNo,
138
+ }
139
+ }
140
+ const response = await this.makeRequest<any>("post", this.cinCompanyVerificationEndPoint, data);
141
+ const successData = await this.pingTaskUntilSuccess(response.request_id)
142
+
143
+ return successData?.[0]?.result?.source_output;
144
+ } catch (error) {
145
+ // if(error?.response?.data?.error){
146
+ // const errorObj = this.idfyError[error?.response?.data?.error]
147
+ // if(errorObj)
148
+ // throw ({ ...this.standardErrorThrowFormat, message: [errorObj.message] })
149
+ // }
150
+ throw error;
151
+ }
152
+ }
153
+ async getIndividualPANInfo({ panNo }: { panNo: string }): Promise<any> {
154
+ try {
155
+ const data = {
156
+ ...(this.bodyTaskIdGroupId),
157
+ data: {
158
+ "id_number": panNo,
159
+ }
160
+ }
161
+ const response = await this.makeRequest<any>("post", this.panIndividualVerificationEndPoint, data);
162
+ const successData = await this.pingTaskUntilSuccess(response.request_id)
163
+
164
+ return successData;
165
+ } catch (error) {
166
+ // if(error?.response?.data?.error){
167
+ // const errorObj = this.idfyError[error?.response?.data?.error]
168
+ // if(errorObj)
169
+ // throw ({ ...this.standardErrorThrowFormat, message: [errorObj.message] })
170
+ // }
171
+ throw error;
172
+ }
173
+ }
174
+
175
+ async getSyncIndividualAadharScanInfo({ frontScanBase64,backScanBase64 }: { frontScanBase64: string,backScanBase64:string }): Promise<any> {
176
+ try {
177
+ const data = {
178
+ ...(this.bodyTaskIdGroupId),
179
+ data: {
180
+ "document1":frontScanBase64,
181
+ "document2":backScanBase64,
182
+ "consent":"yes",
183
+ "advanced_details": {
184
+ "extract_qr_info": true,
185
+ "extract_last_4_digit":false
186
+ }
187
+ }
188
+ }
189
+ const response = await this.makeRequest<any>("post", this.syncIndividualAadharScanInfoEndpoint, data);
190
+
191
+ return response?.result;
192
+ } catch (error) {
193
+ // if(error?.response?.data?.error){
194
+ // const errorObj = this.idfyError[error?.response?.data?.error]
195
+ // if(errorObj)
196
+ // throw ({ ...this.standardErrorThrowFormat, message: [errorObj.message] })
197
+ // }
198
+ throw error;
199
+ }
200
+ }
201
+
202
+ async getSyncIndividualPANScanInfo({ frontScanBase64 }: { frontScanBase64: string }): Promise<any> {
203
+ try {
204
+ const data = {
205
+ ...(this.bodyTaskIdGroupId),
206
+ data: {
207
+ "document1":frontScanBase64,
208
+ "consent":"yes",
209
+ }
210
+ }
211
+ const response = await this.makeRequest<any>("post", this.syncIndividualPANScanInfoEndpoint, data);
212
+
213
+ return response?.result;
214
+ } catch (error) {
215
+ // if(error?.response?.data?.error){
216
+ // const errorObj = this.idfyError[error?.response?.data?.error]
217
+ // if(errorObj)
218
+ // throw ({ ...this.standardErrorThrowFormat, message: [errorObj.message] })
219
+ // }
220
+ throw error;
221
+ }
222
+ }
223
+
224
+
225
+ async getSyncCompanyGSTScanInfo({ frontScanBase64 }: { frontScanBase64: string }): Promise<any> {
226
+ try {
227
+ const data = {
228
+ ...(this.bodyTaskIdGroupId),
229
+ data: {
230
+ "document1":frontScanBase64
231
+ }
232
+ }
233
+ const response = await this.makeRequest<any>("post", this.syncIndividualGSTScanInfoEndpoint, data);
234
+
235
+ return response?.result;
236
+ } catch (error) {
237
+ // if(error?.response?.data?.error){
238
+ // const errorObj = this.idfyError[error?.response?.data?.error]
239
+ // if(errorObj)
240
+ // throw ({ ...this.standardErrorThrowFormat, message: [errorObj.message] })
241
+ // }
242
+ throw error;
243
+ }
244
+ }
245
+
246
+
247
+ async getSyncIndividualLivenessSelfyScanInfo({ faceScanBase64 }: { faceScanBase64: string }): Promise<any> {
248
+ try {
249
+ const data = {
250
+ ...(this.bodyTaskIdGroupId),
251
+ data: {
252
+ "document1":faceScanBase64,
253
+ "consent":"yes",
254
+ }
255
+ }
256
+ const response = await this.makeRequest<any>("post", this.syncIndividualLiveFaceLivenessEndpoint, data);
257
+
258
+ return response?.result;
259
+ } catch (error) {
260
+ // if(error?.response?.data?.error){
261
+ // const errorObj = this.idfyError[error?.response?.data?.error]
262
+ // if(errorObj)
263
+ // throw ({ ...this.standardErrorThrowFormat, message: [errorObj.message] })
264
+ // }
265
+ throw error;
266
+ }
267
+ }
268
+
269
+
270
+ async getAsyncAadhaarLiteInfo({ aadhaarNo }: { aadhaarNo: string }): Promise<any> {
271
+ try {
272
+ const data = {
273
+ ...(this.bodyTaskIdGroupId),
274
+ data: {
275
+ "aadhaar_number": aadhaarNo
276
+ }
277
+ }
278
+ const response = await this.makeRequest<any>("post", this.asyncIndividualAadhaarLiteInfoEndPoint, data);
279
+ const successData = await this.pingTaskUntilSuccess(response.request_id)
280
+
281
+ return successData;
282
+ } catch (error) {
283
+ // if(error?.response?.data?.error){
284
+ // const errorObj = this.idfyError[error?.response?.data?.error]
285
+ // if(errorObj)
286
+ // throw ({ ...this.standardErrorThrowFormat, message: [errorObj.message] })
287
+ // }
288
+ throw error;
289
+ }
290
+ }
291
+
205
292
  }
@@ -1,5 +1,7 @@
1
- import IdfyAPIWrapper from './idfy'
2
-
3
- export const finance = {
4
- idFy : IdfyAPIWrapper
5
- }
1
+ import IdfyAPIWrapper from "./idfy";
2
+ import NovelApiWrapper from "./novel";
3
+
4
+ export const finance = {
5
+ idFy: IdfyAPIWrapper,
6
+ novel: NovelApiWrapper,
7
+ };