UNPKG

google-trends-api-client

Version:

An fully typed and easy to use client for the google trends api.

27 lines 1.47 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.useSessionTokenForCookieCacheIfPossible = exports.findOrCreateSessionTokenForCookieCache = void 0; const common_1 = require("./common"); /** * we use a session-token to send the same user-agent through got-scraping when using cookies * - that way, when the site assigns an id cookie to our browser, they dont suddenly see a new browser with that same id */ const findOrCreateSessionTokenForCookieCache = async ({ cookieCache, }) => { // try to find it const foundSessionToken = await cookieCache.get(common_1.COOKIES_CACHE_SESSION_TOKEN_KEY); if (foundSessionToken) return foundSessionToken; // create it if not found await cookieCache.set(common_1.COOKIES_CACHE_SESSION_TOKEN_KEY, `${new Date().getTime()}`); return (0, exports.findOrCreateSessionTokenForCookieCache)({ cookieCache }); // and run it again now, since it is now set }; exports.findOrCreateSessionTokenForCookieCache = findOrCreateSessionTokenForCookieCache; const useSessionTokenForCookieCacheIfPossible = ({ cookieCache, }) => { // if no cache, not possible if (!cookieCache) return null; // otherwise, find or create it return (0, exports.findOrCreateSessionTokenForCookieCache)({ cookieCache }); }; exports.useSessionTokenForCookieCacheIfPossible = useSessionTokenForCookieCacheIfPossible; //# sourceMappingURL=useSessionTokenForCookieCacheIfPossible.js.map