UNPKG

aba-pos-sdk-node

Version:

Node.js Addons for ABA POS SDK developed by ABA Bank. This package allows you to connect with the ABA POS terminal.

12 lines 4.14 kB
/** * @module aba-pos-sdk-node * @description * Node.js native bindings for ABA POS SDK. This module dynamically loads a platform- and architecture-specific * native addon (`aba_pos_sdk_node_addon.node`) from the `addons` directory and exposes a set of high-level * asynchronous utility methods to interact with the POS terminal via USB or IP connection. * * @copyright * Copyright (C) 2025 ABA Bank (Advanced Bank of Asia Ltd). * All copyrights of the code are owned or licensed by ABA Bank. */ const r=require("path"),t=process.platform,a=process.arch;if("darwin"!==t&&"win32"!==t&&"linux"!==t)throw new AbaPosSdkError(e,`Unsupported platform: ${t}`);const s=r.resolve(__dirname,"addons",t,a,"aba_pos_sdk_node_addon"),o=require(s),e=-101;class AbaPosSdk{constructor(){throw new AbaPosSdkError(e,"AbaPosSdk is a static class and cannot be instantiated.")}static async initUsbConnection(r){if("string"!=typeof r)throw new AbaPosSdkError(e,"initUsbConnection() error. 'key' must be a string.");0!==await o.initUsbConnection(r)&&await AbaPosSdk.t()}static async sendDataByUsb(r,t){if("string"!=typeof r)throw new AbaPosSdkError(e,"sendDataByUsb() error. 'data' must be a string.");if(!Number.isInteger(t))throw new AbaPosSdkError(e,"sendDataByUsb() error. 'timeout' must be an integer.");0!==await o.sendDataByUsb(r,t)&&await AbaPosSdk.t()}static async releaseUsbConnection(){await o.releaseUsbConnection()}static async initIpConnection(r,t){if("string"!=typeof r)throw new AbaPosSdkError(e,"initIpConnection() error. 'ipAddress' must be a string.");if("string"!=typeof t)throw new AbaPosSdkError(e,"initIpConnection() error. 'key' must be a string.");0!==await o.initIpConnection(r,t)&&await AbaPosSdk.t()}static async updateIpAddress(r){if("string"!=typeof r)throw new AbaPosSdkError(e,"updateIpAddress() error. 'newIpAddress' must be a string.");0!==await o.updateIpAddress(r)&&await AbaPosSdk.t()}static async sendDataByIp(r,t){if("string"!=typeof r)throw new AbaPosSdkError(e,"sendDataByIp() error. 'data' must be a string.");if(!Number.isInteger(t))throw new AbaPosSdkError(e,"sendDataByIp() error. 'timeout' must be an integer.");0!==await o.sendDataByIp(r,t)&&await AbaPosSdk.t()}static async releaseIpConnection(){await o.releaseIpConnection()}static async cancelWaitingPosTerminal(){0!==await o.cancelWaitingPosTerminal()&&await AbaPosSdk.t()}static waitForResponse(){return new Promise(((r,t)=>{o.waitForResponseAsync((async(a,s)=>{a?t(a):0==await AbaPosSdk.getErrorCode()?r(s):t(await AbaPosSdk.o())}))}))}static async getErrorMessage(){return await o.getErrorMessage()}static async getErrorCode(){return await o.getErrorCode()}static async setLogDirectoryPath(r){if("string"!=typeof r)throw new AbaPosSdkError(e,"setLogDirectoryPath() error. 'absolutePath' must be a string.");0!==await o.setLogDirectoryPath(r)&&await AbaPosSdk.t()}static async removeLogDirectoryPath(){0!==await o.removeLogDirectoryPath()&&await AbaPosSdk.t()}static async updateKey(r){if("string"!=typeof r)throw new AbaPosSdkError(e,"updateKey() error. 'newKey' must be a string.");0!==await o.updateKey(r)&&await AbaPosSdk.t()}static generateTimestamp(){const r=new Date;return`${r.getFullYear()}-${String(r.getMonth()+1).padStart(2,"0")}-${String(r.getDate()).padStart(2,"0")} ${String(r.getHours()).padStart(2,"0")}:${String(r.getMinutes()).padStart(2,"0")}:${String(r.getSeconds()).padStart(2,"0")}`}static async t(){throw new AbaPosSdkError(await AbaPosSdk.getErrorCode(),await AbaPosSdk.getErrorMessage())}static async o(){return new AbaPosSdkError(await AbaPosSdk.getErrorCode(),await AbaPosSdk.getErrorMessage())}}class AbaPosSdkError extends Error{constructor(r,t){if(super(t),!Number.isInteger(r))throw new AbaPosSdkError(e,"'errorCode' must be an integer.");if("string"!=typeof t)throw new AbaPosSdkError(e,"'errorMessage' must be a string.");this.name="AbaPosSdkError",this.errorCode=r,this.errorMessage=t,Error.captureStackTrace&&Error.captureStackTrace(this,AbaPosSdkError)}toString(){return`AbaPosSdkError: ${this.errorMessage} (Error Code: ${this.errorCode})`}}module.exports={AbaPosSdk:AbaPosSdk,AbaPosSdkError:AbaPosSdkError};