@claudeye/linux-arm64 1.0.4-beta.9 → 1.0.4
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/assets/standalone/.next/BUILD_ID +1 -1
- package/assets/standalone/.next/build-manifest.json +2 -2
- package/assets/standalone/.next/prerender-manifest.json +3 -3
- package/assets/standalone/.next/required-server-files.json +0 -3
- package/assets/standalone/.next/server/app/_global-error/page_client-reference-manifest.js +1 -1
- package/assets/standalone/.next/server/app/_global-error.html +2 -2
- package/assets/standalone/.next/server/app/_global-error.rsc +7 -7
- package/assets/standalone/.next/server/app/_global-error.segments/__PAGE__.segment.rsc +2 -2
- package/assets/standalone/.next/server/app/_global-error.segments/_full.segment.rsc +7 -7
- package/assets/standalone/.next/server/app/_global-error.segments/_head.segment.rsc +3 -3
- package/assets/standalone/.next/server/app/_global-error.segments/_index.segment.rsc +3 -3
- package/assets/standalone/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
- package/assets/standalone/.next/server/app/_not-found/page/server-reference-manifest.json +1 -1
- package/assets/standalone/.next/server/app/_not-found/page_client-reference-manifest.js +1 -1
- package/assets/standalone/.next/server/app/_not-found.html +2 -2
- package/assets/standalone/.next/server/app/_not-found.rsc +14 -14
- package/assets/standalone/.next/server/app/_not-found.segments/_full.segment.rsc +14 -14
- package/assets/standalone/.next/server/app/_not-found.segments/_head.segment.rsc +4 -4
- package/assets/standalone/.next/server/app/_not-found.segments/_index.segment.rsc +9 -9
- package/assets/standalone/.next/server/app/_not-found.segments/_not-found/__PAGE__.segment.rsc +2 -2
- package/assets/standalone/.next/server/app/_not-found.segments/_not-found.segment.rsc +3 -3
- package/assets/standalone/.next/server/app/_not-found.segments/_tree.segment.rsc +2 -2
- package/assets/standalone/.next/server/app/api/completed-history/route.js +1 -1
- package/assets/standalone/.next/server/app/api/queue-item/route.js +2 -2
- package/assets/standalone/.next/server/app/api/queue-status/route.js +1 -1
- package/assets/standalone/.next/server/app/dashboard/[viewName]/page/server-reference-manifest.json +4 -4
- package/assets/standalone/.next/server/app/dashboard/[viewName]/page_client-reference-manifest.js +1 -1
- package/assets/standalone/.next/server/app/dashboard/page/server-reference-manifest.json +4 -4
- package/assets/standalone/.next/server/app/dashboard/page_client-reference-manifest.js +1 -1
- package/assets/standalone/.next/server/app/login/page/server-reference-manifest.json +2 -2
- package/assets/standalone/.next/server/app/login/page_client-reference-manifest.js +1 -1
- package/assets/standalone/.next/server/app/login.html +2 -2
- package/assets/standalone/.next/server/app/login.rsc +15 -15
- package/assets/standalone/.next/server/app/login.segments/_full.segment.rsc +15 -15
- package/assets/standalone/.next/server/app/login.segments/_head.segment.rsc +4 -4
- package/assets/standalone/.next/server/app/login.segments/_index.segment.rsc +9 -9
- package/assets/standalone/.next/server/app/login.segments/_tree.segment.rsc +2 -2
- package/assets/standalone/.next/server/app/login.segments/login/__PAGE__.segment.rsc +4 -4
- package/assets/standalone/.next/server/app/login.segments/login.segment.rsc +3 -3
- package/assets/standalone/.next/server/app/page/server-reference-manifest.json +1 -1
- package/assets/standalone/.next/server/app/page_client-reference-manifest.js +1 -1
- package/assets/standalone/.next/server/app/project/[name]/page/server-reference-manifest.json +1 -1
- package/assets/standalone/.next/server/app/project/[name]/page_client-reference-manifest.js +1 -1
- package/assets/standalone/.next/server/app/project/[name]/session/[sessionId]/page/react-loadable-manifest.json +2 -2
- package/assets/standalone/.next/server/app/project/[name]/session/[sessionId]/page/server-reference-manifest.json +8 -8
- package/assets/standalone/.next/server/app/project/[name]/session/[sessionId]/page.js +1 -1
- package/assets/standalone/.next/server/app/project/[name]/session/[sessionId]/page_client-reference-manifest.js +1 -1
- package/assets/standalone/.next/server/app/queue/page/server-reference-manifest.json +3 -3
- package/assets/standalone/.next/server/app/queue/page.js +2 -2
- package/assets/standalone/.next/server/app/queue/page_client-reference-manifest.js +1 -1
- package/assets/standalone/.next/server/chunks/{[externals]_next_dist_db0236a7._.js → [externals]__06cd15c5._.js} +2 -2
- package/assets/standalone/.next/server/chunks/[externals]__10373a08._.js +3 -0
- package/assets/standalone/.next/server/chunks/[externals]__d78bcb54._.js +3 -0
- package/assets/standalone/.next/server/chunks/[root-of-the-server]__067f11b8._.js +3 -0
- package/assets/standalone/.next/server/chunks/[root-of-the-server]__22ffcb4e._.js +3 -0
- package/assets/standalone/.next/server/chunks/{[root-of-the-server]__3232b9b5._.js → [root-of-the-server]__292809cf._.js} +1 -1
- package/assets/standalone/.next/server/chunks/{[root-of-the-server]__bf0c3d33._.js → [root-of-the-server]__3c3ad1da._.js} +4 -4
- package/assets/standalone/.next/server/chunks/{[root-of-the-server]__6d076258._.js → [root-of-the-server]__43c4e0bc._.js} +1 -1
- package/assets/standalone/.next/server/chunks/{[root-of-the-server]__6fc9da2e._.js → [root-of-the-server]__7c44135a._.js} +1 -1
- package/assets/standalone/.next/server/chunks/{[root-of-the-server]__ffb39c82._.js → [root-of-the-server]__939bf5b3._.js} +2 -2
- package/assets/standalone/.next/server/chunks/{[root-of-the-server]__fe48bb1c._.js → [root-of-the-server]__bd194a73._.js} +2 -2
- package/assets/standalone/.next/server/chunks/{[root-of-the-server]__b2f1c82c._.js → [root-of-the-server]__ca12b24d._.js} +2 -2
- package/assets/standalone/.next/server/chunks/[root-of-the-server]__d7355d04._.js +1 -1
- package/assets/standalone/.next/server/chunks/{[root-of-the-server]__255e6fbc._.js → [root-of-the-server]__dcb3f873._.js} +1 -1
- package/assets/standalone/.next/server/chunks/[root-of-the-server]__e3e9ab09._.js +4 -0
- package/assets/standalone/.next/server/chunks/[root-of-the-server]__f26a70d1._.js +3 -0
- package/assets/standalone/.next/server/chunks/_3f3c09bf._.js +1 -1
- package/assets/standalone/.next/server/chunks/_5336fde9._.js +3 -0
- package/assets/standalone/.next/server/chunks/_7e07bbd9._.js +1 -1
- package/assets/standalone/.next/server/chunks/_8f856fad._.js +1 -1
- package/assets/standalone/.next/server/chunks/{_717db053._.js → _b7316450._.js} +1 -1
- package/assets/standalone/.next/server/chunks/_b8adaa37._.js +2 -2
- package/assets/standalone/.next/server/chunks/node_modules_next_dist_esm_build_templates_app-route_7a66d362.js +1 -1
- package/assets/standalone/.next/server/chunks/node_modules_posthog-node_dist_entrypoints_index_node_mjs_05ab10df._.js +3 -0
- package/assets/standalone/.next/server/chunks/node_modules_posthog-node_dist_entrypoints_index_node_mjs_20debb74._.js +3 -0
- package/assets/standalone/.next/server/chunks/package_json_4b1b4d6f._.js +1 -1
- package/assets/standalone/.next/server/chunks/ssr/[externals]__10373a08._.js +3 -0
- package/assets/standalone/.next/server/chunks/ssr/{[root-of-the-server]__16a44ef3._.js → [root-of-the-server]__acea31a9._.js} +3 -3
- package/assets/standalone/.next/server/chunks/ssr/{[root-of-the-server]__10ac3567._.js → [root-of-the-server]__c3591792._.js} +3 -3
- package/assets/standalone/.next/server/chunks/ssr/_14858238._.js +1 -1
- package/assets/standalone/.next/server/chunks/ssr/_19a3e694._.js +2 -2
- package/assets/standalone/.next/server/chunks/ssr/_1d335924._.js +1 -1
- package/assets/standalone/.next/server/chunks/ssr/_3dacef09._.js +1 -1
- package/assets/standalone/.next/server/chunks/ssr/_617143fc._.js +2 -2
- package/assets/standalone/.next/server/chunks/ssr/_76ab933f._.js +1 -1
- package/assets/standalone/.next/server/chunks/ssr/_7ae321cd._.js +2 -2
- package/assets/standalone/.next/server/chunks/ssr/_87e025a1._.js +1 -1
- package/assets/standalone/.next/server/chunks/ssr/_986c0cdb._.js +2 -2
- package/assets/standalone/.next/server/chunks/ssr/_c9400c33._.js +2 -2
- package/assets/standalone/.next/server/chunks/ssr/_d7159840._.js +1 -1
- package/assets/standalone/.next/server/chunks/ssr/_fa9c2bed._.js +2 -2
- package/assets/standalone/.next/server/chunks/ssr/app_actions_compute-dashboard_ts_fc151dbb._.js +1 -1
- package/assets/standalone/.next/server/chunks/ssr/app_login_page_tsx_ccc0019b._.js +1 -1
- package/assets/standalone/.next/server/chunks/ssr/app_queue_queue-client_tsx_45f040f7._.js +1 -1
- package/assets/standalone/.next/server/chunks/ssr/node_modules_next_dist_274ac3eb._.js +1 -1
- package/assets/standalone/.next/server/chunks/ssr/node_modules_posthog-node_dist_entrypoints_index_node_mjs_8222e100._.js +3 -0
- package/assets/standalone/.next/server/instrumentation.js +1 -1
- package/assets/standalone/.next/server/middleware.js +2 -2
- package/assets/standalone/.next/server/pages/404.html +2 -2
- package/assets/standalone/.next/server/pages/500.html +2 -2
- package/assets/standalone/.next/server/server-reference-manifest.js +1 -1
- package/assets/standalone/.next/server/server-reference-manifest.json +15 -15
- package/assets/standalone/.next/static/chunks/{723f2367261046f4.js → 11f25fc2615691ff.js} +1 -1
- package/assets/standalone/.next/static/chunks/{98ef6309c816722d.css → 14b2a22c2d5f76c5.css} +1 -1
- package/assets/standalone/.next/static/chunks/{d2be314c3ece3fbe.js → 2b423cf30d3964a3.js} +1 -1
- package/assets/standalone/.next/static/chunks/{97c295191089a1c2.js → 5920eabcfc97a878.js} +1 -1
- package/assets/standalone/.next/static/chunks/{dbec35204e8940b4.js → 6f48312d9fefe6e7.js} +1 -1
- package/assets/standalone/.next/static/chunks/8da8518dc46b9734.js +1 -0
- package/assets/standalone/.next/static/chunks/91129b8c2a80b1b2.js +4 -0
- package/assets/standalone/.next/static/chunks/{fd8c1fc19ac30592.js → 96e6f5987bb7f381.js} +3 -3
- package/assets/standalone/.next/static/chunks/{27fc246b001f7ba2.js → ef5e745c131e6572.js} +1 -1
- package/assets/standalone/instrumentation.node.ts +54 -0
- package/assets/standalone/package.json +3 -2
- package/assets/standalone/server.js +1 -1
- package/bin/claudeye +0 -0
- package/package.json +1 -1
- package/assets/standalone/.next/server/chunks/[externals]_posthog-node_4a68be38._.js +0 -3
- package/assets/standalone/.next/server/chunks/[root-of-the-server]__19c9c5af._.js +0 -4
- package/assets/standalone/.next/server/chunks/[root-of-the-server]__365c750b._.js +0 -3
- package/assets/standalone/.next/server/chunks/[root-of-the-server]__4ea757c2._.js +0 -3
- package/assets/standalone/.next/server/chunks/[root-of-the-server]__c84cf1dc._.js +0 -3
- package/assets/standalone/.next/server/chunks/ssr/[externals]_posthog-node_4a68be38._.js +0 -3
- package/assets/standalone/.next/static/chunks/13ab76b2fb94bd45.js +0 -1
- package/assets/standalone/.next/static/chunks/3346a6085951648c.js +0 -4
- package/assets/standalone/node_modules/@posthog/core/dist/error-tracking/chunk-ids.mjs +0 -34
- package/assets/standalone/node_modules/@posthog/core/dist/error-tracking/coercers/dom-exception-coercer.mjs +0 -31
- package/assets/standalone/node_modules/@posthog/core/dist/error-tracking/coercers/error-coercer.mjs +0 -27
- package/assets/standalone/node_modules/@posthog/core/dist/error-tracking/coercers/error-event-coercer.mjs +0 -18
- package/assets/standalone/node_modules/@posthog/core/dist/error-tracking/coercers/event-coercer.mjs +0 -17
- package/assets/standalone/node_modules/@posthog/core/dist/error-tracking/coercers/index.mjs +0 -8
- package/assets/standalone/node_modules/@posthog/core/dist/error-tracking/coercers/object-coercer.mjs +0 -51
- package/assets/standalone/node_modules/@posthog/core/dist/error-tracking/coercers/primitive-coercer.mjs +0 -15
- package/assets/standalone/node_modules/@posthog/core/dist/error-tracking/coercers/promise-rejection-event.mjs +0 -25
- package/assets/standalone/node_modules/@posthog/core/dist/error-tracking/coercers/string-coercer.mjs +0 -29
- package/assets/standalone/node_modules/@posthog/core/dist/error-tracking/coercers/utils.mjs +0 -18
- package/assets/standalone/node_modules/@posthog/core/dist/error-tracking/error-properties-builder.mjs +0 -112
- package/assets/standalone/node_modules/@posthog/core/dist/error-tracking/index.mjs +0 -4
- package/assets/standalone/node_modules/@posthog/core/dist/error-tracking/parsers/base.mjs +0 -14
- package/assets/standalone/node_modules/@posthog/core/dist/error-tracking/parsers/chrome.mjs +0 -27
- package/assets/standalone/node_modules/@posthog/core/dist/error-tracking/parsers/gecko.mjs +0 -24
- package/assets/standalone/node_modules/@posthog/core/dist/error-tracking/parsers/index.mjs +0 -47
- package/assets/standalone/node_modules/@posthog/core/dist/error-tracking/parsers/node.mjs +0 -65
- package/assets/standalone/node_modules/@posthog/core/dist/error-tracking/parsers/opera.mjs +0 -12
- package/assets/standalone/node_modules/@posthog/core/dist/error-tracking/parsers/safari.mjs +0 -13
- package/assets/standalone/node_modules/@posthog/core/dist/error-tracking/parsers/winjs.mjs +0 -7
- package/assets/standalone/node_modules/@posthog/core/dist/error-tracking/types.mjs +0 -9
- package/assets/standalone/node_modules/@posthog/core/dist/error-tracking/utils.mjs +0 -23
- package/assets/standalone/node_modules/@posthog/core/dist/eventemitter.mjs +0 -18
- package/assets/standalone/node_modules/@posthog/core/dist/featureFlagUtils.mjs +0 -113
- package/assets/standalone/node_modules/@posthog/core/dist/gzip.mjs +0 -18
- package/assets/standalone/node_modules/@posthog/core/dist/index.mjs +0 -9
- package/assets/standalone/node_modules/@posthog/core/dist/posthog-core-stateless.mjs +0 -676
- package/assets/standalone/node_modules/@posthog/core/dist/posthog-core.mjs +0 -761
- package/assets/standalone/node_modules/@posthog/core/dist/surveys/validation.mjs +0 -33
- package/assets/standalone/node_modules/@posthog/core/dist/types.mjs +0 -137
- package/assets/standalone/node_modules/@posthog/core/dist/utils/bot-detection.mjs +0 -88
- package/assets/standalone/node_modules/@posthog/core/dist/utils/bucketed-rate-limiter.mjs +0 -41
- package/assets/standalone/node_modules/@posthog/core/dist/utils/index.mjs +0 -59
- package/assets/standalone/node_modules/@posthog/core/dist/utils/logger.mjs +0 -38
- package/assets/standalone/node_modules/@posthog/core/dist/utils/number-utils.mjs +0 -41
- package/assets/standalone/node_modules/@posthog/core/dist/utils/promise-queue.mjs +0 -27
- package/assets/standalone/node_modules/@posthog/core/dist/utils/string-utils.mjs +0 -31
- package/assets/standalone/node_modules/@posthog/core/dist/utils/type-utils.mjs +0 -82
- package/assets/standalone/node_modules/@posthog/core/dist/utils/user-agent-utils.mjs +0 -338
- package/assets/standalone/node_modules/@posthog/core/dist/vendor/uuidv7.mjs +0 -170
- package/assets/standalone/node_modules/@posthog/core/package.json +0 -69
- package/assets/standalone/node_modules/posthog-node/dist/client.mjs +0 -718
- package/assets/standalone/node_modules/posthog-node/dist/entrypoints/index.node.mjs +0 -26
- package/assets/standalone/node_modules/posthog-node/dist/exports.mjs +0 -5
- package/assets/standalone/node_modules/posthog-node/dist/extensions/context/context.mjs +0 -28
- package/assets/standalone/node_modules/posthog-node/dist/extensions/error-tracking/autocapture.mjs +0 -31
- package/assets/standalone/node_modules/posthog-node/dist/extensions/error-tracking/index.mjs +0 -69
- package/assets/standalone/node_modules/posthog-node/dist/extensions/error-tracking/modifiers/context-lines.node.js +0 -227
- package/assets/standalone/node_modules/posthog-node/dist/extensions/error-tracking/modifiers/context-lines.node.mjs +0 -187
- package/assets/standalone/node_modules/posthog-node/dist/extensions/error-tracking/modifiers/module.node.js +0 -64
- package/assets/standalone/node_modules/posthog-node/dist/extensions/error-tracking/modifiers/module.node.mjs +0 -30
- package/assets/standalone/node_modules/posthog-node/dist/extensions/express.mjs +0 -32
- package/assets/standalone/node_modules/posthog-node/dist/extensions/feature-flags/crypto.mjs +0 -8
- package/assets/standalone/node_modules/posthog-node/dist/extensions/feature-flags/feature-flags.mjs +0 -772
- package/assets/standalone/node_modules/posthog-node/dist/extensions/sentry-integration.mjs +0 -72
- package/assets/standalone/node_modules/posthog-node/dist/storage-memory.mjs +0 -12
- package/assets/standalone/node_modules/posthog-node/dist/types.mjs +0 -7
- package/assets/standalone/node_modules/posthog-node/dist/version.mjs +0 -2
- package/assets/standalone/node_modules/posthog-node/package.json +0 -105
- /package/assets/standalone/.next/static/{J4fam3sTS7cM1hFzhpIJy → ooDwT_B4qzYMdxRb-wV62}/_buildManifest.js +0 -0
- /package/assets/standalone/.next/static/{J4fam3sTS7cM1hFzhpIJy → ooDwT_B4qzYMdxRb-wV62}/_clientMiddlewareManifest.json +0 -0
- /package/assets/standalone/.next/static/{J4fam3sTS7cM1hFzhpIJy → ooDwT_B4qzYMdxRb-wV62}/_ssgManifest.js +0 -0
|
@@ -1,761 +0,0 @@
|
|
|
1
|
-
import { createFlagsResponseFromFlagsAndPayloads, getEnabledFromValue, getFeatureFlagValue, getFlagValuesFromFlags, getPayloadsFromFlags, getVariantFromValue, normalizeFlagsResponse, parsePayload, updateFlagValue } from "./featureFlagUtils.mjs";
|
|
2
|
-
import { Compression, FeatureFlagError, PostHogPersistedProperty } from "./types.mjs";
|
|
3
|
-
import { PostHogCoreStateless, QuotaLimitedFeature, maybeAdd } from "./posthog-core-stateless.mjs";
|
|
4
|
-
import { uuidv7 } from "./vendor/uuidv7.mjs";
|
|
5
|
-
import { getPersonPropertiesHash, isEmptyObject, isNullish, isObject, isPlainError } from "./utils/index.mjs";
|
|
6
|
-
class PostHogCore extends PostHogCoreStateless {
|
|
7
|
-
constructor(apiKey, options){
|
|
8
|
-
const disableGeoipOption = options?.disableGeoip ?? false;
|
|
9
|
-
const featureFlagsRequestTimeoutMs = options?.featureFlagsRequestTimeoutMs ?? 10000;
|
|
10
|
-
super(apiKey, {
|
|
11
|
-
...options,
|
|
12
|
-
disableGeoip: disableGeoipOption,
|
|
13
|
-
featureFlagsRequestTimeoutMs
|
|
14
|
-
}), this.flagCallReported = {}, this._sessionMaxLengthSeconds = 86400, this.sessionProps = {}, this._cachedPersonProperties = null;
|
|
15
|
-
this.sendFeatureFlagEvent = options?.sendFeatureFlagEvent ?? true;
|
|
16
|
-
this._sessionExpirationTimeSeconds = options?.sessionExpirationTimeSeconds ?? 1800;
|
|
17
|
-
this._personProfiles = options?.personProfiles ?? 'identified_only';
|
|
18
|
-
this._beforeSend = options?.before_send;
|
|
19
|
-
}
|
|
20
|
-
setupBootstrap(options) {
|
|
21
|
-
const bootstrap = options?.bootstrap;
|
|
22
|
-
if (!bootstrap) return;
|
|
23
|
-
if (bootstrap.distinctId) if (bootstrap.isIdentifiedId) {
|
|
24
|
-
const distinctId = this.getPersistedProperty(PostHogPersistedProperty.DistinctId);
|
|
25
|
-
if (!distinctId) {
|
|
26
|
-
this.setPersistedProperty(PostHogPersistedProperty.DistinctId, bootstrap.distinctId);
|
|
27
|
-
this.setPersistedProperty(PostHogPersistedProperty.PersonMode, 'identified');
|
|
28
|
-
}
|
|
29
|
-
} else {
|
|
30
|
-
const anonymousId = this.getPersistedProperty(PostHogPersistedProperty.AnonymousId);
|
|
31
|
-
if (!anonymousId) this.setPersistedProperty(PostHogPersistedProperty.AnonymousId, bootstrap.distinctId);
|
|
32
|
-
}
|
|
33
|
-
const bootstrapFeatureFlags = bootstrap.featureFlags;
|
|
34
|
-
const bootstrapFeatureFlagPayloads = bootstrap.featureFlagPayloads ?? {};
|
|
35
|
-
if (bootstrapFeatureFlags && Object.keys(bootstrapFeatureFlags).length) {
|
|
36
|
-
const normalizedBootstrapFeatureFlagDetails = createFlagsResponseFromFlagsAndPayloads(bootstrapFeatureFlags, bootstrapFeatureFlagPayloads);
|
|
37
|
-
if (Object.keys(normalizedBootstrapFeatureFlagDetails.flags).length > 0) {
|
|
38
|
-
this.setBootstrappedFeatureFlagDetails(normalizedBootstrapFeatureFlagDetails);
|
|
39
|
-
const currentFeatureFlagDetails = this.getKnownFeatureFlagDetails() || {
|
|
40
|
-
flags: {},
|
|
41
|
-
requestId: void 0
|
|
42
|
-
};
|
|
43
|
-
const newFeatureFlagDetails = {
|
|
44
|
-
flags: {
|
|
45
|
-
...normalizedBootstrapFeatureFlagDetails.flags,
|
|
46
|
-
...currentFeatureFlagDetails.flags
|
|
47
|
-
},
|
|
48
|
-
requestId: normalizedBootstrapFeatureFlagDetails.requestId
|
|
49
|
-
};
|
|
50
|
-
this.setKnownFeatureFlagDetails(newFeatureFlagDetails);
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
clearProps() {
|
|
55
|
-
this.props = void 0;
|
|
56
|
-
this.sessionProps = {};
|
|
57
|
-
this.flagCallReported = {};
|
|
58
|
-
}
|
|
59
|
-
on(event, cb) {
|
|
60
|
-
return this._events.on(event, cb);
|
|
61
|
-
}
|
|
62
|
-
reset(propertiesToKeep) {
|
|
63
|
-
this.wrap(()=>{
|
|
64
|
-
const allPropertiesToKeep = [
|
|
65
|
-
PostHogPersistedProperty.Queue,
|
|
66
|
-
...propertiesToKeep || []
|
|
67
|
-
];
|
|
68
|
-
this.clearProps();
|
|
69
|
-
this._cachedPersonProperties = null;
|
|
70
|
-
for (const key of Object.keys(PostHogPersistedProperty))if (!allPropertiesToKeep.includes(PostHogPersistedProperty[key])) this.setPersistedProperty(PostHogPersistedProperty[key], null);
|
|
71
|
-
this.reloadFeatureFlags();
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
getCommonEventProperties() {
|
|
75
|
-
const featureFlags = this.getFeatureFlags();
|
|
76
|
-
const featureVariantProperties = {};
|
|
77
|
-
if (featureFlags) for (const [feature, variant] of Object.entries(featureFlags))featureVariantProperties[`$feature/${feature}`] = variant;
|
|
78
|
-
return {
|
|
79
|
-
...maybeAdd('$active_feature_flags', featureFlags ? Object.keys(featureFlags) : void 0),
|
|
80
|
-
...featureVariantProperties,
|
|
81
|
-
...super.getCommonEventProperties()
|
|
82
|
-
};
|
|
83
|
-
}
|
|
84
|
-
enrichProperties(properties) {
|
|
85
|
-
return {
|
|
86
|
-
...this.props,
|
|
87
|
-
...this.sessionProps,
|
|
88
|
-
...properties || {},
|
|
89
|
-
...this.getCommonEventProperties(),
|
|
90
|
-
$session_id: this.getSessionId()
|
|
91
|
-
};
|
|
92
|
-
}
|
|
93
|
-
getSessionId() {
|
|
94
|
-
if (!this._isInitialized) return '';
|
|
95
|
-
let sessionId = this.getPersistedProperty(PostHogPersistedProperty.SessionId);
|
|
96
|
-
const sessionLastTimestamp = this.getPersistedProperty(PostHogPersistedProperty.SessionLastTimestamp) || 0;
|
|
97
|
-
const sessionStartTimestamp = this.getPersistedProperty(PostHogPersistedProperty.SessionStartTimestamp) || 0;
|
|
98
|
-
const now = Date.now();
|
|
99
|
-
const sessionLastDif = now - sessionLastTimestamp;
|
|
100
|
-
const sessionStartDif = now - sessionStartTimestamp;
|
|
101
|
-
if (!sessionId || sessionLastDif > 1000 * this._sessionExpirationTimeSeconds || sessionStartDif > 1000 * this._sessionMaxLengthSeconds) {
|
|
102
|
-
sessionId = uuidv7();
|
|
103
|
-
this.setPersistedProperty(PostHogPersistedProperty.SessionId, sessionId);
|
|
104
|
-
this.setPersistedProperty(PostHogPersistedProperty.SessionStartTimestamp, now);
|
|
105
|
-
}
|
|
106
|
-
this.setPersistedProperty(PostHogPersistedProperty.SessionLastTimestamp, now);
|
|
107
|
-
return sessionId;
|
|
108
|
-
}
|
|
109
|
-
resetSessionId() {
|
|
110
|
-
this.wrap(()=>{
|
|
111
|
-
this.setPersistedProperty(PostHogPersistedProperty.SessionId, null);
|
|
112
|
-
this.setPersistedProperty(PostHogPersistedProperty.SessionLastTimestamp, null);
|
|
113
|
-
this.setPersistedProperty(PostHogPersistedProperty.SessionStartTimestamp, null);
|
|
114
|
-
});
|
|
115
|
-
}
|
|
116
|
-
getAnonymousId() {
|
|
117
|
-
if (!this._isInitialized) return '';
|
|
118
|
-
let anonId = this.getPersistedProperty(PostHogPersistedProperty.AnonymousId);
|
|
119
|
-
if (!anonId) {
|
|
120
|
-
anonId = uuidv7();
|
|
121
|
-
this.setPersistedProperty(PostHogPersistedProperty.AnonymousId, anonId);
|
|
122
|
-
}
|
|
123
|
-
return anonId;
|
|
124
|
-
}
|
|
125
|
-
getDistinctId() {
|
|
126
|
-
if (!this._isInitialized) return '';
|
|
127
|
-
return this.getPersistedProperty(PostHogPersistedProperty.DistinctId) || this.getAnonymousId();
|
|
128
|
-
}
|
|
129
|
-
registerForSession(properties) {
|
|
130
|
-
this.sessionProps = {
|
|
131
|
-
...this.sessionProps,
|
|
132
|
-
...properties
|
|
133
|
-
};
|
|
134
|
-
}
|
|
135
|
-
unregisterForSession(property) {
|
|
136
|
-
delete this.sessionProps[property];
|
|
137
|
-
}
|
|
138
|
-
identify(distinctId, properties, options) {
|
|
139
|
-
this.wrap(()=>{
|
|
140
|
-
if (!this._requirePersonProcessing('posthog.identify')) return;
|
|
141
|
-
const previousDistinctId = this.getDistinctId();
|
|
142
|
-
distinctId = distinctId || previousDistinctId;
|
|
143
|
-
if (properties?.$groups) this.groups(properties.$groups);
|
|
144
|
-
const userPropsOnce = properties?.$set_once;
|
|
145
|
-
delete properties?.$set_once;
|
|
146
|
-
const userProps = properties?.$set || properties;
|
|
147
|
-
const allProperties = this.enrichProperties({
|
|
148
|
-
$anon_distinct_id: this.getAnonymousId(),
|
|
149
|
-
...maybeAdd('$set', userProps),
|
|
150
|
-
...maybeAdd('$set_once', userPropsOnce)
|
|
151
|
-
});
|
|
152
|
-
const userPropsObj = isObject(userProps) ? userProps : void 0;
|
|
153
|
-
const userPropsOnceObj = isObject(userPropsOnce) ? userPropsOnce : void 0;
|
|
154
|
-
if (distinctId !== previousDistinctId) {
|
|
155
|
-
this.setPersistedProperty(PostHogPersistedProperty.AnonymousId, previousDistinctId);
|
|
156
|
-
this.setPersistedProperty(PostHogPersistedProperty.DistinctId, distinctId);
|
|
157
|
-
this.setPersistedProperty(PostHogPersistedProperty.PersonMode, 'identified');
|
|
158
|
-
this.reloadFeatureFlags();
|
|
159
|
-
super.identifyStateless(distinctId, allProperties, options);
|
|
160
|
-
this._cachedPersonProperties = getPersonPropertiesHash(distinctId, userPropsObj, userPropsOnceObj);
|
|
161
|
-
} else if (userPropsObj || userPropsOnceObj) this.setPersonProperties(userPropsObj, userPropsOnceObj);
|
|
162
|
-
});
|
|
163
|
-
}
|
|
164
|
-
capture(event, properties, options) {
|
|
165
|
-
if ('$exception' === event && !options?._originatedFromCaptureException) this._logger.warn("Using `posthog.capture('$exception')` is unreliable because it does not attach required metadata. Use `posthog.captureException(error)` instead, which attaches required metadata automatically.");
|
|
166
|
-
this.wrap(()=>{
|
|
167
|
-
const distinctId = this.getDistinctId();
|
|
168
|
-
if (properties?.$groups) this.groups(properties.$groups);
|
|
169
|
-
const allProperties = this.enrichProperties(properties);
|
|
170
|
-
const hasPersonProcessing = this._hasPersonProcessing();
|
|
171
|
-
allProperties['$process_person_profile'] = hasPersonProcessing;
|
|
172
|
-
allProperties['$is_identified'] = this._isIdentified();
|
|
173
|
-
if (hasPersonProcessing) this._requirePersonProcessing('capture');
|
|
174
|
-
super.captureStateless(distinctId, event, allProperties, options);
|
|
175
|
-
});
|
|
176
|
-
}
|
|
177
|
-
alias(alias) {
|
|
178
|
-
this.wrap(()=>{
|
|
179
|
-
if (!this._requirePersonProcessing('posthog.alias')) return;
|
|
180
|
-
const distinctId = this.getDistinctId();
|
|
181
|
-
const allProperties = this.enrichProperties({});
|
|
182
|
-
super.aliasStateless(alias, distinctId, allProperties);
|
|
183
|
-
});
|
|
184
|
-
}
|
|
185
|
-
autocapture(eventType, elements, properties = {}, options) {
|
|
186
|
-
this.wrap(()=>{
|
|
187
|
-
const distinctId = this.getDistinctId();
|
|
188
|
-
const payload = {
|
|
189
|
-
distinct_id: distinctId,
|
|
190
|
-
event: '$autocapture',
|
|
191
|
-
properties: {
|
|
192
|
-
...this.enrichProperties(properties),
|
|
193
|
-
$event_type: eventType,
|
|
194
|
-
$elements: elements
|
|
195
|
-
}
|
|
196
|
-
};
|
|
197
|
-
this.enqueue('autocapture', payload, options);
|
|
198
|
-
});
|
|
199
|
-
}
|
|
200
|
-
groups(groups) {
|
|
201
|
-
this.wrap(()=>{
|
|
202
|
-
if (!this._requirePersonProcessing('posthog.group')) return;
|
|
203
|
-
const existingGroups = this.props.$groups || {};
|
|
204
|
-
this.register({
|
|
205
|
-
$groups: {
|
|
206
|
-
...existingGroups,
|
|
207
|
-
...groups
|
|
208
|
-
}
|
|
209
|
-
});
|
|
210
|
-
if (Object.keys(groups).find((type)=>existingGroups[type] !== groups[type])) this.reloadFeatureFlags();
|
|
211
|
-
});
|
|
212
|
-
}
|
|
213
|
-
group(groupType, groupKey, groupProperties, options) {
|
|
214
|
-
this.wrap(()=>{
|
|
215
|
-
this.groups({
|
|
216
|
-
[groupType]: groupKey
|
|
217
|
-
});
|
|
218
|
-
if (groupProperties) this.groupIdentify(groupType, groupKey, groupProperties, options);
|
|
219
|
-
});
|
|
220
|
-
}
|
|
221
|
-
groupIdentify(groupType, groupKey, groupProperties, options) {
|
|
222
|
-
this.wrap(()=>{
|
|
223
|
-
if (!this._requirePersonProcessing('posthog.groupIdentify')) return;
|
|
224
|
-
const distinctId = this.getDistinctId();
|
|
225
|
-
const eventProperties = this.enrichProperties({});
|
|
226
|
-
super.groupIdentifyStateless(groupType, groupKey, groupProperties, options, distinctId, eventProperties);
|
|
227
|
-
});
|
|
228
|
-
}
|
|
229
|
-
setPersonPropertiesForFlags(properties, reloadFeatureFlags = true) {
|
|
230
|
-
this.wrap(()=>{
|
|
231
|
-
const existingProperties = this.getPersistedProperty(PostHogPersistedProperty.PersonProperties) || {};
|
|
232
|
-
this.setPersistedProperty(PostHogPersistedProperty.PersonProperties, {
|
|
233
|
-
...existingProperties,
|
|
234
|
-
...properties
|
|
235
|
-
});
|
|
236
|
-
if (reloadFeatureFlags) this.reloadFeatureFlags();
|
|
237
|
-
});
|
|
238
|
-
}
|
|
239
|
-
resetPersonPropertiesForFlags() {
|
|
240
|
-
this.wrap(()=>{
|
|
241
|
-
this.setPersistedProperty(PostHogPersistedProperty.PersonProperties, null);
|
|
242
|
-
});
|
|
243
|
-
}
|
|
244
|
-
setGroupPropertiesForFlags(properties) {
|
|
245
|
-
this.wrap(()=>{
|
|
246
|
-
const existingProperties = this.getPersistedProperty(PostHogPersistedProperty.GroupProperties) || {};
|
|
247
|
-
if (0 !== Object.keys(existingProperties).length) Object.keys(existingProperties).forEach((groupType)=>{
|
|
248
|
-
existingProperties[groupType] = {
|
|
249
|
-
...existingProperties[groupType],
|
|
250
|
-
...properties[groupType]
|
|
251
|
-
};
|
|
252
|
-
delete properties[groupType];
|
|
253
|
-
});
|
|
254
|
-
this.setPersistedProperty(PostHogPersistedProperty.GroupProperties, {
|
|
255
|
-
...existingProperties,
|
|
256
|
-
...properties
|
|
257
|
-
});
|
|
258
|
-
});
|
|
259
|
-
}
|
|
260
|
-
resetGroupPropertiesForFlags() {
|
|
261
|
-
this.wrap(()=>{
|
|
262
|
-
this.setPersistedProperty(PostHogPersistedProperty.GroupProperties, null);
|
|
263
|
-
});
|
|
264
|
-
}
|
|
265
|
-
async remoteConfigAsync() {
|
|
266
|
-
await this._initPromise;
|
|
267
|
-
if (this._remoteConfigResponsePromise) return this._remoteConfigResponsePromise;
|
|
268
|
-
return this._remoteConfigAsync();
|
|
269
|
-
}
|
|
270
|
-
async flagsAsync(options) {
|
|
271
|
-
const { sendAnonDistinctId = true, fetchConfig = false, triggerOnRemoteConfig = false } = options ?? {};
|
|
272
|
-
await this._initPromise;
|
|
273
|
-
if (this._flagsResponsePromise) {
|
|
274
|
-
this._logger.info('Feature flags are being loaded already, queuing reload.');
|
|
275
|
-
if (this._pendingFlagsRequest) this._flagsResponsePromise.then(this._pendingFlagsRequest.resolve).catch(this._pendingFlagsRequest.reject);
|
|
276
|
-
return new Promise((resolve, reject)=>{
|
|
277
|
-
this._pendingFlagsRequest = {
|
|
278
|
-
sendAnonDistinctId,
|
|
279
|
-
fetchConfig,
|
|
280
|
-
triggerOnRemoteConfig,
|
|
281
|
-
resolve,
|
|
282
|
-
reject
|
|
283
|
-
};
|
|
284
|
-
});
|
|
285
|
-
}
|
|
286
|
-
return this._flagsAsync({
|
|
287
|
-
sendAnonDistinctId,
|
|
288
|
-
fetchConfig,
|
|
289
|
-
triggerOnRemoteConfig
|
|
290
|
-
});
|
|
291
|
-
}
|
|
292
|
-
onRemoteConfig(_response) {}
|
|
293
|
-
maybeNotifyRemoteConfig(shouldTrigger, response) {
|
|
294
|
-
if (shouldTrigger) try {
|
|
295
|
-
this.onRemoteConfig(response);
|
|
296
|
-
} catch (e) {
|
|
297
|
-
this._logger.error('Error in onRemoteConfig callback:', e);
|
|
298
|
-
}
|
|
299
|
-
}
|
|
300
|
-
cacheSessionReplay(source, response) {
|
|
301
|
-
const sessionReplay = response?.sessionRecording;
|
|
302
|
-
if (sessionReplay) {
|
|
303
|
-
this.setPersistedProperty(PostHogPersistedProperty.SessionReplay, sessionReplay);
|
|
304
|
-
this._logger.info(`Session replay config from ${source}: `, JSON.stringify(sessionReplay));
|
|
305
|
-
} else if ('boolean' == typeof sessionReplay && false === sessionReplay) {
|
|
306
|
-
this._logger.info(`Session replay config from ${source} disabled.`);
|
|
307
|
-
this.setPersistedProperty(PostHogPersistedProperty.SessionReplay, null);
|
|
308
|
-
}
|
|
309
|
-
}
|
|
310
|
-
async _remoteConfigAsync() {
|
|
311
|
-
this._remoteConfigResponsePromise = this._initPromise.then(()=>{
|
|
312
|
-
let remoteConfig = this.getPersistedProperty(PostHogPersistedProperty.RemoteConfig);
|
|
313
|
-
this._logger.info('Cached remote config: ', JSON.stringify(remoteConfig));
|
|
314
|
-
return super.getRemoteConfig().then((response)=>{
|
|
315
|
-
if (response) {
|
|
316
|
-
const remoteConfigWithoutSurveys = {
|
|
317
|
-
...response
|
|
318
|
-
};
|
|
319
|
-
delete remoteConfigWithoutSurveys.surveys;
|
|
320
|
-
this._logger.info('Fetched remote config: ', JSON.stringify(remoteConfigWithoutSurveys));
|
|
321
|
-
if (false === this.disableSurveys) {
|
|
322
|
-
const surveys = response.surveys;
|
|
323
|
-
let hasSurveys = true;
|
|
324
|
-
if (Array.isArray(surveys)) this._logger.info('Surveys fetched from remote config: ', JSON.stringify(surveys));
|
|
325
|
-
else {
|
|
326
|
-
this._logger.info('There are no surveys.');
|
|
327
|
-
hasSurveys = false;
|
|
328
|
-
}
|
|
329
|
-
if (hasSurveys) this.setPersistedProperty(PostHogPersistedProperty.Surveys, surveys);
|
|
330
|
-
else this.setPersistedProperty(PostHogPersistedProperty.Surveys, null);
|
|
331
|
-
} else this.setPersistedProperty(PostHogPersistedProperty.Surveys, null);
|
|
332
|
-
this.setPersistedProperty(PostHogPersistedProperty.RemoteConfig, remoteConfigWithoutSurveys);
|
|
333
|
-
this.cacheSessionReplay('remote config', response);
|
|
334
|
-
let willLoadFlags = false;
|
|
335
|
-
if (false === response.hasFeatureFlags) {
|
|
336
|
-
this.setKnownFeatureFlagDetails({
|
|
337
|
-
flags: {}
|
|
338
|
-
});
|
|
339
|
-
this._logger.warn('Remote config has no feature flags, will not load feature flags.');
|
|
340
|
-
} else if (false !== this.preloadFeatureFlags) {
|
|
341
|
-
willLoadFlags = true;
|
|
342
|
-
this.flagsAsync({
|
|
343
|
-
sendAnonDistinctId: true,
|
|
344
|
-
fetchConfig: true,
|
|
345
|
-
triggerOnRemoteConfig: true
|
|
346
|
-
});
|
|
347
|
-
}
|
|
348
|
-
if (!response.supportedCompression?.includes(Compression.GZipJS)) this.disableCompression = true;
|
|
349
|
-
this.maybeNotifyRemoteConfig(!willLoadFlags, response);
|
|
350
|
-
remoteConfig = response;
|
|
351
|
-
}
|
|
352
|
-
return remoteConfig;
|
|
353
|
-
});
|
|
354
|
-
}).finally(()=>{
|
|
355
|
-
this._remoteConfigResponsePromise = void 0;
|
|
356
|
-
});
|
|
357
|
-
return this._remoteConfigResponsePromise;
|
|
358
|
-
}
|
|
359
|
-
async _flagsAsync(options) {
|
|
360
|
-
const sendAnonDistinctId = options?.sendAnonDistinctId ?? true;
|
|
361
|
-
const fetchConfig = options?.fetchConfig ?? false;
|
|
362
|
-
const triggerOnRemoteConfig = options?.triggerOnRemoteConfig ?? false;
|
|
363
|
-
this._flagsResponsePromise = this._initPromise.then(async ()=>{
|
|
364
|
-
const distinctId = this.getDistinctId();
|
|
365
|
-
const groups = this.props.$groups || {};
|
|
366
|
-
const personProperties = this.getPersistedProperty(PostHogPersistedProperty.PersonProperties) || {};
|
|
367
|
-
const groupProperties = this.getPersistedProperty(PostHogPersistedProperty.GroupProperties) || {};
|
|
368
|
-
const extraProperties = {
|
|
369
|
-
$anon_distinct_id: sendAnonDistinctId ? this.getAnonymousId() : void 0
|
|
370
|
-
};
|
|
371
|
-
const result = await super.getFlags(distinctId, groups, personProperties, groupProperties, extraProperties, fetchConfig);
|
|
372
|
-
if (!result.success) return void this.setKnownFeatureFlagDetails({
|
|
373
|
-
flags: this.getKnownFeatureFlagDetails()?.flags ?? {},
|
|
374
|
-
requestError: result.error
|
|
375
|
-
});
|
|
376
|
-
const res = result.response;
|
|
377
|
-
if (res?.quotaLimited?.includes(QuotaLimitedFeature.FeatureFlags)) {
|
|
378
|
-
this.setKnownFeatureFlagDetails({
|
|
379
|
-
flags: this.getKnownFeatureFlagDetails()?.flags ?? {},
|
|
380
|
-
quotaLimited: res.quotaLimited
|
|
381
|
-
});
|
|
382
|
-
this._logger.warn('[FEATURE FLAGS] Feature flags quota limit exceeded. Learn more about billing limits at https://posthog.com/docs/billing/limits-alerts');
|
|
383
|
-
this.maybeNotifyRemoteConfig(triggerOnRemoteConfig, res);
|
|
384
|
-
return res;
|
|
385
|
-
}
|
|
386
|
-
if (res?.featureFlags) {
|
|
387
|
-
if (this.sendFeatureFlagEvent) this.flagCallReported = {};
|
|
388
|
-
let newFeatureFlagDetails = res;
|
|
389
|
-
if (res.errorsWhileComputingFlags) {
|
|
390
|
-
const currentFlagDetails = this.getKnownFeatureFlagDetails();
|
|
391
|
-
this._logger.info('Cached feature flags: ', JSON.stringify(currentFlagDetails));
|
|
392
|
-
const filteredFlags = {};
|
|
393
|
-
for(const key in res.flags)if (!res.flags[key].failed) filteredFlags[key] = res.flags[key];
|
|
394
|
-
newFeatureFlagDetails = {
|
|
395
|
-
...res,
|
|
396
|
-
flags: {
|
|
397
|
-
...currentFlagDetails?.flags,
|
|
398
|
-
...filteredFlags
|
|
399
|
-
}
|
|
400
|
-
};
|
|
401
|
-
}
|
|
402
|
-
this.setKnownFeatureFlagDetails({
|
|
403
|
-
flags: newFeatureFlagDetails.flags,
|
|
404
|
-
requestId: res.requestId,
|
|
405
|
-
evaluatedAt: res.evaluatedAt,
|
|
406
|
-
errorsWhileComputingFlags: res.errorsWhileComputingFlags,
|
|
407
|
-
quotaLimited: res.quotaLimited
|
|
408
|
-
});
|
|
409
|
-
this.setPersistedProperty(PostHogPersistedProperty.FlagsEndpointWasHit, true);
|
|
410
|
-
this.cacheSessionReplay('flags', res);
|
|
411
|
-
this.maybeNotifyRemoteConfig(triggerOnRemoteConfig, res);
|
|
412
|
-
}
|
|
413
|
-
return res;
|
|
414
|
-
}).finally(()=>{
|
|
415
|
-
this._flagsResponsePromise = void 0;
|
|
416
|
-
const pendingRequest = this._pendingFlagsRequest;
|
|
417
|
-
if (pendingRequest) {
|
|
418
|
-
this._pendingFlagsRequest = void 0;
|
|
419
|
-
this._logger.info('Executing pending feature flags reload.');
|
|
420
|
-
this.flagsAsync({
|
|
421
|
-
sendAnonDistinctId: pendingRequest.sendAnonDistinctId,
|
|
422
|
-
fetchConfig: pendingRequest.fetchConfig,
|
|
423
|
-
triggerOnRemoteConfig: pendingRequest.triggerOnRemoteConfig
|
|
424
|
-
}).then(pendingRequest.resolve).catch(pendingRequest.reject);
|
|
425
|
-
}
|
|
426
|
-
});
|
|
427
|
-
return this._flagsResponsePromise;
|
|
428
|
-
}
|
|
429
|
-
setKnownFeatureFlagDetails(flagsResponse) {
|
|
430
|
-
this.wrap(()=>{
|
|
431
|
-
this.setPersistedProperty(PostHogPersistedProperty.FeatureFlagDetails, flagsResponse);
|
|
432
|
-
this._events.emit('featureflags', getFlagValuesFromFlags(flagsResponse?.flags ?? {}));
|
|
433
|
-
});
|
|
434
|
-
}
|
|
435
|
-
getKnownFeatureFlagDetails() {
|
|
436
|
-
const storedDetails = this.getPersistedProperty(PostHogPersistedProperty.FeatureFlagDetails);
|
|
437
|
-
if (!storedDetails) {
|
|
438
|
-
const featureFlags = this.getPersistedProperty(PostHogPersistedProperty.FeatureFlags);
|
|
439
|
-
const featureFlagPayloads = this.getPersistedProperty(PostHogPersistedProperty.FeatureFlagPayloads);
|
|
440
|
-
if (void 0 === featureFlags && void 0 === featureFlagPayloads) return;
|
|
441
|
-
return createFlagsResponseFromFlagsAndPayloads(featureFlags ?? {}, featureFlagPayloads ?? {});
|
|
442
|
-
}
|
|
443
|
-
return normalizeFlagsResponse(storedDetails);
|
|
444
|
-
}
|
|
445
|
-
getStoredFlagDetails() {
|
|
446
|
-
return this.getPersistedProperty(PostHogPersistedProperty.FeatureFlagDetails);
|
|
447
|
-
}
|
|
448
|
-
getKnownFeatureFlags() {
|
|
449
|
-
const featureFlagDetails = this.getKnownFeatureFlagDetails();
|
|
450
|
-
if (!featureFlagDetails) return;
|
|
451
|
-
return getFlagValuesFromFlags(featureFlagDetails.flags);
|
|
452
|
-
}
|
|
453
|
-
getBootstrappedFeatureFlagDetails() {
|
|
454
|
-
const details = this.getPersistedProperty(PostHogPersistedProperty.BootstrapFeatureFlagDetails);
|
|
455
|
-
if (!details) return;
|
|
456
|
-
return details;
|
|
457
|
-
}
|
|
458
|
-
setBootstrappedFeatureFlagDetails(details) {
|
|
459
|
-
this.setPersistedProperty(PostHogPersistedProperty.BootstrapFeatureFlagDetails, details);
|
|
460
|
-
}
|
|
461
|
-
getBootstrappedFeatureFlags() {
|
|
462
|
-
const details = this.getBootstrappedFeatureFlagDetails();
|
|
463
|
-
if (!details) return;
|
|
464
|
-
return getFlagValuesFromFlags(details.flags);
|
|
465
|
-
}
|
|
466
|
-
getBootstrappedFeatureFlagPayloads() {
|
|
467
|
-
const details = this.getBootstrappedFeatureFlagDetails();
|
|
468
|
-
if (!details) return;
|
|
469
|
-
return getPayloadsFromFlags(details.flags);
|
|
470
|
-
}
|
|
471
|
-
getFeatureFlagResult(key, options) {
|
|
472
|
-
return this._getFeatureFlagResult(key, options);
|
|
473
|
-
}
|
|
474
|
-
_getFeatureFlagResult(key, options = {}) {
|
|
475
|
-
const storedDetails = this.getStoredFlagDetails();
|
|
476
|
-
const details = this.getFeatureFlagDetails();
|
|
477
|
-
const isQuotaLimited = storedDetails?.quotaLimited?.includes(QuotaLimitedFeature.FeatureFlags);
|
|
478
|
-
const featureFlag = details?.flags[key];
|
|
479
|
-
const sendEvent = (options.sendEvent ?? this.sendFeatureFlagEvent) && !this.flagCallReported[key];
|
|
480
|
-
const flagValue = getFeatureFlagValue(featureFlag);
|
|
481
|
-
if (sendEvent) {
|
|
482
|
-
const errors = [];
|
|
483
|
-
if (storedDetails?.requestError) {
|
|
484
|
-
const { type, statusCode } = storedDetails.requestError;
|
|
485
|
-
if ('timeout' === type) errors.push(FeatureFlagError.TIMEOUT);
|
|
486
|
-
else if ('api_error' === type && void 0 !== statusCode) errors.push(FeatureFlagError.apiError(statusCode));
|
|
487
|
-
else if ('connection_error' === type) errors.push(FeatureFlagError.CONNECTION_ERROR);
|
|
488
|
-
else errors.push(FeatureFlagError.UNKNOWN_ERROR);
|
|
489
|
-
} else if (storedDetails) {
|
|
490
|
-
if (storedDetails.errorsWhileComputingFlags) errors.push(FeatureFlagError.ERRORS_WHILE_COMPUTING);
|
|
491
|
-
if (isQuotaLimited) errors.push(FeatureFlagError.QUOTA_LIMITED);
|
|
492
|
-
else if (void 0 === flagValue && !featureFlag) errors.push(FeatureFlagError.FLAG_MISSING);
|
|
493
|
-
}
|
|
494
|
-
const bootstrappedResponse = this.getBootstrappedFeatureFlags()?.[key];
|
|
495
|
-
const bootstrappedPayload = this.getBootstrappedFeatureFlagPayloads()?.[key];
|
|
496
|
-
const featureFlagError = errors.length > 0 ? errors.join(',') : void 0;
|
|
497
|
-
this.flagCallReported[key] = true;
|
|
498
|
-
const properties = {
|
|
499
|
-
$feature_flag: key,
|
|
500
|
-
$feature_flag_response: flagValue,
|
|
501
|
-
...maybeAdd('$feature_flag_id', featureFlag?.metadata?.id),
|
|
502
|
-
...maybeAdd('$feature_flag_version', featureFlag?.metadata?.version),
|
|
503
|
-
...maybeAdd('$feature_flag_reason', featureFlag?.reason?.description ?? featureFlag?.reason?.code),
|
|
504
|
-
...maybeAdd('$feature_flag_bootstrapped_response', bootstrappedResponse),
|
|
505
|
-
...maybeAdd('$feature_flag_bootstrapped_payload', bootstrappedPayload),
|
|
506
|
-
$used_bootstrap_value: !this.getPersistedProperty(PostHogPersistedProperty.FlagsEndpointWasHit),
|
|
507
|
-
...maybeAdd('$feature_flag_request_id', details?.requestId),
|
|
508
|
-
...maybeAdd('$feature_flag_evaluated_at', details?.evaluatedAt),
|
|
509
|
-
...maybeAdd('$feature_flag_error', featureFlagError)
|
|
510
|
-
};
|
|
511
|
-
this.capture('$feature_flag_called', properties);
|
|
512
|
-
}
|
|
513
|
-
if (void 0 === flagValue) switch(options.missingFlagBehavior){
|
|
514
|
-
case 'getFeatureFlagPayload':
|
|
515
|
-
return details ? {
|
|
516
|
-
key,
|
|
517
|
-
enabled: false,
|
|
518
|
-
payload: null
|
|
519
|
-
} : void 0;
|
|
520
|
-
case 'getFeatureFlag':
|
|
521
|
-
return details && Object.keys(details.flags).length ? {
|
|
522
|
-
key,
|
|
523
|
-
enabled: false,
|
|
524
|
-
payload: null
|
|
525
|
-
} : void 0;
|
|
526
|
-
case void 0:
|
|
527
|
-
return;
|
|
528
|
-
}
|
|
529
|
-
const rawPayload = featureFlag?.metadata?.payload;
|
|
530
|
-
const payload = void 0 !== rawPayload ? parsePayload(rawPayload) : null;
|
|
531
|
-
return {
|
|
532
|
-
key,
|
|
533
|
-
enabled: getEnabledFromValue(flagValue),
|
|
534
|
-
variant: getVariantFromValue(flagValue),
|
|
535
|
-
payload
|
|
536
|
-
};
|
|
537
|
-
}
|
|
538
|
-
getFeatureFlag(key) {
|
|
539
|
-
const result = this._getFeatureFlagResult(key, {
|
|
540
|
-
missingFlagBehavior: 'getFeatureFlag'
|
|
541
|
-
});
|
|
542
|
-
return result?.variant ?? result?.enabled;
|
|
543
|
-
}
|
|
544
|
-
getFeatureFlagPayload(key) {
|
|
545
|
-
const result = this._getFeatureFlagResult(key, {
|
|
546
|
-
missingFlagBehavior: 'getFeatureFlagPayload',
|
|
547
|
-
sendEvent: false
|
|
548
|
-
});
|
|
549
|
-
return result?.payload;
|
|
550
|
-
}
|
|
551
|
-
getFeatureFlagPayloads() {
|
|
552
|
-
return this.getFeatureFlagDetails()?.featureFlagPayloads;
|
|
553
|
-
}
|
|
554
|
-
getFeatureFlags() {
|
|
555
|
-
return this.getFeatureFlagDetails()?.featureFlags;
|
|
556
|
-
}
|
|
557
|
-
getFeatureFlagDetails() {
|
|
558
|
-
let details = this.getKnownFeatureFlagDetails();
|
|
559
|
-
const overriddenFlags = this.getPersistedProperty(PostHogPersistedProperty.OverrideFeatureFlags);
|
|
560
|
-
if (!overriddenFlags) return details;
|
|
561
|
-
details = details ?? {
|
|
562
|
-
featureFlags: {},
|
|
563
|
-
featureFlagPayloads: {},
|
|
564
|
-
flags: {}
|
|
565
|
-
};
|
|
566
|
-
const flags = details.flags ?? {};
|
|
567
|
-
for(const key in overriddenFlags)if (overriddenFlags[key]) flags[key] = updateFlagValue(flags[key], overriddenFlags[key]);
|
|
568
|
-
else delete flags[key];
|
|
569
|
-
const result = {
|
|
570
|
-
...details,
|
|
571
|
-
flags
|
|
572
|
-
};
|
|
573
|
-
return normalizeFlagsResponse(result);
|
|
574
|
-
}
|
|
575
|
-
getFeatureFlagsAndPayloads() {
|
|
576
|
-
const flags = this.getFeatureFlags();
|
|
577
|
-
const payloads = this.getFeatureFlagPayloads();
|
|
578
|
-
return {
|
|
579
|
-
flags,
|
|
580
|
-
payloads
|
|
581
|
-
};
|
|
582
|
-
}
|
|
583
|
-
isFeatureEnabled(key) {
|
|
584
|
-
const response = this.getFeatureFlag(key);
|
|
585
|
-
if (void 0 === response) return;
|
|
586
|
-
return !!response;
|
|
587
|
-
}
|
|
588
|
-
reloadFeatureFlags(options) {
|
|
589
|
-
this.flagsAsync({
|
|
590
|
-
sendAnonDistinctId: true
|
|
591
|
-
}).then((res)=>{
|
|
592
|
-
options?.cb?.(void 0, res?.featureFlags);
|
|
593
|
-
}).catch((e)=>{
|
|
594
|
-
options?.cb?.(e, void 0);
|
|
595
|
-
if (!options?.cb) this._logger.info('Error reloading feature flags', e);
|
|
596
|
-
});
|
|
597
|
-
}
|
|
598
|
-
async reloadRemoteConfigAsync() {
|
|
599
|
-
return await this.remoteConfigAsync();
|
|
600
|
-
}
|
|
601
|
-
async reloadFeatureFlagsAsync(sendAnonDistinctId) {
|
|
602
|
-
return (await this.flagsAsync({
|
|
603
|
-
sendAnonDistinctId: sendAnonDistinctId
|
|
604
|
-
}))?.featureFlags;
|
|
605
|
-
}
|
|
606
|
-
onFeatureFlags(cb) {
|
|
607
|
-
return this.on('featureflags', async ()=>{
|
|
608
|
-
const flags = this.getFeatureFlags();
|
|
609
|
-
if (flags) cb(flags);
|
|
610
|
-
});
|
|
611
|
-
}
|
|
612
|
-
onFeatureFlag(key, cb) {
|
|
613
|
-
return this.on('featureflags', async ()=>{
|
|
614
|
-
const flagResponse = this.getFeatureFlag(key);
|
|
615
|
-
if (void 0 !== flagResponse) cb(flagResponse);
|
|
616
|
-
});
|
|
617
|
-
}
|
|
618
|
-
async overrideFeatureFlag(flags) {
|
|
619
|
-
this.wrap(()=>{
|
|
620
|
-
if (null === flags) return this.setPersistedProperty(PostHogPersistedProperty.OverrideFeatureFlags, null);
|
|
621
|
-
return this.setPersistedProperty(PostHogPersistedProperty.OverrideFeatureFlags, flags);
|
|
622
|
-
});
|
|
623
|
-
}
|
|
624
|
-
captureException(error, additionalProperties) {
|
|
625
|
-
const properties = {
|
|
626
|
-
$exception_level: 'error',
|
|
627
|
-
$exception_list: [
|
|
628
|
-
{
|
|
629
|
-
type: isPlainError(error) ? error.name : 'Error',
|
|
630
|
-
value: isPlainError(error) ? error.message : error,
|
|
631
|
-
mechanism: {
|
|
632
|
-
handled: true,
|
|
633
|
-
synthetic: false
|
|
634
|
-
}
|
|
635
|
-
}
|
|
636
|
-
],
|
|
637
|
-
...additionalProperties
|
|
638
|
-
};
|
|
639
|
-
this.capture('$exception', properties, {
|
|
640
|
-
_originatedFromCaptureException: true
|
|
641
|
-
});
|
|
642
|
-
}
|
|
643
|
-
captureTraceFeedback(traceId, userFeedback) {
|
|
644
|
-
this.capture('$ai_feedback', {
|
|
645
|
-
$ai_feedback_text: userFeedback,
|
|
646
|
-
$ai_trace_id: String(traceId)
|
|
647
|
-
});
|
|
648
|
-
}
|
|
649
|
-
captureTraceMetric(traceId, metricName, metricValue) {
|
|
650
|
-
this.capture('$ai_metric', {
|
|
651
|
-
$ai_metric_name: metricName,
|
|
652
|
-
$ai_metric_value: String(metricValue),
|
|
653
|
-
$ai_trace_id: String(traceId)
|
|
654
|
-
});
|
|
655
|
-
}
|
|
656
|
-
_isIdentified() {
|
|
657
|
-
const personMode = this.getPersistedProperty(PostHogPersistedProperty.PersonMode);
|
|
658
|
-
if ('identified' === personMode) return true;
|
|
659
|
-
if (void 0 === personMode) {
|
|
660
|
-
const distinctId = this.getPersistedProperty(PostHogPersistedProperty.DistinctId);
|
|
661
|
-
const anonymousId = this.getPersistedProperty(PostHogPersistedProperty.AnonymousId);
|
|
662
|
-
if (distinctId && anonymousId && distinctId !== anonymousId) return true;
|
|
663
|
-
}
|
|
664
|
-
return false;
|
|
665
|
-
}
|
|
666
|
-
_getGroups() {
|
|
667
|
-
return this.props.$groups || {};
|
|
668
|
-
}
|
|
669
|
-
_hasPersonProcessing() {
|
|
670
|
-
if ('always' === this._personProfiles) return true;
|
|
671
|
-
if ('never' === this._personProfiles) return false;
|
|
672
|
-
const isIdentified = this._isIdentified();
|
|
673
|
-
const hasGroups = Object.keys(this._getGroups()).length > 0;
|
|
674
|
-
const personProcessingEnabled = true === this.getPersistedProperty(PostHogPersistedProperty.EnablePersonProcessing);
|
|
675
|
-
return isIdentified || hasGroups || personProcessingEnabled;
|
|
676
|
-
}
|
|
677
|
-
_requirePersonProcessing(functionName) {
|
|
678
|
-
if ('never' === this._personProfiles) {
|
|
679
|
-
this._logger.error(`${functionName} was called, but personProfiles is set to "never". This call will be ignored.`);
|
|
680
|
-
return false;
|
|
681
|
-
}
|
|
682
|
-
this.setPersistedProperty(PostHogPersistedProperty.EnablePersonProcessing, true);
|
|
683
|
-
return true;
|
|
684
|
-
}
|
|
685
|
-
createPersonProfile() {
|
|
686
|
-
if (this._hasPersonProcessing()) return;
|
|
687
|
-
if (!this._requirePersonProcessing('posthog.createPersonProfile')) return;
|
|
688
|
-
this.capture('$set', {
|
|
689
|
-
$set: {},
|
|
690
|
-
$set_once: {}
|
|
691
|
-
});
|
|
692
|
-
}
|
|
693
|
-
setPersonProperties(userPropertiesToSet, userPropertiesToSetOnce, reloadFeatureFlags = true) {
|
|
694
|
-
this.wrap(()=>{
|
|
695
|
-
const isSetEmpty = isNullish(userPropertiesToSet) || isEmptyObject(userPropertiesToSet);
|
|
696
|
-
const isSetOnceEmpty = isNullish(userPropertiesToSetOnce) || isEmptyObject(userPropertiesToSetOnce);
|
|
697
|
-
if (isSetEmpty && isSetOnceEmpty) return;
|
|
698
|
-
if (!this._requirePersonProcessing('posthog.setPersonProperties')) return;
|
|
699
|
-
const hash = getPersonPropertiesHash(this.getDistinctId(), userPropertiesToSet, userPropertiesToSetOnce);
|
|
700
|
-
if (this._cachedPersonProperties === hash) return void this._logger.info('A duplicate setPersonProperties call was made with the same properties. It has been ignored.');
|
|
701
|
-
const mergedProperties = {
|
|
702
|
-
...userPropertiesToSetOnce || {},
|
|
703
|
-
...userPropertiesToSet || {}
|
|
704
|
-
};
|
|
705
|
-
this.setPersonPropertiesForFlags(mergedProperties, reloadFeatureFlags);
|
|
706
|
-
this.capture('$set', {
|
|
707
|
-
$set: userPropertiesToSet || {},
|
|
708
|
-
$set_once: userPropertiesToSetOnce || {}
|
|
709
|
-
});
|
|
710
|
-
this._cachedPersonProperties = hash;
|
|
711
|
-
});
|
|
712
|
-
}
|
|
713
|
-
processBeforeEnqueue(message) {
|
|
714
|
-
if (!this._beforeSend) return message;
|
|
715
|
-
const timestamp = message.timestamp;
|
|
716
|
-
const props = message.properties || {};
|
|
717
|
-
const captureEvent = {
|
|
718
|
-
uuid: message.uuid,
|
|
719
|
-
event: message.event,
|
|
720
|
-
properties: props,
|
|
721
|
-
$set: props.$set,
|
|
722
|
-
$set_once: props.$set_once,
|
|
723
|
-
timestamp: 'string' == typeof timestamp ? new Date(timestamp) : timestamp
|
|
724
|
-
};
|
|
725
|
-
const result = this._runBeforeSend(captureEvent);
|
|
726
|
-
if (!result) return null;
|
|
727
|
-
const resultProps = {
|
|
728
|
-
...result.properties ?? props
|
|
729
|
-
};
|
|
730
|
-
if (void 0 !== result.$set) resultProps.$set = result.$set;
|
|
731
|
-
else delete resultProps.$set;
|
|
732
|
-
if (void 0 !== result.$set_once) resultProps.$set_once = result.$set_once;
|
|
733
|
-
else delete resultProps.$set_once;
|
|
734
|
-
return {
|
|
735
|
-
...message,
|
|
736
|
-
uuid: result.uuid ?? message.uuid,
|
|
737
|
-
event: result.event,
|
|
738
|
-
properties: resultProps,
|
|
739
|
-
timestamp: result.timestamp
|
|
740
|
-
};
|
|
741
|
-
}
|
|
742
|
-
_runBeforeSend(captureEvent) {
|
|
743
|
-
const beforeSend = this._beforeSend;
|
|
744
|
-
if (!beforeSend) return captureEvent;
|
|
745
|
-
const fns = Array.isArray(beforeSend) ? beforeSend : [
|
|
746
|
-
beforeSend
|
|
747
|
-
];
|
|
748
|
-
let result = captureEvent;
|
|
749
|
-
for (const fn of fns)try {
|
|
750
|
-
result = fn(result);
|
|
751
|
-
if (!result) {
|
|
752
|
-
this._logger.info(`Event '${captureEvent.event}' was rejected in before_send function`);
|
|
753
|
-
return null;
|
|
754
|
-
}
|
|
755
|
-
} catch (e) {
|
|
756
|
-
this._logger.error(`Error in before_send function for event '${captureEvent.event}':`, e);
|
|
757
|
-
}
|
|
758
|
-
return result;
|
|
759
|
-
}
|
|
760
|
-
}
|
|
761
|
-
export { PostHogCore };
|