UNPKG

@thoughtspot/visual-embed-sdk

Version:
39 lines 1.36 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.tokenizedFetch = void 0; const authToken_1 = require("./authToken"); const embedConfig_1 = require("./embed/embedConfig"); const types_1 = require("./types"); /** * Fetch wrapper that adds the authentication token to the request. * Use this to call the ThoughtSpot APIs when using the visual embed sdk. * The interface for this method is the same as Web `Fetch`. * @param input * @param init * @example * ```js * tokenizedFetch("<TS_ORIGIN>/api/rest/2.0/auth/session/user", { * // .. fetch options .. * }); *``` * @version SDK: 1.28.0 * @group Global methods */ const tokenizedFetch = async (input, init) => { const embedConfig = (0, embedConfig_1.getEmbedConfig)(); if (embedConfig.authType !== types_1.AuthType.TrustedAuthTokenCookieless) { return fetch(input, { // ensure cookies are included for the non cookie-less api calls. credentials: 'include', ...init, }); } const req = new Request(input, init); const authToken = await (0, authToken_1.getAuthenticationToken)(embedConfig); if (authToken) { req.headers.append('Authorization', `Bearer ${authToken}`); } return fetch(req); }; exports.tokenizedFetch = tokenizedFetch; //# sourceMappingURL=tokenizedFetch.js.map