Commit e4a39519 authored by Panagiotis Skarvelis's avatar Panagiotis Skarvelis
Browse files

working client

parent cd303e39
node_modules
docs
.DS_Store
*.jar
# retrieveInfoByNameClient
Search for data of Individuals based on the full name
\ No newline at end of file
Client to connect on GSIS service.
Returns Natural and Non-Natural Persons data based on Name.
#### Example
```
import getInfo from '@digigov-oss/retreive-info-by-name-client';
import config from './config.json';
const test = async () => {
const input = {
surnameA: "ΠΑΠΠΑΣ",
secondSurname: 'ΓΩΓΟΣ',
nameA: "ΓΕΩΡΓΙΟΣ",
mothersFirstName: 'ΚΩΣΤΟΥΛΑ',
fathersFirstName: "ΚΩΝΣΤΑΝΤΙΝΟΣ"
}
try {
const Info = await getInfo(input, config.user, config.pass);
console.log(Info);
} catch (error) {
console.log(error);
}
}
test();
}
```
* you can use `overrides` to override the default values for auditrecord and input fields.
* for your tests, you don't need to use the `overrides` mechanism, in that case, the default storage path will be used ie `/tmp`
* look at [KED](https://www.gsis.gr/dimosia-dioikisi/ked/) standard guides for records you can use on auditInit"
Also, you can use `overrides` to override the default storage engine. Look at module [AuditRecordDB](https://gitlab.grnet.gr/digigov-oss/auditRecordDB/-/blob/main/README.md) for more details on how to use the AuditEngine.
#### Returns
an object like the following:
```
{
retrieveInfoByNameRecord: {
dataNameArray: {
record: [
{
afm: '067801958',
surname: 'ΠΑΠΠΑΣ',
secondSurname: 'ΓΩΓΟΣ',
firstName: 'ΓΕΩΡΓΙΟΣ',
fathersFirstName: 'ΚΩΝΣΤΑΝΤΙΝΟΣ',
mothersFirstName: 'ΚΩΣΤΟΥΛΑ',
birthDate: Wed Sep 29 1965 00:00:00 GMT+0200 (Θερινή ώρα Ανατολικής Ευρώπης),
doy: '6311',
doyDescr: 'ΙΩΑΝΝΙΝΩΝ',
cardNo: 'Λ544311',
cardKindDescr: 'ΑΤ ΑΣΤΥΝΟΜΙΚΗ ΤΑΥΤΟΤΗΤΑ',
firmFlagDescr: 'ΜΗ ΕΠΙΤΗΔΕΥΜΑΤΙΑΣ',
residenceAddress: 'ΑΡΗ ΒΕΛΟΥΧΙΩΤΗ',
residenceNo: '52',
parResidence: 45332,
parResidenceDescr: 'ΙΩΑΝΝΙΝΑ'
}
]
}
},
callSequenceId: 49245917,
callSequenceDate: Mon May 09 2022 12:58:57 GMT+0300 (Θερινή ώρα Ανατολικής Ευρώπης),
errorRecord: null,
auditUnit: 'gov.gr',
auditTransactionId: '87',
auditProtocol: '87/2022-05-09',
auditTransactionDate: '2022-05-09T09:58:56Z',
auditUserIp: '127.0.0.1',
auditUserId: 'system'
}
```
or an error object like the following:
```
{
retrieveInfoByNameRecord: {
dataNameArray: null
},
callSequenceId: 49253014,
callSequenceDate: Mon May 09 2022 14:41:02 GMT+0300 (Θερινή ώρα Ανατολικής Ευρώπης),
errorRecord: {
errorCode: 'GEN_NO_RECORDS_FOUND',
errorDescr: 'Δεν βρέθηκαν αποτελέσματα, αλλάξτε τα κριτήρια αναζήτησης'
},
auditUnit: 'gov.gr',
auditTransactionId: '90',
auditProtocol: '90/2022-05-09',
auditTransactionDate: '2022-05-09T11:40:59Z',
auditUserIp: '127.0.0.1',
auditUserId: 'system'
}
}
```
### Notes
In case of KED advertises wrong endpoint on production you have to use (override) the endpoint: `https://ked.gsis.gr/esb/registryService`
You can do that by setting the `endpoint` property on the `overrides` object.
```
const overrides = {
endpoint: 'https://ked.gsis.gr/esb/registryService',
}
```
\ No newline at end of file
{
"test": {
"wsdl": "https://test.gsis.gr/esbpilot/registryService?wsdl"
},
"prod": {
"wsdl": "https://ked.gsis.gr/esb/registryService?wsdl"
}
}
import { AuditRecord, AuditEngine } from '@digigov-oss/gsis-audit-record-db';
export declare type record = {
afm: string;
surname: string;
secondSurname: string;
firstName: string;
fathersFirstName: string;
mothersFirstName: string;
birthDate: string;
deathDate: string;
doy: string;
doyDescr: string;
cardNo: string;
cardKindDescr: string;
firmFlagDescr: "1" | "2" | "3";
residenceAddress: string;
residenceNo: string;
parResidence: string;
parResidenceDescr: string;
firmAddress: string;
firmNo: string;
parBusiness: string;
parBusinessDescr: string;
code: string;
description: string;
};
export declare type retrieveInfoByNameRecord = {
dataNameArray: {
record: record[];
};
};
export declare type errorRecord = {
errorCode: string;
errorDescr: string;
};
export declare type retrieveInfoByNameInputRecord = {
surnameA: string;
surnameB?: string;
nameA: string;
nameB?: string;
fathersFirstName: string;
mothersFirstName?: string;
birthYear?: string;
birthMonth?: string;
birthDay?: string;
carPlateNumber?: string;
};
export declare type retrieveInfoByNameRequest = {
nameRecord: retrieveInfoByNameInputRecord;
callSequenceId: string;
callSequenceDate: string;
errorRecord: errorRecord | null;
};
/**
* @type Overrides
* @description Overrides for the SOAP client
* @param {string} endpoint - The endpoint to connect to
* @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
*/
export declare type overrides = {
endpoint?: string;
prod?: boolean;
auditInit?: AuditRecord;
auditStoragePath?: string;
auditEngine?: AuditEngine;
};
/**
*
* @param input retrieveInfoByNameInputRecord;
* @param user string;
* @param pass string;
* @param overrides overrides;
* @returns retrieveInfoByNameRecord | errorRecord
*/
export declare const getInfo: (input: retrieveInfoByNameInputRecord, user: string, pass: string, overrides?: overrides | undefined) => Promise<any>;
export default getInfo;
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getInfo = void 0;
const soapClient_js_1 = __importDefault(require("./soapClient.js"));
const gsis_audit_record_db_1 = require("@digigov-oss/gsis-audit-record-db");
const config_json_1 = __importDefault(require("./config.json"));
/**
*
* @param input retrieveInfoByNameInputRecord;
* @param user string;
* @param pass string;
* @param overrides overrides;
* @returns retrieveInfoByNameRecord | errorRecord
*/
const getInfo = (input, user, pass, overrides) => __awaiter(void 0, void 0, void 0, function* () {
var _a, _b, _c, _d, _e;
const endpoint = (_a = overrides === null || overrides === void 0 ? void 0 : overrides.endpoint) !== null && _a !== void 0 ? _a : "";
const prod = (_b = overrides === null || overrides === void 0 ? void 0 : overrides.prod) !== null && _b !== void 0 ? _b : false;
const auditInit = (_c = overrides === null || overrides === void 0 ? void 0 : overrides.auditInit) !== null && _c !== void 0 ? _c : {};
const auditStoragePath = (_d = overrides === null || overrides === void 0 ? void 0 : overrides.auditStoragePath) !== null && _d !== void 0 ? _d : "/tmp";
const auditEngine = (_e = overrides === null || overrides === void 0 ? void 0 : overrides.auditEngine) !== null && _e !== void 0 ? _e : new gsis_audit_record_db_1.FileEngine(auditStoragePath);
const wsdl = prod == true ? config_json_1.default.prod.wsdl : config_json_1.default.test.wsdl;
const auditRecord = yield (0, gsis_audit_record_db_1.generateAuditRecord)(auditInit, auditEngine);
if (!auditRecord)
throw new Error('Audit record is not initialized');
try {
const s = new soapClient_js_1.default(wsdl, user, pass, auditRecord, endpoint);
const Info = yield s.getInfo(input);
return Object.assign(Object.assign({}, Info), auditRecord);
}
catch (error) {
throw (error);
}
});
exports.getInfo = getInfo;
exports.default = exports.getInfo;
{
"type": "commonjs"
}
import { retrieveInfoByNameInputRecord } from './index.js';
import { AuditRecord } from '@digigov-oss/gsis-audit-record-db';
/**
* SOAP client for retrieveInfoByAFM
* @class Soap
* @description SOAP client for retrieveInfoByAFM
* @param {string} wsdl - The URL of the SOAP service
* @param {string} username
* @param {string} password
* @param {AuditRecord} auditRecord
* @param {string} endpoint
*/
declare class Soap {
private _wsdl;
private _username;
private _password;
private _auditRecord;
private _endpoint;
constructor(wsdl: string, username: string, password: string, auditRecord: AuditRecord, endpoint: string);
init(): Promise<any>;
getInfo(input: retrieveInfoByNameInputRecord): Promise<any>;
}
export default Soap;
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const soap_1 = __importDefault(require("soap"));
let soap = soap_1.default;
try {
soap = require('soap');
}
catch (error) {
//my hackish way to make soap work on both esm and cjs
//theshoap on esm is undefined
//On esm require is not defined, however on cjs require can be used.
//So we try to use require and if it fails we use the thesoap module
}
/**
* SOAP client for retrieveInfoByAFM
* @class Soap
* @description SOAP client for retrieveInfoByAFM
* @param {string} wsdl - The URL of the SOAP service
* @param {string} username
* @param {string} password
* @param {AuditRecord} auditRecord
* @param {string} endpoint
*/
class Soap {
constructor(wsdl, username, password, auditRecord, endpoint) {
this._wsdl = wsdl;
this._username = username;
this._password = password;
this._auditRecord = auditRecord;
this._endpoint = endpoint;
}
init() {
return __awaiter(this, void 0, void 0, function* () {
try {
const client = yield soap.createClientAsync(this._wsdl, {
wsdl_headers: {
'Authorization': 'Basic ' + Buffer.from(`${this._username}:${this._password}`).toString('base64'),
},
});
if (this._endpoint) {
client.setEndpoint(this._endpoint);
}
return client;
}
catch (e) {
throw e;
}
});
}
getInfo(input) {
return __awaiter(this, void 0, void 0, function* () {
try {
const client = yield this.init();
var options = {
hasNonce: true,
actor: 'actor'
};
var wsSecurity = new soap.WSSecurity(this._username, this._password, options);
client.setSecurity(wsSecurity);
const auditRecord = this._auditRecord;
const args = {
auditRecord: auditRecord,
retrieveInfoByNameRecord: input,
};
const result = yield client.retrieveInfoByNameAsync(args);
return result[0];
}
catch (e) {
throw e;
}
});
}
}
exports.default = Soap;
{
"test": {
"wsdl": "https://test.gsis.gr/esbpilot/registryService?wsdl"
},
"prod": {
"wsdl": "https://ked.gsis.gr/esb/registryService?wsdl"
}
}
import { AuditRecord, AuditEngine } from '@digigov-oss/gsis-audit-record-db';
export declare type record = {
afm: string;
surname: string;
secondSurname: string;
firstName: string;
fathersFirstName: string;
mothersFirstName: string;
birthDate: string;
deathDate: string;
doy: string;
doyDescr: string;
cardNo: string;
cardKindDescr: string;
firmFlagDescr: "1" | "2" | "3";
residenceAddress: string;
residenceNo: string;
parResidence: string;
parResidenceDescr: string;
firmAddress: string;
firmNo: string;
parBusiness: string;
parBusinessDescr: string;
code: string;
description: string;
};
export declare type retrieveInfoByNameRecord = {
dataNameArray: {
record: record[];
};
};
export declare type errorRecord = {
errorCode: string;
errorDescr: string;
};
export declare type retrieveInfoByNameInputRecord = {
surnameA: string;
surnameB?: string;
nameA: string;
nameB?: string;
fathersFirstName: string;
mothersFirstName?: string;
birthYear?: string;
birthMonth?: string;
birthDay?: string;
carPlateNumber?: string;
};
export declare type retrieveInfoByNameRequest = {
nameRecord: retrieveInfoByNameInputRecord;
callSequenceId: string;
callSequenceDate: string;
errorRecord: errorRecord | null;
};
/**
* @type Overrides
* @description Overrides for the SOAP client
* @param {string} endpoint - The endpoint to connect to
* @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
*/
export declare type overrides = {
endpoint?: string;
prod?: boolean;
auditInit?: AuditRecord;
auditStoragePath?: string;
auditEngine?: AuditEngine;
};
/**
*
* @param input retrieveInfoByNameInputRecord;
* @param user string;
* @param pass string;
* @param overrides overrides;
* @returns retrieveInfoByNameRecord | errorRecord
*/
export declare const getInfo: (input: retrieveInfoByNameInputRecord, user: string, pass: string, overrides?: overrides | undefined) => Promise<any>;
export default getInfo;
import soapClient from './soapClient.js';
import { generateAuditRecord, FileEngine } from '@digigov-oss/gsis-audit-record-db';
import config from './config.json';
/**
*
* @param input retrieveInfoByNameInputRecord;
* @param user string;
* @param pass string;
* @param overrides overrides;
* @returns retrieveInfoByNameRecord | errorRecord
*/
export const getInfo = async (input, user, pass, overrides) => {
const endpoint = overrides?.endpoint ?? "";
const prod = overrides?.prod ?? false;
const auditInit = overrides?.auditInit ?? {};
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 Info = await s.getInfo(input);
return { ...Info, ...auditRecord };
}
catch (error) {
throw (error);
}
};
export default getInfo;
{
"type": "module"
}
import { retrieveInfoByNameInputRecord } from './index.js';
import { AuditRecord } from '@digigov-oss/gsis-audit-record-db';
/**
* SOAP client for retrieveInfoByAFM
* @class Soap
* @description SOAP client for retrieveInfoByAFM
* @param {string} wsdl - The URL of the SOAP service
* @param {string} username
* @param {string} password
* @param {AuditRecord} auditRecord
* @param {string} endpoint
*/
declare class Soap {
private _wsdl;
private _username;
private _password;
private _auditRecord;
private _endpoint;
constructor(wsdl: string, username: string, password: string, auditRecord: AuditRecord, endpoint: string);
init(): Promise<any>;
getInfo(input: retrieveInfoByNameInputRecord): Promise<any>;
}
export default Soap;
import thesoap from 'soap';
let soap = thesoap;
try {
soap = require('soap');
}
catch (error) {
//my hackish way to make soap work on both esm and cjs
//theshoap on esm is undefined
//On esm require is not defined, however on cjs require can be used.
//So we try to use require and if it fails we use the thesoap module
}
/**
* SOAP client for retrieveInfoByAFM
* @class Soap
* @description SOAP client for retrieveInfoByAFM
* @param {string} wsdl - The URL of the SOAP service
* @param {string} username
* @param {string} password
* @param {AuditRecord} auditRecord
* @param {string} endpoint
*/
class Soap {
_wsdl;
_username;
_password;
_auditRecord;
_endpoint;
constructor(wsdl, username, password, auditRecord, endpoint) {
this._wsdl = wsdl;
this._username = username;
this._password = password;
this._auditRecord = auditRecord;
this._endpoint = endpoint;
}
async init() {
try {
const client = await soap.createClientAsync(this._wsdl, {
wsdl_headers: {
'Authorization': 'Basic ' + Buffer.from(`${this._username}:${this._password}`).toString('base64'),
},
});
if (this._endpoint) {
client.setEndpoint(this._endpoint);
}
return client;
}
catch (e) {
throw e;
}
}
async getInfo(input) {
try {
const client = await this.init();
var options = {
hasNonce: true,
actor: 'actor'
};
var wsSecurity = new soap.WSSecurity(this._username, this._password, options);
client.setSecurity(wsSecurity);
const auditRecord = this._auditRecord;
const args = {
auditRecord: auditRecord,
retrieveInfoByNameRecord: input,
};
const result = await client.retrieveInfoByNameAsync(args);
return result[0];
}
catch (e) {
throw e;
}
}
}
export default Soap;
{
"name": "@digigov-oss/retreive-info-by-name-client",
"version": "1.0.0",
"type": "module",
"description": "Client for retrieveInfoByName service of gsis",
"engines": {
"node": ">=16.13.1"
},
"author": "Panagiotis Skarvelis <pskarvelis@admin.grnet.gr>",
"dependencies": {
"@digigov-oss/gsis-audit-record-db": "^1.3.1",
"soap": "^0.43.0"
},
"repository": {
"type": "git",
"url": "git+https://gitlab.grnet.gr/digigov-oss/retrieveinfobynameclient.git"