@posthog/browser 0.5.0 → 0.6.0
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/ARCHITECTURE.md +17 -17
- package/README.md +42 -7
- package/dist/composition/npm/core.d.ts +1 -1
- package/dist/composition/npm/index.d.ts +2 -2
- package/dist/core/posthog.js +88 -14
- package/dist/core/posthog.mjs +88 -14
- package/dist/core/state/state.d.ts +32 -3
- package/dist/core/state/state.js +117 -25
- package/dist/core/state/state.mjs +105 -25
- package/dist/core/types.d.ts +87 -5
- package/dist/persistence/cookie.d.ts +19 -0
- package/dist/persistence/cookie.js +273 -0
- package/dist/persistence/cookie.mjs +235 -0
- package/dist/platform/logger.d.ts +5 -1
- package/dist/platform/logger.js +3 -3
- package/dist/platform/logger.mjs +3 -3
- package/dist/primitives/id.d.ts +5 -0
- package/dist/primitives/id.js +10 -2
- package/dist/primitives/id.mjs +6 -1
- package/dist/primitives/version.js +1 -1
- package/dist/primitives/version.mjs +1 -1
- package/dist/products/analytics/analytics-core.d.ts +17 -4
- package/dist/products/analytics/analytics-core.js +101 -10
- package/dist/products/analytics/analytics-core.mjs +101 -10
- package/dist/products/analytics/analytics-internal.d.ts +3 -2
- package/dist/products/analytics/delivery/analytics-delivery.js +1 -1
- package/dist/products/analytics/delivery/analytics-delivery.mjs +1 -1
- package/dist/products/analytics/delivery/lane.d.ts +8 -1
- package/dist/products/analytics/delivery/lane.js +16 -4
- package/dist/products/analytics/delivery/lane.mjs +16 -4
- package/dist/products/analytics/groups.js +1 -1
- package/dist/products/analytics/groups.mjs +1 -1
- package/dist/products/analytics/person.js +1 -1
- package/dist/products/analytics/person.mjs +1 -1
- package/dist/products/analytics/properties/analytics-properties.d.ts +1 -0
- package/dist/products/analytics/properties/analytics-properties.js +3 -0
- package/dist/products/analytics/properties/analytics-properties.mjs +1 -1
- package/dist/products/flags/flags-internal.d.ts +3 -0
- package/dist/products/flags/flags-options.d.ts +16 -2
- package/dist/products/flags/flags-token.d.ts +28 -2
- package/dist/products/flags/flags.d.ts +1 -1
- package/dist/products/flags/flags.js +110 -4
- package/dist/products/flags/flags.mjs +110 -4
- package/dist/products/surveys/surveys-extension.js +75 -26
- package/dist/products/surveys/surveys-extension.mjs +77 -28
- package/dist/products/surveys/surveys-internal.d.ts +6 -0
- package/package.json +9 -4
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type { KeyValueStore, SessionContext } from '@posthog/browser-common';
|
|
2
|
-
import type { NewSessionReason, StorageLike } from '../types';
|
|
2
|
+
import type { CookiePersistence, NewSessionReason, StorageLike } from '../types';
|
|
3
3
|
export declare const CLIENT_KV_NAMESPACE = "core";
|
|
4
4
|
export type ConsentState = 'implicit' | 'granted' | 'denied';
|
|
5
|
+
type ConsentChoice = Exclude<ConsentState, 'implicit'>;
|
|
5
6
|
interface PersistedSession {
|
|
6
7
|
sessionId: string;
|
|
7
8
|
sessionStartTimestamp: number;
|
|
@@ -20,11 +21,19 @@ interface PreparedSession {
|
|
|
20
21
|
readonly previousWindowStorageInitialized: boolean;
|
|
21
22
|
readonly previousPendingReason: 'reset' | undefined;
|
|
22
23
|
}
|
|
24
|
+
export declare const isRecord: (value: unknown) => value is Record<string, unknown>;
|
|
25
|
+
export declare const isTimestamp: (value: unknown) => value is number;
|
|
26
|
+
export declare const incrementRevision: (revision: string) => string;
|
|
27
|
+
/** A caller-supplied session ID and the start time encoded in it. */
|
|
28
|
+
type BootstrapSession = [sessionId: string, sessionStartTimestamp: number];
|
|
29
|
+
/** Reads a UUIDv7 session ID's start time, rejecting IDs more than a minute in the future. */
|
|
30
|
+
export declare const readBootstrapSession: (sessionId: unknown, now?: number) => BootstrapSession | undefined;
|
|
23
31
|
export declare const getDefaultStorage: () => StorageLike | undefined;
|
|
24
32
|
export declare const getDefaultSessionStorage: () => StorageLike | undefined;
|
|
25
33
|
export declare class BrowserState {
|
|
26
34
|
private _state;
|
|
27
35
|
private _consent;
|
|
36
|
+
private _consentChoice;
|
|
28
37
|
private readonly _stateKey;
|
|
29
38
|
readonly consentKey: string;
|
|
30
39
|
private readonly _windowKey;
|
|
@@ -35,7 +44,12 @@ export declare class BrowserState {
|
|
|
35
44
|
private _windowListenerInstalled;
|
|
36
45
|
private _lastActivityWriteTimestamp;
|
|
37
46
|
private _pendingSessionReason;
|
|
47
|
+
private _bootstrapSession;
|
|
38
48
|
private _stateReadPending;
|
|
49
|
+
private _generated;
|
|
50
|
+
private readonly _sharesIdentity;
|
|
51
|
+
/** The stored identity this context last read, which a sibling subdomain's change replaces. */
|
|
52
|
+
private _storedIdentity;
|
|
39
53
|
private _lastConsentValue;
|
|
40
54
|
private _ignoredConsentValue;
|
|
41
55
|
private _hasIgnoredConsentValue;
|
|
@@ -44,8 +58,15 @@ export declare class BrowserState {
|
|
|
44
58
|
private readonly _defaultConsent;
|
|
45
59
|
private readonly _onConsentChange;
|
|
46
60
|
private readonly _beforeUnload;
|
|
47
|
-
constructor(projectToken: string, storage: StorageLike | undefined, persistenceKey: string | undefined, consentPersistenceName: string | undefined, optOutByDefault: boolean, windowStorageFactory: (() => StorageLike | undefined) | undefined, onConsentChange: (consent: ConsentState, previousConsent: ConsentState) => void);
|
|
61
|
+
constructor(projectToken: string, storage: StorageLike | undefined, persistenceKey: string | undefined, consentPersistenceName: string | undefined, optOutByDefault: boolean, windowStorageFactory: (() => StorageLike | undefined) | undefined, onConsentChange: (consent: ConsentState, previousConsent: ConsentState, explicit: boolean) => void, cookie?: CookiePersistence);
|
|
48
62
|
prepare(): boolean;
|
|
63
|
+
/**
|
|
64
|
+
* Adopts an identity that another subdomain stored since this context last read it, as posthog-js does before
|
|
65
|
+
* each identity operation and event. Session authority still follows revisions. Returns whether it changed.
|
|
66
|
+
*/
|
|
67
|
+
adoptStoredIdentity(): boolean;
|
|
68
|
+
/** Whether this identity was generated rather than read from storage, including a later successful read. */
|
|
69
|
+
get generated(): boolean;
|
|
49
70
|
get deviceId(): string;
|
|
50
71
|
get anonymousId(): string;
|
|
51
72
|
get distinctId(): string;
|
|
@@ -55,17 +76,25 @@ export declare class BrowserState {
|
|
|
55
76
|
get activeSessionId(): string | undefined;
|
|
56
77
|
get session(): SessionContext | undefined;
|
|
57
78
|
get consent(): ConsentState;
|
|
79
|
+
/** The persisted opt-in or opt-out choice, independently of `optOutByDefault`. */
|
|
80
|
+
get consentChoice(): ConsentChoice | undefined;
|
|
58
81
|
refreshConsent(): ConsentState;
|
|
59
82
|
observeConsent(value: unknown): ConsentState;
|
|
60
83
|
identify(distinctId: string): void;
|
|
84
|
+
/** Seeds a generated identity. An anonymous ID also becomes the device ID, as in posthog-js. */
|
|
85
|
+
bootstrapIdentity(distinctId: string, identified: boolean): void;
|
|
86
|
+
/** Uses the session for the next admitted event unless it has exceeded the maximum session length by then. */
|
|
87
|
+
bootstrapSession(session: BootstrapSession): void;
|
|
61
88
|
group(type: string, key: string): boolean;
|
|
62
89
|
resetGroups(): void;
|
|
63
90
|
prepareSessionForEvent(now?: number): PreparedSession;
|
|
64
91
|
sessionAdmitted(prepared: PreparedSession): boolean;
|
|
65
|
-
reset(): void;
|
|
92
|
+
reset(resetDeviceId?: boolean, bootstrap?: readonly [distinctId: string, identified: boolean], bootstrapSession?: BootstrapSession): void;
|
|
66
93
|
dispose(): void;
|
|
67
94
|
optIn(): boolean;
|
|
68
95
|
optOut(): boolean;
|
|
96
|
+
/** Forgets the persisted choice, returning consent to the configured default. */
|
|
97
|
+
clearConsent(): boolean;
|
|
69
98
|
keyValueStore(namespace: string, canAccess?: () => boolean): KeyValueStore;
|
|
70
99
|
tabKeyValueStore(namespace: string, canAccess: () => boolean): KeyValueStore;
|
|
71
100
|
private _tabStorage;
|
package/dist/core/state/state.js
CHANGED
|
@@ -31,12 +31,17 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
31
31
|
BrowserState: ()=>BrowserState,
|
|
32
32
|
CLIENT_KV_NAMESPACE: ()=>CLIENT_KV_NAMESPACE,
|
|
33
33
|
getDefaultSessionStorage: ()=>getDefaultSessionStorage,
|
|
34
|
-
getDefaultStorage: ()=>getDefaultStorage
|
|
34
|
+
getDefaultStorage: ()=>getDefaultStorage,
|
|
35
|
+
incrementRevision: ()=>incrementRevision,
|
|
36
|
+
isRecord: ()=>isRecord,
|
|
37
|
+
isTimestamp: ()=>isTimestamp,
|
|
38
|
+
readBootstrapSession: ()=>readBootstrapSession
|
|
35
39
|
});
|
|
36
40
|
const id_js_namespaceObject = require("../../primitives/id.js");
|
|
37
41
|
const external_key_value_store_js_namespaceObject = require("./key-value-store.js");
|
|
38
42
|
const CLIENT_KV_NAMESPACE = 'core';
|
|
39
43
|
const STORED_GROUP_PROPERTIES_KEY = '$stored_group_properties';
|
|
44
|
+
const SESSION_MAX_LENGTH_MS = 86400000;
|
|
40
45
|
const emptyRecord = ()=>Object.create(null);
|
|
41
46
|
const isRecord = (value)=>'object' == typeof value && null !== value && !Array.isArray(value);
|
|
42
47
|
const readGroups = (value)=>{
|
|
@@ -51,7 +56,7 @@ const sessionExpiryReason = (session, now)=>{
|
|
|
51
56
|
if (!session) return;
|
|
52
57
|
const safeNow = isTimestamp(now) ? now : 0;
|
|
53
58
|
if (Math.abs(safeNow - session.lastActivityTimestamp) > 1800000) return 'idleTimeout';
|
|
54
|
-
if (Math.abs(safeNow - session.sessionStartTimestamp) >
|
|
59
|
+
if (Math.abs(safeNow - session.sessionStartTimestamp) > SESSION_MAX_LENGTH_MS) return 'maxLength';
|
|
55
60
|
};
|
|
56
61
|
const readRevision = (value, fallback)=>{
|
|
57
62
|
if ('string' == typeof value && /^(0|[1-9]\d*)$/.test(value)) return value;
|
|
@@ -100,12 +105,23 @@ const readExtensionData = (value)=>{
|
|
|
100
105
|
});
|
|
101
106
|
return extensionData;
|
|
102
107
|
};
|
|
103
|
-
const createSession = (now, revision
|
|
104
|
-
|
|
105
|
-
|
|
108
|
+
const createSession = (now, revision, [sessionId, sessionStartTimestamp] = [
|
|
109
|
+
(0, id_js_namespaceObject.createTimeId)(now),
|
|
110
|
+
now
|
|
111
|
+
])=>({
|
|
112
|
+
sessionId,
|
|
113
|
+
sessionStartTimestamp,
|
|
106
114
|
lastActivityTimestamp: now,
|
|
107
115
|
revision
|
|
108
116
|
});
|
|
117
|
+
const readBootstrapSession = (sessionId, now = Date.now())=>{
|
|
118
|
+
const hex = 'string' == typeof sessionId ? sessionId.replace(/-/g, '') : '';
|
|
119
|
+
const start = /^[0-9a-f]{12}7[0-9a-f]{19}$/i.test(hex) ? parseInt(hex.slice(0, 12), 16) : 0 / 0;
|
|
120
|
+
return start <= now + 60000 ? [
|
|
121
|
+
sessionId,
|
|
122
|
+
start
|
|
123
|
+
] : void 0;
|
|
124
|
+
};
|
|
109
125
|
const authorityRevision = (state)=>state?.session?.revision ?? state?.sessionReset;
|
|
110
126
|
const persistedAuthorityWins = (persisted, local)=>{
|
|
111
127
|
const persistedRevision = authorityRevision(persisted);
|
|
@@ -139,6 +155,16 @@ const createInitialState = (deviceId = (0, id_js_namespaceObject.createId)(), an
|
|
|
139
155
|
groups: emptyRecord(),
|
|
140
156
|
extensionData: emptyRecord()
|
|
141
157
|
});
|
|
158
|
+
const identityOf = (state)=>JSON.stringify([
|
|
159
|
+
state.distinctId,
|
|
160
|
+
state.isIdentified,
|
|
161
|
+
state.deviceId
|
|
162
|
+
]);
|
|
163
|
+
const seedIdentity = (state, distinctId, identified)=>{
|
|
164
|
+
state.distinctId = distinctId;
|
|
165
|
+
if (identified) state.isIdentified = true;
|
|
166
|
+
else state.anonymousId = distinctId;
|
|
167
|
+
};
|
|
142
168
|
const decodeConsent = (value)=>{
|
|
143
169
|
const normalized = 'string' == typeof value ? value.trim().toLowerCase() : value;
|
|
144
170
|
return true === normalized || 1 === normalized || '1' === normalized || 'true' === normalized || 'yes' === normalized ? 'granted' : false === normalized || 0 === normalized || '0' === normalized || 'false' === normalized || 'no' === normalized ? 'denied' : void 0;
|
|
@@ -190,7 +216,7 @@ const getDefaultSessionStorage = ()=>{
|
|
|
190
216
|
}
|
|
191
217
|
};
|
|
192
218
|
class BrowserState {
|
|
193
|
-
constructor(projectToken, storage, persistenceKey, consentPersistenceName, optOutByDefault, windowStorageFactory, onConsentChange){
|
|
219
|
+
constructor(projectToken, storage, persistenceKey, consentPersistenceName, optOutByDefault, windowStorageFactory, onConsentChange, cookie){
|
|
194
220
|
this._windowId = '';
|
|
195
221
|
this._windowStorageInitialized = false;
|
|
196
222
|
this._windowListenerInstalled = false;
|
|
@@ -202,9 +228,14 @@ class BrowserState {
|
|
|
202
228
|
this._flushSession();
|
|
203
229
|
this._windowRemove(this._primaryWindowKey);
|
|
204
230
|
};
|
|
205
|
-
this._storage = storage;
|
|
206
|
-
this._windowStorageFactory = windowStorageFactory;
|
|
207
231
|
this._stateKey = persistenceKey ?? `ph_${projectToken}_posthog_browser_v2`;
|
|
232
|
+
try {
|
|
233
|
+
this._storage = storage && cookie ? cookie.wrap(storage, this._stateKey, projectToken) : storage;
|
|
234
|
+
} catch {
|
|
235
|
+
this._storage = storage;
|
|
236
|
+
}
|
|
237
|
+
this._sharesIdentity = this._storage !== storage;
|
|
238
|
+
this._windowStorageFactory = windowStorageFactory;
|
|
208
239
|
const windowPrefix = persistenceKey ?? `ph_${projectToken}`;
|
|
209
240
|
this._windowKey = `${windowPrefix}_window_id`;
|
|
210
241
|
this._primaryWindowKey = `${windowPrefix}_primary_window_exists`;
|
|
@@ -215,13 +246,19 @@ class BrowserState {
|
|
|
215
246
|
const [consentRead, storedConsent] = this._read(this.consentKey);
|
|
216
247
|
if (consentRead) {
|
|
217
248
|
this._lastConsentValue = storedConsent;
|
|
218
|
-
this.
|
|
249
|
+
this._consentChoice = decodeConsent(storedConsent);
|
|
250
|
+
this._consent = this._consentChoice ?? this._defaultConsent;
|
|
219
251
|
}
|
|
220
252
|
const [stateRead, storedState] = this._read(this._stateKey);
|
|
221
|
-
|
|
253
|
+
const persisted = parseState('string' == typeof storedState ? storedState : null);
|
|
254
|
+
this._generated = !persisted;
|
|
255
|
+
this._state = persisted ?? createInitialState();
|
|
222
256
|
this._lastActivityWriteTimestamp = this._state.session?.lastActivityTimestamp ?? 0;
|
|
223
257
|
this._stateReadPending = !stateRead;
|
|
224
|
-
if (stateRead)
|
|
258
|
+
if (stateRead) {
|
|
259
|
+
this._save();
|
|
260
|
+
this._storedIdentity = identityOf(this._state);
|
|
261
|
+
}
|
|
225
262
|
}
|
|
226
263
|
prepare() {
|
|
227
264
|
if (!this._stateReadPending) return true;
|
|
@@ -231,10 +268,30 @@ class BrowserState {
|
|
|
231
268
|
const persisted = parseState('string' == typeof storedState ? storedState : null);
|
|
232
269
|
if (persisted) {
|
|
233
270
|
this._state = persisted;
|
|
271
|
+
this._generated = false;
|
|
234
272
|
this._lastActivityWriteTimestamp = persisted.session?.lastActivityTimestamp ?? 0;
|
|
235
273
|
} else this._save(false);
|
|
274
|
+
this._storedIdentity = identityOf(this._state);
|
|
275
|
+
return true;
|
|
276
|
+
}
|
|
277
|
+
adoptStoredIdentity() {
|
|
278
|
+
const known = this._storedIdentity;
|
|
279
|
+
const [, stored] = this._sharesIdentity && known ? this._readPersistedState() : [];
|
|
280
|
+
if (!stored) return false;
|
|
281
|
+
this._storedIdentity = identityOf(stored);
|
|
282
|
+
if (this._storedIdentity === identityOf(this._state)) {
|
|
283
|
+
if (stored.extensionData[CLIENT_KV_NAMESPACE]?.personProcessingEnabled === true) (this._state.extensionData[CLIENT_KV_NAMESPACE] ??= emptyRecord()).personProcessingEnabled = true;
|
|
284
|
+
return false;
|
|
285
|
+
}
|
|
286
|
+
if (this._storedIdentity === known) return false;
|
|
287
|
+
copyAuthority(stored, this._state);
|
|
288
|
+
this._state = stored;
|
|
289
|
+
this._save();
|
|
236
290
|
return true;
|
|
237
291
|
}
|
|
292
|
+
get generated() {
|
|
293
|
+
return this._generated;
|
|
294
|
+
}
|
|
238
295
|
get deviceId() {
|
|
239
296
|
return this._state.deviceId;
|
|
240
297
|
}
|
|
@@ -273,6 +330,10 @@ class BrowserState {
|
|
|
273
330
|
get consent() {
|
|
274
331
|
return this.refreshConsent();
|
|
275
332
|
}
|
|
333
|
+
get consentChoice() {
|
|
334
|
+
this.refreshConsent();
|
|
335
|
+
return this._consentChoice;
|
|
336
|
+
}
|
|
276
337
|
refreshConsent() {
|
|
277
338
|
const [read, value] = this._read(this.consentKey);
|
|
278
339
|
return read ? this.observeConsent(value) : this._consent;
|
|
@@ -281,7 +342,8 @@ class BrowserState {
|
|
|
281
342
|
if (this._hasIgnoredConsentValue && value === this._ignoredConsentValue) return this._consent;
|
|
282
343
|
this._hasIgnoredConsentValue = false;
|
|
283
344
|
this._lastConsentValue = value;
|
|
284
|
-
this.
|
|
345
|
+
this._consentChoice = decodeConsent(value);
|
|
346
|
+
this._applyConsent(this._consentChoice ?? this._defaultConsent);
|
|
285
347
|
return this._consent;
|
|
286
348
|
}
|
|
287
349
|
identify(distinctId) {
|
|
@@ -289,6 +351,14 @@ class BrowserState {
|
|
|
289
351
|
this._state.isIdentified = true;
|
|
290
352
|
this._save();
|
|
291
353
|
}
|
|
354
|
+
bootstrapIdentity(distinctId, identified) {
|
|
355
|
+
seedIdentity(this._state, distinctId, identified);
|
|
356
|
+
if (!identified) this._state.deviceId = distinctId;
|
|
357
|
+
this._save();
|
|
358
|
+
}
|
|
359
|
+
bootstrapSession(session) {
|
|
360
|
+
this._bootstrapSession = session;
|
|
361
|
+
}
|
|
292
362
|
group(type, key) {
|
|
293
363
|
if (this._state.groups[type] === key) return false;
|
|
294
364
|
this._state.groups[type] = key;
|
|
@@ -306,13 +376,14 @@ class BrowserState {
|
|
|
306
376
|
const { external, session, lastActivityWriteTimestamp, adoptedAfterReset } = this._readSessionAuthority();
|
|
307
377
|
const pendingReason = this._pendingSessionReason;
|
|
308
378
|
const expiry = sessionExpiryReason(session, safeNow);
|
|
309
|
-
const
|
|
379
|
+
const bootstrap = this._bootstrapSession && safeNow - this._bootstrapSession[1] <= SESSION_MAX_LENGTH_MS ? this._bootstrapSession : void 0;
|
|
380
|
+
const rotated = !!(pendingReason || !session || expiry || bootstrap && bootstrap[0] !== session.sessionId);
|
|
310
381
|
const reason = adoptedAfterReset ? 'reset' : pendingReason ?? expiry;
|
|
311
|
-
const preparedSession = rotated ? createSession(safeNow, nextRevision(safeNow, this._state, external)) : {
|
|
382
|
+
const preparedSession = rotated ? createSession(safeNow, nextRevision(safeNow, this._state, external), bootstrap) : {
|
|
312
383
|
...session,
|
|
313
384
|
lastActivityTimestamp: Math.max(safeNow, session.lastActivityTimestamp)
|
|
314
385
|
};
|
|
315
|
-
const window = this._prepareWindow(rotated);
|
|
386
|
+
const window = this._prepareWindow(rotated, safeNow);
|
|
316
387
|
return {
|
|
317
388
|
context: {
|
|
318
389
|
sessionId: preparedSession.sessionId,
|
|
@@ -361,17 +432,20 @@ class BrowserState {
|
|
|
361
432
|
else this._clearWindow(true);
|
|
362
433
|
return false;
|
|
363
434
|
}
|
|
435
|
+
this._bootstrapSession = void 0;
|
|
364
436
|
return true;
|
|
365
437
|
}
|
|
366
|
-
reset() {
|
|
438
|
+
reset(resetDeviceId = false, bootstrap, bootstrapSession) {
|
|
367
439
|
const [, external] = this._readPersistedState();
|
|
368
440
|
const now = Date.now();
|
|
369
441
|
const safeNow = isTimestamp(now) ? now : 0;
|
|
370
442
|
const resetRevision = nextRevision(safeNow, this._state, external);
|
|
371
|
-
this._state = createInitialState(this._state.deviceId, (0, id_js_namespaceObject.createId)());
|
|
443
|
+
this._state = createInitialState(resetDeviceId ? (0, id_js_namespaceObject.createId)() : this._state.deviceId, (0, id_js_namespaceObject.createId)());
|
|
444
|
+
if (bootstrap) seedIdentity(this._state, ...bootstrap);
|
|
372
445
|
this._state.sessionReset = resetRevision;
|
|
373
446
|
this._lastActivityWriteTimestamp = 0;
|
|
374
447
|
this._pendingSessionReason = 'reset';
|
|
448
|
+
this._bootstrapSession = bootstrapSession;
|
|
375
449
|
this._clearWindow(true);
|
|
376
450
|
this._save(false);
|
|
377
451
|
}
|
|
@@ -381,14 +455,23 @@ class BrowserState {
|
|
|
381
455
|
this._windowRemove(this._primaryWindowKey);
|
|
382
456
|
}
|
|
383
457
|
optIn() {
|
|
384
|
-
this.
|
|
458
|
+
this._consentChoice = 'granted';
|
|
385
459
|
const written = this._writeConsent('1');
|
|
460
|
+
this._applyConsent('granted');
|
|
386
461
|
this._save();
|
|
387
462
|
return written;
|
|
388
463
|
}
|
|
389
464
|
optOut() {
|
|
465
|
+
this._consentChoice = 'denied';
|
|
466
|
+
const written = this._writeConsent('0');
|
|
390
467
|
this._applyConsent('denied');
|
|
391
|
-
return
|
|
468
|
+
return written;
|
|
469
|
+
}
|
|
470
|
+
clearConsent() {
|
|
471
|
+
this._consentChoice = void 0;
|
|
472
|
+
const written = this._writeConsent(null);
|
|
473
|
+
this._applyConsent(this._defaultConsent);
|
|
474
|
+
return written;
|
|
392
475
|
}
|
|
393
476
|
keyValueStore(namespace, canAccess = ()=>true) {
|
|
394
477
|
return (0, external_key_value_store_js_namespaceObject.createKeyValueStore)({
|
|
@@ -441,9 +524,9 @@ class BrowserState {
|
|
|
441
524
|
adoptedAfterReset: adopted && void 0 !== session && 'reset' === this._pendingSessionReason
|
|
442
525
|
};
|
|
443
526
|
}
|
|
444
|
-
_prepareWindow(rotated) {
|
|
527
|
+
_prepareWindow(rotated, now) {
|
|
445
528
|
if (rotated || this._windowId) return {
|
|
446
|
-
windowId: rotated ? (0, id_js_namespaceObject.
|
|
529
|
+
windowId: rotated ? (0, id_js_namespaceObject.createTimeId)(now) : this._windowId,
|
|
447
530
|
storage: void 0,
|
|
448
531
|
storageResolved: false
|
|
449
532
|
};
|
|
@@ -463,7 +546,7 @@ class BrowserState {
|
|
|
463
546
|
} catch {}
|
|
464
547
|
const reusable = lastWindowId && (!primaryWindowExists || this._isReload()) ? lastWindowId : void 0;
|
|
465
548
|
return {
|
|
466
|
-
windowId: reusable ?? (0, id_js_namespaceObject.
|
|
549
|
+
windowId: reusable ?? (0, id_js_namespaceObject.createTimeId)(now),
|
|
467
550
|
storage,
|
|
468
551
|
storageResolved: true
|
|
469
552
|
};
|
|
@@ -557,7 +640,7 @@ class BrowserState {
|
|
|
557
640
|
const previousConsent = this._consent;
|
|
558
641
|
this._consent = consent;
|
|
559
642
|
try {
|
|
560
|
-
this._onConsentChange(consent, previousConsent);
|
|
643
|
+
this._onConsentChange(consent, previousConsent, void 0 !== this._consentChoice);
|
|
561
644
|
} catch {}
|
|
562
645
|
}
|
|
563
646
|
_save(preserveSession = true) {
|
|
@@ -583,7 +666,8 @@ class BrowserState {
|
|
|
583
666
|
return false;
|
|
584
667
|
}
|
|
585
668
|
try {
|
|
586
|
-
this._storage.
|
|
669
|
+
if (null === value) this._storage.removeItem(this.consentKey);
|
|
670
|
+
else this._storage.setItem(this.consentKey, value);
|
|
587
671
|
this._lastConsentValue = value;
|
|
588
672
|
this._hasIgnoredConsentValue = false;
|
|
589
673
|
return true;
|
|
@@ -615,11 +699,19 @@ exports.BrowserState = __webpack_exports__.BrowserState;
|
|
|
615
699
|
exports.CLIENT_KV_NAMESPACE = __webpack_exports__.CLIENT_KV_NAMESPACE;
|
|
616
700
|
exports.getDefaultSessionStorage = __webpack_exports__.getDefaultSessionStorage;
|
|
617
701
|
exports.getDefaultStorage = __webpack_exports__.getDefaultStorage;
|
|
702
|
+
exports.incrementRevision = __webpack_exports__.incrementRevision;
|
|
703
|
+
exports.isRecord = __webpack_exports__.isRecord;
|
|
704
|
+
exports.isTimestamp = __webpack_exports__.isTimestamp;
|
|
705
|
+
exports.readBootstrapSession = __webpack_exports__.readBootstrapSession;
|
|
618
706
|
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
619
707
|
"BrowserState",
|
|
620
708
|
"CLIENT_KV_NAMESPACE",
|
|
621
709
|
"getDefaultSessionStorage",
|
|
622
|
-
"getDefaultStorage"
|
|
710
|
+
"getDefaultStorage",
|
|
711
|
+
"incrementRevision",
|
|
712
|
+
"isRecord",
|
|
713
|
+
"isTimestamp",
|
|
714
|
+
"readBootstrapSession"
|
|
623
715
|
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
624
716
|
Object.defineProperty(exports, '__esModule', {
|
|
625
717
|
value: true
|