index.ts 2.11 KB
Newer Older
1
import soapClient from './soapClient.js';
2
import {generateAuditRecord, AuditRecord, FileEngine, AuditEngine } from '@digigov-oss/gsis-audit-record-db';
3
4
import config from './config.json'; 

Panagiotis Skarvelis's avatar
Panagiotis Skarvelis committed
5

Panagiotis Skarvelis's avatar
Panagiotis Skarvelis committed
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
export type AuditInit = AuditRecord;
export type getNncIdentityOutputRecord = {
countryCode?:string;
countryDescr?:string;
addressStreet?:string;
addressNumber?:string;
addressCity?:string;
addressZipCode?:string;
telephone?:string;
countryCode2?:string;
countryDescr2?:string;
addressStreet2?:string;
addressNumber2?:string;
addressCity2?:string;
addressZipCode2?:string;
telephone2?:string;
mobile?:string;
email?:string;
epikForeisFlag?:string;
epidForeisFlag?:string;
message?:string;
}

export type errorRecord = {
    errorCode:string;
    errorDescr:string;
}

Panagiotis Skarvelis's avatar
Panagiotis Skarvelis committed
34
35
36
37
38
39
40
/**
 * @type Overrides
 * @description Overrides for the SOAP client
 * @param {boolean} prod - Set to true for production environment
 * @param {string} auditInit - Audit record initializer to be used for the audit record produced
 * @param {string} auditStoragePath - Path to the audit record storage
 */
Panagiotis Skarvelis's avatar
Panagiotis Skarvelis committed
41
export type Overides = {
Panagiotis Skarvelis's avatar
Panagiotis Skarvelis committed
42
   prod?:boolean;
Panagiotis Skarvelis's avatar
Panagiotis Skarvelis committed
43
44
   auditInit?: AuditRecord;
   auditStoragePath?: string;
45
   auditEngine?: AuditEngine;
Panagiotis Skarvelis's avatar
Panagiotis Skarvelis committed
46
}
Panagiotis Skarvelis's avatar
Panagiotis Skarvelis committed
47

48

Panagiotis Skarvelis's avatar
Panagiotis Skarvelis committed
49
50
51
52
53
54
55
56
57

/**
 * 
 * @param afm string;
 * @param user string;
 * @param pass string;
 * @param overides Overides;
 * @returns AuditRecord | errorRecord
 */
Panagiotis Skarvelis's avatar
Panagiotis Skarvelis committed
58
export const getIdentity = async (afm:string, user:string, pass:string, overides?:Overides) => {
Panagiotis Skarvelis's avatar
Panagiotis Skarvelis committed
59
    const prod = overides?.prod ?? false;
Panagiotis Skarvelis's avatar
Panagiotis Skarvelis committed
60
61
    const auditInit = overides?.auditInit ?? {} as AuditRecord;
    const auditStoragePath = overides?.auditStoragePath ?? "/tmp"
62
    const auditEngine = overides?.auditEngine ?? new FileEngine(auditStoragePath);
Panagiotis Skarvelis's avatar
Panagiotis Skarvelis committed
63
    const wsdl = prod==true? config.prod.wsdl : config.test.wsdl;
Panagiotis Skarvelis's avatar
v1.0.9    
Panagiotis Skarvelis committed
64
    const auditRecord = await generateAuditRecord(auditInit, auditEngine);
Panagiotis Skarvelis's avatar
Panagiotis Skarvelis committed
65
    if (!auditRecord) throw new Error('Audit record is not initialized');
Panagiotis Skarvelis's avatar
Panagiotis Skarvelis committed
66
   
Panagiotis Skarvelis's avatar
Panagiotis Skarvelis committed
67
    try {
68
    const s = new soapClient(wsdl, user, pass, auditRecord);
Panagiotis Skarvelis's avatar
Panagiotis Skarvelis committed
69
    const Identity = await s.getIdentity(afm);
70
    return {...Identity,...auditRecord};
Panagiotis Skarvelis's avatar
Panagiotis Skarvelis committed
71
72
73
   } catch (error) {
       throw(error);
   }
Panagiotis Skarvelis's avatar
Panagiotis Skarvelis committed
74
75


Panagiotis Skarvelis's avatar
Panagiotis Skarvelis committed
76
77
78
79
   };

export default getIdentity;