UNPKG

n8n-nodes-salutespeech

Version:

User-friendly SaluteSpeech (Sber) community node

48 lines 1.66 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.post_auth = post_auth; const uuid_1 = require("uuid"); const constants_1 = require("./constants"); const exception_1 = require("./exception"); function getRequestConfig(args) { const headers = { Authorization: `Basic ${args.credentials}`, RqUID: (0, uuid_1.v4)(), 'User-Agent': constants_1.USER_AGENT, 'Content-Type': 'application/x-www-form-urlencoded', Accept: 'application/json', }; return { method: 'POST', url: args.url, data: { scope: args.scope }, headers: headers, }; } function buildResponse(response) { if (response.status === 200) { return response.data; } else if (response.status === 401) { console.error(response.data); throw new exception_1.AuthenticationError(response); } else { console.error(response.data); throw new exception_1.ResponseError(response); } } function validateCredentials(credentials) { const base64regex = /^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/; if (!base64regex.test(credentials)) { console.warn('Possibly invalid credentials format. Please use only base64 credentials (Authorization data, not client secret!)'); } } async function post_auth(client, args) { validateCredentials(args.credentials); const config = getRequestConfig(args); const response = await client.request(config); console.log('post_auth.response', !!response.data.access_token); return buildResponse(response); } //# sourceMappingURL=PostAuth.js.map