@posthog/core 1.69.9 → 1.71.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/capture-v1/package.json +6 -0
- package/dist/capture-v1/compression.d.ts +18 -0
- package/dist/capture-v1/compression.d.ts.map +1 -0
- package/dist/capture-v1/compression.js +70 -0
- package/dist/capture-v1/compression.mjs +26 -0
- package/dist/capture-v1/errors.d.ts +48 -0
- package/dist/capture-v1/errors.d.ts.map +1 -0
- package/dist/capture-v1/errors.js +82 -0
- package/dist/capture-v1/errors.mjs +38 -0
- package/dist/capture-v1/index.d.ts +15 -0
- package/dist/capture-v1/index.d.ts.map +1 -0
- package/dist/capture-v1/index.js +88 -0
- package/dist/capture-v1/index.mjs +7 -0
- package/dist/capture-v1/sender.d.ts +150 -0
- package/dist/capture-v1/sender.d.ts.map +1 -0
- package/dist/capture-v1/sender.js +554 -0
- package/dist/capture-v1/sender.mjs +507 -0
- package/dist/capture-v1/serialize.d.ts +30 -0
- package/dist/capture-v1/serialize.d.ts.map +1 -0
- package/dist/capture-v1/serialize.js +106 -0
- package/dist/capture-v1/serialize.mjs +59 -0
- package/dist/capture-v1/transform.d.ts +19 -0
- package/dist/capture-v1/transform.d.ts.map +1 -0
- package/dist/capture-v1/transform.js +118 -0
- package/dist/capture-v1/transform.mjs +77 -0
- package/dist/capture-v1/types.d.ts +52 -0
- package/dist/capture-v1/types.d.ts.map +1 -0
- package/dist/capture-v1/types.js +44 -0
- package/dist/capture-v1/types.mjs +3 -0
- package/dist/capture-v1/uuid.d.ts +9 -0
- package/dist/capture-v1/uuid.d.ts.map +1 -0
- package/dist/capture-v1/uuid.js +75 -0
- package/dist/capture-v1/uuid.mjs +34 -0
- package/dist/featureFlagLocalEvaluation.d.ts +2 -0
- package/dist/featureFlagLocalEvaluation.d.ts.map +1 -1
- package/dist/featureFlagLocalEvaluation.js +38 -0
- package/dist/featureFlagLocalEvaluation.mjs +38 -0
- package/dist/featureFlagUtils.d.ts +7 -5
- package/dist/featureFlagUtils.d.ts.map +1 -1
- package/dist/featureFlagUtils.js +17 -11
- package/dist/featureFlagUtils.mjs +14 -11
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +27 -16
- package/dist/index.mjs +1 -1
- package/dist/posthog-core-stateless.d.ts +44 -7
- package/dist/posthog-core-stateless.d.ts.map +1 -1
- package/dist/posthog-core-stateless.js +103 -24
- package/dist/posthog-core-stateless.mjs +103 -24
- package/dist/posthog-core.d.ts +138 -53
- package/dist/posthog-core.d.ts.map +1 -1
- package/dist/posthog-core.js +341 -115
- package/dist/posthog-core.mjs +338 -115
- package/dist/types.d.ts +33 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/index.d.ts +1 -1
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +25 -12
- package/dist/utils/index.mjs +1 -1
- package/dist/utils/json-utils.d.ts +11 -1
- package/dist/utils/json-utils.d.ts.map +1 -1
- package/dist/utils/json-utils.js +50 -2
- package/dist/utils/json-utils.mjs +46 -1
- package/package.json +13 -3
- package/src/capture-v1/compression.ts +50 -0
- package/src/capture-v1/errors.ts +91 -0
- package/src/capture-v1/index.ts +34 -0
- package/src/capture-v1/sender.ts +779 -0
- package/src/capture-v1/serialize.ts +113 -0
- package/src/capture-v1/transform.ts +135 -0
- package/src/capture-v1/types.ts +59 -0
- package/src/capture-v1/uuid.ts +53 -0
- package/src/featureFlagLocalEvaluation.ts +51 -0
- package/src/featureFlagUtils.ts +22 -10
- package/src/index.ts +1 -0
- package/src/posthog-core-stateless.ts +190 -35
- package/src/posthog-core.ts +615 -178
- package/src/types.ts +31 -1
- package/src/utils/index.ts +1 -1
- package/src/utils/json-utils.ts +64 -1
- package/src/error-tracking/chunk-ids.spec.ts +0 -77
- package/src/error-tracking/coercers/error-event-coercer.spec.ts +0 -142
- package/src/error-tracking/coercers/promise-rejection-event.spec.ts +0 -77
- package/src/error-tracking/coercers/string-coercer.spec.ts +0 -26
- package/src/error-tracking/error-properties-builder.aggregate-errors.spec.ts +0 -412
- package/src/error-tracking/error-properties-builder.coerce.spec.ts +0 -337
- package/src/error-tracking/error-properties-builder.metadata.spec.ts +0 -318
- package/src/error-tracking/error-properties-builder.parse.spec.ts +0 -37
- package/src/error-tracking/exception-steps.spec.ts +0 -115
- package/src/error-tracking/parsers/base.spec.ts +0 -156
- package/src/error-tracking/parsers/index.spec.ts +0 -270
- package/src/error-tracking/parsers/node.spec.ts +0 -34
- package/src/error-tracking/release.spec.ts +0 -34
- package/src/logs/index.spec.ts +0 -2421
- package/src/logs/logs-utils.spec.ts +0 -266
- package/src/metrics/index.spec.ts +0 -1249
- package/src/surveys/activation.spec.ts +0 -61
- package/src/surveys/events.spec.ts +0 -183
- package/src/surveys/keys.spec.ts +0 -29
- package/src/surveys/property-matching.spec.ts +0 -539
- package/src/surveys/shuffling.spec.ts +0 -51
- package/src/surveys/translations.spec.ts +0 -274
- package/src/surveys/validation.spec.ts +0 -168
- package/src/traces/config.spec.ts +0 -271
- package/src/traces/ids.spec.ts +0 -115
- package/src/traces/index.spec.ts +0 -3287
- package/src/traces/live-spans.spec.ts +0 -69
- package/src/traces/otlp.spec.ts +0 -368
- package/src/traces/span.spec.ts +0 -1137
- package/src/traces/traceparent.spec.ts +0 -184
- package/src/utils/bot-detection.spec.ts +0 -107
- package/src/utils/bucketed-rate-limiter.spec.ts +0 -327
- package/src/utils/json-utils.spec.ts +0 -115
- package/src/utils/named-error.spec.ts +0 -36
- package/src/utils/number-utils.spec.ts +0 -212
- package/src/utils/otlp-any-value.spec.ts +0 -376
- package/src/utils/otlp-resource.spec.ts +0 -171
- package/src/utils/promise-queue.spec.ts +0 -55
- package/src/utils/string-utils.spec.ts +0 -158
- package/src/utils/type-utils.spec.ts +0 -38
- package/src/utils/webview-app-utils.spec.ts +0 -118
- package/src/vendor/uuidv7.spec.ts +0 -26
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { safeJsonStringify } from "../utils/string-utils.mjs";
|
|
2
|
+
import { buildV1Event } from "./transform.mjs";
|
|
3
|
+
const encoder = "u" < typeof TextEncoder ? void 0 : new TextEncoder();
|
|
4
|
+
function utf8Length(value) {
|
|
5
|
+
return encoder ? encoder.encode(value).length : countUtf8Bytes(value);
|
|
6
|
+
}
|
|
7
|
+
function countUtf8Bytes(value) {
|
|
8
|
+
let bytes = 0;
|
|
9
|
+
for(let index = 0; index < value.length; index++){
|
|
10
|
+
const code = value.charCodeAt(index);
|
|
11
|
+
if (code < 0x80) bytes += 1;
|
|
12
|
+
else if (code < 0x800) bytes += 2;
|
|
13
|
+
else if (code >= 0xd800 && code <= 0xdbff && index + 1 < value.length) {
|
|
14
|
+
const next = value.charCodeAt(index + 1);
|
|
15
|
+
if (next >= 0xdc00 && next <= 0xdfff) {
|
|
16
|
+
bytes += 4;
|
|
17
|
+
index++;
|
|
18
|
+
} else bytes += 3;
|
|
19
|
+
} else bytes += 3;
|
|
20
|
+
}
|
|
21
|
+
return bytes;
|
|
22
|
+
}
|
|
23
|
+
const PROPERTIES_KEY = ',"properties":';
|
|
24
|
+
const PROPERTIES_KEY_BYTES = utf8Length(PROPERTIES_KEY);
|
|
25
|
+
const LONE_SURROGATE = /[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:^|[^\uD800-\uDBFF])[\uDC00-\uDFFF]/;
|
|
26
|
+
const LONE_SURROGATE_ESCAPE = /\\\\|\\u[dD][89a-fA-F][0-9a-fA-F]{2}/g;
|
|
27
|
+
function wireProblem(message) {
|
|
28
|
+
const { event, distinct_id: distinctId, properties } = message;
|
|
29
|
+
if ('string' != typeof event || '' === event) return 'event name is missing, empty or not a string';
|
|
30
|
+
if ('string' != typeof distinctId) return 'distinct id is missing or not a string';
|
|
31
|
+
const props = properties ?? {};
|
|
32
|
+
const ids = [
|
|
33
|
+
event,
|
|
34
|
+
distinctId,
|
|
35
|
+
props.$session_id,
|
|
36
|
+
props.$window_id
|
|
37
|
+
];
|
|
38
|
+
if (ids.some((value)=>'string' == typeof value && LONE_SURROGATE.test(value))) return 'event name or id is not well-formed Unicode';
|
|
39
|
+
}
|
|
40
|
+
function repairLoneSurrogates(json) {
|
|
41
|
+
return json.includes('\\ud') || json.includes('\\uD') ? json.replace(LONE_SURROGATE_ESCAPE, (match)=>2 === match.length ? match : '\\ufffd') : json;
|
|
42
|
+
}
|
|
43
|
+
function serializeV1Event(message) {
|
|
44
|
+
const { properties, ...rest } = buildV1Event(message);
|
|
45
|
+
const restJson = repairLoneSurrogates(safeJsonStringify(rest));
|
|
46
|
+
const propertiesJson = repairLoneSurrogates(safeJsonStringify(properties));
|
|
47
|
+
const propertiesBytes = utf8Length(propertiesJson);
|
|
48
|
+
return {
|
|
49
|
+
uuid: rest.uuid,
|
|
50
|
+
json: `${restJson.slice(0, -1)}${PROPERTIES_KEY}${propertiesJson}}`,
|
|
51
|
+
bytes: utf8Length(restJson) + PROPERTIES_KEY_BYTES + propertiesBytes,
|
|
52
|
+
propertiesBytes
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
function buildV1Body(events, { createdAt, historicalMigration }) {
|
|
56
|
+
const migration = historicalMigration ? ',"historical_migration":true' : '';
|
|
57
|
+
return `{"created_at":${JSON.stringify(createdAt)}${migration},"batch":[${events.map((event)=>event.json).join(',')}]}`;
|
|
58
|
+
}
|
|
59
|
+
export { buildV1Body, serializeV1Event, utf8Length, wireProblem };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { JsonType, PostHogEventProperties } from '../types';
|
|
2
|
+
import type { V1Event } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* A copy of the caller's per-event options, or undefined when there are none. Any value that
|
|
5
|
+
* is not an object is reported and ignored, so the event is still sent.
|
|
6
|
+
*/
|
|
7
|
+
export declare function readEventOptions(value: unknown): Record<string, JsonType> | undefined;
|
|
8
|
+
/**
|
|
9
|
+
* Transform one already-normalized queued message into a Capture V1 wire event.
|
|
10
|
+
*
|
|
11
|
+
* The input message is never mutated (events may be retried or handed to
|
|
12
|
+
* callbacks): fresh `options` and `properties` maps are built. Option values are
|
|
13
|
+
* sent unchanged; capture reads them. Each legacy option property is removed from
|
|
14
|
+
* `properties` and fills its option when the caller left that option missing or
|
|
15
|
+
* `null`. `$session_id`/`$window_id` move to the top-level `session_id`/`window_id`
|
|
16
|
+
* fields; top-level `$set`/`$set_once` are relocated into `properties`.
|
|
17
|
+
*/
|
|
18
|
+
export declare function buildV1Event(message: PostHogEventProperties): V1Event;
|
|
19
|
+
//# sourceMappingURL=transform.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transform.d.ts","sourceRoot":"","sources":["../../src/capture-v1/transform.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,sBAAsB,EAAE,MAAM,UAAU,CAAA;AAEhE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AAgBtC;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,GAAG,SAAS,CAYrF;AA6CD;;;;;;;;;GASG;AACH,wBAAgB,YAAY,CAAC,OAAO,EAAE,sBAAsB,GAAG,OAAO,CA4CrE"}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.d = (exports1, getters, values)=>{
|
|
5
|
+
var define = (defs, kind)=>{
|
|
6
|
+
for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
[kind]: defs[key]
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
define(getters, "get");
|
|
12
|
+
define(values, "value");
|
|
13
|
+
};
|
|
14
|
+
})();
|
|
15
|
+
(()=>{
|
|
16
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
17
|
+
})();
|
|
18
|
+
(()=>{
|
|
19
|
+
__webpack_require__.r = (exports1)=>{
|
|
20
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
21
|
+
value: 'Module'
|
|
22
|
+
});
|
|
23
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
24
|
+
value: true
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
})();
|
|
28
|
+
var __webpack_exports__ = {};
|
|
29
|
+
__webpack_require__.r(__webpack_exports__);
|
|
30
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
31
|
+
buildV1Event: ()=>buildV1Event,
|
|
32
|
+
readEventOptions: ()=>readEventOptions
|
|
33
|
+
});
|
|
34
|
+
const external_event_options_js_namespaceObject = require("../event-options.js");
|
|
35
|
+
const TOPLEVEL_SENTINELS = [
|
|
36
|
+
{
|
|
37
|
+
property: '$session_id',
|
|
38
|
+
field: 'session_id'
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
property: '$window_id',
|
|
42
|
+
field: 'window_id'
|
|
43
|
+
}
|
|
44
|
+
];
|
|
45
|
+
function isRecord(value) {
|
|
46
|
+
return 'object' == typeof value && null !== value && !Array.isArray(value);
|
|
47
|
+
}
|
|
48
|
+
function jsonTypeName(value) {
|
|
49
|
+
return Array.isArray(value) ? 'array' : typeof value;
|
|
50
|
+
}
|
|
51
|
+
function readEventOptions(value) {
|
|
52
|
+
if (null == value) return;
|
|
53
|
+
if (isRecord(value)) return {
|
|
54
|
+
...value
|
|
55
|
+
};
|
|
56
|
+
console.error(`[PostHog] options must be an object, got ${jsonTypeName(value)}; sending the event without its options`);
|
|
57
|
+
}
|
|
58
|
+
function replaceUnparseableTimestamp() {
|
|
59
|
+
console.warn('[PostHog] replacing an unparseable event timestamp with the current time');
|
|
60
|
+
return new Date().toISOString();
|
|
61
|
+
}
|
|
62
|
+
function toRfc3339(timestamp) {
|
|
63
|
+
if ('string' == typeof timestamp) {
|
|
64
|
+
const asDate = new Date(timestamp);
|
|
65
|
+
if (Number.isNaN(asDate.getTime())) return replaceUnparseableTimestamp();
|
|
66
|
+
const normalized = asDate.toISOString();
|
|
67
|
+
const fractionalSeconds = timestamp.match(/\.(\d+)(?:Z|[+-]\d{2}:?\d{2})?$/i)?.[1];
|
|
68
|
+
return fractionalSeconds && fractionalSeconds.length > 3 ? normalized.replace(/\.\d{3}Z$/, `.${fractionalSeconds}Z`) : normalized;
|
|
69
|
+
}
|
|
70
|
+
if (timestamp instanceof Date) return Number.isNaN(timestamp.getTime()) ? replaceUnparseableTimestamp() : timestamp.toISOString();
|
|
71
|
+
const asDate = null == timestamp ? new Date() : new Date(timestamp);
|
|
72
|
+
return Number.isNaN(asDate.getTime()) ? new Date().toISOString() : asDate.toISOString();
|
|
73
|
+
}
|
|
74
|
+
function relocateInto(properties, key, value) {
|
|
75
|
+
if (void 0 !== value && !(key in properties)) properties[key] = value;
|
|
76
|
+
}
|
|
77
|
+
function buildV1Event(message) {
|
|
78
|
+
const sourceProperties = isRecord(message.properties) ? message.properties : {};
|
|
79
|
+
const properties = {
|
|
80
|
+
...sourceProperties
|
|
81
|
+
};
|
|
82
|
+
const options = readEventOptions(message.options) ?? {};
|
|
83
|
+
for (const [optionKey, property] of Object.entries(external_event_options_js_namespaceObject.EVENT_OPTION_LEGACY_PROPERTIES)){
|
|
84
|
+
if (!(property in properties)) continue;
|
|
85
|
+
const legacyValue = properties[property];
|
|
86
|
+
delete properties[property];
|
|
87
|
+
const option = options[optionKey];
|
|
88
|
+
if (null == option && void 0 !== legacyValue) options[optionKey] = legacyValue;
|
|
89
|
+
}
|
|
90
|
+
const topLevel = {};
|
|
91
|
+
for (const { property, field } of TOPLEVEL_SENTINELS){
|
|
92
|
+
if (!(property in properties)) continue;
|
|
93
|
+
const value = properties[property];
|
|
94
|
+
delete properties[property];
|
|
95
|
+
if ('string' == typeof value) topLevel[field] = value;
|
|
96
|
+
else if (null != value) console.warn(`[PostHog] dropping ${property}: a ${jsonTypeName(value)} value is not a string`);
|
|
97
|
+
}
|
|
98
|
+
relocateInto(properties, '$set', message.$set);
|
|
99
|
+
relocateInto(properties, '$set_once', message.$set_once);
|
|
100
|
+
return {
|
|
101
|
+
event: String(message.event ?? ''),
|
|
102
|
+
uuid: String(message.uuid ?? ''),
|
|
103
|
+
distinct_id: String(message.distinct_id ?? ''),
|
|
104
|
+
timestamp: toRfc3339(message.timestamp),
|
|
105
|
+
...topLevel,
|
|
106
|
+
options,
|
|
107
|
+
properties
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
exports.buildV1Event = __webpack_exports__.buildV1Event;
|
|
111
|
+
exports.readEventOptions = __webpack_exports__.readEventOptions;
|
|
112
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
113
|
+
"buildV1Event",
|
|
114
|
+
"readEventOptions"
|
|
115
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
116
|
+
Object.defineProperty(exports, '__esModule', {
|
|
117
|
+
value: true
|
|
118
|
+
});
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { EVENT_OPTION_LEGACY_PROPERTIES } from "../event-options.mjs";
|
|
2
|
+
const TOPLEVEL_SENTINELS = [
|
|
3
|
+
{
|
|
4
|
+
property: '$session_id',
|
|
5
|
+
field: 'session_id'
|
|
6
|
+
},
|
|
7
|
+
{
|
|
8
|
+
property: '$window_id',
|
|
9
|
+
field: 'window_id'
|
|
10
|
+
}
|
|
11
|
+
];
|
|
12
|
+
function isRecord(value) {
|
|
13
|
+
return 'object' == typeof value && null !== value && !Array.isArray(value);
|
|
14
|
+
}
|
|
15
|
+
function jsonTypeName(value) {
|
|
16
|
+
return Array.isArray(value) ? 'array' : typeof value;
|
|
17
|
+
}
|
|
18
|
+
function readEventOptions(value) {
|
|
19
|
+
if (null == value) return;
|
|
20
|
+
if (isRecord(value)) return {
|
|
21
|
+
...value
|
|
22
|
+
};
|
|
23
|
+
console.error(`[PostHog] options must be an object, got ${jsonTypeName(value)}; sending the event without its options`);
|
|
24
|
+
}
|
|
25
|
+
function replaceUnparseableTimestamp() {
|
|
26
|
+
console.warn('[PostHog] replacing an unparseable event timestamp with the current time');
|
|
27
|
+
return new Date().toISOString();
|
|
28
|
+
}
|
|
29
|
+
function toRfc3339(timestamp) {
|
|
30
|
+
if ('string' == typeof timestamp) {
|
|
31
|
+
const asDate = new Date(timestamp);
|
|
32
|
+
if (Number.isNaN(asDate.getTime())) return replaceUnparseableTimestamp();
|
|
33
|
+
const normalized = asDate.toISOString();
|
|
34
|
+
const fractionalSeconds = timestamp.match(/\.(\d+)(?:Z|[+-]\d{2}:?\d{2})?$/i)?.[1];
|
|
35
|
+
return fractionalSeconds && fractionalSeconds.length > 3 ? normalized.replace(/\.\d{3}Z$/, `.${fractionalSeconds}Z`) : normalized;
|
|
36
|
+
}
|
|
37
|
+
if (timestamp instanceof Date) return Number.isNaN(timestamp.getTime()) ? replaceUnparseableTimestamp() : timestamp.toISOString();
|
|
38
|
+
const asDate = null == timestamp ? new Date() : new Date(timestamp);
|
|
39
|
+
return Number.isNaN(asDate.getTime()) ? new Date().toISOString() : asDate.toISOString();
|
|
40
|
+
}
|
|
41
|
+
function relocateInto(properties, key, value) {
|
|
42
|
+
if (void 0 !== value && !(key in properties)) properties[key] = value;
|
|
43
|
+
}
|
|
44
|
+
function buildV1Event(message) {
|
|
45
|
+
const sourceProperties = isRecord(message.properties) ? message.properties : {};
|
|
46
|
+
const properties = {
|
|
47
|
+
...sourceProperties
|
|
48
|
+
};
|
|
49
|
+
const options = readEventOptions(message.options) ?? {};
|
|
50
|
+
for (const [optionKey, property] of Object.entries(EVENT_OPTION_LEGACY_PROPERTIES)){
|
|
51
|
+
if (!(property in properties)) continue;
|
|
52
|
+
const legacyValue = properties[property];
|
|
53
|
+
delete properties[property];
|
|
54
|
+
const option = options[optionKey];
|
|
55
|
+
if (null == option && void 0 !== legacyValue) options[optionKey] = legacyValue;
|
|
56
|
+
}
|
|
57
|
+
const topLevel = {};
|
|
58
|
+
for (const { property, field } of TOPLEVEL_SENTINELS){
|
|
59
|
+
if (!(property in properties)) continue;
|
|
60
|
+
const value = properties[property];
|
|
61
|
+
delete properties[property];
|
|
62
|
+
if ('string' == typeof value) topLevel[field] = value;
|
|
63
|
+
else if (null != value) console.warn(`[PostHog] dropping ${property}: a ${jsonTypeName(value)} value is not a string`);
|
|
64
|
+
}
|
|
65
|
+
relocateInto(properties, '$set', message.$set);
|
|
66
|
+
relocateInto(properties, '$set_once', message.$set_once);
|
|
67
|
+
return {
|
|
68
|
+
event: String(message.event ?? ''),
|
|
69
|
+
uuid: String(message.uuid ?? ''),
|
|
70
|
+
distinct_id: String(message.distinct_id ?? ''),
|
|
71
|
+
timestamp: toRfc3339(message.timestamp),
|
|
72
|
+
...topLevel,
|
|
73
|
+
options,
|
|
74
|
+
properties
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
export { buildV1Event, readEventOptions };
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { JsonType, PostHogEventProperties } from '../types';
|
|
2
|
+
/** Capture lane for analytics events. */
|
|
3
|
+
export declare const ANALYTICS_CAPTURE_ENDPOINT = "/i/v1/analytics/events";
|
|
4
|
+
/** Capture lane for events sent through `captureAi`. */
|
|
5
|
+
export declare const AI_CAPTURE_ENDPOINT = "/i/v1/ai/events";
|
|
6
|
+
export type CaptureEndpoint = typeof ANALYTICS_CAPTURE_ENDPOINT | typeof AI_CAPTURE_ENDPOINT;
|
|
7
|
+
/**
|
|
8
|
+
* The `options` object on a Capture V1 event: the caller's options plus any legacy
|
|
9
|
+
* `$`-prefixed option properties lifted by the transform. Values are sent unchanged.
|
|
10
|
+
* Always serialized as an object (`{}` when empty), never `null`.
|
|
11
|
+
*/
|
|
12
|
+
export interface V1EventOptions {
|
|
13
|
+
/** Whether to process this event in cookieless mode. */
|
|
14
|
+
cookieless_mode?: boolean;
|
|
15
|
+
/** Whether to disable server-side timestamp skew correction for this event. */
|
|
16
|
+
disable_skew_correction?: boolean;
|
|
17
|
+
/** Whether to create or update a person profile for this event. */
|
|
18
|
+
process_person_profile?: boolean;
|
|
19
|
+
/** Additional capture options, sent to capture v1 unchanged. */
|
|
20
|
+
[key: string]: JsonType | undefined;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* A single event in a Capture V1 batch.
|
|
24
|
+
* `session_id`/`window_id` are promoted from the `$session_id`/`$window_id`
|
|
25
|
+
* sentinels; there is no top-level `api_key`.
|
|
26
|
+
*/
|
|
27
|
+
export interface V1Event {
|
|
28
|
+
event: string;
|
|
29
|
+
uuid: string;
|
|
30
|
+
distinct_id: string;
|
|
31
|
+
timestamp: string;
|
|
32
|
+
session_id?: string;
|
|
33
|
+
window_id?: string;
|
|
34
|
+
options: V1EventOptions;
|
|
35
|
+
properties: PostHogEventProperties;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Per-event result codes in a v1 2xx response body. Unknown strings are
|
|
39
|
+
* tolerated as terminal success for forward compatibility.
|
|
40
|
+
*/
|
|
41
|
+
export type V1ResultCode = 'ok' | 'warning' | 'drop' | 'retry';
|
|
42
|
+
export interface V1EventResult {
|
|
43
|
+
result: V1ResultCode | string;
|
|
44
|
+
details?: string | null;
|
|
45
|
+
/** How many later copies of this uuid in the request the server dropped as duplicates. */
|
|
46
|
+
duplicates_dropped?: number;
|
|
47
|
+
}
|
|
48
|
+
/** Shape of a v1 2xx response body: a per-uuid map of results. */
|
|
49
|
+
export interface V1BatchResponse {
|
|
50
|
+
results: Record<string, V1EventResult>;
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/capture-v1/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,sBAAsB,EAAE,MAAM,UAAU,CAAA;AAEhE,yCAAyC;AACzC,eAAO,MAAM,0BAA0B,2BAA2B,CAAA;AAElE,wDAAwD;AACxD,eAAO,MAAM,mBAAmB,oBAAoB,CAAA;AAEpD,MAAM,MAAM,eAAe,GAAG,OAAO,0BAA0B,GAAG,OAAO,mBAAmB,CAAA;AAE5F;;;;GAIG;AACH,MAAM,WAAW,cAAc;IAC7B,wDAAwD;IACxD,eAAe,CAAC,EAAE,OAAO,CAAA;IACzB,+EAA+E;IAC/E,uBAAuB,CAAC,EAAE,OAAO,CAAA;IACjC,mEAAmE;IACnE,sBAAsB,CAAC,EAAE,OAAO,CAAA;IAChC,gEAAgE;IAChE,CAAC,GAAG,EAAE,MAAM,GAAG,QAAQ,GAAG,SAAS,CAAA;CACpC;AAED;;;;GAIG;AACH,MAAM,WAAW,OAAO;IACtB,KAAK,EAAE,MAAM,CAAA;IACb,IAAI,EAAE,MAAM,CAAA;IACZ,WAAW,EAAE,MAAM,CAAA;IACnB,SAAS,EAAE,MAAM,CAAA;IACjB,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,OAAO,EAAE,cAAc,CAAA;IACvB,UAAU,EAAE,sBAAsB,CAAA;CACnC;AAED;;;GAGG;AACH,MAAM,MAAM,YAAY,GAAG,IAAI,GAAG,SAAS,GAAG,MAAM,GAAG,OAAO,CAAA;AAE9D,MAAM,WAAW,aAAa;IAC5B,MAAM,EAAE,YAAY,GAAG,MAAM,CAAA;IAC7B,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IACvB,0FAA0F;IAC1F,kBAAkB,CAAC,EAAE,MAAM,CAAA;CAC5B;AAED,kEAAkE;AAClE,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAA;CACvC"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.d = (exports1, getters, values)=>{
|
|
5
|
+
var define = (defs, kind)=>{
|
|
6
|
+
for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
[kind]: defs[key]
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
define(getters, "get");
|
|
12
|
+
define(values, "value");
|
|
13
|
+
};
|
|
14
|
+
})();
|
|
15
|
+
(()=>{
|
|
16
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
17
|
+
})();
|
|
18
|
+
(()=>{
|
|
19
|
+
__webpack_require__.r = (exports1)=>{
|
|
20
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
21
|
+
value: 'Module'
|
|
22
|
+
});
|
|
23
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
24
|
+
value: true
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
})();
|
|
28
|
+
var __webpack_exports__ = {};
|
|
29
|
+
__webpack_require__.r(__webpack_exports__);
|
|
30
|
+
const ANALYTICS_CAPTURE_ENDPOINT = '/i/v1/analytics/events';
|
|
31
|
+
const AI_CAPTURE_ENDPOINT = '/i/v1/ai/events';
|
|
32
|
+
__webpack_require__.d(__webpack_exports__, {}, {
|
|
33
|
+
AI_CAPTURE_ENDPOINT: AI_CAPTURE_ENDPOINT,
|
|
34
|
+
ANALYTICS_CAPTURE_ENDPOINT: ANALYTICS_CAPTURE_ENDPOINT
|
|
35
|
+
});
|
|
36
|
+
exports.AI_CAPTURE_ENDPOINT = __webpack_exports__.AI_CAPTURE_ENDPOINT;
|
|
37
|
+
exports.ANALYTICS_CAPTURE_ENDPOINT = __webpack_exports__.ANALYTICS_CAPTURE_ENDPOINT;
|
|
38
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
39
|
+
"AI_CAPTURE_ENDPOINT",
|
|
40
|
+
"ANALYTICS_CAPTURE_ENDPOINT"
|
|
41
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
42
|
+
Object.defineProperty(exports, '__esModule', {
|
|
43
|
+
value: true
|
|
44
|
+
});
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The lowercase, hyphenated form of an RFC 4122 uuid string, or undefined for anything else.
|
|
3
|
+
* Accepts 32 hex digits, the hyphenated form, the hyphenated form in braces, and the
|
|
4
|
+
* `urn:uuid:` form, in any case.
|
|
5
|
+
*/
|
|
6
|
+
export declare function canonicalizeUuid(value: string): string | undefined;
|
|
7
|
+
/** A v7 uuid for an event or a personless distinct id, with random bits from `crypto.getRandomValues`. */
|
|
8
|
+
export declare function eventUuidv7(): string;
|
|
9
|
+
//# sourceMappingURL=uuid.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"uuid.d.ts","sourceRoot":"","sources":["../../src/capture-v1/uuid.ts"],"names":[],"mappings":"AAMA;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAUlE;AA4BD,0GAA0G;AAC1G,wBAAgB,WAAW,IAAI,MAAM,CAEpC"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.d = (exports1, getters, values)=>{
|
|
5
|
+
var define = (defs, kind)=>{
|
|
6
|
+
for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
[kind]: defs[key]
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
define(getters, "get");
|
|
12
|
+
define(values, "value");
|
|
13
|
+
};
|
|
14
|
+
})();
|
|
15
|
+
(()=>{
|
|
16
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
17
|
+
})();
|
|
18
|
+
(()=>{
|
|
19
|
+
__webpack_require__.r = (exports1)=>{
|
|
20
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
21
|
+
value: 'Module'
|
|
22
|
+
});
|
|
23
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
24
|
+
value: true
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
})();
|
|
28
|
+
var __webpack_exports__ = {};
|
|
29
|
+
__webpack_require__.r(__webpack_exports__);
|
|
30
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
31
|
+
canonicalizeUuid: ()=>canonicalizeUuid,
|
|
32
|
+
eventUuidv7: ()=>eventUuidv7
|
|
33
|
+
});
|
|
34
|
+
const uuidv7_js_namespaceObject = require("../vendor/uuidv7.js");
|
|
35
|
+
const HYPHENATED = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
36
|
+
const HEX_32 = /^[0-9a-f]{32}$/i;
|
|
37
|
+
const URN_PREFIX = 'urn:uuid:';
|
|
38
|
+
function canonicalizeUuid(value) {
|
|
39
|
+
let hyphenated = value;
|
|
40
|
+
if (38 === value.length && value.startsWith('{') && value.endsWith('}')) hyphenated = value.slice(1, -1);
|
|
41
|
+
else if (45 === value.length && value.slice(0, URN_PREFIX.length).toLowerCase() === URN_PREFIX) hyphenated = value.slice(URN_PREFIX.length);
|
|
42
|
+
else if (HEX_32.test(value)) hyphenated = `${value.slice(0, 8)}-${value.slice(8, 12)}-${value.slice(12, 16)}-${value.slice(16, 20)}-${value.slice(20)}`;
|
|
43
|
+
return HYPHENATED.test(hyphenated) ? hyphenated.toLowerCase() : void 0;
|
|
44
|
+
}
|
|
45
|
+
class CryptoRandom {
|
|
46
|
+
constructor(crypto){
|
|
47
|
+
this.crypto = crypto;
|
|
48
|
+
this.words = new Uint32Array(8);
|
|
49
|
+
this.cursor = this.words.length;
|
|
50
|
+
}
|
|
51
|
+
nextUint32() {
|
|
52
|
+
if (this.cursor >= this.words.length) {
|
|
53
|
+
this.crypto.getRandomValues(this.words);
|
|
54
|
+
this.cursor = 0;
|
|
55
|
+
}
|
|
56
|
+
return this.words[this.cursor++];
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
function cryptoRandom() {
|
|
60
|
+
const crypto = globalThis.crypto;
|
|
61
|
+
return 'function' == typeof crypto?.getRandomValues ? new CryptoRandom(crypto) : void 0;
|
|
62
|
+
}
|
|
63
|
+
const generator = new uuidv7_js_namespaceObject.V7Generator(cryptoRandom());
|
|
64
|
+
function eventUuidv7() {
|
|
65
|
+
return generator.generate().toString();
|
|
66
|
+
}
|
|
67
|
+
exports.canonicalizeUuid = __webpack_exports__.canonicalizeUuid;
|
|
68
|
+
exports.eventUuidv7 = __webpack_exports__.eventUuidv7;
|
|
69
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
70
|
+
"canonicalizeUuid",
|
|
71
|
+
"eventUuidv7"
|
|
72
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
73
|
+
Object.defineProperty(exports, '__esModule', {
|
|
74
|
+
value: true
|
|
75
|
+
});
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { V7Generator } from "../vendor/uuidv7.mjs";
|
|
2
|
+
const HYPHENATED = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
3
|
+
const HEX_32 = /^[0-9a-f]{32}$/i;
|
|
4
|
+
const URN_PREFIX = 'urn:uuid:';
|
|
5
|
+
function canonicalizeUuid(value) {
|
|
6
|
+
let hyphenated = value;
|
|
7
|
+
if (38 === value.length && value.startsWith('{') && value.endsWith('}')) hyphenated = value.slice(1, -1);
|
|
8
|
+
else if (45 === value.length && value.slice(0, URN_PREFIX.length).toLowerCase() === URN_PREFIX) hyphenated = value.slice(URN_PREFIX.length);
|
|
9
|
+
else if (HEX_32.test(value)) hyphenated = `${value.slice(0, 8)}-${value.slice(8, 12)}-${value.slice(12, 16)}-${value.slice(16, 20)}-${value.slice(20)}`;
|
|
10
|
+
return HYPHENATED.test(hyphenated) ? hyphenated.toLowerCase() : void 0;
|
|
11
|
+
}
|
|
12
|
+
class CryptoRandom {
|
|
13
|
+
constructor(crypto){
|
|
14
|
+
this.crypto = crypto;
|
|
15
|
+
this.words = new Uint32Array(8);
|
|
16
|
+
this.cursor = this.words.length;
|
|
17
|
+
}
|
|
18
|
+
nextUint32() {
|
|
19
|
+
if (this.cursor >= this.words.length) {
|
|
20
|
+
this.crypto.getRandomValues(this.words);
|
|
21
|
+
this.cursor = 0;
|
|
22
|
+
}
|
|
23
|
+
return this.words[this.cursor++];
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
function cryptoRandom() {
|
|
27
|
+
const crypto = globalThis.crypto;
|
|
28
|
+
return 'function' == typeof crypto?.getRandomValues ? new CryptoRandom(crypto) : void 0;
|
|
29
|
+
}
|
|
30
|
+
const generator = new V7Generator(cryptoRandom());
|
|
31
|
+
function eventUuidv7() {
|
|
32
|
+
return generator.generate().toString();
|
|
33
|
+
}
|
|
34
|
+
export { canonicalizeUuid, eventUuidv7 };
|
|
@@ -11,6 +11,8 @@ export type MatchFeatureFlagPropertyOptions = {
|
|
|
11
11
|
semverParsingPolicy?: FeatureFlagSemverParsingPolicy;
|
|
12
12
|
/** Only version 2 enables explicit equality; absent/other versions use service legacy matching. */
|
|
13
13
|
propertyMatchingVersion?: number;
|
|
14
|
+
/** Keys the caller knows are absent. A listed key is absent even when `propertyValues` has a value for it. */
|
|
15
|
+
knownAbsentKeys?: ReadonlySet<string>;
|
|
14
16
|
};
|
|
15
17
|
export type FeatureFlagVariant = {
|
|
16
18
|
key: string;
|
|
@@ -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;
|
|
1
|
+
{"version":3,"file":"featureFlagLocalEvaluation.d.ts","sourceRoot":"","sources":["../src/featureFlagLocalEvaluation.ts"],"names":[],"mappings":"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"}
|
|
@@ -53,6 +53,38 @@ const NULL_VALUES_ALLOWED_OPERATORS = [
|
|
|
53
53
|
'regex',
|
|
54
54
|
'not_regex'
|
|
55
55
|
];
|
|
56
|
+
const KNOWN_ABSENT_MATCHING_OPERATORS = [
|
|
57
|
+
'is_not_set',
|
|
58
|
+
'is_not',
|
|
59
|
+
'not_icontains',
|
|
60
|
+
'not_starts_with',
|
|
61
|
+
'not_ends_with',
|
|
62
|
+
'not_regex'
|
|
63
|
+
];
|
|
64
|
+
const LOCALLY_SUPPORTED_OPERATORS = [
|
|
65
|
+
...KNOWN_ABSENT_MATCHING_OPERATORS,
|
|
66
|
+
'is_set',
|
|
67
|
+
'exact',
|
|
68
|
+
'icontains',
|
|
69
|
+
'starts_with',
|
|
70
|
+
'ends_with',
|
|
71
|
+
'regex',
|
|
72
|
+
'gt',
|
|
73
|
+
'gte',
|
|
74
|
+
'lt',
|
|
75
|
+
'lte',
|
|
76
|
+
'is_date_after',
|
|
77
|
+
'is_date_before',
|
|
78
|
+
'semver_eq',
|
|
79
|
+
'semver_neq',
|
|
80
|
+
'semver_gt',
|
|
81
|
+
'semver_gte',
|
|
82
|
+
'semver_lt',
|
|
83
|
+
'semver_lte',
|
|
84
|
+
'semver_tilde',
|
|
85
|
+
'semver_caret',
|
|
86
|
+
'semver_wildcard'
|
|
87
|
+
];
|
|
56
88
|
const LONG_SCALE = 0xfffffffffffffff;
|
|
57
89
|
class InconclusiveMatchError extends Error {
|
|
58
90
|
constructor(message, reason = 'unsupported_definition'){
|
|
@@ -494,6 +526,12 @@ function assertFeatureFlagFilterSupported(property, options = {}) {
|
|
|
494
526
|
}
|
|
495
527
|
}
|
|
496
528
|
function matchFeatureFlagProperty(property, propertyValues, options = {}) {
|
|
529
|
+
if (options.knownAbsentKeys?.has(property.key)) {
|
|
530
|
+
const operator = property.operator || 'exact';
|
|
531
|
+
if (null == property.value && 'is_set' !== operator && 'is_not_set' !== operator) throw new InconclusiveMatchError(`Operator ${operator} requires a condition value`);
|
|
532
|
+
if (!LOCALLY_SUPPORTED_OPERATORS.includes(operator)) throw new InconclusiveMatchError(`Unknown operator: ${property.operator}`);
|
|
533
|
+
return KNOWN_ABSENT_MATCHING_OPERATORS.includes(operator);
|
|
534
|
+
}
|
|
497
535
|
try {
|
|
498
536
|
return matchPropertyValue(property, propertyValues, options);
|
|
499
537
|
} catch (e) {
|
|
@@ -11,6 +11,38 @@ const NULL_VALUES_ALLOWED_OPERATORS = [
|
|
|
11
11
|
'regex',
|
|
12
12
|
'not_regex'
|
|
13
13
|
];
|
|
14
|
+
const KNOWN_ABSENT_MATCHING_OPERATORS = [
|
|
15
|
+
'is_not_set',
|
|
16
|
+
'is_not',
|
|
17
|
+
'not_icontains',
|
|
18
|
+
'not_starts_with',
|
|
19
|
+
'not_ends_with',
|
|
20
|
+
'not_regex'
|
|
21
|
+
];
|
|
22
|
+
const LOCALLY_SUPPORTED_OPERATORS = [
|
|
23
|
+
...KNOWN_ABSENT_MATCHING_OPERATORS,
|
|
24
|
+
'is_set',
|
|
25
|
+
'exact',
|
|
26
|
+
'icontains',
|
|
27
|
+
'starts_with',
|
|
28
|
+
'ends_with',
|
|
29
|
+
'regex',
|
|
30
|
+
'gt',
|
|
31
|
+
'gte',
|
|
32
|
+
'lt',
|
|
33
|
+
'lte',
|
|
34
|
+
'is_date_after',
|
|
35
|
+
'is_date_before',
|
|
36
|
+
'semver_eq',
|
|
37
|
+
'semver_neq',
|
|
38
|
+
'semver_gt',
|
|
39
|
+
'semver_gte',
|
|
40
|
+
'semver_lt',
|
|
41
|
+
'semver_lte',
|
|
42
|
+
'semver_tilde',
|
|
43
|
+
'semver_caret',
|
|
44
|
+
'semver_wildcard'
|
|
45
|
+
];
|
|
14
46
|
const LONG_SCALE = 0xfffffffffffffff;
|
|
15
47
|
class InconclusiveMatchError extends Error {
|
|
16
48
|
constructor(message, reason = 'unsupported_definition'){
|
|
@@ -452,6 +484,12 @@ function assertFeatureFlagFilterSupported(property, options = {}) {
|
|
|
452
484
|
}
|
|
453
485
|
}
|
|
454
486
|
function matchFeatureFlagProperty(property, propertyValues, options = {}) {
|
|
487
|
+
if (options.knownAbsentKeys?.has(property.key)) {
|
|
488
|
+
const operator = property.operator || 'exact';
|
|
489
|
+
if (null == property.value && 'is_set' !== operator && 'is_not_set' !== operator) throw new InconclusiveMatchError(`Operator ${operator} requires a condition value`);
|
|
490
|
+
if (!LOCALLY_SUPPORTED_OPERATORS.includes(operator)) throw new InconclusiveMatchError(`Unknown operator: ${property.operator}`);
|
|
491
|
+
return KNOWN_ABSENT_MATCHING_OPERATORS.includes(operator);
|
|
492
|
+
}
|
|
455
493
|
try {
|
|
456
494
|
return matchPropertyValue(property, propertyValues, options);
|
|
457
495
|
} catch (e) {
|