diff --git a/CHANGELOG.md b/CHANGELOG.md index 4e659f8..777aba3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ Given a version number MAJOR.MINOR.PATCH, increment: ## [Unreleased] ### Fixed - paymentRequest duplicated payment +- download transfer locally ## [0.6.5] - 2024-06-28 ### Added diff --git a/src/.clasp.json b/src/.clasp.json index f8833d9..9ae0549 100644 --- a/src/.clasp.json +++ b/src/.clasp.json @@ -1 +1 @@ -{"scriptId":"1JAupf57mwkjPaC3FFC8Ydx-yo6LkoIjnIrpQx2_95JenFfQ0G2ov4rbO","rootDir":"/Users/luis.almeida/Documents/starkbank/google-sheets/src"} \ No newline at end of file +{"scriptId":"199zM22Q3FVHJK5EOZtrz7EQ7bH5wm_vnQCu-YVI7kOz6N455TDq-XmMq"} \ No newline at end of file diff --git a/src/utilsRequest.js b/src/utilsRequest.js index 6d59026..6f3960c 100644 --- a/src/utilsRequest.js +++ b/src/utilsRequest.js @@ -102,53 +102,69 @@ function parseResponse(responseApi) { } -function fetchBuffer(path, method = 'GET', payload = null, query = null, version = 'v2') { +function fetchBuffer(path, method='GET', payload=null, query=null, version="v2", environment=null, privateKeyPem=null, challengeId=null) { let user = new getDefaultUser(); - let hostname = getHostname(user.environment.toLowerCase(), version); - let options = {method: method}; + if (!user.privateKey) { + throw JSON.stringify({"message": "Erro de autenticação! Por favor, faça login novamente."}); + } + if (!environment) { + environment = environment || user.environment.toLowerCase(); + } + let hostname = getHostname(environment, version); + let options = { + method: method, + muteHttpExceptions: true, + }; let url = hostname + path; if (query) { - let queryString = ''; - let separator = '?'; - for (let key in query) { - if (query[key]) { - queryString += separator + key + '=' + query[key]; - separator = '&'; + let queryString = ''; + let separator = '?'; + for (let key in query) { + if (query[key]) { + queryString += separator + key + '=' + query[key]; + separator = '&'; + } } - } - url += queryString; + url += queryString; } - paths = ["/session", "/boleto-payment"] - - if (paths.includes(path) && method != "GET") { - var accessId = KeyGen.generateMemberAccessId(user.workspaceId, user.email) - } else { - var accessId = user.accessId; - } - - let accessTime = Math.round((new Date()).getTime() / 1000).toString(); - options['headers'] = { - 'Access-Id': accessId, - 'User-Agent': 'GoogleSheets-SDK-0.4.3', - 'Accept-Language': 'pt-BR', - 'Content-Type': 'application/json', - 'Access-Time': accessTime - }; - - let body = JSON.stringify(payload); - if (!payload) { - body = ""; - } + if (privateKeyPem) { + var accessId = KeyGen.generateMemberAccessId(user.workspaceId, user.email) + } else { + var accessId = user.accessId; + } - options['payload'] = body; - if (!privateKeyPem) { - var privateKeyPem = user.privateKey; + var privateKeyPem = user.privateKey; } - - let message = accessId + ':' + accessTime + ':' + body; + + let accessTime = Math.round((new Date()).getTime() / 1000).toString(); + options['headers'] = { + 'Access-Id': accessId, + 'User-Agent': 'App-StarkBank-GSheets-v0.6.5b', + 'User-Agent-Override': 'App-StarkBank-GSheets-v0.6.5b', + 'PlatFormId' : 'gsheets', + 'PlatFormVersion' : '0.6.5', + 'Accept-Language': 'pt-BR', + 'Content-Type': 'application/pdf', + 'Access-Time': accessTime + }; + + let body = "" + if (payload) { + body = payload; + } + + options['payload'] = body; + + let message = accessId + ':' + accessTime + ':' + body + + if (challengeId) { + message += ":" + challengeId + options['headers']['Access-Challenge-Ids'] = challengeId + } + let signature = easySign(message, privateKeyPem); options['headers']['Access-Signature'] = signature;