@posthog/core 1.71.0 → 1.71.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cookie.d.ts +9 -0
- package/dist/cookie.d.ts.map +1 -1
- package/dist/cookie.js +4 -1
- package/dist/cookie.mjs +5 -2
- package/dist/utils/string-utils.js +2 -2
- package/dist/utils/string-utils.mjs +2 -2
- package/package.json +1 -1
- package/src/cookie.ts +17 -3
- package/src/utils/string-utils.ts +1 -1
package/dist/cookie.d.ts
CHANGED
|
@@ -69,5 +69,14 @@ export declare function getConsentCookieName(apiKey: string, config?: ConsentCoo
|
|
|
69
69
|
export interface ConsentConfig extends ConsentCookieConfig {
|
|
70
70
|
opt_out_capturing_by_default?: boolean;
|
|
71
71
|
}
|
|
72
|
+
/**
|
|
73
|
+
* Determines whether capturing is opted out based on the consent cookie and config.
|
|
74
|
+
*
|
|
75
|
+
* Evaluates the consent cookie as a tri-state:
|
|
76
|
+
* - Yes-like values (`'1'`, `'true'`, `'yes'`) return `false` (opted in).
|
|
77
|
+
* - No-like values (`'0'`, `'false'`, `'no'`) return `true` (opted out).
|
|
78
|
+
* - Missing, empty, or unrecognized values are treated as pending and fall back to
|
|
79
|
+
* `config?.opt_out_capturing_by_default ?? false`.
|
|
80
|
+
*/
|
|
72
81
|
export declare function isOptedOut(cookies: CookieStore, apiKey: string, config?: ConsentConfig): boolean;
|
|
73
82
|
//# sourceMappingURL=cookie.d.ts.map
|
package/dist/cookie.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cookie.d.ts","sourceRoot":"","sources":["../src/cookie.ts"],"names":[],"mappings":"AAMA;;;GAGG;AACH,MAAM,WAAW,WAAW;IAC1B,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG;QAAE,KAAK,EAAE,MAAM,CAAA;KAAE,GAAG,SAAS,CAAA;CACjD;AAED;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,YAAY,EAA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D;AAID,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,mBAAmB,GAAG,MAAM,CAQzF;AAED,MAAM,WAAW,aAAc,SAAQ,mBAAmB;IACxD,4BAA4B,CAAC,EAAE,OAAO,CAAA;CACvC;AAED;;;;;;;;GAQG;AACH,wBAAgB,UAAU,CAAC,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,aAAa,GAAG,OAAO,CAehG"}
|
package/dist/cookie.js
CHANGED
|
@@ -121,7 +121,10 @@ function getConsentCookieName(apiKey, config) {
|
|
|
121
121
|
function isOptedOut(cookies, apiKey, config) {
|
|
122
122
|
const cookieName = getConsentCookieName(apiKey, config);
|
|
123
123
|
const cookie = cookies.get(cookieName);
|
|
124
|
-
if (cookie)
|
|
124
|
+
if (cookie) {
|
|
125
|
+
if ((0, index_js_namespaceObject.isYesLike)(cookie.value)) return false;
|
|
126
|
+
if ((0, index_js_namespaceObject.isNoLike)(cookie.value)) return true;
|
|
127
|
+
}
|
|
125
128
|
return config?.opt_out_capturing_by_default ?? false;
|
|
126
129
|
}
|
|
127
130
|
exports.cookieStateToProperties = __webpack_exports__.cookieStateToProperties;
|
package/dist/cookie.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isArray, isNoLike } from "./utils/index.mjs";
|
|
1
|
+
import { isArray, isNoLike, isYesLike } from "./utils/index.mjs";
|
|
2
2
|
import { uuidv7 } from "./vendor/uuidv7.mjs";
|
|
3
3
|
const COOKIE_PREFIX = 'ph_';
|
|
4
4
|
const COOKIE_SUFFIX = '_posthog';
|
|
@@ -82,7 +82,10 @@ function getConsentCookieName(apiKey, config) {
|
|
|
82
82
|
function isOptedOut(cookies, apiKey, config) {
|
|
83
83
|
const cookieName = getConsentCookieName(apiKey, config);
|
|
84
84
|
const cookie = cookies.get(cookieName);
|
|
85
|
-
if (cookie)
|
|
85
|
+
if (cookie) {
|
|
86
|
+
if (isYesLike(cookie.value)) return false;
|
|
87
|
+
if (isNoLike(cookie.value)) return true;
|
|
88
|
+
}
|
|
86
89
|
return config?.opt_out_capturing_by_default ?? false;
|
|
87
90
|
}
|
|
88
91
|
export { cookieStateToProperties, cookieStoreFromHeader, getConsentCookieName, getPostHogCookieName, isOptedOut, parsePostHogCookie, readPostHogCookie, serializePostHogCookie };
|
|
@@ -37,10 +37,10 @@ const stripLeadingDollar = function(s) {
|
|
|
37
37
|
return s.replace(/^\$/, '');
|
|
38
38
|
};
|
|
39
39
|
function isDistinctIdStringLike(value) {
|
|
40
|
-
return [
|
|
40
|
+
return includes([
|
|
41
41
|
'distinct_id',
|
|
42
42
|
'distinctid'
|
|
43
|
-
]
|
|
43
|
+
], value.toLowerCase());
|
|
44
44
|
}
|
|
45
45
|
function safeJsonStringify(value) {
|
|
46
46
|
const ancestors = [];
|
|
@@ -8,10 +8,10 @@ const stripLeadingDollar = function(s) {
|
|
|
8
8
|
return s.replace(/^\$/, '');
|
|
9
9
|
};
|
|
10
10
|
function isDistinctIdStringLike(value) {
|
|
11
|
-
return [
|
|
11
|
+
return includes([
|
|
12
12
|
'distinct_id',
|
|
13
13
|
'distinctid'
|
|
14
|
-
]
|
|
14
|
+
], value.toLowerCase());
|
|
15
15
|
}
|
|
16
16
|
function safeJsonStringify(value) {
|
|
17
17
|
const ancestors = [];
|
package/package.json
CHANGED
package/src/cookie.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isArray, isNoLike } from './utils'
|
|
1
|
+
import { isArray, isNoLike, isYesLike } from './utils'
|
|
2
2
|
import { uuidv7 } from './vendor/uuidv7'
|
|
3
3
|
|
|
4
4
|
const COOKIE_PREFIX = 'ph_'
|
|
@@ -171,14 +171,28 @@ export interface ConsentConfig extends ConsentCookieConfig {
|
|
|
171
171
|
opt_out_capturing_by_default?: boolean
|
|
172
172
|
}
|
|
173
173
|
|
|
174
|
+
/**
|
|
175
|
+
* Determines whether capturing is opted out based on the consent cookie and config.
|
|
176
|
+
*
|
|
177
|
+
* Evaluates the consent cookie as a tri-state:
|
|
178
|
+
* - Yes-like values (`'1'`, `'true'`, `'yes'`) return `false` (opted in).
|
|
179
|
+
* - No-like values (`'0'`, `'false'`, `'no'`) return `true` (opted out).
|
|
180
|
+
* - Missing, empty, or unrecognized values are treated as pending and fall back to
|
|
181
|
+
* `config?.opt_out_capturing_by_default ?? false`.
|
|
182
|
+
*/
|
|
174
183
|
export function isOptedOut(cookies: CookieStore, apiKey: string, config?: ConsentConfig): boolean {
|
|
175
184
|
const cookieName = getConsentCookieName(apiKey, config)
|
|
176
185
|
const cookie = cookies.get(cookieName)
|
|
177
186
|
|
|
178
187
|
if (cookie) {
|
|
179
|
-
|
|
188
|
+
if (isYesLike(cookie.value)) {
|
|
189
|
+
return false
|
|
190
|
+
}
|
|
191
|
+
if (isNoLike(cookie.value)) {
|
|
192
|
+
return true
|
|
193
|
+
}
|
|
180
194
|
}
|
|
181
195
|
|
|
182
|
-
//
|
|
196
|
+
// Missing, empty, or unrecognized consent cookie means pending — defer to config
|
|
183
197
|
return config?.opt_out_capturing_by_default ?? false
|
|
184
198
|
}
|
|
@@ -21,7 +21,7 @@ export const stripLeadingDollar = function (s: string): string {
|
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
export function isDistinctIdStringLike(value: string): boolean {
|
|
24
|
-
return ['distinct_id', 'distinctid']
|
|
24
|
+
return includes(['distinct_id', 'distinctid'], value.toLowerCase())
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
export function safeJsonStringify(value: unknown): string {
|