aeremmiddleware 1.0.2 → 1.0.4

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,528 @@
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
-
205
- }
1
+ import axios, { AxiosRequestConfig, AxiosResponse } from "axios";
2
+
3
+ export default class IdfyAPIWrapper {
4
+ private bodyTaskIdGroupId = {
5
+ task_id: "",
6
+ group_id: "",
7
+ };
8
+ private defaultHeaderIdfyApi = {
9
+ "account-id": "",
10
+ "api-key": "",
11
+ };
12
+ private standardErrorThrowFormat = {
13
+ statusCode: 400,
14
+ message: ["bad request"],
15
+ };
16
+ private baseUrl: string = "https://eve.idfy.com/";
17
+ private gstVerificationEndPoint =
18
+ "v3/tasks/sync/verify_with_source/ind_gst_certificate";
19
+ private panIndividualVerificationEndPoint =
20
+ "v3/tasks/async/verify_with_source/ind_pan_plus";
21
+ private cinCompanyVerificationEndPoint =
22
+ "v3/tasks/async/verify_with_source/ind_mca";
23
+ private taskUrl = "v3/tasks?request_id=";
24
+ private asyncIndividualAadhaarLiteInfoEndPoint =
25
+ "v3/tasks/async/verify_with_source/aadhaar_lite";
26
+ private syncIndividualAadharScanInfoEndpoint =
27
+ "v3/tasks/sync/extract/ind_aadhaar_plus";
28
+ private syncIndividualPANScanInfoEndpoint = "v3/tasks/sync/extract/ind_pan";
29
+ private syncIndividualGSTScanInfoEndpoint =
30
+ "v3/tasks/sync/extract/ind_gst_certificate";
31
+ private syncIndividualLiveFaceLivenessEndpoint =
32
+ "v3/tasks/sync/check_photo_liveness/face";
33
+
34
+ private idfyCompanySearch = {
35
+ defaultHeader: {
36
+ "api-key": "",
37
+ "Content-Type": "application/json",
38
+ },
39
+ version: "v1",
40
+ companySearchUrl: "https://riskai.idfystaging.com/api/v1/company/search",
41
+ taskBaseUrl: "https://riskai.idfystaging.com/api/v1/task/",
42
+ cinllpinUrl: "https://riskai.idfystaging.com/api/v1/company/basic",
43
+ };
44
+
45
+ private idfyError = {
46
+ INVALID_IMAGE: {
47
+ idfyErrorCode: "IDFY_ERR_100",
48
+ message: "Please scan correct document",
49
+ },
50
+ INSUFFICIENT_CREDITS: {
51
+ idfyErrorCode: "IDFY_ERR_101",
52
+ message: "Please renew credit",
53
+ },
54
+ };
55
+
56
+ constructor({
57
+ IDFY_TASK_ID,
58
+ IDFY_GROUP_ID,
59
+ IDFY_ACCOUNT_ID,
60
+ IDFY_API_KEY,
61
+ IDFY_COMPANY_SEARCH_API_KEY,
62
+ }) {
63
+ this.bodyTaskIdGroupId.task_id = IDFY_TASK_ID;
64
+ this.bodyTaskIdGroupId.group_id = IDFY_GROUP_ID;
65
+ this.defaultHeaderIdfyApi["account-id"] = IDFY_ACCOUNT_ID;
66
+ this.defaultHeaderIdfyApi["api-key"] = IDFY_API_KEY;
67
+ this.idfyCompanySearch.defaultHeader["api-key"] =
68
+ IDFY_COMPANY_SEARCH_API_KEY;
69
+ }
70
+
71
+ private async makeRequest<T>(
72
+ method: string,
73
+ endpoint: string,
74
+ data?: any
75
+ ): Promise<T> {
76
+ const requestConfig: AxiosRequestConfig = {
77
+ method,
78
+ url: this.baseUrl + endpoint,
79
+ headers: this.defaultHeaderIdfyApi,
80
+ data,
81
+ };
82
+
83
+ try {
84
+ const response: AxiosResponse<T> = await axios(requestConfig);
85
+ return response.data;
86
+ } catch (error) {
87
+ console.error("Error while making Idfy Axios API request:", error);
88
+ throw error;
89
+ }
90
+ }
91
+
92
+ private async makeAxiosRequest<T>({
93
+ method,
94
+ url,
95
+ data,
96
+ headers,
97
+ }: {
98
+ method: string;
99
+ url: string;
100
+ data?: any;
101
+ headers: any;
102
+ }): Promise<T> {
103
+ const requestConfig: AxiosRequestConfig = {
104
+ method,
105
+ url,
106
+ headers,
107
+ data,
108
+ };
109
+
110
+ try {
111
+ const response: AxiosResponse<T> = await axios(requestConfig);
112
+ return response.data;
113
+ } catch (error) {
114
+ console.error(
115
+ "Error while making Idfy makeAxiosRequest API request:",
116
+ error
117
+ );
118
+ throw error;
119
+ }
120
+ }
121
+
122
+ private async getTask(requestId: string): Promise<any> {
123
+ try {
124
+ // const data = {}
125
+ const urlEndPoint = this.taskUrl + requestId;
126
+ const response = await this.makeRequest<any>("get", urlEndPoint);
127
+ return response;
128
+ } catch (error) {
129
+ console.error("Error while fetching Idfy getTask API data:", error);
130
+ throw error;
131
+ }
132
+ }
133
+
134
+ private async getCompanySearchTask({
135
+ requestId,
136
+ }: {
137
+ requestId: string;
138
+ }): Promise<any> {
139
+ try {
140
+ const taskBaseUrl = this.idfyCompanySearch.taskBaseUrl + requestId;
141
+ const response = await this.makeAxiosRequest({
142
+ method: "get",
143
+ url: taskBaseUrl,
144
+ headers: this.idfyCompanySearch.defaultHeader,
145
+ });
146
+ return response;
147
+ } catch (error) {
148
+ console.error(
149
+ "Error while fetching Idfy getCompanySearchTask API data:",
150
+ error
151
+ );
152
+ throw error;
153
+ }
154
+ }
155
+
156
+ private async pingTaskUntilSuccess(requestId: string): Promise<any> {
157
+ try {
158
+ let res: any = null;
159
+ const checkTaskAfter1sec = (requestId) => {
160
+ return new Promise<any>((resolve, reject) => {
161
+ try {
162
+ setTimeout(async () => {
163
+ const data = await this.getTask(requestId);
164
+ if (res?.[0].status == "failed") {
165
+ reject(res);
166
+ }
167
+ resolve(data);
168
+ }, 1000);
169
+ } catch (e) {
170
+ reject(e);
171
+ }
172
+ });
173
+ };
174
+ do {
175
+ res = await checkTaskAfter1sec(requestId);
176
+
177
+ console.log("### res ", res);
178
+ } while (res?.[0].status !== "completed");
179
+
180
+ return res;
181
+ } catch (error) {
182
+ console.error("Error while fetching Idfy getTask API data:", error);
183
+ throw error;
184
+ }
185
+ }
186
+
187
+ private async pingCompanySearchTaskUntilSuccess(
188
+ requestId: string
189
+ ): Promise<any> {
190
+ try {
191
+ console.log(" ## requestId ", requestId);
192
+ let res: any = null;
193
+ const checkTaskAfter1sec = (requestId) => {
194
+ return new Promise<any>((resolve, reject) => {
195
+ try {
196
+ setTimeout(async () => {
197
+ const data = await this.getCompanySearchTask({ requestId });
198
+ if (data.status != "failed") {
199
+ resolve(data);
200
+ } else {
201
+ reject(res);
202
+ }
203
+ }, 1000);
204
+ } catch (e) {
205
+ reject(e);
206
+ }
207
+ });
208
+ };
209
+ do {
210
+ res = await checkTaskAfter1sec(requestId);
211
+ console.log("### res ", res);
212
+ } while (res?.status !== "completed");
213
+
214
+ return res;
215
+ } catch (error) {
216
+ console.error("Error while fetching Idfy getTask API data:", error);
217
+ throw error;
218
+ }
219
+ }
220
+ async getCompanyGstInfo({ gstNo }: { gstNo: string }): Promise<any> {
221
+ try {
222
+ const data = {
223
+ ...this.bodyTaskIdGroupId,
224
+ data: {
225
+ gstin: gstNo,
226
+ },
227
+ };
228
+ const response = await this.makeRequest<any>(
229
+ "post",
230
+ this.gstVerificationEndPoint,
231
+ data
232
+ );
233
+ return response;
234
+ } catch (error) {
235
+ if (error?.response?.data?.error) {
236
+ const errorObj = this.idfyError[error?.response?.data?.error];
237
+ if (errorObj)
238
+ throw {
239
+ ...this.standardErrorThrowFormat,
240
+ message: [errorObj.message],
241
+ };
242
+ }
243
+
244
+ throw error;
245
+ }
246
+ }
247
+ async getCompanyCINInfo({ cinNo }: { cinNo: string }): Promise<any> {
248
+ try {
249
+ const data = {
250
+ ...this.bodyTaskIdGroupId,
251
+ data: {
252
+ cin: cinNo,
253
+ },
254
+ };
255
+ const response = await this.makeRequest<any>(
256
+ "post",
257
+ this.cinCompanyVerificationEndPoint,
258
+ data
259
+ );
260
+ const successData = await this.pingTaskUntilSuccess(response.request_id);
261
+
262
+ return successData?.[0]?.result?.source_output;
263
+ } catch (error) {
264
+ if (error?.response?.data?.error) {
265
+ const errorObj = this.idfyError[error?.response?.data?.error];
266
+ if (errorObj)
267
+ throw {
268
+ ...this.standardErrorThrowFormat,
269
+ message: [errorObj.message],
270
+ };
271
+ }
272
+ throw error;
273
+ }
274
+ }
275
+ async getIndividualPANInfo({ panNo }: { panNo: string }): Promise<any> {
276
+ try {
277
+ const data = {
278
+ ...this.bodyTaskIdGroupId,
279
+ data: {
280
+ id_number: panNo,
281
+ },
282
+ };
283
+ const response = await this.makeRequest<any>(
284
+ "post",
285
+ this.panIndividualVerificationEndPoint,
286
+ data
287
+ );
288
+ const successData = await this.pingTaskUntilSuccess(response.request_id);
289
+
290
+ return successData;
291
+ } catch (error) {
292
+ if (error?.response?.data?.error) {
293
+ const errorObj = this.idfyError[error?.response?.data?.error];
294
+ if (errorObj)
295
+ throw {
296
+ ...this.standardErrorThrowFormat,
297
+ message: [errorObj.message],
298
+ };
299
+ }
300
+ throw error;
301
+ }
302
+ }
303
+
304
+ async getSyncIndividualAadharScanInfo({
305
+ frontScanBase64,
306
+ backScanBase64,
307
+ }: {
308
+ frontScanBase64: string;
309
+ backScanBase64: string;
310
+ }): Promise<any> {
311
+ try {
312
+ const data = {
313
+ ...this.bodyTaskIdGroupId,
314
+ data: {
315
+ document1: frontScanBase64,
316
+ document2: backScanBase64,
317
+ consent: "yes",
318
+ advanced_details: {
319
+ extract_qr_info: true,
320
+ extract_last_4_digit: false,
321
+ },
322
+ },
323
+ };
324
+ const response = await this.makeRequest<any>(
325
+ "post",
326
+ this.syncIndividualAadharScanInfoEndpoint,
327
+ data
328
+ );
329
+
330
+ return response?.result;
331
+ } catch (error) {
332
+ if (error?.response?.data?.error) {
333
+ const errorObj = this.idfyError[error?.response?.data?.error];
334
+ if (errorObj)
335
+ throw {
336
+ ...this.standardErrorThrowFormat,
337
+ message: [errorObj.message],
338
+ };
339
+ }
340
+ throw error;
341
+ }
342
+ }
343
+
344
+ async getSyncIndividualPANScanInfo({
345
+ frontScanBase64,
346
+ }: {
347
+ frontScanBase64: string;
348
+ }): Promise<any> {
349
+ try {
350
+ const data = {
351
+ ...this.bodyTaskIdGroupId,
352
+ data: {
353
+ document1: frontScanBase64,
354
+ consent: "yes",
355
+ },
356
+ };
357
+ const response = await this.makeRequest<any>(
358
+ "post",
359
+ this.syncIndividualPANScanInfoEndpoint,
360
+ data
361
+ );
362
+
363
+ return response?.result;
364
+ } catch (error) {
365
+ if (error?.response?.data?.error) {
366
+ const errorObj = this.idfyError[error?.response?.data?.error];
367
+ if (errorObj)
368
+ throw {
369
+ ...this.standardErrorThrowFormat,
370
+ message: [errorObj.message],
371
+ };
372
+ }
373
+ throw error;
374
+ }
375
+ }
376
+
377
+ async getSyncCompanyGSTScanInfo({
378
+ frontScanBase64,
379
+ }: {
380
+ frontScanBase64: string;
381
+ }): Promise<any> {
382
+ try {
383
+ const data = {
384
+ ...this.bodyTaskIdGroupId,
385
+ data: {
386
+ document1: frontScanBase64,
387
+ },
388
+ };
389
+ const response = await this.makeRequest<any>(
390
+ "post",
391
+ this.syncIndividualGSTScanInfoEndpoint,
392
+ data
393
+ );
394
+
395
+ return response?.result;
396
+ } catch (error) {
397
+ if (error?.response?.data?.error) {
398
+ const errorObj = this.idfyError[error?.response?.data?.error];
399
+ if (errorObj)
400
+ throw {
401
+ ...this.standardErrorThrowFormat,
402
+ message: [errorObj.message],
403
+ };
404
+ }
405
+ throw error;
406
+ }
407
+ }
408
+
409
+ async getSyncIndividualLivenessSelfyScanInfo({
410
+ faceScanBase64,
411
+ }: {
412
+ faceScanBase64: string;
413
+ }): Promise<any> {
414
+ try {
415
+ const data = {
416
+ ...this.bodyTaskIdGroupId,
417
+ data: {
418
+ document1: faceScanBase64,
419
+ consent: "yes",
420
+ },
421
+ };
422
+ const response = await this.makeRequest<any>(
423
+ "post",
424
+ this.syncIndividualLiveFaceLivenessEndpoint,
425
+ data
426
+ );
427
+
428
+ return response?.result;
429
+ } catch (error) {
430
+ if (error?.response?.data?.error) {
431
+ const errorObj = this.idfyError[error?.response?.data?.error];
432
+ if (errorObj)
433
+ throw {
434
+ ...this.standardErrorThrowFormat,
435
+ message: [errorObj.message],
436
+ };
437
+ }
438
+ throw error;
439
+ }
440
+ }
441
+
442
+ async getAsyncAadhaarLiteInfo({
443
+ aadhaarNo,
444
+ }: {
445
+ aadhaarNo: string;
446
+ }): Promise<any> {
447
+ try {
448
+ const data = {
449
+ ...this.bodyTaskIdGroupId,
450
+ data: {
451
+ aadhaar_number: aadhaarNo,
452
+ },
453
+ };
454
+ const response = await this.makeRequest<any>(
455
+ "post",
456
+ this.asyncIndividualAadhaarLiteInfoEndPoint,
457
+ data
458
+ );
459
+ const successData = await this.pingTaskUntilSuccess(response.request_id);
460
+
461
+ return successData;
462
+ } catch (error) {
463
+ if (error?.response?.data?.error) {
464
+ const errorObj = this.idfyError[error?.response?.data?.error];
465
+ if (errorObj)
466
+ throw {
467
+ ...this.standardErrorThrowFormat,
468
+ message: [errorObj.message],
469
+ };
470
+ }
471
+ throw error;
472
+ }
473
+ }
474
+
475
+ async getCompanyDetailsByName({
476
+ legalName,
477
+ }: {
478
+ legalName: string;
479
+ }): Promise<any> {
480
+ try {
481
+ const data = {
482
+ version: this.idfyCompanySearch.version,
483
+ ...this.bodyTaskIdGroupId,
484
+ data: {
485
+ name: legalName,
486
+ },
487
+ };
488
+ const response = await this.makeAxiosRequest<any>({
489
+ method: "post",
490
+ url: this.idfyCompanySearch.companySearchUrl,
491
+ data,
492
+ headers: this.idfyCompanySearch.defaultHeader,
493
+ });
494
+ const successData = await this.pingCompanySearchTaskUntilSuccess(
495
+ response.request_id
496
+ );
497
+
498
+ return { request_id: response, successData: successData };
499
+ } catch (error) {
500
+ throw error;
501
+ }
502
+ }
503
+
504
+ async getCompanyDetailsByLlpinOrCin({
505
+ cinOrLlpin,
506
+ }: {
507
+ cinOrLlpin: string;
508
+ }): Promise<any> {
509
+ try {
510
+ const data = {
511
+ version: this.idfyCompanySearch.version,
512
+ ...this.bodyTaskIdGroupId,
513
+ data: {
514
+ cin_llpin: cinOrLlpin,
515
+ },
516
+ };
517
+ const response = await this.makeAxiosRequest<any>({
518
+ method: "post",
519
+ url: this.idfyCompanySearch.cinllpinUrl,
520
+ data,
521
+ headers: this.idfyCompanySearch.defaultHeader,
522
+ });
523
+ return { response: response };
524
+ } catch (error) {
525
+ throw error;
526
+ }
527
+ }
528
+ }