Commit e84f157a authored by Dimitris Massaad's avatar Dimitris Massaad
Browse files

Small refactor: catch error response when status is 200.

Renamed all interfaces to start with a capital
Added a small known-issue for windows file systems
parent 7775c6cb
......@@ -137,4 +137,12 @@ You can do that by setting the `endpoint` property on the `overrides` object.
```
const overrides = {
endpoint: 'https://ked.gsis.gr/esb/policeIdentitySearchService',
}
\ No newline at end of file
}
```
On windows you might face the error "/tmp/sequence" Path not found.
This is because the filestorage module is set by default to work on the UNIX temporary folder /tmp.
We can solve this by changing the call of `getIdentitys` and giving an overriddes.auditStoragePath property
```
const Identitys = await getIdentitys(input, config.user, config.pass, {auditStoragePath:'./test'});
```
\ No newline at end of file
import soapClient from './soapClient.js';
import {generateAuditRecord, AuditRecord, FileEngine, AuditEngine } from '@digigov-oss/gsis-audit-record-db';
import config from './config.json';
import soapClient from "./soapClient.js";
import {
generateAuditRecord,
AuditRecord,
FileEngine,
AuditEngine,
} from "@digigov-oss/gsis-audit-record-db";
import config from "./config.json";
export type AuditInit = AuditRecord;
export type searchIdentitiesByIdOutputRecord = {
status: 0 | 1;
errorCode?:string;
errorMessage?:string;
errorDescription?:string;
recordsNumber:number;
transactionId: 0 | number;
identities:{
identity:Identity[]
}
}
export type SearchIdentitiesByIdOutputRecord = {
status: 0 | 1;
errorCode?: string;
errorMessage?: string;
errorDescription?: string;
recordsNumber: number;
transactionId: 0 | number;
identities: {
identity: Identity[];
};
};
export type serviceOutputRecord = {
searchIdentitiesByIdOutputRecord:searchIdentitiesByIdOutputRecord;
callSequenceId:number;
callSequenceDate:string;
errorRecord:errorRecord | null;
auditRecord:AuditRecord;
}
export type ServiceOutputRecord = {
searchIdentitiesByIdOutputRecord: SearchIdentitiesByIdOutputRecord;
callSequenceId: number;
callSequenceDate: string;
errorRecord: ErrorRecord | null;
auditRecord: AuditRecord;
};
export type Identity = {
birthDate:string;
birthPlace:string;
birthDate: string;
birthPlace: string;
cancelReason: {
id:string;
description:string;
cancelDate:string;
}
fatherName:string;
fatherNameLatin:string;
gender:"Α"|"Γ";
idnumber:string;
isActive:boolean|"true"|"True"|"false"|"False";
issueDate:string;
issueInstitution:{
id:string;
description:string;
}
lastUpdateDate:string;
motherName:string;
municipality:string;
name:string;
nameLatin:string;
populationRegistryNo:string;
previousId:string|null;
previousIdNumber:string;
surname:string;
surnameLatin:string;
}
id: string;
description: string;
cancelDate: string;
};
fatherName: string;
fatherNameLatin: string;
gender: "Α" | "Γ";
idnumber: string;
isActive: boolean | "true" | "True" | "false" | "False";
issueDate: string;
issueInstitution: {
id: string;
description: string;
};
lastUpdateDate: string;
motherName: string;
municipality: string;
name: string;
nameLatin: string;
populationRegistryNo: string;
previousId: string | null;
previousIdNumber: string;
surname: string;
surnameLatin: string;
};
export type errorRecord = {
errorCode:string;
errorDescr:string;
}
export type ErrorRecord = {
errorCode: string;
errorDescr: string;
};
export type searchIdentitiesByIdInputRecord = {
adt: string;
reasonDesc:string;
}
export type SearchIdentitiesByIdInputRecord = {
adt: string;
reasonDesc: string;
};
/**
* @type Overrides
......@@ -71,37 +76,43 @@ export type searchIdentitiesByIdInputRecord = {
* @param {string} auditStoragePath - Path to the audit record storage
*/
export type overrides = {
endpoint?:string;
prod?:boolean;
auditInit?: AuditRecord;
auditStoragePath?: string;
auditEngine?: AuditEngine;
}
endpoint?: string;
prod?: boolean;
auditInit?: AuditRecord;
auditStoragePath?: string;
auditEngine?: AuditEngine;
};
/**
*
*
* @param input searchIdentitiesByNameInputRecord;
* @param user string;
* @param pass string;
* @param overrides overrides;
* @returns searchIdentitiesByNameOutputRecord | errorRecord
*/
export const getIdentitys = async (input:searchIdentitiesByIdInputRecord, user:string, pass:string, overrides?:overrides) => {
const endpoint = overrides?.endpoint ?? "";
const prod = overrides?.prod ?? false;
const auditInit = overrides?.auditInit ?? {} as AuditRecord;
const auditStoragePath = overrides?.auditStoragePath ?? "/tmp"
const auditEngine = overrides?.auditEngine ?? new FileEngine(auditStoragePath);
const wsdl = prod==true? config.prod.wsdl : config.test.wsdl;
const auditRecord = await generateAuditRecord(auditInit, auditEngine);
if (!auditRecord) throw new Error('Audit record is not initialized');
try {
const s = new soapClient(wsdl, user, pass, auditRecord, endpoint);
const Identitys = await s.getIdentitys(input);
return {...Identitys,...auditRecord};
} catch (error) {
throw(error);
}
}
export default getIdentitys;
\ No newline at end of file
export const getIdentitys = async (
input: SearchIdentitiesByIdInputRecord,
user: string,
pass: string,
overrides?: overrides
) => {
const endpoint = overrides?.endpoint ?? "";
const prod = overrides?.prod ?? false;
const auditInit = overrides?.auditInit ?? ({} as AuditRecord);
const auditStoragePath = overrides?.auditStoragePath ?? "/tmp";
const auditEngine =
overrides?.auditEngine ?? new FileEngine(auditStoragePath);
const wsdl = prod == true ? config.prod.wsdl : config.test.wsdl;
const auditRecord = await generateAuditRecord(auditInit, auditEngine);
if (!auditRecord) throw new Error("Audit record is not initialized");
try {
const s = new soapClient(wsdl, user, pass, auditRecord, endpoint);
const Identitys = await s.getIdentitys(input);
return { ...Identitys, ...auditRecord };
} catch (error) {
throw error;
}
};
export default getIdentitys;
import {searchIdentitiesByIdInputRecord} from './index.js'
import thesoap from 'soap';
let soap:any = thesoap;
import { SearchIdentitiesByIdInputRecord } from "./index.js";
import thesoap from "soap";
let soap: any = thesoap;
try {
soap = require('soap');
soap = require("soap");
} catch (error) {
//my hackish way to make soap work on both esm and cjs
//theshoap on esm is undefined
......@@ -10,7 +10,7 @@ try {
//So we try to use require and if it fails we use the thesoap module
}
import {AuditRecord} from '@digigov-oss/gsis-audit-record-db';
import { AuditRecord } from "@digigov-oss/gsis-audit-record-db";
/**
* SOAP client for getNncIdentity
* @class Soap
......@@ -28,8 +28,13 @@ class Soap {
private _auditRecord: AuditRecord;
private _endpoint: string;
constructor(wsdl: string, username: string, password: string,auditRecord: AuditRecord, endpoint: string) {
constructor(
wsdl: string,
username: string,
password: string,
auditRecord: AuditRecord,
endpoint: string
) {
this._wsdl = wsdl;
this._username = username;
this._password = password;
......@@ -41,7 +46,11 @@ class Soap {
try {
const client = await soap.createClientAsync(this._wsdl, {
wsdl_headers: {
'Authorization': 'Basic ' + Buffer.from(`${this._username}:${this._password}`).toString('base64'),
Authorization:
"Basic " +
Buffer.from(`${this._username}:${this._password}`).toString(
"base64"
),
},
});
if (this._endpoint) {
......@@ -53,26 +62,35 @@ class Soap {
}
}
public async getIdentitys(input:searchIdentitiesByIdInputRecord) {
public async getIdentitys(input: SearchIdentitiesByIdInputRecord) {
try {
const client = await this.init();
var options = {
hasNonce: true,
actor: 'actor'
actor: "actor",
};
var wsSecurity = new soap.WSSecurity(this._username, this._password, options)
var wsSecurity = new soap.WSSecurity(
this._username,
this._password,
options
);
client.setSecurity(wsSecurity);
const auditRecord = this._auditRecord;
const args = {
auditRecord: auditRecord,
searchIdentitiesByIdInputRecord: input,
}
};
const result = await client.searchIdentitiesByIdAsync(args);
return result[0];
const errorRecord = result[0].errorRecord;
if (errorRecord) {
return errorRecord;
} else {
return result[0];
}
} catch (e) {
throw e;
}
}
}
export default Soap;
\ No newline at end of file
export default Soap;
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment