posthog-node 5.10.0 → 5.10.1
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/extensions/feature-flags/feature-flags.d.ts +4 -1
- package/dist/extensions/feature-flags/feature-flags.d.ts.map +1 -1
- package/dist/extensions/feature-flags/feature-flags.js +18 -4
- package/dist/extensions/feature-flags/feature-flags.mjs +15 -4
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/version.mjs +1 -1
- package/package.json +1 -1
- package/src/extensions/feature-flags/feature-flags.ts +35 -10
- package/src/version.ts +1 -1
|
@@ -6,6 +6,9 @@ declare class ClientError extends Error {
|
|
|
6
6
|
declare class InconclusiveMatchError extends Error {
|
|
7
7
|
constructor(message: string);
|
|
8
8
|
}
|
|
9
|
+
declare class RequiresServerEvaluation extends Error {
|
|
10
|
+
constructor(message: string);
|
|
11
|
+
}
|
|
9
12
|
type FeatureFlagsPollerOptions = {
|
|
10
13
|
personalApiKey: string;
|
|
11
14
|
projectApiKey: string;
|
|
@@ -85,5 +88,5 @@ declare class FeatureFlagsPoller {
|
|
|
85
88
|
}
|
|
86
89
|
declare function matchProperty(property: FeatureFlagCondition['properties'][number], propertyValues: Record<string, any>, warnFunction?: (msg: string) => void): boolean;
|
|
87
90
|
declare function relativeDateParseForFeatureFlagMatching(value: string): Date | null;
|
|
88
|
-
export { FeatureFlagsPoller, matchProperty, relativeDateParseForFeatureFlagMatching, InconclusiveMatchError, ClientError, };
|
|
91
|
+
export { FeatureFlagsPoller, matchProperty, relativeDateParseForFeatureFlagMatching, InconclusiveMatchError, RequiresServerEvaluation, ClientError, };
|
|
89
92
|
//# sourceMappingURL=feature-flags.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"feature-flags.d.ts","sourceRoot":"","sources":["../../../src/extensions/feature-flags/feature-flags.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAmC,kBAAkB,EAA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AAuC,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI,CAmC3E;AAED,OAAO,EACL,kBAAkB,EAClB,aAAa,EACb,uCAAuC,EACvC,sBAAsB,EACtB,wBAAwB,EACxB,WAAW,GACZ,CAAA"}
|
|
@@ -24,11 +24,12 @@ var __webpack_require__ = {};
|
|
|
24
24
|
var __webpack_exports__ = {};
|
|
25
25
|
__webpack_require__.r(__webpack_exports__);
|
|
26
26
|
__webpack_require__.d(__webpack_exports__, {
|
|
27
|
+
matchProperty: ()=>matchProperty,
|
|
27
28
|
ClientError: ()=>ClientError,
|
|
28
29
|
relativeDateParseForFeatureFlagMatching: ()=>relativeDateParseForFeatureFlagMatching,
|
|
29
30
|
InconclusiveMatchError: ()=>InconclusiveMatchError,
|
|
30
31
|
FeatureFlagsPoller: ()=>FeatureFlagsPoller,
|
|
31
|
-
|
|
32
|
+
RequiresServerEvaluation: ()=>RequiresServerEvaluation
|
|
32
33
|
});
|
|
33
34
|
const core_namespaceObject = require("@posthog/core");
|
|
34
35
|
const external_crypto_js_namespaceObject = require("./crypto.js");
|
|
@@ -54,6 +55,14 @@ class InconclusiveMatchError extends Error {
|
|
|
54
55
|
Object.setPrototypeOf(this, InconclusiveMatchError.prototype);
|
|
55
56
|
}
|
|
56
57
|
}
|
|
58
|
+
class RequiresServerEvaluation extends Error {
|
|
59
|
+
constructor(message){
|
|
60
|
+
super(message);
|
|
61
|
+
this.name = this.constructor.name;
|
|
62
|
+
Error.captureStackTrace(this, this.constructor);
|
|
63
|
+
Object.setPrototypeOf(this, RequiresServerEvaluation.prototype);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
57
66
|
class FeatureFlagsPoller {
|
|
58
67
|
constructor({ pollingInterval, personalApiKey, projectApiKey, timeout, host, customHeaders, ...options }){
|
|
59
68
|
this.debugMode = false;
|
|
@@ -93,7 +102,7 @@ class FeatureFlagsPoller {
|
|
|
93
102
|
response = result.value;
|
|
94
103
|
this.logMsgIfDebug(()=>console.debug(`Successfully computed flag locally: ${key} -> ${response}`));
|
|
95
104
|
} catch (e) {
|
|
96
|
-
if (e instanceof InconclusiveMatchError) this.logMsgIfDebug(()=>console.debug(
|
|
105
|
+
if (e instanceof RequiresServerEvaluation || e instanceof InconclusiveMatchError) this.logMsgIfDebug(()=>console.debug(`${e.name} when computing flag locally: ${key}: ${e.message}`));
|
|
97
106
|
else if (e instanceof Error) this.onError?.(new Error(`Error computing flag locally: ${key}: ${e}`));
|
|
98
107
|
}
|
|
99
108
|
return response;
|
|
@@ -111,7 +120,7 @@ class FeatureFlagsPoller {
|
|
|
111
120
|
response[flag.key] = matchValue;
|
|
112
121
|
if (matchPayload) payloads[flag.key] = matchPayload;
|
|
113
122
|
} catch (e) {
|
|
114
|
-
if (e instanceof InconclusiveMatchError) this.logMsgIfDebug(()=>console.debug(
|
|
123
|
+
if (e instanceof RequiresServerEvaluation || e instanceof InconclusiveMatchError) this.logMsgIfDebug(()=>console.debug(`${e.name} when computing flag locally: ${flag.key}: ${e.message}`));
|
|
115
124
|
else if (e instanceof Error) this.onError?.(new Error(`Error computing flag locally: ${flag.key}: ${e}`));
|
|
116
125
|
fallbackToFlags = true;
|
|
117
126
|
}
|
|
@@ -214,6 +223,7 @@ class FeatureFlagsPoller {
|
|
|
214
223
|
break;
|
|
215
224
|
}
|
|
216
225
|
} catch (e) {
|
|
226
|
+
if (e instanceof RequiresServerEvaluation) throw e;
|
|
217
227
|
if (e instanceof InconclusiveMatchError) isInconclusive = true;
|
|
218
228
|
else throw e;
|
|
219
229
|
}
|
|
@@ -425,7 +435,7 @@ function matchProperty(property, propertyValues, warnFunction) {
|
|
|
425
435
|
}
|
|
426
436
|
function matchCohort(property, propertyValues, cohortProperties, debugMode = false) {
|
|
427
437
|
const cohortId = String(property.value);
|
|
428
|
-
if (!(cohortId in cohortProperties)) throw new
|
|
438
|
+
if (!(cohortId in cohortProperties)) throw new RequiresServerEvaluation(`cohort ${cohortId} not found in local cohorts - likely a static cohort that requires server evaluation`);
|
|
429
439
|
const propertyGroup = cohortProperties[cohortId];
|
|
430
440
|
return matchPropertyGroup(propertyGroup, propertyValues, cohortProperties, debugMode);
|
|
431
441
|
}
|
|
@@ -442,6 +452,7 @@ function matchPropertyGroup(propertyGroup, propertyValues, cohortProperties, deb
|
|
|
442
452
|
if (!matches) return false;
|
|
443
453
|
} else if (matches) return true;
|
|
444
454
|
} catch (err) {
|
|
455
|
+
if (err instanceof RequiresServerEvaluation) throw err;
|
|
445
456
|
if (err instanceof InconclusiveMatchError) {
|
|
446
457
|
if (debugMode) console.debug(`Failed to compute property ${prop} locally: ${err}`);
|
|
447
458
|
errorMatchingLocally = true;
|
|
@@ -466,6 +477,7 @@ function matchPropertyGroup(propertyGroup, propertyValues, cohortProperties, deb
|
|
|
466
477
|
if (!matches && negation) return true;
|
|
467
478
|
}
|
|
468
479
|
} catch (err) {
|
|
480
|
+
if (err instanceof RequiresServerEvaluation) throw err;
|
|
469
481
|
if (err instanceof InconclusiveMatchError) {
|
|
470
482
|
if (debugMode) console.debug(`Failed to compute property ${prop} locally: ${err}`);
|
|
471
483
|
errorMatchingLocally = true;
|
|
@@ -515,12 +527,14 @@ function relativeDateParseForFeatureFlagMatching(value) {
|
|
|
515
527
|
exports.ClientError = __webpack_exports__.ClientError;
|
|
516
528
|
exports.FeatureFlagsPoller = __webpack_exports__.FeatureFlagsPoller;
|
|
517
529
|
exports.InconclusiveMatchError = __webpack_exports__.InconclusiveMatchError;
|
|
530
|
+
exports.RequiresServerEvaluation = __webpack_exports__.RequiresServerEvaluation;
|
|
518
531
|
exports.matchProperty = __webpack_exports__.matchProperty;
|
|
519
532
|
exports.relativeDateParseForFeatureFlagMatching = __webpack_exports__.relativeDateParseForFeatureFlagMatching;
|
|
520
533
|
for(var __webpack_i__ in __webpack_exports__)if (-1 === [
|
|
521
534
|
"ClientError",
|
|
522
535
|
"FeatureFlagsPoller",
|
|
523
536
|
"InconclusiveMatchError",
|
|
537
|
+
"RequiresServerEvaluation",
|
|
524
538
|
"matchProperty",
|
|
525
539
|
"relativeDateParseForFeatureFlagMatching"
|
|
526
540
|
].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
|
|
@@ -22,6 +22,14 @@ class InconclusiveMatchError extends Error {
|
|
|
22
22
|
Object.setPrototypeOf(this, InconclusiveMatchError.prototype);
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
|
+
class RequiresServerEvaluation extends Error {
|
|
26
|
+
constructor(message){
|
|
27
|
+
super(message);
|
|
28
|
+
this.name = this.constructor.name;
|
|
29
|
+
Error.captureStackTrace(this, this.constructor);
|
|
30
|
+
Object.setPrototypeOf(this, RequiresServerEvaluation.prototype);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
25
33
|
class FeatureFlagsPoller {
|
|
26
34
|
constructor({ pollingInterval, personalApiKey, projectApiKey, timeout, host, customHeaders, ...options }){
|
|
27
35
|
this.debugMode = false;
|
|
@@ -61,7 +69,7 @@ class FeatureFlagsPoller {
|
|
|
61
69
|
response = result.value;
|
|
62
70
|
this.logMsgIfDebug(()=>console.debug(`Successfully computed flag locally: ${key} -> ${response}`));
|
|
63
71
|
} catch (e) {
|
|
64
|
-
if (e instanceof InconclusiveMatchError) this.logMsgIfDebug(()=>console.debug(
|
|
72
|
+
if (e instanceof RequiresServerEvaluation || e instanceof InconclusiveMatchError) this.logMsgIfDebug(()=>console.debug(`${e.name} when computing flag locally: ${key}: ${e.message}`));
|
|
65
73
|
else if (e instanceof Error) this.onError?.(new Error(`Error computing flag locally: ${key}: ${e}`));
|
|
66
74
|
}
|
|
67
75
|
return response;
|
|
@@ -79,7 +87,7 @@ class FeatureFlagsPoller {
|
|
|
79
87
|
response[flag.key] = matchValue;
|
|
80
88
|
if (matchPayload) payloads[flag.key] = matchPayload;
|
|
81
89
|
} catch (e) {
|
|
82
|
-
if (e instanceof InconclusiveMatchError) this.logMsgIfDebug(()=>console.debug(
|
|
90
|
+
if (e instanceof RequiresServerEvaluation || e instanceof InconclusiveMatchError) this.logMsgIfDebug(()=>console.debug(`${e.name} when computing flag locally: ${flag.key}: ${e.message}`));
|
|
83
91
|
else if (e instanceof Error) this.onError?.(new Error(`Error computing flag locally: ${flag.key}: ${e}`));
|
|
84
92
|
fallbackToFlags = true;
|
|
85
93
|
}
|
|
@@ -182,6 +190,7 @@ class FeatureFlagsPoller {
|
|
|
182
190
|
break;
|
|
183
191
|
}
|
|
184
192
|
} catch (e) {
|
|
193
|
+
if (e instanceof RequiresServerEvaluation) throw e;
|
|
185
194
|
if (e instanceof InconclusiveMatchError) isInconclusive = true;
|
|
186
195
|
else throw e;
|
|
187
196
|
}
|
|
@@ -393,7 +402,7 @@ function matchProperty(property, propertyValues, warnFunction) {
|
|
|
393
402
|
}
|
|
394
403
|
function matchCohort(property, propertyValues, cohortProperties, debugMode = false) {
|
|
395
404
|
const cohortId = String(property.value);
|
|
396
|
-
if (!(cohortId in cohortProperties)) throw new
|
|
405
|
+
if (!(cohortId in cohortProperties)) throw new RequiresServerEvaluation(`cohort ${cohortId} not found in local cohorts - likely a static cohort that requires server evaluation`);
|
|
397
406
|
const propertyGroup = cohortProperties[cohortId];
|
|
398
407
|
return matchPropertyGroup(propertyGroup, propertyValues, cohortProperties, debugMode);
|
|
399
408
|
}
|
|
@@ -410,6 +419,7 @@ function matchPropertyGroup(propertyGroup, propertyValues, cohortProperties, deb
|
|
|
410
419
|
if (!matches) return false;
|
|
411
420
|
} else if (matches) return true;
|
|
412
421
|
} catch (err) {
|
|
422
|
+
if (err instanceof RequiresServerEvaluation) throw err;
|
|
413
423
|
if (err instanceof InconclusiveMatchError) {
|
|
414
424
|
if (debugMode) console.debug(`Failed to compute property ${prop} locally: ${err}`);
|
|
415
425
|
errorMatchingLocally = true;
|
|
@@ -434,6 +444,7 @@ function matchPropertyGroup(propertyGroup, propertyValues, cohortProperties, deb
|
|
|
434
444
|
if (!matches && negation) return true;
|
|
435
445
|
}
|
|
436
446
|
} catch (err) {
|
|
447
|
+
if (err instanceof RequiresServerEvaluation) throw err;
|
|
437
448
|
if (err instanceof InconclusiveMatchError) {
|
|
438
449
|
if (debugMode) console.debug(`Failed to compute property ${prop} locally: ${err}`);
|
|
439
450
|
errorMatchingLocally = true;
|
|
@@ -480,4 +491,4 @@ function relativeDateParseForFeatureFlagMatching(value) {
|
|
|
480
491
|
return parsedDt;
|
|
481
492
|
}
|
|
482
493
|
}
|
|
483
|
-
export { ClientError, FeatureFlagsPoller, InconclusiveMatchError, matchProperty, relativeDateParseForFeatureFlagMatching };
|
|
494
|
+
export { ClientError, FeatureFlagsPoller, InconclusiveMatchError, RequiresServerEvaluation, matchProperty, relativeDateParseForFeatureFlagMatching };
|
package/dist/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const version = "5.10.
|
|
1
|
+
export declare const version = "5.10.1";
|
|
2
2
|
//# sourceMappingURL=version.d.ts.map
|
package/dist/version.js
CHANGED
|
@@ -26,7 +26,7 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
26
26
|
__webpack_require__.d(__webpack_exports__, {
|
|
27
27
|
version: ()=>version
|
|
28
28
|
});
|
|
29
|
-
const version = '5.10.
|
|
29
|
+
const version = '5.10.1';
|
|
30
30
|
exports.version = __webpack_exports__.version;
|
|
31
31
|
for(var __webpack_i__ in __webpack_exports__)if (-1 === [
|
|
32
32
|
"version"
|
package/dist/version.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const version = '5.10.
|
|
1
|
+
const version = '5.10.1';
|
|
2
2
|
export { version };
|
package/package.json
CHANGED
|
@@ -31,6 +31,18 @@ class InconclusiveMatchError extends Error {
|
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
+
class RequiresServerEvaluation extends Error {
|
|
35
|
+
constructor(message: string) {
|
|
36
|
+
super(message)
|
|
37
|
+
this.name = this.constructor.name
|
|
38
|
+
Error.captureStackTrace(this, this.constructor)
|
|
39
|
+
// instanceof doesn't work in ES3 or ES5
|
|
40
|
+
// https://www.dannyguo.com/blog/how-to-fix-instanceof-not-working-for-custom-errors-in-typescript/
|
|
41
|
+
// this is the workaround
|
|
42
|
+
Object.setPrototypeOf(this, RequiresServerEvaluation.prototype)
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
34
46
|
type FeatureFlagsPollerOptions = {
|
|
35
47
|
personalApiKey: string
|
|
36
48
|
projectApiKey: string
|
|
@@ -130,8 +142,8 @@ class FeatureFlagsPoller {
|
|
|
130
142
|
response = result.value
|
|
131
143
|
this.logMsgIfDebug(() => console.debug(`Successfully computed flag locally: ${key} -> ${response}`))
|
|
132
144
|
} catch (e) {
|
|
133
|
-
if (e instanceof InconclusiveMatchError) {
|
|
134
|
-
this.logMsgIfDebug(() => console.debug(
|
|
145
|
+
if (e instanceof RequiresServerEvaluation || e instanceof InconclusiveMatchError) {
|
|
146
|
+
this.logMsgIfDebug(() => console.debug(`${e.name} when computing flag locally: ${key}: ${e.message}`))
|
|
135
147
|
} else if (e instanceof Error) {
|
|
136
148
|
this.onError?.(new Error(`Error computing flag locally: ${key}: ${e}`))
|
|
137
149
|
}
|
|
@@ -182,10 +194,8 @@ class FeatureFlagsPoller {
|
|
|
182
194
|
payloads[flag.key] = matchPayload
|
|
183
195
|
}
|
|
184
196
|
} catch (e) {
|
|
185
|
-
if (e instanceof InconclusiveMatchError) {
|
|
186
|
-
this.logMsgIfDebug(() =>
|
|
187
|
-
console.debug(`InconclusiveMatchError when computing flag locally: ${flag.key}: ${e}`)
|
|
188
|
-
)
|
|
197
|
+
if (e instanceof RequiresServerEvaluation || e instanceof InconclusiveMatchError) {
|
|
198
|
+
this.logMsgIfDebug(() => console.debug(`${e.name} when computing flag locally: ${flag.key}: ${e.message}`))
|
|
189
199
|
} else if (e instanceof Error) {
|
|
190
200
|
this.onError?.(new Error(`Error computing flag locally: ${flag.key}: ${e}`))
|
|
191
201
|
}
|
|
@@ -432,7 +442,12 @@ class FeatureFlagsPoller {
|
|
|
432
442
|
break
|
|
433
443
|
}
|
|
434
444
|
} catch (e) {
|
|
435
|
-
if (e instanceof
|
|
445
|
+
if (e instanceof RequiresServerEvaluation) {
|
|
446
|
+
// Static cohort or other missing server-side data - must fallback to API
|
|
447
|
+
throw e
|
|
448
|
+
} else if (e instanceof InconclusiveMatchError) {
|
|
449
|
+
// Evaluation error (bad regex, invalid date, missing property, etc.)
|
|
450
|
+
// Track that we had an inconclusive match, but try other conditions
|
|
436
451
|
isInconclusive = true
|
|
437
452
|
} else {
|
|
438
453
|
throw e
|
|
@@ -443,6 +458,7 @@ class FeatureFlagsPoller {
|
|
|
443
458
|
if (result !== undefined) {
|
|
444
459
|
return result
|
|
445
460
|
} else if (isInconclusive) {
|
|
461
|
+
// Had evaluation errors and no successful match - can't determine locally
|
|
446
462
|
throw new InconclusiveMatchError("Can't determine if feature flag is enabled or not with given properties")
|
|
447
463
|
}
|
|
448
464
|
|
|
@@ -817,7 +833,9 @@ function matchCohort(
|
|
|
817
833
|
): boolean {
|
|
818
834
|
const cohortId = String(property.value)
|
|
819
835
|
if (!(cohortId in cohortProperties)) {
|
|
820
|
-
throw new
|
|
836
|
+
throw new RequiresServerEvaluation(
|
|
837
|
+
`cohort ${cohortId} not found in local cohorts - likely a static cohort that requires server evaluation`
|
|
838
|
+
)
|
|
821
839
|
}
|
|
822
840
|
|
|
823
841
|
const propertyGroup = cohortProperties[cohortId]
|
|
@@ -860,7 +878,10 @@ function matchPropertyGroup(
|
|
|
860
878
|
}
|
|
861
879
|
}
|
|
862
880
|
} catch (err) {
|
|
863
|
-
if (err instanceof
|
|
881
|
+
if (err instanceof RequiresServerEvaluation) {
|
|
882
|
+
// Immediately propagate - this condition requires server-side data
|
|
883
|
+
throw err
|
|
884
|
+
} else if (err instanceof InconclusiveMatchError) {
|
|
864
885
|
if (debugMode) {
|
|
865
886
|
console.debug(`Failed to compute property ${prop} locally: ${err}`)
|
|
866
887
|
}
|
|
@@ -914,7 +935,10 @@ function matchPropertyGroup(
|
|
|
914
935
|
}
|
|
915
936
|
}
|
|
916
937
|
} catch (err) {
|
|
917
|
-
if (err instanceof
|
|
938
|
+
if (err instanceof RequiresServerEvaluation) {
|
|
939
|
+
// Immediately propagate - this condition requires server-side data
|
|
940
|
+
throw err
|
|
941
|
+
} else if (err instanceof InconclusiveMatchError) {
|
|
918
942
|
if (debugMode) {
|
|
919
943
|
console.debug(`Failed to compute property ${prop} locally: ${err}`)
|
|
920
944
|
}
|
|
@@ -999,5 +1023,6 @@ export {
|
|
|
999
1023
|
matchProperty,
|
|
1000
1024
|
relativeDateParseForFeatureFlagMatching,
|
|
1001
1025
|
InconclusiveMatchError,
|
|
1026
|
+
RequiresServerEvaluation,
|
|
1002
1027
|
ClientError,
|
|
1003
1028
|
}
|
package/src/version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = '5.10.
|
|
1
|
+
export const version = '5.10.1'
|