UNPKG

tc-check

Version:

A Node.js and TypeScript package to validate Turkish citizens using first name, last name, birth year, and T.C. Kimlik Number via the official government API.

47 lines (46 loc) 1.73 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.APIService = void 0; const https_1 = __importDefault(require("https")); class APIService { constructor(soapService) { this.serviceUrl = 'tckimlik.nvi.gov.tr'; this.servicePath = '/service/kpspublic.asmx'; this.soapService = soapService; } verifyPerson(person) { return new Promise((resolve, reject) => { const soapEnvelope = this.soapService.createEnvelope(person); const options = { hostname: this.serviceUrl, port: 443, path: this.servicePath, method: 'POST', headers: { 'Content-Type': 'application/soap+xml; charset=utf-8', 'Content-Length': Buffer.byteLength(soapEnvelope), }, }; const req = https_1.default.request(options, (res) => { let data = ''; res.on('data', (chunk) => (data += chunk)); res.on('end', () => { try { const valid = this.soapService.parseResponse(data); resolve({ person, valid, message: valid ? 'Valid' : 'Invalid' }); } catch (err) { reject(err); } }); }); req.on('error', (err) => reject(err)); req.write(soapEnvelope); req.end(); }); } } exports.APIService = APIService;