@rudderstack/analytics-js-cookies
Advanced tools
Comparing version 0.1.0 to 0.2.0
@@ -5,2 +5,9 @@ # Changelog | ||
## [0.2.0](https://github.com/rudderlabs/rudder-sdk-js/compare/@rudderstack/analytics-js-cookies@0.1.0...@rudderstack/analytics-js-cookies@0.2.0) (2024-06-25) | ||
### Features | ||
* add getDecryptedValue utility ([#1762](https://github.com/rudderlabs/rudder-sdk-js/issues/1762)) ([04cf7e9](https://github.com/rudderlabs/rudder-sdk-js/commit/04cf7e996a6dd09e6c83fff8606135c3941d34c8)) | ||
## 0.1.0 (2024-06-25) | ||
@@ -7,0 +14,0 @@ |
@@ -11,2 +11,3 @@ type Nullable<T> = T | null; | ||
declare const getDecryptedValue: (value: string) => Nullable<string | ApiObject>; | ||
declare const getDecryptedCookie: (cookieKey: string) => Nullable<string | ApiObject>; | ||
@@ -25,2 +26,2 @@ //# sourceMappingURL=cookiesUtilities.d.ts.map | ||
export { anonymousUserIdKey, authTokenKey, getDecryptedCookie, groupIdKey, groupTraitsKey, pageInitialReferrerKey, pageInitialReferringDomainKey, sessionInfoKey, userIdKey, userTraitsKey }; | ||
export { anonymousUserIdKey, authTokenKey, getDecryptedCookie, getDecryptedValue, groupIdKey, groupTraitsKey, pageInitialReferrerKey, pageInitialReferringDomainKey, sessionInfoKey, userIdKey, userTraitsKey }; |
@@ -100,3 +100,3 @@ 'use strict'; | ||
const decrypt=value=>{if(value!==null&&value!==void 0&&value.startsWith(ENCRYPTION_PREFIX_V3)){return fromBase64(value.substring(ENCRYPTION_PREFIX_V3.length));}return value;};const getDecryptedCookie=cookieKey=>{const fallbackValue=null;try{if(Object.values(COOKIE_KEYS).includes(cookieKey)){const decryptedVal=decrypt(cookie(cookieKey));if(isNullOrUndefined(decryptedVal)){return fallbackValue;}return JSON.parse(decryptedVal);}return fallbackValue;}catch(err){return fallbackValue;}}; | ||
const decrypt=value=>{if(value!==null&&value!==void 0&&value.startsWith(ENCRYPTION_PREFIX_V3)){return fromBase64(value.substring(ENCRYPTION_PREFIX_V3.length));}return value;};const getDecryptedValue=value=>{const fallbackValue=null;try{const decryptedVal=decrypt(value);if(isNullOrUndefined(decryptedVal)){return fallbackValue;}return JSON.parse(decryptedVal);}catch(err){return fallbackValue;}};const getDecryptedCookie=cookieKey=>{if(Object.values(COOKIE_KEYS).includes(cookieKey)){return getDecryptedValue(cookie(cookieKey));}return null;}; | ||
@@ -106,2 +106,3 @@ exports.anonymousUserIdKey = anonymousUserIdKey; | ||
exports.getDecryptedCookie = getDecryptedCookie; | ||
exports.getDecryptedValue = getDecryptedValue; | ||
exports.groupIdKey = groupIdKey; | ||
@@ -108,0 +109,0 @@ exports.groupTraitsKey = groupTraitsKey; |
@@ -96,4 +96,4 @@ /** | ||
const decrypt=value=>{if(value!==null&&value!==void 0&&value.startsWith(ENCRYPTION_PREFIX_V3)){return fromBase64(value.substring(ENCRYPTION_PREFIX_V3.length));}return value;};const getDecryptedCookie=cookieKey=>{const fallbackValue=null;try{if(Object.values(COOKIE_KEYS).includes(cookieKey)){const decryptedVal=decrypt(cookie(cookieKey));if(isNullOrUndefined(decryptedVal)){return fallbackValue;}return JSON.parse(decryptedVal);}return fallbackValue;}catch(err){return fallbackValue;}}; | ||
const decrypt=value=>{if(value!==null&&value!==void 0&&value.startsWith(ENCRYPTION_PREFIX_V3)){return fromBase64(value.substring(ENCRYPTION_PREFIX_V3.length));}return value;};const getDecryptedValue=value=>{const fallbackValue=null;try{const decryptedVal=decrypt(value);if(isNullOrUndefined(decryptedVal)){return fallbackValue;}return JSON.parse(decryptedVal);}catch(err){return fallbackValue;}};const getDecryptedCookie=cookieKey=>{if(Object.values(COOKIE_KEYS).includes(cookieKey)){return getDecryptedValue(cookie(cookieKey));}return null;}; | ||
export { anonymousUserIdKey, authTokenKey, getDecryptedCookie, groupIdKey, groupTraitsKey, pageInitialReferrerKey, pageInitialReferringDomainKey, sessionInfoKey, userIdKey, userTraitsKey }; | ||
export { anonymousUserIdKey, authTokenKey, getDecryptedCookie, getDecryptedValue, groupIdKey, groupTraitsKey, pageInitialReferrerKey, pageInitialReferringDomainKey, sessionInfoKey, userIdKey, userTraitsKey }; |
@@ -102,3 +102,3 @@ (function (global, factory) { | ||
const decrypt=value=>{if(value!==null&&value!==void 0&&value.startsWith(ENCRYPTION_PREFIX_V3)){return fromBase64(value.substring(ENCRYPTION_PREFIX_V3.length));}return value;};const getDecryptedCookie=cookieKey=>{const fallbackValue=null;try{if(Object.values(COOKIE_KEYS).includes(cookieKey)){const decryptedVal=decrypt(cookie(cookieKey));if(isNullOrUndefined(decryptedVal)){return fallbackValue;}return JSON.parse(decryptedVal);}return fallbackValue;}catch(err){return fallbackValue;}}; | ||
const decrypt=value=>{if(value!==null&&value!==void 0&&value.startsWith(ENCRYPTION_PREFIX_V3)){return fromBase64(value.substring(ENCRYPTION_PREFIX_V3.length));}return value;};const getDecryptedValue=value=>{const fallbackValue=null;try{const decryptedVal=decrypt(value);if(isNullOrUndefined(decryptedVal)){return fallbackValue;}return JSON.parse(decryptedVal);}catch(err){return fallbackValue;}};const getDecryptedCookie=cookieKey=>{if(Object.values(COOKIE_KEYS).includes(cookieKey)){return getDecryptedValue(cookie(cookieKey));}return null;}; | ||
@@ -108,2 +108,3 @@ exports.anonymousUserIdKey = anonymousUserIdKey; | ||
exports.getDecryptedCookie = getDecryptedCookie; | ||
exports.getDecryptedValue = getDecryptedValue; | ||
exports.groupIdKey = groupIdKey; | ||
@@ -110,0 +111,0 @@ exports.groupTraitsKey = groupTraitsKey; |
{ | ||
"name": "@rudderstack/analytics-js-cookies", | ||
"version": "0.1.0", | ||
"description": "RudderStack JavaScript SDK Cookies Module", | ||
"version": "0.2.0", | ||
"description": "RudderStack JavaScript SDK Cookies Utilities", | ||
"main": "dist/npm/modern/cjs/index.js", | ||
@@ -6,0 +6,0 @@ "module": "dist/npm/modern/esm/index.js", |
@@ -28,2 +28,19 @@ ## [![TypeScript](https://img.shields.io/badge/%3C%2F%3E-TypeScript-%230074c1.svg)](https://www.typescriptlang.org/) | ||
### `getDecryptedValue` | ||
This function decrypts the provided encrypted RudderStack JavaScript cookie value using the RudderStack JavaScript SDK encryption version "v3". | ||
> The encrypted value should be a string starting with `RS_ENC_v3_`. | ||
> If the provided value is not properly encrypted, the function will throw an exception. | ||
```javascript | ||
import { decrypt } from '@rudderstack/analytics-js-cookies'; | ||
const encryptedCookieValue = 'RS_ENC_v3_InRlc3QtZGF0YSI='; | ||
const decryptedCookieValue = decrypt(encryptedCookieValue); | ||
console.log('Decrypted Cookie Value: ', decryptedCookieValue); | ||
// Output: Decrypted Cookie Value: test-data | ||
``` | ||
### `getDecryptedCookie` | ||
@@ -43,7 +60,6 @@ | ||
> If unencrypted, the cookie value will be returned as is. | ||
> Any errors during decryption are swallowed by the function, returning `null`. | ||
The following are the available cookie key exports: | ||
- `userIdKey`: The key for the user ID cookie. | ||
@@ -59,3 +75,2 @@ - `userTraitsKey`: The key for the user traits cookie. | ||
```javascript | ||
@@ -62,0 +77,0 @@ import { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
46202
11
665
94