-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2e05899
commit 2ac27fb
Showing
12 changed files
with
161 additions
and
245 deletions.
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
dotcom-rendering/src/client/userFeatures/cookies/adFree.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { getCookie, removeCookie, setCookie } from '@guardian/libs'; | ||
|
||
const AD_FREE_USER_COOKIE = 'GU_AF1'; | ||
|
||
export const getAdFreeCookie = (): string | null => | ||
getCookie({ name: AD_FREE_USER_COOKIE }); | ||
|
||
/* | ||
* Set the ad free cookie | ||
* | ||
* @param daysToLive - number of days the cookie should be valid | ||
*/ | ||
export const setAdFreeCookie = (daysToLive = 1): void => { | ||
const expires = new Date(); | ||
expires.setMonth(expires.getMonth() + 6); | ||
setCookie({ | ||
name: AD_FREE_USER_COOKIE, | ||
value: expires.getTime().toString(), | ||
daysToLive, | ||
}); | ||
}; | ||
|
||
export const adFreeDataIsPresent = (): boolean => { | ||
const cookieVal = getAdFreeCookie(); | ||
if (!cookieVal) return false; | ||
return !Number.isNaN(parseInt(cookieVal, 10)); | ||
}; | ||
|
||
export const removeAdFreeCookie = (): void => | ||
removeCookie({ name: AD_FREE_USER_COOKIE }); |
16 changes: 16 additions & 0 deletions
16
dotcom-rendering/src/client/userFeatures/cookies/hideSupportMessaging.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { getCookie, removeCookie, setCookie } from '@guardian/libs'; | ||
|
||
const HIDE_SUPPORT_MESSAGING_COOKIE = 'gu_hide_support_messaging'; | ||
|
||
export const getHideSupportMessagingCookie = (): string | null => | ||
getCookie({ name: HIDE_SUPPORT_MESSAGING_COOKIE }); | ||
|
||
export const setHideSupportMessagingCookie = (value: boolean): void => { | ||
setCookie({ | ||
name: HIDE_SUPPORT_MESSAGING_COOKIE, | ||
value: String(value), | ||
}); | ||
}; | ||
|
||
export const removeHideSupportMessagingCookie = (): void => | ||
removeCookie({ name: HIDE_SUPPORT_MESSAGING_COOKIE }); |
20 changes: 20 additions & 0 deletions
20
dotcom-rendering/src/client/userFeatures/cookies/userFeaturesExpiry.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { getCookie, removeCookie, setCookie } from '@guardian/libs'; | ||
|
||
const USER_FEATURES_EXPIRY_COOKIE = 'gu_user_features_expiry'; | ||
|
||
export const getUserFeaturesExpiryCookie = (): string | null => | ||
getCookie({ name: USER_FEATURES_EXPIRY_COOKIE }); | ||
|
||
export const setUserFeaturesExpiryCookie = (expiryTime: string): void => | ||
setCookie({ name: USER_FEATURES_EXPIRY_COOKIE, value: expiryTime }); | ||
|
||
export const removeUserFeaturesExpiryCookie = (): void => | ||
removeCookie({ name: USER_FEATURES_EXPIRY_COOKIE }); | ||
|
||
export const featuresDataIsOld = (): boolean => { | ||
const cookie = getUserFeaturesExpiryCookie(); | ||
if (!cookie) return true; | ||
const expiryTime = parseInt(cookie, 10); | ||
const timeNow = new Date().getTime(); | ||
return timeNow >= expiryTime; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
export const fetchJson = async ( | ||
path: string, | ||
init: RequestInit = {}, | ||
): Promise<unknown> => { | ||
const resp = await fetch(path, init); | ||
if (resp.ok) { | ||
try { | ||
return resp.json(); | ||
} catch (ex) { | ||
throw new Error( | ||
`Fetch error while requesting ${path}: Invalid JSON response`, | ||
); | ||
} | ||
} | ||
throw new Error(`Fetch error while requesting ${path}: ${resp.statusText}`); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97 changes: 0 additions & 97 deletions
97
dotcom-rendering/src/client/userFeatures/user-features-lib.ts
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.