UNPKG

@mikezimm/fps-core-v7

Version:

Library of reusable core interfaces, types and constants migrated from fps-library-v2

76 lines 3.96 kB
import { check4ThisFPSDigest, } from "../../helpers/check4ThisFPSDigestValue"; import { startPerformOpV2, updatePerformanceEndV2 } from "../../../Performance/functions"; import { check4This } from "../../../../../logic/Links/CheckSearch"; import { getFormDigestValueNoContext } from "./getFormDigestValueNoContext"; import { getSiteCollectionUrlFromLink } from "../../../../../logic/Strings/getSiteCollectionUrlFromLink"; import { getCurrentFPSDigest } from "../../helpers/getCurrentFPSDigest"; import { AnalyticsWebAbsolute, SecureCDNalyticsWebAbsolute } from "../../../../../restAPIs/logging/interfaces/constants"; import { CurrentSiteAbsolute } from "../../../source-props/WindowLocationConstants"; /** * DOES NOT REQUIRES Context - 2024-09-29: NEED TO TEST getFormDigestValueNoContext before widespread use * * getThisFPSDigestValue will first check for a valid digestValue, if not found, will try to request from getRequestDigestFromClass * * If you need to use digestValues, such as in SE or certain calls, * It's best to call this during the onInit because you have the context. * * Then later on, you can pass in null for the context because the digestValue will already be updated * * @param classContext * @param absoluteUrl * @returns */ export async function getThisFPSDigestValueFromUrl(absoluteUrl) { let thisPerformance = startPerformOpV2({ label: `Single-Digest`, includeMsStr: true }); // const startTime = Date.now(); // let fpsWindowProps: IFPSDigestValues = getCurrentFPSDigest(); absoluteUrl = getSiteCollectionUrlFromLink(absoluteUrl); const returnDigest = check4ThisFPSDigest(absoluteUrl); returnDigest.queries++; if (!returnDigest.digestValue) { // Go get the digest value const startTime = Date.now(); let digestValue = await getFormDigestValueNoContext(absoluteUrl); let fpsWindowProps = getCurrentFPSDigest(); returnDigest.new++; if (absoluteUrl === AnalyticsWebAbsolute) { // fpsWindowProps.AnalyticsWeb = thisFPSDigest; fpsWindowProps.AnalyticsWeb.digestValue = digestValue; fpsWindowProps.AnalyticsWeb.new++; fpsWindowProps.AnalyticsWeb.time = startTime; } else if (absoluteUrl === SecureCDNalyticsWebAbsolute) { // fpsWindowProps.SecureCDNAlyticsWeb = thisFPSDigest; fpsWindowProps.SecureCDNAlyticsWeb.digestValue = digestValue; fpsWindowProps.SecureCDNAlyticsWeb.new++; fpsWindowProps.SecureCDNAlyticsWeb.time = startTime; } else if (absoluteUrl === CurrentSiteAbsolute) { // fpsWindowProps.CurrentSite = thisFPSDigest; fpsWindowProps.CurrentSite.digestValue = digestValue; fpsWindowProps.CurrentSite.new++; fpsWindowProps.CurrentSite.time = startTime; } else { /** * 2024-12-15: Added returnDigest.idx === 0 because the first site will always have an idx of 0 * and be missed by second part */ if (returnDigest.idx === 0 || returnDigest.idx) { fpsWindowProps.sites[returnDigest.idx].digestValue = digestValue; fpsWindowProps.sites[returnDigest.idx].new++; fpsWindowProps.sites[returnDigest.idx].time = startTime; } else { alert('Oops! have a strange error here:</br>getThisFPSDigestValueFromUrl ~ 75'); } } } thisPerformance = updatePerformanceEndV2({ op: thisPerformance, updateMiliseconds: true, count: 1 }); if (check4This(`fpsShowDigestValue=true`) === true) { console.log(`fps-core-v7 COMPLETE: getThisFPSDigestValueFromUrl ~ 59`, thisPerformance, returnDigest); } ; return returnDigest.digestValue; } //# sourceMappingURL=getThisFPSDigestValueFromUrl.js.map