UNPKG

@cognigy/rest-api-client

Version:

Cognigy REST-Client

32 lines 1.31 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.BasicAuthentication = void 0; exports.BasicAuthentication = function (credentials, self) { if (!(this instanceof exports.BasicAuthentication)) { return new exports.BasicAuthentication(credentials, self); } else { self.credentials = { username: credentials.username, password: credentials.password, type: credentials.type }; const BasicAuthentication = function () { }; BasicAuthentication.prototype.getAuthenticationHeaders = async () => { const headers = {}; let credential = `${credentials.username}:${credentials.password}`; // accessing an undefined variable Buffer in the browser throws a reference error if (typeof Buffer !== "undefined") { credential = Buffer.from(credential, "binary").toString("base64"); } else { credential = btoa(credential); } headers["Authorization"] = `Basic ${credential}`; return headers; }; return new BasicAuthentication(credentials, self); } }; exports.default = exports.BasicAuthentication; //# sourceMappingURL=BasicAuthentication.js.map