UNPKG

api-beep-onboarding

Version:

Oracle OCI FaaS for Api Beep Onboarding library

78 lines (63 loc) 2.57 kB
/** * * BeePay 2.023-2.024 - Oracle OCI FaaS for Api Beep Onboarding * Way4 WS runtime SOAP request templates manager * * Changes: * jlugo: 2023-dic-01. File creation * jlugo: 2024-apr-25. Moved to a library */ /* RGVzYXJyb2xsYWRvIHBvciBKb25hdGhhbiBMdWdv */ import { fileURLToPath } from "node:url"; import { readFileSync } from "node:fs"; import { resolve, dirname } from "node:path"; import { env } from "./utils.js"; /** * SOAP WS request templates */ export class WSTemplates { static TemplateTypes = { TT_MERCHANT: "merchant", TT_DIVISION: "division", TT_STORE: "store", TT_DEVICE: "device", TT_STATUS: "status", TT_CONTRACT: "contract" } // WS request header and footer static BaseDir; static Header; static Footer; // Way4 web service Application Registration Number generator static AppNumber = Math.floor(1000 + Math.random() * 9000); // Random number 0..9999 static RegistrationDate = new Date().toISOString().slice(0, 10); // Onboarding Date static Counter = 1; // WS ApplRegNumber field unique id // XML Node Info #applRegNumber; #templateName; #xml; static { const __filename = fileURLToPath(import.meta.url); const __dirname = dirname(__filename); this.BaseDir = resolve(dirname(__dirname), "templates"); this.Header = readFileSync(`${this.BaseDir}/header.ws.xml`).toString(); this.Footer = readFileSync(`${this.BaseDir}/footer.ws.xml`).toString(); } /** * @param {String} templateType - TT_MERCHANT|TT_DIVISION|TT_STORE|TT_DEVICE * @param {String} templateName - Template file name * @param {Object} object - Data */ constructor(templateType, templateName, object) { this.#applRegNumber = `${env.bank_code}-${WSTemplates.RegistrationDate}-${WSTemplates.AppNumber}-${(WSTemplates.Counter++).toString().padStart(3, "0")}`; this.#templateName = `${WSTemplates.BaseDir}/${templateType}/${templateName}.ws.xml`; this.#xml = readFileSync(this.#templateName).toString(); this.#xml = this.#xml.replace("${applRegNumber}", this.#applRegNumber); // Set WS fields values Object.entries(object).forEach(([key, value]) => { this.#xml = this.#xml.replaceAll("${" + key + "}", value); }); } getXml() { return this.#xml; } }