UNPKG

voyageai

Version:

[![fern shield](https://img.shields.io/badge/%F0%9F%8C%BF-Built%20with%20Fern-brightgreen)](https://buildwithfern.com?utm_source=github&utm_medium=github&utm_campaign=readme&utm_source=https%3A%2F%2Fgithub.com%2Fvoyage-ai%2Ftypescript-sdk) [![npm shield](

27 lines (26 loc) 903 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.BasicAuth = void 0; const js_base64_1 = require("js-base64"); const BASIC_AUTH_HEADER_PREFIX = /^Basic /i; exports.BasicAuth = { toAuthorizationHeader: (basicAuth) => { if (basicAuth == null) { return undefined; } const token = js_base64_1.Base64.encode(`${basicAuth.username}:${basicAuth.password}`); return `Basic ${token}`; }, fromAuthorizationHeader: (header) => { const credentials = header.replace(BASIC_AUTH_HEADER_PREFIX, ""); const decoded = js_base64_1.Base64.decode(credentials); const [username, password] = decoded.split(":", 2); if (username == null || password == null) { throw new Error("Invalid basic auth"); } return { username, password, }; }, };