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AgB,KAAK,IACrB,qBAAsB,EACtB,qBAAsB,IAE3B,EAEP,EAAE,KAAK,MAGD,EAAc,eAAe,EAAQ,EAAU,GAEjD,GAAK,EAAa,EAAQ,EAAU,GAIpC,IACI,aAAa,MAAM,EAAY,CAC3B,OAAQ,EACR,IAAK,EACL,OAAmB,QAAX,EAAmB,EAAS,KACpC,KAAiB,QAAX,EAAmB,KAAO,IAExC,CAAE,MAAO,GAEL,OADA,KAAK,IAAI,KAAK,UAAU,IACjB,EAAE,QACb,CAEJ,EAAE,KAAK,MAMP,KAAK,IAAM,SAAS,GAChB,QAAQ,KAAI,IAAI,MAAO,cAAgB,iBAAmB,EAC9D,CAEJ,CAEA,OAAO,QAAU","file":"/npm/coinqvest-merchant-sdk@0.0.11/lib/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/coinqvest-merchant-sdk@0.0.11/lib/index.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","#!/usr/bin/env node\nconst axios = require('axios').default;\nconst crypto = require('crypto');\n\n/**\n * NodeJS implementation of a REST client for the COINQVEST Merchant API\n * see https://www.coinqvest.com/en/api-docs\n *\n * @constructor, initialize this with the API key and secret as given by https://www.coinqvest.com/en/api-settings\n *\n * @param key (string) Your COINQVEST API Key\n * @param secret (string) Your COINQVEST API Secret\n */\nfunction Client(key, secret) {\n\n    // @string The API Key as given by https://www.coinqvest.com/en/api-settings\n    this.key = key;\n\n    // @string The API Secret as given by https://www.coinqvest.com/en/api-settings\n    this.secret = secret;\n\n    // @string The current version of this SDK, used in the HTTP user agent (leave it as is)\n    this.clientVersion = require('../package.json').version;\n\n    // @string Used in the HTTP user agent (leave it as is)\n    this.clientName = 'nodejs-merchant-sdk';\n\n    // @string The API version to which we connect (leave it as is)\n    this.apiVersion = 'v1';\n\n    /**\n     * Use this method to communicate with GET endpoints\n     *\n     * @param endpoint (string), e.g. /blockchains\n     * @param params (object), a list of GET parameters to be included in the request\n     */\n    this.get = async function(endpoint, params) {\n        return await sendRequest('get', endpoint, params);\n    };\n\n    /**\n     * Use this method to communicate with POST endpoints\n     *\n     * @param endpoint (string), e.g. /checkout/hosted\n     * @param params (object), a list of POST parameters to be included in the request\n     */\n    this.post = async function(endpoint, params) {\n        return await sendRequest('post', endpoint, params);\n    };\n\n    /**\n     * Use this method to communicate with PUT endpoints\n     *\n     * @param endpoint (string), e.g. /checkout/hosted\n     * @param params (object), a list of PUT parameters to be included in the request\n     */\n    this.put = async function(endpoint, params) {\n        return await sendRequest('put', endpoint, params);\n    };\n\n    /**\n     * Use this method to communicate with DELETE endpoints\n     *\n     * @param endpoint (string), e.g. /checkout/hosted\n     * @param params (object), a list of DELETE parameters to be included in the request\n     */\n    this.delete = async function(endpoint, params) {\n        return await sendRequest('delete', endpoint, params);\n    };\n\n    // private validator function\n    const validateArgs = function(method, endpoint, params) {\n\n        if (!validateEndpoint(endpoint)) {\n            this.log(\"Invalid endpoint given to \" + method + \" method.\");\n            return false;\n        }\n\n        if (!validateParams(params)) {\n            this.log(\"Invalid params given to \" + method + \" method.\");\n            return false;\n        }\n\n        return true;\n\n    }.bind(this);\n\n    // private validator function\n    const validateEndpoint = function(endpoint) {\n        return typeof endpoint === 'string' && endpoint.substring(0,1) === '/';\n    };\n\n    // private validator function\n    const validateParams = function(params) {\n\n        if (typeof params === 'object') {\n            return true;\n        }\n\n        return !params;\n\n    };\n\n    // private function to build request configuration\n    const buildConfig = function(extras) {\n\n        // build auth signature\n        let timestamp = Date.now() / 1000 | 0;\n        let signature = crypto.createHmac('sha256', this.secret).update(extras.url + timestamp.toString() + extras.method.toUpperCase() + (extras.method === 'get' ? '' : JSON.stringify(extras.data))).digest('hex');\n\n        // build request config\n        return Object.assign({\n            baseURL: 'https://www.coinqvest.com/api/' + this.apiVersion + '/',\n            responseType: 'json',\n            responseEncoding: 'utf8',\n            headers: {\n                'User-Agent': this.clientName + ' ' + this.clientVersion,\n                'Accept': 'application/json',\n                'X-Digest-Key': this.key,\n                'X-Digest-Signature': signature,\n                'X-Digest-Timestamp': timestamp\n            }\n        }, extras);\n\n    }.bind(this);\n\n    // private function to send the request\n    const sendRequest = async function(method, endpoint, params) {\n\n        if (!validateArgs(method, endpoint, params)) {\n            return;\n        }\n\n        try {\n            return await axios(buildConfig({\n                method: method,\n                url: endpoint,\n                params: method === 'get' ? params : null,\n                data: method === 'get' ? null : params\n            }));\n        } catch (e) {\n            this.log(JSON.stringify(e));\n            return e.response;\n        }\n\n    }.bind(this);\n\n    /**\n     * Normalized Logging for COINQVEST SDK related events and errors.\n     * @param message\n     */\n    this.log = function(message) {\n        console.log(new Date().toISOString() + ' [COINQVEST]: ' + message)\n    };\n\n}\n\nmodule.exports = Client;\n\n"]}