@posthog/core 1.71.3 → 1.71.5
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/featureFlagLocalEvaluation.d.ts.map +1 -1
- package/dist/featureFlagLocalEvaluation.js +116 -36
- package/dist/featureFlagLocalEvaluation.mjs +116 -36
- package/dist/posthog-core.d.ts +1 -1
- package/dist/posthog-core.d.ts.map +1 -1
- package/dist/posthog-core.js +28 -9
- package/dist/posthog-core.mjs +28 -9
- package/package.json +1 -1
- package/src/featureFlagLocalEvaluation.ts +141 -35
- package/src/posthog-core.ts +31 -12
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"featureFlagLocalEvaluation.d.ts","sourceRoot":"","sources":["../src/featureFlagLocalEvaluation.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAEzD,MAAM,MAAM,wBAAwB,GAAG,QAAQ,CAAA;AAE/C,MAAM,MAAM,mBAAmB,GAAG;IAChC,GAAG,EAAE,MAAM,CAAA;IACX,KAAK,EAAE,wBAAwB,CAAA;IAC/B,QAAQ,CAAC,EAAE,MAAM,CAAA;CAClB,CAAA;AAED,MAAM,MAAM,8BAA8B,GAAG,QAAQ,GAAG,mBAAmB,CAAA;AAE3E,MAAM,MAAM,+BAA+B,GAAG;IAC5C,YAAY,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAA;IACxC,mBAAmB,CAAC,EAAE,8BAA8B,CAAA;IACpD,mGAAmG;IACnG,uBAAuB,CAAC,EAAE,MAAM,CAAA;IAChC,8GAA8G;IAC9G,eAAe,CAAC,EAAE,WAAW,CAAC,MAAM,CAAC,CAAA;CACtC,CAAA;AAED,MAAM,MAAM,kBAAkB,GAAG;IAC/B,GAAG,EAAE,MAAM,CAAA;IACX,kBAAkB,EAAE,MAAM,CAAA;CAC3B,CAAA;AAED,MAAM,MAAM,6BA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,MAAM,CAAA;CAAE,GAAG,IAAI,GAAG,SAAS,EACxE,cAAc,EAAE,MAAM,GACrB,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CA0B7B;AAED,wBAAgB,gCAAgC,CAC9C,QAAQ,EAAE,SAAS,kBAAkB,EAAE,GACtC,6BAA6B,EAAE,CASjC;AAED,wBAAsB,qBAAqB,CACzC,GAAG,EAAE,MAAM,EACX,cAAc,EAAE,MAAM,EACtB,QAAQ,EAAE,SAAS,kBAAkB,EAAE,GACtC,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAK7B;AAED,wBAAgB,yBAAyB,CACvC,QAAQ,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,QAAQ,GAAG,SAAS,CAAC,CAAC,GAAG,IAAI,GAAG,SAAS,EAC3E,SAAS,EAAE,gBAAgB,GAAG,IAAI,GAAG,SAAS,GAC7C,QAAQ,GAAG,IAAI,CAMjB"}
|
|
@@ -227,13 +227,65 @@ function exactMatchString(value) {
|
|
|
227
227
|
return serializeJsonValue(value);
|
|
228
228
|
}
|
|
229
229
|
const LITERAL_ESCAPED_PUNCTUATION = /[\x20-\x2f:;=?@\x5b-\x60\x7b-\x7e]/;
|
|
230
|
+
const MAX_UNICODE_CLASS_COPIES = 100;
|
|
231
|
+
const MAX_ATOM_COPIES = 10000;
|
|
232
|
+
const MAX_GROUP_DEPTH = 32;
|
|
233
|
+
function newRegexTerm(atoms, unicodeClasses, consumes) {
|
|
234
|
+
return {
|
|
235
|
+
atoms,
|
|
236
|
+
unicodeClasses,
|
|
237
|
+
consumes,
|
|
238
|
+
variable: false,
|
|
239
|
+
zeroWidthPart: false
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
function addRegexTerm(group, term, copies = 1) {
|
|
243
|
+
group.atoms += term.atoms * copies;
|
|
244
|
+
group.unicodeClasses += term.unicodeClasses * copies;
|
|
245
|
+
group.consumes ||= term.consumes;
|
|
246
|
+
group.variable ||= term.variable;
|
|
247
|
+
group.zeroWidthPart ||= term.zeroWidthPart;
|
|
248
|
+
return group.atoms <= MAX_ATOM_COPIES && group.unicodeClasses <= MAX_UNICODE_CLASS_COPIES;
|
|
249
|
+
}
|
|
250
|
+
function readRegexRepetition(pattern, index) {
|
|
251
|
+
const character = pattern[index];
|
|
252
|
+
if ('*' === character) return {
|
|
253
|
+
length: 1,
|
|
254
|
+
min: 0,
|
|
255
|
+
max: 1 / 0
|
|
256
|
+
};
|
|
257
|
+
if ('+' === character) return {
|
|
258
|
+
length: 1,
|
|
259
|
+
min: 1,
|
|
260
|
+
max: 1 / 0
|
|
261
|
+
};
|
|
262
|
+
if ('?' === character) return {
|
|
263
|
+
length: 1,
|
|
264
|
+
min: 0,
|
|
265
|
+
max: 1
|
|
266
|
+
};
|
|
267
|
+
const counts = /^\{(\d+)(?:,(\d*))?\}/.exec(pattern.slice(index));
|
|
268
|
+
if (!counts || counts.slice(1).some((count)=>Number(count) > 0xffffffff)) return null;
|
|
269
|
+
const min = Number(counts[1]);
|
|
270
|
+
const max = void 0 === counts[2] ? min : '' === counts[2] ? 1 / 0 : Number(counts[2]);
|
|
271
|
+
return {
|
|
272
|
+
length: counts[0].length,
|
|
273
|
+
min,
|
|
274
|
+
max
|
|
275
|
+
};
|
|
276
|
+
}
|
|
230
277
|
function getPortableRegexClasses(pattern) {
|
|
231
278
|
const classes = [];
|
|
279
|
+
const groups = [
|
|
280
|
+
newRegexTerm(0, 0, false)
|
|
281
|
+
];
|
|
282
|
+
let term = null;
|
|
232
283
|
let classStart = -1;
|
|
233
|
-
let
|
|
284
|
+
let classHasUnicode = false;
|
|
234
285
|
for(let index = 0; index < pattern.length; index++){
|
|
235
286
|
const character = pattern[index];
|
|
236
287
|
if (character.charCodeAt(0) > 0x7f) return null;
|
|
288
|
+
const group = groups[groups.length - 1];
|
|
237
289
|
if ('\\' === character) {
|
|
238
290
|
const escaped = pattern[++index];
|
|
239
291
|
if (void 0 === escaped) break;
|
|
@@ -241,49 +293,77 @@ function getPortableRegexClasses(pattern) {
|
|
|
241
293
|
if (!/^[\da-f]{2}$/i.test(pattern.slice(index + 1, index + 3))) return null;
|
|
242
294
|
index += 2;
|
|
243
295
|
} else if (!'dDsSwWbBfnrtv'.includes(escaped) && !LITERAL_ESCAPED_PUNCTUATION.test(escaped)) return null;
|
|
244
|
-
|
|
245
|
-
|
|
296
|
+
const isUnicodeClass = 'dDsSwW'.includes(escaped);
|
|
297
|
+
if (-1 !== classStart) {
|
|
298
|
+
classHasUnicode ||= isUnicodeClass;
|
|
299
|
+
continue;
|
|
300
|
+
}
|
|
301
|
+
if ('bB'.includes(escaped)) return null;
|
|
302
|
+
term = newRegexTerm(1, isUnicodeClass ? 1 : 0, true);
|
|
303
|
+
if (!addRegexTerm(group, term)) return null;
|
|
246
304
|
continue;
|
|
247
305
|
}
|
|
248
|
-
if (
|
|
249
|
-
if (
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
} else if (-1 !== classStart) {
|
|
259
|
-
if ([
|
|
306
|
+
if (-1 !== classStart) {
|
|
307
|
+
if ('[' === character) return null;
|
|
308
|
+
if (']' === character) {
|
|
309
|
+
const contentStart = classStart + ('^' === pattern[classStart + 1] ? 2 : 1);
|
|
310
|
+
if (index === contentStart) return null;
|
|
311
|
+
classes.push(pattern.slice(classStart, index + 1));
|
|
312
|
+
classStart = -1;
|
|
313
|
+
term = newRegexTerm(1, classHasUnicode ? 1 : 0, true);
|
|
314
|
+
if (!addRegexTerm(group, term)) return null;
|
|
315
|
+
} else if ([
|
|
260
316
|
'&&',
|
|
261
317
|
'--',
|
|
262
318
|
'~~'
|
|
263
319
|
].includes(pattern.slice(index, index + 2))) return null;
|
|
264
320
|
continue;
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
if (
|
|
271
|
-
''
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
321
|
+
}
|
|
322
|
+
if ('[' === character) {
|
|
323
|
+
classStart = index;
|
|
324
|
+
classHasUnicode = '^' === pattern[index + 1];
|
|
325
|
+
} else if ('(' === character) {
|
|
326
|
+
if ('?' === pattern[index + 1]) {
|
|
327
|
+
if (':' !== pattern[index + 2]) return null;
|
|
328
|
+
index += 2;
|
|
329
|
+
}
|
|
330
|
+
if (groups.length > MAX_GROUP_DEPTH) return null;
|
|
331
|
+
groups.push(newRegexTerm(0, 0, false));
|
|
332
|
+
term = null;
|
|
333
|
+
} else if (')' === character) {
|
|
334
|
+
if (groups.length > 1) {
|
|
335
|
+
term = groups.pop();
|
|
336
|
+
term.zeroWidthPart ||= !term.consumes;
|
|
337
|
+
if (!addRegexTerm(groups[groups.length - 1], term)) return null;
|
|
338
|
+
} else if (null === term || !term.zeroWidthPart) term = newRegexTerm(0, 0, true);
|
|
339
|
+
} else if ('|' === character) term = null;
|
|
340
|
+
else if ('*+?{'.includes(character)) {
|
|
341
|
+
const repetition = readRegexRepetition(pattern, index);
|
|
342
|
+
if (!repetition) return null;
|
|
343
|
+
if ('+' === pattern[index + repetition.length] || '{' === pattern[index + repetition.length]) return null;
|
|
344
|
+
index += repetition.length - 1;
|
|
345
|
+
if (null === term) {
|
|
346
|
+
if ('{' === character) return null;
|
|
347
|
+
continue;
|
|
348
|
+
}
|
|
349
|
+
if (term.zeroWidthPart) return null;
|
|
350
|
+
if (repetition.max > 1 && term.variable) return null;
|
|
351
|
+
const copies = 1 / 0 === repetition.max ? repetition.min + 1 : repetition.max;
|
|
352
|
+
if (!addRegexTerm(group, term, Math.max(copies, 1) - 1)) return null;
|
|
353
|
+
group.variable ||= repetition.min !== repetition.max;
|
|
354
|
+
term = null;
|
|
355
|
+
} else if ('^' === character || '$' === character) {
|
|
356
|
+
term = newRegexTerm(0, 0, false);
|
|
357
|
+
term.zeroWidthPart = true;
|
|
358
|
+
addRegexTerm(group, term);
|
|
359
|
+
} else {
|
|
360
|
+
if ('}' === character && ('+' === pattern[index + 1] || '{' === pattern[index + 1])) return null;
|
|
361
|
+
term = newRegexTerm(1, '.' === character ? 1 : 0, true);
|
|
362
|
+
if (!addRegexTerm(group, term)) return null;
|
|
363
|
+
}
|
|
285
364
|
}
|
|
286
|
-
|
|
365
|
+
const total = newRegexTerm(0, 0, false);
|
|
366
|
+
return groups.every((group)=>addRegexTerm(total, group)) ? classes : null;
|
|
287
367
|
}
|
|
288
368
|
function regexRequiresServerEvaluation(message) {
|
|
289
369
|
const error = new InconclusiveMatchError(message);
|
|
@@ -185,13 +185,65 @@ function exactMatchString(value) {
|
|
|
185
185
|
return serializeJsonValue(value);
|
|
186
186
|
}
|
|
187
187
|
const LITERAL_ESCAPED_PUNCTUATION = /[\x20-\x2f:;=?@\x5b-\x60\x7b-\x7e]/;
|
|
188
|
+
const MAX_UNICODE_CLASS_COPIES = 100;
|
|
189
|
+
const MAX_ATOM_COPIES = 10000;
|
|
190
|
+
const MAX_GROUP_DEPTH = 32;
|
|
191
|
+
function newRegexTerm(atoms, unicodeClasses, consumes) {
|
|
192
|
+
return {
|
|
193
|
+
atoms,
|
|
194
|
+
unicodeClasses,
|
|
195
|
+
consumes,
|
|
196
|
+
variable: false,
|
|
197
|
+
zeroWidthPart: false
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
function addRegexTerm(group, term, copies = 1) {
|
|
201
|
+
group.atoms += term.atoms * copies;
|
|
202
|
+
group.unicodeClasses += term.unicodeClasses * copies;
|
|
203
|
+
group.consumes ||= term.consumes;
|
|
204
|
+
group.variable ||= term.variable;
|
|
205
|
+
group.zeroWidthPart ||= term.zeroWidthPart;
|
|
206
|
+
return group.atoms <= MAX_ATOM_COPIES && group.unicodeClasses <= MAX_UNICODE_CLASS_COPIES;
|
|
207
|
+
}
|
|
208
|
+
function readRegexRepetition(pattern, index) {
|
|
209
|
+
const character = pattern[index];
|
|
210
|
+
if ('*' === character) return {
|
|
211
|
+
length: 1,
|
|
212
|
+
min: 0,
|
|
213
|
+
max: 1 / 0
|
|
214
|
+
};
|
|
215
|
+
if ('+' === character) return {
|
|
216
|
+
length: 1,
|
|
217
|
+
min: 1,
|
|
218
|
+
max: 1 / 0
|
|
219
|
+
};
|
|
220
|
+
if ('?' === character) return {
|
|
221
|
+
length: 1,
|
|
222
|
+
min: 0,
|
|
223
|
+
max: 1
|
|
224
|
+
};
|
|
225
|
+
const counts = /^\{(\d+)(?:,(\d*))?\}/.exec(pattern.slice(index));
|
|
226
|
+
if (!counts || counts.slice(1).some((count)=>Number(count) > 0xffffffff)) return null;
|
|
227
|
+
const min = Number(counts[1]);
|
|
228
|
+
const max = void 0 === counts[2] ? min : '' === counts[2] ? 1 / 0 : Number(counts[2]);
|
|
229
|
+
return {
|
|
230
|
+
length: counts[0].length,
|
|
231
|
+
min,
|
|
232
|
+
max
|
|
233
|
+
};
|
|
234
|
+
}
|
|
188
235
|
function getPortableRegexClasses(pattern) {
|
|
189
236
|
const classes = [];
|
|
237
|
+
const groups = [
|
|
238
|
+
newRegexTerm(0, 0, false)
|
|
239
|
+
];
|
|
240
|
+
let term = null;
|
|
190
241
|
let classStart = -1;
|
|
191
|
-
let
|
|
242
|
+
let classHasUnicode = false;
|
|
192
243
|
for(let index = 0; index < pattern.length; index++){
|
|
193
244
|
const character = pattern[index];
|
|
194
245
|
if (character.charCodeAt(0) > 0x7f) return null;
|
|
246
|
+
const group = groups[groups.length - 1];
|
|
195
247
|
if ('\\' === character) {
|
|
196
248
|
const escaped = pattern[++index];
|
|
197
249
|
if (void 0 === escaped) break;
|
|
@@ -199,49 +251,77 @@ function getPortableRegexClasses(pattern) {
|
|
|
199
251
|
if (!/^[\da-f]{2}$/i.test(pattern.slice(index + 1, index + 3))) return null;
|
|
200
252
|
index += 2;
|
|
201
253
|
} else if (!'dDsSwWbBfnrtv'.includes(escaped) && !LITERAL_ESCAPED_PUNCTUATION.test(escaped)) return null;
|
|
202
|
-
|
|
203
|
-
|
|
254
|
+
const isUnicodeClass = 'dDsSwW'.includes(escaped);
|
|
255
|
+
if (-1 !== classStart) {
|
|
256
|
+
classHasUnicode ||= isUnicodeClass;
|
|
257
|
+
continue;
|
|
258
|
+
}
|
|
259
|
+
if ('bB'.includes(escaped)) return null;
|
|
260
|
+
term = newRegexTerm(1, isUnicodeClass ? 1 : 0, true);
|
|
261
|
+
if (!addRegexTerm(group, term)) return null;
|
|
204
262
|
continue;
|
|
205
263
|
}
|
|
206
|
-
if (
|
|
207
|
-
if (
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
} else if (-1 !== classStart) {
|
|
217
|
-
if ([
|
|
264
|
+
if (-1 !== classStart) {
|
|
265
|
+
if ('[' === character) return null;
|
|
266
|
+
if (']' === character) {
|
|
267
|
+
const contentStart = classStart + ('^' === pattern[classStart + 1] ? 2 : 1);
|
|
268
|
+
if (index === contentStart) return null;
|
|
269
|
+
classes.push(pattern.slice(classStart, index + 1));
|
|
270
|
+
classStart = -1;
|
|
271
|
+
term = newRegexTerm(1, classHasUnicode ? 1 : 0, true);
|
|
272
|
+
if (!addRegexTerm(group, term)) return null;
|
|
273
|
+
} else if ([
|
|
218
274
|
'&&',
|
|
219
275
|
'--',
|
|
220
276
|
'~~'
|
|
221
277
|
].includes(pattern.slice(index, index + 2))) return null;
|
|
222
278
|
continue;
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
if (
|
|
229
|
-
''
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
279
|
+
}
|
|
280
|
+
if ('[' === character) {
|
|
281
|
+
classStart = index;
|
|
282
|
+
classHasUnicode = '^' === pattern[index + 1];
|
|
283
|
+
} else if ('(' === character) {
|
|
284
|
+
if ('?' === pattern[index + 1]) {
|
|
285
|
+
if (':' !== pattern[index + 2]) return null;
|
|
286
|
+
index += 2;
|
|
287
|
+
}
|
|
288
|
+
if (groups.length > MAX_GROUP_DEPTH) return null;
|
|
289
|
+
groups.push(newRegexTerm(0, 0, false));
|
|
290
|
+
term = null;
|
|
291
|
+
} else if (')' === character) {
|
|
292
|
+
if (groups.length > 1) {
|
|
293
|
+
term = groups.pop();
|
|
294
|
+
term.zeroWidthPart ||= !term.consumes;
|
|
295
|
+
if (!addRegexTerm(groups[groups.length - 1], term)) return null;
|
|
296
|
+
} else if (null === term || !term.zeroWidthPart) term = newRegexTerm(0, 0, true);
|
|
297
|
+
} else if ('|' === character) term = null;
|
|
298
|
+
else if ('*+?{'.includes(character)) {
|
|
299
|
+
const repetition = readRegexRepetition(pattern, index);
|
|
300
|
+
if (!repetition) return null;
|
|
301
|
+
if ('+' === pattern[index + repetition.length] || '{' === pattern[index + repetition.length]) return null;
|
|
302
|
+
index += repetition.length - 1;
|
|
303
|
+
if (null === term) {
|
|
304
|
+
if ('{' === character) return null;
|
|
305
|
+
continue;
|
|
306
|
+
}
|
|
307
|
+
if (term.zeroWidthPart) return null;
|
|
308
|
+
if (repetition.max > 1 && term.variable) return null;
|
|
309
|
+
const copies = 1 / 0 === repetition.max ? repetition.min + 1 : repetition.max;
|
|
310
|
+
if (!addRegexTerm(group, term, Math.max(copies, 1) - 1)) return null;
|
|
311
|
+
group.variable ||= repetition.min !== repetition.max;
|
|
312
|
+
term = null;
|
|
313
|
+
} else if ('^' === character || '$' === character) {
|
|
314
|
+
term = newRegexTerm(0, 0, false);
|
|
315
|
+
term.zeroWidthPart = true;
|
|
316
|
+
addRegexTerm(group, term);
|
|
317
|
+
} else {
|
|
318
|
+
if ('}' === character && ('+' === pattern[index + 1] || '{' === pattern[index + 1])) return null;
|
|
319
|
+
term = newRegexTerm(1, '.' === character ? 1 : 0, true);
|
|
320
|
+
if (!addRegexTerm(group, term)) return null;
|
|
321
|
+
}
|
|
243
322
|
}
|
|
244
|
-
|
|
323
|
+
const total = newRegexTerm(0, 0, false);
|
|
324
|
+
return groups.every((group)=>addRegexTerm(total, group)) ? classes : null;
|
|
245
325
|
}
|
|
246
326
|
function regexRequiresServerEvaluation(message) {
|
|
247
327
|
const error = new InconclusiveMatchError(message);
|
package/dist/posthog-core.d.ts
CHANGED
|
@@ -23,7 +23,7 @@ export declare abstract class PostHogCoreBase extends PostHogCoreStateless {
|
|
|
23
23
|
private _sessionActivity?;
|
|
24
24
|
protected sessionProps: PostHogEventProperties;
|
|
25
25
|
private _pendingFlagsRequest?;
|
|
26
|
-
private
|
|
26
|
+
private _flagsIdentityEpoch;
|
|
27
27
|
private _sessionRecordingReplacedByFlags?;
|
|
28
28
|
protected _personProfiles: 'always' | 'identified_only' | 'never';
|
|
29
29
|
protected _cachedPersonProperties: string | null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"posthog-core.d.ts","sourceRoot":"","sources":["../src/posthog-core.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,yBAAyB,EACzB,oBAAoB,EACpB,2BAA2B,EAC3B,kBAAkB,EAClB,sBAAsB,EACtB,qBAAqB,EAErB,QAAQ,EACR,mBAAmB,EACnB,gBAAgB,EAChB,iBAAiB,EACjB,wBAAwB,EACxB,uBAAuB,EAGvB,yBAAyB,EACzB,cAAc,EAKd,sBAAsB,EAGvB,MAAM,SAAS,CAAA;AAchB,OAAO,EAAiC,wBAAwB,EAAE,MAAM,SAAS,CAAA;AACjF,OAAO,EAAY,oBAAoB,EAAuB,MAAM,0BAA0B,CAAA;AAG9F,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAA;AAG5C,UAAU,iBAAiB;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AA0B,IAAI;QAC5B,KAAK,EAAE,oBAAoB,CAAC,cAAc,CAAC,GAAG,SAAS,CAAA;QACvD,QAAQ,EAAE,oBAAoB,CAAC,qBAAqB,CAAC,GAAG,SAAS,CAAA;KAClE,CAQA;IAED;;;;OAIG;IACH,aAAa,CAAC,GAAG,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,KAAK,EAAE,gBAAgB,KAAK,IAAI,GAAG,MAAM,IAAI,CAO5E;IAED;;;;OAIG;IACG,mBAAmB,CAAC,KAAK,EAAE,oBAAoB,CAAC,cAAc,CAAC,GAAG,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAO3F;CACF"}
|
package/dist/posthog-core.js
CHANGED
|
@@ -86,7 +86,7 @@ class PostHogCoreBase extends external_posthog_core_stateless_js_namespaceObject
|
|
|
86
86
|
...options,
|
|
87
87
|
disableGeoip: disableGeoipOption,
|
|
88
88
|
featureFlagsRequestTimeoutMs
|
|
89
|
-
}), this.flagCallReported = {}, this.flagCallsPendingOptIn = new Set(), this._sessionMaxLengthSeconds = 86400, this.sessionProps = {}, this.
|
|
89
|
+
}), this.flagCallReported = {}, this.flagCallsPendingOptIn = new Set(), this._sessionMaxLengthSeconds = 86400, this.sessionProps = {}, this._flagsIdentityEpoch = 0, this._cachedPersonProperties = null, this._pendingPersonPropertiesHash = void 0;
|
|
90
90
|
this.sendFeatureFlagEvent = options?.sendFeatureFlagEvent ?? true;
|
|
91
91
|
this.disableRemoteFeatureFlags = options?.disableRemoteFeatureFlags ?? false;
|
|
92
92
|
this._sessionExpirationTimeSeconds = options?.sessionExpirationTimeSeconds ?? 1800;
|
|
@@ -154,7 +154,6 @@ class PostHogCoreBase extends external_posthog_core_stateless_js_namespaceObject
|
|
|
154
154
|
}
|
|
155
155
|
reset(propertiesToKeep) {
|
|
156
156
|
this.wrap(()=>{
|
|
157
|
-
this._flagsResetCount++;
|
|
158
157
|
const allPropertiesToKeep = [
|
|
159
158
|
external_types_js_namespaceObject.PostHogPersistedProperty.Queue,
|
|
160
159
|
external_types_js_namespaceObject.PostHogPersistedProperty.AiQueue,
|
|
@@ -162,6 +161,7 @@ class PostHogCoreBase extends external_posthog_core_stateless_js_namespaceObject
|
|
|
162
161
|
external_types_js_namespaceObject.PostHogPersistedProperty.LogsQueue,
|
|
163
162
|
...propertiesToKeep || []
|
|
164
163
|
];
|
|
164
|
+
this._flagsIdentityEpoch++;
|
|
165
165
|
this.clearProps();
|
|
166
166
|
this._cachedPersonProperties = null;
|
|
167
167
|
for (const key of Object.keys(external_types_js_namespaceObject.PostHogPersistedProperty))if (!allPropertiesToKeep.includes(external_types_js_namespaceObject.PostHogPersistedProperty[key])) this.setPersistedProperty(external_types_js_namespaceObject.PostHogPersistedProperty[key], null);
|
|
@@ -368,6 +368,7 @@ class PostHogCoreBase extends external_posthog_core_stateless_js_namespaceObject
|
|
|
368
368
|
const identityChanged = distinctId !== previousDistinctId;
|
|
369
369
|
const shouldTransitionToIdentified = idWasSupplied && !identityChanged && !this._isIdentified();
|
|
370
370
|
if (identityChanged) {
|
|
371
|
+
this._flagsIdentityEpoch++;
|
|
371
372
|
this.flagCallsPendingOptIn = new Set();
|
|
372
373
|
this.setPersistedProperty(external_types_js_namespaceObject.PostHogPersistedProperty.AnonymousId, previousDistinctId);
|
|
373
374
|
this.setPersistedProperty(external_types_js_namespaceObject.PostHogPersistedProperty.DistinctId, distinctId);
|
|
@@ -636,8 +637,10 @@ class PostHogCoreBase extends external_posthog_core_stateless_js_namespaceObject
|
|
|
636
637
|
const sendAnonDistinctId = options?.sendAnonDistinctId ?? true;
|
|
637
638
|
const fetchConfig = options?.fetchConfig ?? false;
|
|
638
639
|
const triggerOnRemoteConfig = options?.triggerOnRemoteConfig ?? false;
|
|
640
|
+
let discardedForPreviousIdentity = false;
|
|
641
|
+
let queuedReloadForNewIdentity;
|
|
639
642
|
this._flagsResponsePromise = this._initPromise.then(async ()=>{
|
|
640
|
-
const
|
|
643
|
+
const identityEpoch = this._flagsIdentityEpoch;
|
|
641
644
|
const distinctId = this.getDistinctId();
|
|
642
645
|
const groups = this.props.$groups || {};
|
|
643
646
|
const personProperties = this.getPersistedProperty(external_types_js_namespaceObject.PostHogPersistedProperty.PersonProperties) || {};
|
|
@@ -653,9 +656,18 @@ class PostHogCoreBase extends external_posthog_core_stateless_js_namespaceObject
|
|
|
653
656
|
};
|
|
654
657
|
const result = await this.getFlagsForContext(distinctId, groups, personProperties, groupProperties, extraProperties, fetchConfig);
|
|
655
658
|
if (void 0 === result) return;
|
|
656
|
-
|
|
659
|
+
if (identityEpoch !== this._flagsIdentityEpoch) {
|
|
660
|
+
this._logger.info('[FEATURE FLAGS] Discarding flags evaluated before reset() or identify().');
|
|
661
|
+
if (result.success) {
|
|
662
|
+
this.cacheSessionReplay('flags', result.response);
|
|
663
|
+
this.syncRemoteConfigSessionRecording(result.response);
|
|
664
|
+
this.maybeNotifyRemoteConfig(triggerOnRemoteConfig, result.response);
|
|
665
|
+
}
|
|
666
|
+
discardedForPreviousIdentity = true;
|
|
667
|
+
return;
|
|
668
|
+
}
|
|
657
669
|
if (!result.success) {
|
|
658
|
-
if (!this.disableRemoteFeatureFlags
|
|
670
|
+
if (!this.disableRemoteFeatureFlags) {
|
|
659
671
|
const storedDetails = this.getStoredFlagDetails();
|
|
660
672
|
this.setKnownFeatureFlagDetails({
|
|
661
673
|
flags: this.getKnownFeatureFlagDetails()?.flags ?? {},
|
|
@@ -668,7 +680,7 @@ class PostHogCoreBase extends external_posthog_core_stateless_js_namespaceObject
|
|
|
668
680
|
}
|
|
669
681
|
const res = result.response;
|
|
670
682
|
if (res?.quotaLimited?.includes(external_posthog_core_stateless_js_namespaceObject.QuotaLimitedFeature.FeatureFlags)) {
|
|
671
|
-
if (!this.disableRemoteFeatureFlags
|
|
683
|
+
if (!this.disableRemoteFeatureFlags) {
|
|
672
684
|
const storedDetails = this.getStoredFlagDetails();
|
|
673
685
|
this.setKnownFeatureFlagDetails({
|
|
674
686
|
flags: this.getKnownFeatureFlagDetails()?.flags ?? {},
|
|
@@ -682,11 +694,11 @@ class PostHogCoreBase extends external_posthog_core_stateless_js_namespaceObject
|
|
|
682
694
|
return res;
|
|
683
695
|
}
|
|
684
696
|
if (res?.featureFlags) {
|
|
685
|
-
if (this.disableRemoteFeatureFlags
|
|
697
|
+
if (this.disableRemoteFeatureFlags) {
|
|
686
698
|
this.cacheSessionReplay('flags', res);
|
|
687
699
|
this.syncRemoteConfigSessionRecording(res);
|
|
688
700
|
this.maybeNotifyRemoteConfig(triggerOnRemoteConfig, res);
|
|
689
|
-
return
|
|
701
|
+
return res;
|
|
690
702
|
}
|
|
691
703
|
let newFeatureFlagDetails = res;
|
|
692
704
|
if (res.errorsWhileComputingFlags) {
|
|
@@ -720,6 +732,12 @@ class PostHogCoreBase extends external_posthog_core_stateless_js_namespaceObject
|
|
|
720
732
|
this._flagsResponsePromise = void 0;
|
|
721
733
|
const pendingRequest = this._pendingFlagsRequest;
|
|
722
734
|
if (pendingRequest) {
|
|
735
|
+
if (discardedForPreviousIdentity) queuedReloadForNewIdentity = new Promise((resolve, reject)=>{
|
|
736
|
+
pendingRequest.waiters.push({
|
|
737
|
+
resolve,
|
|
738
|
+
reject
|
|
739
|
+
});
|
|
740
|
+
});
|
|
723
741
|
this._pendingFlagsRequest = void 0;
|
|
724
742
|
this._logger.info('Executing pending feature flags reload.');
|
|
725
743
|
this.flagsAsync({
|
|
@@ -729,7 +747,8 @@ class PostHogCoreBase extends external_posthog_core_stateless_js_namespaceObject
|
|
|
729
747
|
}).then((res)=>pendingRequest.waiters.forEach((w)=>w.resolve(res))).catch((e)=>pendingRequest.waiters.forEach((w)=>w.reject(e)));
|
|
730
748
|
}
|
|
731
749
|
});
|
|
732
|
-
|
|
750
|
+
const res = await this._flagsResponsePromise;
|
|
751
|
+
return queuedReloadForNewIdentity ?? res;
|
|
733
752
|
}
|
|
734
753
|
setKnownFeatureFlagDetails(flagsResponse) {
|
|
735
754
|
this.wrap(()=>{
|
package/dist/posthog-core.mjs
CHANGED
|
@@ -53,7 +53,7 @@ class PostHogCoreBase extends PostHogCoreStateless {
|
|
|
53
53
|
...options,
|
|
54
54
|
disableGeoip: disableGeoipOption,
|
|
55
55
|
featureFlagsRequestTimeoutMs
|
|
56
|
-
}), this.flagCallReported = {}, this.flagCallsPendingOptIn = new Set(), this._sessionMaxLengthSeconds = 86400, this.sessionProps = {}, this.
|
|
56
|
+
}), this.flagCallReported = {}, this.flagCallsPendingOptIn = new Set(), this._sessionMaxLengthSeconds = 86400, this.sessionProps = {}, this._flagsIdentityEpoch = 0, this._cachedPersonProperties = null, this._pendingPersonPropertiesHash = void 0;
|
|
57
57
|
this.sendFeatureFlagEvent = options?.sendFeatureFlagEvent ?? true;
|
|
58
58
|
this.disableRemoteFeatureFlags = options?.disableRemoteFeatureFlags ?? false;
|
|
59
59
|
this._sessionExpirationTimeSeconds = options?.sessionExpirationTimeSeconds ?? 1800;
|
|
@@ -121,7 +121,6 @@ class PostHogCoreBase extends PostHogCoreStateless {
|
|
|
121
121
|
}
|
|
122
122
|
reset(propertiesToKeep) {
|
|
123
123
|
this.wrap(()=>{
|
|
124
|
-
this._flagsResetCount++;
|
|
125
124
|
const allPropertiesToKeep = [
|
|
126
125
|
PostHogPersistedProperty.Queue,
|
|
127
126
|
PostHogPersistedProperty.AiQueue,
|
|
@@ -129,6 +128,7 @@ class PostHogCoreBase extends PostHogCoreStateless {
|
|
|
129
128
|
PostHogPersistedProperty.LogsQueue,
|
|
130
129
|
...propertiesToKeep || []
|
|
131
130
|
];
|
|
131
|
+
this._flagsIdentityEpoch++;
|
|
132
132
|
this.clearProps();
|
|
133
133
|
this._cachedPersonProperties = null;
|
|
134
134
|
for (const key of Object.keys(PostHogPersistedProperty))if (!allPropertiesToKeep.includes(PostHogPersistedProperty[key])) this.setPersistedProperty(PostHogPersistedProperty[key], null);
|
|
@@ -335,6 +335,7 @@ class PostHogCoreBase extends PostHogCoreStateless {
|
|
|
335
335
|
const identityChanged = distinctId !== previousDistinctId;
|
|
336
336
|
const shouldTransitionToIdentified = idWasSupplied && !identityChanged && !this._isIdentified();
|
|
337
337
|
if (identityChanged) {
|
|
338
|
+
this._flagsIdentityEpoch++;
|
|
338
339
|
this.flagCallsPendingOptIn = new Set();
|
|
339
340
|
this.setPersistedProperty(PostHogPersistedProperty.AnonymousId, previousDistinctId);
|
|
340
341
|
this.setPersistedProperty(PostHogPersistedProperty.DistinctId, distinctId);
|
|
@@ -603,8 +604,10 @@ class PostHogCoreBase extends PostHogCoreStateless {
|
|
|
603
604
|
const sendAnonDistinctId = options?.sendAnonDistinctId ?? true;
|
|
604
605
|
const fetchConfig = options?.fetchConfig ?? false;
|
|
605
606
|
const triggerOnRemoteConfig = options?.triggerOnRemoteConfig ?? false;
|
|
607
|
+
let discardedForPreviousIdentity = false;
|
|
608
|
+
let queuedReloadForNewIdentity;
|
|
606
609
|
this._flagsResponsePromise = this._initPromise.then(async ()=>{
|
|
607
|
-
const
|
|
610
|
+
const identityEpoch = this._flagsIdentityEpoch;
|
|
608
611
|
const distinctId = this.getDistinctId();
|
|
609
612
|
const groups = this.props.$groups || {};
|
|
610
613
|
const personProperties = this.getPersistedProperty(PostHogPersistedProperty.PersonProperties) || {};
|
|
@@ -620,9 +623,18 @@ class PostHogCoreBase extends PostHogCoreStateless {
|
|
|
620
623
|
};
|
|
621
624
|
const result = await this.getFlagsForContext(distinctId, groups, personProperties, groupProperties, extraProperties, fetchConfig);
|
|
622
625
|
if (void 0 === result) return;
|
|
623
|
-
|
|
626
|
+
if (identityEpoch !== this._flagsIdentityEpoch) {
|
|
627
|
+
this._logger.info('[FEATURE FLAGS] Discarding flags evaluated before reset() or identify().');
|
|
628
|
+
if (result.success) {
|
|
629
|
+
this.cacheSessionReplay('flags', result.response);
|
|
630
|
+
this.syncRemoteConfigSessionRecording(result.response);
|
|
631
|
+
this.maybeNotifyRemoteConfig(triggerOnRemoteConfig, result.response);
|
|
632
|
+
}
|
|
633
|
+
discardedForPreviousIdentity = true;
|
|
634
|
+
return;
|
|
635
|
+
}
|
|
624
636
|
if (!result.success) {
|
|
625
|
-
if (!this.disableRemoteFeatureFlags
|
|
637
|
+
if (!this.disableRemoteFeatureFlags) {
|
|
626
638
|
const storedDetails = this.getStoredFlagDetails();
|
|
627
639
|
this.setKnownFeatureFlagDetails({
|
|
628
640
|
flags: this.getKnownFeatureFlagDetails()?.flags ?? {},
|
|
@@ -635,7 +647,7 @@ class PostHogCoreBase extends PostHogCoreStateless {
|
|
|
635
647
|
}
|
|
636
648
|
const res = result.response;
|
|
637
649
|
if (res?.quotaLimited?.includes(QuotaLimitedFeature.FeatureFlags)) {
|
|
638
|
-
if (!this.disableRemoteFeatureFlags
|
|
650
|
+
if (!this.disableRemoteFeatureFlags) {
|
|
639
651
|
const storedDetails = this.getStoredFlagDetails();
|
|
640
652
|
this.setKnownFeatureFlagDetails({
|
|
641
653
|
flags: this.getKnownFeatureFlagDetails()?.flags ?? {},
|
|
@@ -649,11 +661,11 @@ class PostHogCoreBase extends PostHogCoreStateless {
|
|
|
649
661
|
return res;
|
|
650
662
|
}
|
|
651
663
|
if (res?.featureFlags) {
|
|
652
|
-
if (this.disableRemoteFeatureFlags
|
|
664
|
+
if (this.disableRemoteFeatureFlags) {
|
|
653
665
|
this.cacheSessionReplay('flags', res);
|
|
654
666
|
this.syncRemoteConfigSessionRecording(res);
|
|
655
667
|
this.maybeNotifyRemoteConfig(triggerOnRemoteConfig, res);
|
|
656
|
-
return
|
|
668
|
+
return res;
|
|
657
669
|
}
|
|
658
670
|
let newFeatureFlagDetails = res;
|
|
659
671
|
if (res.errorsWhileComputingFlags) {
|
|
@@ -687,6 +699,12 @@ class PostHogCoreBase extends PostHogCoreStateless {
|
|
|
687
699
|
this._flagsResponsePromise = void 0;
|
|
688
700
|
const pendingRequest = this._pendingFlagsRequest;
|
|
689
701
|
if (pendingRequest) {
|
|
702
|
+
if (discardedForPreviousIdentity) queuedReloadForNewIdentity = new Promise((resolve, reject)=>{
|
|
703
|
+
pendingRequest.waiters.push({
|
|
704
|
+
resolve,
|
|
705
|
+
reject
|
|
706
|
+
});
|
|
707
|
+
});
|
|
690
708
|
this._pendingFlagsRequest = void 0;
|
|
691
709
|
this._logger.info('Executing pending feature flags reload.');
|
|
692
710
|
this.flagsAsync({
|
|
@@ -696,7 +714,8 @@ class PostHogCoreBase extends PostHogCoreStateless {
|
|
|
696
714
|
}).then((res)=>pendingRequest.waiters.forEach((w)=>w.resolve(res))).catch((e)=>pendingRequest.waiters.forEach((w)=>w.reject(e)));
|
|
697
715
|
}
|
|
698
716
|
});
|
|
699
|
-
|
|
717
|
+
const res = await this._flagsResponsePromise;
|
|
718
|
+
return queuedReloadForNewIdentity ?? res;
|
|
700
719
|
}
|
|
701
720
|
setKnownFeatureFlagDetails(flagsResponse) {
|
|
702
721
|
this.wrap(()=>{
|
package/package.json
CHANGED
|
@@ -290,13 +290,72 @@ function exactMatchString(value: unknown): string {
|
|
|
290
290
|
// Both engines treat escaped spaces and ASCII punctuation as literals, except Rust's \< and \> word boundaries.
|
|
291
291
|
const LITERAL_ESCAPED_PUNCTUATION = /[\x20-\x2f:;=?@\x5b-\x60\x7b-\x7e]/
|
|
292
292
|
|
|
293
|
+
// The flags service compiles a pattern in the subset with Rust's `regex` crate, whose program must
|
|
294
|
+
// fit in 10 MiB, so it rejects a pattern that JavaScript accepts once it holds too many atoms. A
|
|
295
|
+
// Unicode class is the costliest atom: the service compiles at most 209 copies of `\w`, about
|
|
296
|
+
// 2,000 of `\d` and 10,000 of `.`, against 145,000 ASCII classes or 327,000 literals. These bounds
|
|
297
|
+
// keep under half of the `\w` limit, and leave room for the ASCII atoms beside them.
|
|
298
|
+
const MAX_UNICODE_CLASS_COPIES = 100
|
|
299
|
+
const MAX_ATOM_COPIES = 10_000
|
|
300
|
+
// The service rejects groups nested 64 deep. JavaScript accepts them.
|
|
301
|
+
const MAX_GROUP_DEPTH = 32
|
|
302
|
+
|
|
303
|
+
// An atom, an anchor, or a group with everything in it.
|
|
304
|
+
type RegexTerm = {
|
|
305
|
+
// The copies of atoms, and of atoms that are Unicode classes, that it compiles to.
|
|
306
|
+
atoms: number
|
|
307
|
+
unicodeClasses: number
|
|
308
|
+
// Whether it can consume input, and whether it holds a repetition of variable length.
|
|
309
|
+
consumes: boolean
|
|
310
|
+
variable: boolean
|
|
311
|
+
// Whether it holds an anchor or a group that consumes nothing, which repeating it would quantify.
|
|
312
|
+
zeroWidthPart: boolean
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
function newRegexTerm(atoms: number, unicodeClasses: number, consumes: boolean): RegexTerm {
|
|
316
|
+
return { atoms, unicodeClasses, consumes, variable: false, zeroWidthPart: false }
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
// Adds `copies` copies of the term to the group, and returns whether the group still fits the bounds.
|
|
320
|
+
function addRegexTerm(group: RegexTerm, term: RegexTerm, copies: number = 1): boolean {
|
|
321
|
+
group.atoms += term.atoms * copies
|
|
322
|
+
group.unicodeClasses += term.unicodeClasses * copies
|
|
323
|
+
group.consumes ||= term.consumes
|
|
324
|
+
group.variable ||= term.variable
|
|
325
|
+
group.zeroWidthPart ||= term.zeroWidthPart
|
|
326
|
+
return group.atoms <= MAX_ATOM_COPIES && group.unicodeClasses <= MAX_UNICODE_CLASS_COPIES
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
function readRegexRepetition(pattern: string, index: number): { length: number; min: number; max: number } | null {
|
|
330
|
+
const character = pattern[index]
|
|
331
|
+
if (character === '*') return { length: 1, min: 0, max: Infinity }
|
|
332
|
+
if (character === '+') return { length: 1, min: 1, max: Infinity }
|
|
333
|
+
if (character === '?') return { length: 1, min: 0, max: 1 }
|
|
334
|
+
const counts = /^\{(\d+)(?:,(\d*))?\}/.exec(pattern.slice(index))
|
|
335
|
+
// JavaScript reads a malformed repetition such as `a{,2}` as literal text, and accepts counts
|
|
336
|
+
// above 4,294,967,295, which the flags service rejects.
|
|
337
|
+
if (!counts || counts.slice(1).some((count) => Number(count) > 0xffffffff)) return null
|
|
338
|
+
const min = Number(counts[1])
|
|
339
|
+
const max = counts[2] === undefined ? min : counts[2] === '' ? Infinity : Number(counts[2])
|
|
340
|
+
return { length: counts[0].length, min, max }
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
/**
|
|
344
|
+
* The character classes of a pattern in the portable subset, for a stricter syntax check, or null
|
|
345
|
+
* when the flags service and JavaScript could disagree on the pattern.
|
|
346
|
+
*/
|
|
293
347
|
function getPortableRegexClasses(pattern: string): string[] | null {
|
|
294
348
|
const classes: string[] = []
|
|
349
|
+
// The innermost open group is last. A group is added to its parent when it closes.
|
|
350
|
+
const groups: RegexTerm[] = [newRegexTerm(0, 0, false)]
|
|
351
|
+
// What a repetition here would repeat, or null where there is nothing to repeat.
|
|
352
|
+
let term: RegexTerm | null = null
|
|
295
353
|
let classStart = -1
|
|
296
|
-
let
|
|
354
|
+
let classHasUnicode = false
|
|
297
355
|
for (let index = 0; index < pattern.length; index++) {
|
|
298
356
|
const character = pattern[index]
|
|
299
357
|
if (character.charCodeAt(0) > 0x7f) return null
|
|
358
|
+
const group = groups[groups.length - 1]
|
|
300
359
|
if (character === '\\') {
|
|
301
360
|
const escaped = pattern[++index]
|
|
302
361
|
if (escaped === undefined) break
|
|
@@ -306,48 +365,94 @@ function getPortableRegexClasses(pattern: string): string[] | null {
|
|
|
306
365
|
} else if (!'dDsSwWbBfnrtv'.includes(escaped) && !LITERAL_ESCAPED_PUNCTUATION.test(escaped)) {
|
|
307
366
|
return null
|
|
308
367
|
}
|
|
368
|
+
const isUnicodeClass = 'dDsSwW'.includes(escaped)
|
|
369
|
+
if (classStart !== -1) {
|
|
370
|
+
classHasUnicode ||= isUnicodeClass
|
|
371
|
+
continue
|
|
372
|
+
}
|
|
309
373
|
// Word boundaries can exhaust the service's backtracking limit even for short ASCII values.
|
|
310
|
-
if (
|
|
311
|
-
|
|
374
|
+
if ('bB'.includes(escaped)) return null
|
|
375
|
+
term = newRegexTerm(1, isUnicodeClass ? 1 : 0, true)
|
|
376
|
+
if (!addRegexTerm(group, term)) return null
|
|
377
|
+
continue
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
if (classStart !== -1) {
|
|
381
|
+
if (character === '[') return null
|
|
382
|
+
if (character === ']') {
|
|
383
|
+
const contentStart = classStart + (pattern[classStart + 1] === '^' ? 2 : 1)
|
|
384
|
+
if (index === contentStart) return null
|
|
385
|
+
classes.push(pattern.slice(classStart, index + 1))
|
|
386
|
+
classStart = -1
|
|
387
|
+
// A negated class holds most of Unicode, like a class that holds a shorthand.
|
|
388
|
+
term = newRegexTerm(1, classHasUnicode ? 1 : 0, true)
|
|
389
|
+
if (!addRegexTerm(group, term)) return null
|
|
390
|
+
} else if (['&&', '--', '~~'].includes(pattern.slice(index, index + 2))) {
|
|
391
|
+
return null
|
|
392
|
+
}
|
|
312
393
|
continue
|
|
313
394
|
}
|
|
314
395
|
|
|
315
396
|
if (character === '[') {
|
|
316
|
-
if (classStart !== -1) return null
|
|
317
397
|
classStart = index
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
if (index ===
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
!repetition ||
|
|
337
|
-
['', '|', '('].includes(previousToken) ||
|
|
338
|
-
repetition.slice(1).some((count) => Number(count) > 0xffffffff)
|
|
339
|
-
) {
|
|
340
|
-
return null
|
|
398
|
+
classHasUnicode = pattern[index + 1] === '^'
|
|
399
|
+
} else if (character === '(') {
|
|
400
|
+
if (pattern[index + 1] === '?') {
|
|
401
|
+
if (pattern[index + 2] !== ':') return null
|
|
402
|
+
index += 2
|
|
403
|
+
}
|
|
404
|
+
if (groups.length > MAX_GROUP_DEPTH) return null
|
|
405
|
+
groups.push(newRegexTerm(0, 0, false))
|
|
406
|
+
term = null
|
|
407
|
+
} else if (character === ')') {
|
|
408
|
+
if (groups.length > 1) {
|
|
409
|
+
term = groups.pop() as RegexTerm
|
|
410
|
+
term.zeroWidthPart ||= !term.consumes
|
|
411
|
+
if (!addRegexTerm(groups[groups.length - 1], term)) return null
|
|
412
|
+
} else if (term === null || !term.zeroWidthPart) {
|
|
413
|
+
// Both engines reject an unmatched parenthesis. One after a term that a repetition would
|
|
414
|
+
// defer keeps that term.
|
|
415
|
+
term = newRegexTerm(0, 0, true)
|
|
341
416
|
}
|
|
342
|
-
} else if (
|
|
343
|
-
|
|
417
|
+
} else if (character === '|') {
|
|
418
|
+
term = null
|
|
419
|
+
} else if ('*+?{'.includes(character)) {
|
|
420
|
+
const repetition = readRegexRepetition(pattern, index)
|
|
421
|
+
if (!repetition) return null
|
|
422
|
+
// Rust accepts possessive and stacked repetitions such as `a++` and `a*{2}`. JavaScript rejects them.
|
|
423
|
+
if (pattern[index + repetition.length] === '+' || pattern[index + repetition.length] === '{') return null
|
|
424
|
+
index += repetition.length - 1
|
|
425
|
+
if (term === null) {
|
|
426
|
+
// Rust reads `{n}` with nothing before it as literal text. JavaScript rejects it.
|
|
427
|
+
if (character === '{') return null
|
|
428
|
+
// Otherwise this makes a repetition lazy, or both engines reject it.
|
|
429
|
+
continue
|
|
430
|
+
}
|
|
431
|
+
// JavaScript rejects a repeated anchor such as `^?`. Rust rejects a repeated empty group such
|
|
432
|
+
// as `(?:)*`. Repeating a group that holds either, such as `(?:^)*`, quantifies an assertion.
|
|
433
|
+
if (term.zeroWidthPart) return null
|
|
434
|
+
// A repeated group that holds a variable-length repetition, such as `(a+)+`, can backtrack
|
|
435
|
+
// exponentially in JavaScript, while the service matches it in linear time.
|
|
436
|
+
if (repetition.max > 1 && term.variable) return null
|
|
437
|
+
// A repetition compiles to as many copies as its maximum, or one more than its minimum.
|
|
438
|
+
const copies = repetition.max === Infinity ? repetition.min + 1 : repetition.max
|
|
439
|
+
if (!addRegexTerm(group, term, Math.max(copies, 1) - 1)) return null
|
|
440
|
+
group.variable ||= repetition.min !== repetition.max
|
|
441
|
+
term = null
|
|
442
|
+
} else if (character === '^' || character === '$') {
|
|
443
|
+
term = newRegexTerm(0, 0, false)
|
|
444
|
+
term.zeroWidthPart = true
|
|
445
|
+
addRegexTerm(group, term)
|
|
446
|
+
} else {
|
|
447
|
+
// A literal `}` before `+` or `{` reads like the end of a stacked repetition, so it defers too.
|
|
448
|
+
if (character === '}' && (pattern[index + 1] === '+' || pattern[index + 1] === '{')) return null
|
|
449
|
+
term = newRegexTerm(1, character === '.' ? 1 : 0, true)
|
|
450
|
+
if (!addRegexTerm(group, term)) return null
|
|
344
451
|
}
|
|
345
|
-
// JavaScript rejects a repeated anchor such as `^?`. Rust accepts it.
|
|
346
|
-
// Rust rejects a repeated empty group such as `(?:)*`. JavaScript accepts it.
|
|
347
|
-
if ('*+?{'.includes(character) && ['^', '$', 'empty group'].includes(previousToken)) return null
|
|
348
|
-
previousToken = character === ')' && ['(', 'empty group'].includes(previousToken) ? 'empty group' : character
|
|
349
452
|
}
|
|
350
|
-
|
|
453
|
+
// Groups still open belong to no parent yet. Both engines reject them, but count them anyway.
|
|
454
|
+
const total = newRegexTerm(0, 0, false)
|
|
455
|
+
return groups.every((group) => addRegexTerm(total, group)) ? classes : null
|
|
351
456
|
}
|
|
352
457
|
|
|
353
458
|
// Adapters must preserve regex uncertainty across variant rules without changing missing-context fallback.
|
|
@@ -360,7 +465,8 @@ function regexRequiresServerEvaluation(message: string): InconclusiveMatchError
|
|
|
360
465
|
function matchFeatureFlagRegex(pattern: string, value: string): boolean | null {
|
|
361
466
|
if (pattern === '') return true
|
|
362
467
|
|
|
363
|
-
// Rust uses Unicode scalar semantics and
|
|
468
|
+
// Rust uses Unicode scalar semantics, additional syntax and other limits. Keep local matching to
|
|
469
|
+
// the shared ASCII subset that both engines compile and match within their limits.
|
|
364
470
|
const characterClasses = getPortableRegexClasses(pattern)
|
|
365
471
|
if (characterClasses === null) {
|
|
366
472
|
throw regexRequiresServerEvaluation('Regex syntax requires server evaluation')
|
package/src/posthog-core.ts
CHANGED
|
@@ -158,8 +158,8 @@ export abstract class PostHogCoreBase extends PostHogCoreStateless {
|
|
|
158
158
|
// Track if an additional reload was requested while a request was in flight
|
|
159
159
|
// This prevents dropping reload requests (e.g., from identify()) when preload is in progress
|
|
160
160
|
private _pendingFlagsRequest?: PendingFlagsRequest
|
|
161
|
-
//
|
|
162
|
-
private
|
|
161
|
+
// Incremented by reset() and identity changes so a /flags response evaluated for a discarded identity is dropped.
|
|
162
|
+
private _flagsIdentityEpoch = 0
|
|
163
163
|
|
|
164
164
|
// The cached /config sessionRecording that a /flags `false` replaced, so a later /flags object can restore it.
|
|
165
165
|
private _sessionRecordingReplacedByFlags?: { value: PostHogRemoteConfig['sessionRecording'] }
|
|
@@ -289,7 +289,6 @@ export abstract class PostHogCoreBase extends PostHogCoreStateless {
|
|
|
289
289
|
*/
|
|
290
290
|
reset(propertiesToKeep?: PostHogPersistedProperty[]): void {
|
|
291
291
|
this.wrap(() => {
|
|
292
|
-
this._flagsResetCount++
|
|
293
292
|
const allPropertiesToKeep = [
|
|
294
293
|
PostHogPersistedProperty.Queue,
|
|
295
294
|
PostHogPersistedProperty.AiQueue,
|
|
@@ -298,6 +297,8 @@ export abstract class PostHogCoreBase extends PostHogCoreStateless {
|
|
|
298
297
|
...(propertiesToKeep || []),
|
|
299
298
|
]
|
|
300
299
|
|
|
300
|
+
this._flagsIdentityEpoch++
|
|
301
|
+
|
|
301
302
|
// clean up props
|
|
302
303
|
this.clearProps()
|
|
303
304
|
|
|
@@ -692,6 +693,7 @@ export abstract class PostHogCoreBase extends PostHogCoreStateless {
|
|
|
692
693
|
const shouldTransitionToIdentified = idWasSupplied && !identityChanged && !this._isIdentified()
|
|
693
694
|
|
|
694
695
|
if (identityChanged) {
|
|
696
|
+
this._flagsIdentityEpoch++
|
|
695
697
|
// Reads made while opted out belong to the previous identity
|
|
696
698
|
this.flagCallsPendingOptIn = new Set()
|
|
697
699
|
// We keep the AnonymousId to be used by flags calls and identify to link the previousId
|
|
@@ -1169,9 +1171,11 @@ export abstract class PostHogCoreBase extends PostHogCoreStateless {
|
|
|
1169
1171
|
const sendAnonDistinctId = options?.sendAnonDistinctId ?? true
|
|
1170
1172
|
const fetchConfig = options?.fetchConfig ?? false
|
|
1171
1173
|
const triggerOnRemoteConfig = options?.triggerOnRemoteConfig ?? false
|
|
1174
|
+
let discardedForPreviousIdentity = false
|
|
1175
|
+
let queuedReloadForNewIdentity: Promise<PostHogFeatureFlagsResponse | undefined> | undefined
|
|
1172
1176
|
this._flagsResponsePromise = this._initPromise
|
|
1173
1177
|
.then(async () => {
|
|
1174
|
-
const
|
|
1178
|
+
const identityEpoch = this._flagsIdentityEpoch
|
|
1175
1179
|
const distinctId = this.getDistinctId()
|
|
1176
1180
|
const groups = this.props.$groups || {}
|
|
1177
1181
|
const personProperties =
|
|
@@ -1200,11 +1204,18 @@ export abstract class PostHogCoreBase extends PostHogCoreStateless {
|
|
|
1200
1204
|
)
|
|
1201
1205
|
|
|
1202
1206
|
if (result === undefined) return undefined
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1207
|
+
if (identityEpoch !== this._flagsIdentityEpoch) {
|
|
1208
|
+
this._logger.info('[FEATURE FLAGS] Discarding flags evaluated before reset() or identify().')
|
|
1209
|
+
if (result.success) {
|
|
1210
|
+
this.cacheSessionReplay('flags', result.response)
|
|
1211
|
+
this.syncRemoteConfigSessionRecording(result.response)
|
|
1212
|
+
this.maybeNotifyRemoteConfig(triggerOnRemoteConfig, result.response)
|
|
1213
|
+
}
|
|
1214
|
+
discardedForPreviousIdentity = true
|
|
1215
|
+
return undefined
|
|
1216
|
+
}
|
|
1206
1217
|
if (!result.success) {
|
|
1207
|
-
if (!this.disableRemoteFeatureFlags
|
|
1218
|
+
if (!this.disableRemoteFeatureFlags) {
|
|
1208
1219
|
// Keep the persisted gate alongside the kept flags — a failed request is not a
|
|
1209
1220
|
// signal that the server turned minimal flag-called events off.
|
|
1210
1221
|
const storedDetails = this.getStoredFlagDetails()
|
|
@@ -1221,7 +1232,7 @@ export abstract class PostHogCoreBase extends PostHogCoreStateless {
|
|
|
1221
1232
|
const res = result.response
|
|
1222
1233
|
|
|
1223
1234
|
if (res?.quotaLimited?.includes(QuotaLimitedFeature.FeatureFlags)) {
|
|
1224
|
-
if (!this.disableRemoteFeatureFlags
|
|
1235
|
+
if (!this.disableRemoteFeatureFlags) {
|
|
1225
1236
|
const storedDetails = this.getStoredFlagDetails()
|
|
1226
1237
|
this.setKnownFeatureFlagDetails({
|
|
1227
1238
|
flags: this.getKnownFeatureFlagDetails()?.flags ?? {},
|
|
@@ -1237,11 +1248,11 @@ export abstract class PostHogCoreBase extends PostHogCoreStateless {
|
|
|
1237
1248
|
return res
|
|
1238
1249
|
}
|
|
1239
1250
|
if (res?.featureFlags) {
|
|
1240
|
-
if (this.disableRemoteFeatureFlags
|
|
1251
|
+
if (this.disableRemoteFeatureFlags) {
|
|
1241
1252
|
this.cacheSessionReplay('flags', res)
|
|
1242
1253
|
this.syncRemoteConfigSessionRecording(res)
|
|
1243
1254
|
this.maybeNotifyRemoteConfig(triggerOnRemoteConfig, res)
|
|
1244
|
-
return
|
|
1255
|
+
return res
|
|
1245
1256
|
}
|
|
1246
1257
|
|
|
1247
1258
|
let newFeatureFlagDetails = res
|
|
@@ -1290,6 +1301,13 @@ export abstract class PostHogCoreBase extends PostHogCoreStateless {
|
|
|
1290
1301
|
// Check if there's a pending reload request and execute it
|
|
1291
1302
|
const pendingRequest = this._pendingFlagsRequest
|
|
1292
1303
|
if (pendingRequest) {
|
|
1304
|
+
// Registered here rather than when discarding: the reset()/identify() reload only queues
|
|
1305
|
+
// itself after awaiting _initPromise, so it may not be pending yet at that point.
|
|
1306
|
+
if (discardedForPreviousIdentity) {
|
|
1307
|
+
queuedReloadForNewIdentity = new Promise((resolve, reject) => {
|
|
1308
|
+
pendingRequest.waiters.push({ resolve, reject })
|
|
1309
|
+
})
|
|
1310
|
+
}
|
|
1293
1311
|
this._pendingFlagsRequest = undefined
|
|
1294
1312
|
this._logger.info('Executing pending feature flags reload.')
|
|
1295
1313
|
// Execute the pending request and resolve its promise with the result
|
|
@@ -1302,7 +1320,8 @@ export abstract class PostHogCoreBase extends PostHogCoreStateless {
|
|
|
1302
1320
|
.catch((e) => pendingRequest.waiters.forEach((w) => w.reject(e)))
|
|
1303
1321
|
}
|
|
1304
1322
|
})
|
|
1305
|
-
|
|
1323
|
+
const res = await this._flagsResponsePromise
|
|
1324
|
+
return queuedReloadForNewIdentity ?? res
|
|
1306
1325
|
}
|
|
1307
1326
|
|
|
1308
1327
|
private setKnownFeatureFlagDetails(flagsResponse: PostHogFlagsStorageFormat | null): void {
|