UNPKG

@thoughtspot/visual-embed-sdk

Version:
42 lines 1.4 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)(); const options = { ...init }; let token; if (embedConfig.authType !== types_1.AuthType.TrustedAuthTokenCookieless) { token = (0, authToken_1.getCacheAuthToken)(); if (!token) { return fetch(input, { ...options, credentials: 'include' }); } } else { token = await (0, authToken_1.getAuthenticationToken)(embedConfig); } const req = new Request(input, options); if (token) { req.headers.append('Authorization', `Bearer ${token}`); } return fetch(req); }; exports.tokenizedFetch = tokenizedFetch; //# sourceMappingURL=tokenizedFetch.js.map