@claudeye/linux-x64 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,718 +0,0 @@
|
|
|
1
|
-
import { version } from "./version.mjs";
|
|
2
|
-
import { PostHogCoreStateless, isBlockedUA, isPlainObject, safeSetTimeout, uuidv7 } from "@posthog/core";
|
|
3
|
-
import { FeatureFlagError } from "./types.mjs";
|
|
4
|
-
import { FeatureFlagsPoller, InconclusiveMatchError, RequiresServerEvaluation } from "./extensions/feature-flags/feature-flags.mjs";
|
|
5
|
-
import error_tracking from "./extensions/error-tracking/index.mjs";
|
|
6
|
-
import { PostHogMemoryStorage } from "./storage-memory.mjs";
|
|
7
|
-
const MINIMUM_POLLING_INTERVAL = 100;
|
|
8
|
-
const THIRTY_SECONDS = 30000;
|
|
9
|
-
const MAX_CACHE_SIZE = 50000;
|
|
10
|
-
const WAITUNTIL_DEBOUNCE_MS = 50;
|
|
11
|
-
const WAITUNTIL_MAX_WAIT_MS = 500;
|
|
12
|
-
class PostHogBackendClient extends PostHogCoreStateless {
|
|
13
|
-
constructor(apiKey, options = {}){
|
|
14
|
-
super(apiKey, options), this._memoryStorage = new PostHogMemoryStorage();
|
|
15
|
-
this.options = options;
|
|
16
|
-
this.context = this.initializeContext();
|
|
17
|
-
this.options.featureFlagsPollingInterval = 'number' == typeof options.featureFlagsPollingInterval ? Math.max(options.featureFlagsPollingInterval, MINIMUM_POLLING_INTERVAL) : THIRTY_SECONDS;
|
|
18
|
-
if ('number' == typeof options.waitUntilDebounceMs) this.options.waitUntilDebounceMs = Math.max(options.waitUntilDebounceMs, 0);
|
|
19
|
-
if ('number' == typeof options.waitUntilMaxWaitMs) this.options.waitUntilMaxWaitMs = Math.max(options.waitUntilMaxWaitMs, 0);
|
|
20
|
-
if (options.personalApiKey) {
|
|
21
|
-
if (options.personalApiKey.includes('phc_')) throw new Error('Your Personal API key is invalid. These keys are prefixed with "phx_" and can be created in PostHog project settings.');
|
|
22
|
-
const shouldEnableLocalEvaluation = false !== options.enableLocalEvaluation;
|
|
23
|
-
if (shouldEnableLocalEvaluation) this.featureFlagsPoller = new FeatureFlagsPoller({
|
|
24
|
-
pollingInterval: this.options.featureFlagsPollingInterval,
|
|
25
|
-
personalApiKey: options.personalApiKey,
|
|
26
|
-
projectApiKey: apiKey,
|
|
27
|
-
timeout: options.requestTimeout ?? 10000,
|
|
28
|
-
host: this.host,
|
|
29
|
-
fetch: options.fetch,
|
|
30
|
-
onError: (err)=>{
|
|
31
|
-
this._events.emit('error', err);
|
|
32
|
-
},
|
|
33
|
-
onLoad: (count)=>{
|
|
34
|
-
this._events.emit('localEvaluationFlagsLoaded', count);
|
|
35
|
-
},
|
|
36
|
-
customHeaders: this.getCustomHeaders(),
|
|
37
|
-
cacheProvider: options.flagDefinitionCacheProvider,
|
|
38
|
-
strictLocalEvaluation: options.strictLocalEvaluation
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
this.errorTracking = new error_tracking(this, options, this._logger);
|
|
42
|
-
this.distinctIdHasSentFlagCalls = {};
|
|
43
|
-
this.maxCacheSize = options.maxCacheSize || MAX_CACHE_SIZE;
|
|
44
|
-
}
|
|
45
|
-
enqueue(type, message, options) {
|
|
46
|
-
super.enqueue(type, message, options);
|
|
47
|
-
this.scheduleDebouncedFlush();
|
|
48
|
-
}
|
|
49
|
-
async flush() {
|
|
50
|
-
const flushPromise = super.flush();
|
|
51
|
-
const waitUntil = this.options.waitUntil;
|
|
52
|
-
if (waitUntil && !this._waitUntilCycle) try {
|
|
53
|
-
waitUntil(flushPromise.catch(()=>{}));
|
|
54
|
-
} catch {}
|
|
55
|
-
return flushPromise;
|
|
56
|
-
}
|
|
57
|
-
scheduleDebouncedFlush() {
|
|
58
|
-
const waitUntil = this.options.waitUntil;
|
|
59
|
-
if (!waitUntil) return;
|
|
60
|
-
if (this.disabled || this.optedOut) return;
|
|
61
|
-
if (!this._waitUntilCycle) {
|
|
62
|
-
let resolve;
|
|
63
|
-
const promise = new Promise((r)=>{
|
|
64
|
-
resolve = r;
|
|
65
|
-
});
|
|
66
|
-
try {
|
|
67
|
-
waitUntil(promise);
|
|
68
|
-
} catch {
|
|
69
|
-
return;
|
|
70
|
-
}
|
|
71
|
-
this._waitUntilCycle = {
|
|
72
|
-
resolve: resolve,
|
|
73
|
-
startedAt: Date.now(),
|
|
74
|
-
timer: void 0
|
|
75
|
-
};
|
|
76
|
-
}
|
|
77
|
-
const elapsed = Date.now() - this._waitUntilCycle.startedAt;
|
|
78
|
-
const maxWaitMs = this.options.waitUntilMaxWaitMs ?? WAITUNTIL_MAX_WAIT_MS;
|
|
79
|
-
const flushNow = elapsed >= maxWaitMs;
|
|
80
|
-
if (void 0 !== this._waitUntilCycle.timer) clearTimeout(this._waitUntilCycle.timer);
|
|
81
|
-
if (flushNow) return void this.resolveWaitUntilFlush();
|
|
82
|
-
const debounceMs = this.options.waitUntilDebounceMs ?? WAITUNTIL_DEBOUNCE_MS;
|
|
83
|
-
this._waitUntilCycle.timer = safeSetTimeout(()=>{
|
|
84
|
-
this.resolveWaitUntilFlush();
|
|
85
|
-
}, debounceMs);
|
|
86
|
-
}
|
|
87
|
-
_consumeWaitUntilCycle() {
|
|
88
|
-
const cycle = this._waitUntilCycle;
|
|
89
|
-
if (cycle) {
|
|
90
|
-
clearTimeout(cycle.timer);
|
|
91
|
-
this._waitUntilCycle = void 0;
|
|
92
|
-
}
|
|
93
|
-
return cycle?.resolve;
|
|
94
|
-
}
|
|
95
|
-
async resolveWaitUntilFlush() {
|
|
96
|
-
const resolve = this._consumeWaitUntilCycle();
|
|
97
|
-
try {
|
|
98
|
-
await super.flush();
|
|
99
|
-
} catch {} finally{
|
|
100
|
-
resolve?.();
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
getPersistedProperty(key) {
|
|
104
|
-
return this._memoryStorage.getProperty(key);
|
|
105
|
-
}
|
|
106
|
-
setPersistedProperty(key, value) {
|
|
107
|
-
return this._memoryStorage.setProperty(key, value);
|
|
108
|
-
}
|
|
109
|
-
fetch(url, options) {
|
|
110
|
-
return this.options.fetch ? this.options.fetch(url, options) : fetch(url, options);
|
|
111
|
-
}
|
|
112
|
-
getLibraryVersion() {
|
|
113
|
-
return version;
|
|
114
|
-
}
|
|
115
|
-
getCustomUserAgent() {
|
|
116
|
-
return `${this.getLibraryId()}/${this.getLibraryVersion()}`;
|
|
117
|
-
}
|
|
118
|
-
enable() {
|
|
119
|
-
return super.optIn();
|
|
120
|
-
}
|
|
121
|
-
disable() {
|
|
122
|
-
return super.optOut();
|
|
123
|
-
}
|
|
124
|
-
debug(enabled = true) {
|
|
125
|
-
super.debug(enabled);
|
|
126
|
-
this.featureFlagsPoller?.debug(enabled);
|
|
127
|
-
}
|
|
128
|
-
capture(props) {
|
|
129
|
-
if ('string' == typeof props) this._logger.warn('Called capture() with a string as the first argument when an object was expected.');
|
|
130
|
-
if ('$exception' === props.event && !props._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.");
|
|
131
|
-
this.addPendingPromise(this.prepareEventMessage(props).then(({ distinctId, event, properties, options })=>super.captureStateless(distinctId, event, properties, {
|
|
132
|
-
timestamp: options.timestamp,
|
|
133
|
-
disableGeoip: options.disableGeoip,
|
|
134
|
-
uuid: options.uuid
|
|
135
|
-
})).catch((err)=>{
|
|
136
|
-
if (err) console.error(err);
|
|
137
|
-
}));
|
|
138
|
-
}
|
|
139
|
-
async captureImmediate(props) {
|
|
140
|
-
if ('string' == typeof props) this._logger.warn('Called captureImmediate() with a string as the first argument when an object was expected.');
|
|
141
|
-
if ('$exception' === props.event && !props._originatedFromCaptureException) this._logger.warn("Capturing a `$exception` event via `posthog.captureImmediate('$exception')` is unreliable because it does not attach required metadata. Use `posthog.captureExceptionImmediate(error)` instead, which attaches this metadata by default.");
|
|
142
|
-
return this.addPendingPromise(this.prepareEventMessage(props).then(({ distinctId, event, properties, options })=>super.captureStatelessImmediate(distinctId, event, properties, {
|
|
143
|
-
timestamp: options.timestamp,
|
|
144
|
-
disableGeoip: options.disableGeoip,
|
|
145
|
-
uuid: options.uuid
|
|
146
|
-
})).catch((err)=>{
|
|
147
|
-
if (err) console.error(err);
|
|
148
|
-
}));
|
|
149
|
-
}
|
|
150
|
-
identify({ distinctId, properties = {}, disableGeoip }) {
|
|
151
|
-
const { $set, $set_once, $anon_distinct_id, ...rest } = properties;
|
|
152
|
-
const setProps = $set || rest;
|
|
153
|
-
const setOnceProps = $set_once || {};
|
|
154
|
-
const eventProperties = {
|
|
155
|
-
$set: setProps,
|
|
156
|
-
$set_once: setOnceProps,
|
|
157
|
-
$anon_distinct_id: $anon_distinct_id ?? void 0
|
|
158
|
-
};
|
|
159
|
-
super.identifyStateless(distinctId, eventProperties, {
|
|
160
|
-
disableGeoip
|
|
161
|
-
});
|
|
162
|
-
}
|
|
163
|
-
async identifyImmediate({ distinctId, properties = {}, disableGeoip }) {
|
|
164
|
-
const { $set, $set_once, $anon_distinct_id, ...rest } = properties;
|
|
165
|
-
const setProps = $set || rest;
|
|
166
|
-
const setOnceProps = $set_once || {};
|
|
167
|
-
const eventProperties = {
|
|
168
|
-
$set: setProps,
|
|
169
|
-
$set_once: setOnceProps,
|
|
170
|
-
$anon_distinct_id: $anon_distinct_id ?? void 0
|
|
171
|
-
};
|
|
172
|
-
super.identifyStatelessImmediate(distinctId, eventProperties, {
|
|
173
|
-
disableGeoip
|
|
174
|
-
});
|
|
175
|
-
}
|
|
176
|
-
alias(data) {
|
|
177
|
-
super.aliasStateless(data.alias, data.distinctId, void 0, {
|
|
178
|
-
disableGeoip: data.disableGeoip
|
|
179
|
-
});
|
|
180
|
-
}
|
|
181
|
-
async aliasImmediate(data) {
|
|
182
|
-
await super.aliasStatelessImmediate(data.alias, data.distinctId, void 0, {
|
|
183
|
-
disableGeoip: data.disableGeoip
|
|
184
|
-
});
|
|
185
|
-
}
|
|
186
|
-
isLocalEvaluationReady() {
|
|
187
|
-
return this.featureFlagsPoller?.isLocalEvaluationReady() ?? false;
|
|
188
|
-
}
|
|
189
|
-
async waitForLocalEvaluationReady(timeoutMs = THIRTY_SECONDS) {
|
|
190
|
-
if (this.isLocalEvaluationReady()) return true;
|
|
191
|
-
if (void 0 === this.featureFlagsPoller) return false;
|
|
192
|
-
return new Promise((resolve)=>{
|
|
193
|
-
const timeout = setTimeout(()=>{
|
|
194
|
-
cleanup();
|
|
195
|
-
resolve(false);
|
|
196
|
-
}, timeoutMs);
|
|
197
|
-
const cleanup = this._events.on('localEvaluationFlagsLoaded', (count)=>{
|
|
198
|
-
clearTimeout(timeout);
|
|
199
|
-
cleanup();
|
|
200
|
-
resolve(count > 0);
|
|
201
|
-
});
|
|
202
|
-
});
|
|
203
|
-
}
|
|
204
|
-
_resolveDistinctId(distinctIdOrOptions, options) {
|
|
205
|
-
if ('string' == typeof distinctIdOrOptions) return {
|
|
206
|
-
distinctId: distinctIdOrOptions,
|
|
207
|
-
options
|
|
208
|
-
};
|
|
209
|
-
return {
|
|
210
|
-
distinctId: this.context?.get()?.distinctId,
|
|
211
|
-
options: distinctIdOrOptions
|
|
212
|
-
};
|
|
213
|
-
}
|
|
214
|
-
async _getFeatureFlagResult(key, distinctId, options = {}, matchValue) {
|
|
215
|
-
const sendFeatureFlagEvents = options.sendFeatureFlagEvents ?? true;
|
|
216
|
-
if (void 0 !== this._flagOverrides && key in this._flagOverrides) {
|
|
217
|
-
const overrideValue = this._flagOverrides[key];
|
|
218
|
-
if (void 0 === overrideValue) return;
|
|
219
|
-
const overridePayload = this._payloadOverrides?.[key];
|
|
220
|
-
return {
|
|
221
|
-
key,
|
|
222
|
-
enabled: false !== overrideValue,
|
|
223
|
-
variant: 'string' == typeof overrideValue ? overrideValue : void 0,
|
|
224
|
-
payload: overridePayload
|
|
225
|
-
};
|
|
226
|
-
}
|
|
227
|
-
const { groups, disableGeoip } = options;
|
|
228
|
-
let { onlyEvaluateLocally, personProperties, groupProperties } = options;
|
|
229
|
-
const adjustedProperties = this.addLocalPersonAndGroupProperties(distinctId, groups, personProperties, groupProperties);
|
|
230
|
-
personProperties = adjustedProperties.allPersonProperties;
|
|
231
|
-
groupProperties = adjustedProperties.allGroupProperties;
|
|
232
|
-
const evaluationContext = this.createFeatureFlagEvaluationContext(distinctId, groups, personProperties, groupProperties);
|
|
233
|
-
if (void 0 == onlyEvaluateLocally) onlyEvaluateLocally = this.options.strictLocalEvaluation ?? false;
|
|
234
|
-
let result;
|
|
235
|
-
let flagWasLocallyEvaluated = false;
|
|
236
|
-
let requestId;
|
|
237
|
-
let evaluatedAt;
|
|
238
|
-
let featureFlagError;
|
|
239
|
-
let flagId;
|
|
240
|
-
let flagVersion;
|
|
241
|
-
let flagReason;
|
|
242
|
-
const localEvaluationEnabled = void 0 !== this.featureFlagsPoller;
|
|
243
|
-
if (localEvaluationEnabled) {
|
|
244
|
-
await this.featureFlagsPoller?.loadFeatureFlags();
|
|
245
|
-
const flag = this.featureFlagsPoller?.featureFlagsByKey[key];
|
|
246
|
-
if (flag) try {
|
|
247
|
-
const localResult = await this.featureFlagsPoller?.computeFlagAndPayloadLocally(flag, evaluationContext, {
|
|
248
|
-
matchValue
|
|
249
|
-
});
|
|
250
|
-
if (localResult) {
|
|
251
|
-
flagWasLocallyEvaluated = true;
|
|
252
|
-
const value = localResult.value;
|
|
253
|
-
flagId = flag.id;
|
|
254
|
-
flagReason = 'Evaluated locally';
|
|
255
|
-
result = {
|
|
256
|
-
key,
|
|
257
|
-
enabled: false !== value,
|
|
258
|
-
variant: 'string' == typeof value ? value : void 0,
|
|
259
|
-
payload: localResult.payload ?? void 0
|
|
260
|
-
};
|
|
261
|
-
}
|
|
262
|
-
} catch (e) {
|
|
263
|
-
if (e instanceof RequiresServerEvaluation || e instanceof InconclusiveMatchError) this._logger?.info(`${e.name} when computing flag locally: ${key}: ${e.message}`);
|
|
264
|
-
else throw e;
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
if (!flagWasLocallyEvaluated && !onlyEvaluateLocally) {
|
|
268
|
-
const flagsResponse = await super.getFeatureFlagDetailsStateless(evaluationContext.distinctId, evaluationContext.groups, evaluationContext.personProperties, evaluationContext.groupProperties, disableGeoip, [
|
|
269
|
-
key
|
|
270
|
-
]);
|
|
271
|
-
if (void 0 === flagsResponse) featureFlagError = FeatureFlagError.UNKNOWN_ERROR;
|
|
272
|
-
else {
|
|
273
|
-
requestId = flagsResponse.requestId;
|
|
274
|
-
evaluatedAt = flagsResponse.evaluatedAt;
|
|
275
|
-
const errors = [];
|
|
276
|
-
if (flagsResponse.errorsWhileComputingFlags) errors.push(FeatureFlagError.ERRORS_WHILE_COMPUTING);
|
|
277
|
-
if (flagsResponse.quotaLimited?.includes('feature_flags')) errors.push(FeatureFlagError.QUOTA_LIMITED);
|
|
278
|
-
const flagDetail = flagsResponse.flags[key];
|
|
279
|
-
if (void 0 === flagDetail) errors.push(FeatureFlagError.FLAG_MISSING);
|
|
280
|
-
else {
|
|
281
|
-
flagId = flagDetail.metadata?.id;
|
|
282
|
-
flagVersion = flagDetail.metadata?.version;
|
|
283
|
-
flagReason = flagDetail.reason?.description ?? flagDetail.reason?.code;
|
|
284
|
-
let parsedPayload;
|
|
285
|
-
if (flagDetail.metadata?.payload !== void 0) try {
|
|
286
|
-
parsedPayload = JSON.parse(flagDetail.metadata.payload);
|
|
287
|
-
} catch {
|
|
288
|
-
parsedPayload = flagDetail.metadata.payload;
|
|
289
|
-
}
|
|
290
|
-
result = {
|
|
291
|
-
key,
|
|
292
|
-
enabled: flagDetail.enabled,
|
|
293
|
-
variant: flagDetail.variant,
|
|
294
|
-
payload: parsedPayload
|
|
295
|
-
};
|
|
296
|
-
}
|
|
297
|
-
if (errors.length > 0) featureFlagError = errors.join(',');
|
|
298
|
-
}
|
|
299
|
-
}
|
|
300
|
-
if (sendFeatureFlagEvents) {
|
|
301
|
-
const response = void 0 === result ? void 0 : false === result.enabled ? false : result.variant ?? true;
|
|
302
|
-
const featureFlagReportedKey = `${key}_${response}`;
|
|
303
|
-
if (!(distinctId in this.distinctIdHasSentFlagCalls) || !this.distinctIdHasSentFlagCalls[distinctId].includes(featureFlagReportedKey)) {
|
|
304
|
-
if (Object.keys(this.distinctIdHasSentFlagCalls).length >= this.maxCacheSize) this.distinctIdHasSentFlagCalls = {};
|
|
305
|
-
if (Array.isArray(this.distinctIdHasSentFlagCalls[distinctId])) this.distinctIdHasSentFlagCalls[distinctId].push(featureFlagReportedKey);
|
|
306
|
-
else this.distinctIdHasSentFlagCalls[distinctId] = [
|
|
307
|
-
featureFlagReportedKey
|
|
308
|
-
];
|
|
309
|
-
const properties = {
|
|
310
|
-
$feature_flag: key,
|
|
311
|
-
$feature_flag_response: response,
|
|
312
|
-
$feature_flag_id: flagId,
|
|
313
|
-
$feature_flag_version: flagVersion,
|
|
314
|
-
$feature_flag_reason: flagReason,
|
|
315
|
-
locally_evaluated: flagWasLocallyEvaluated,
|
|
316
|
-
[`$feature/${key}`]: response,
|
|
317
|
-
$feature_flag_request_id: requestId,
|
|
318
|
-
$feature_flag_evaluated_at: flagWasLocallyEvaluated ? Date.now() : evaluatedAt
|
|
319
|
-
};
|
|
320
|
-
if (flagWasLocallyEvaluated && this.featureFlagsPoller) {
|
|
321
|
-
const flagDefinitionsLoadedAt = this.featureFlagsPoller.getFlagDefinitionsLoadedAt();
|
|
322
|
-
if (void 0 !== flagDefinitionsLoadedAt) properties.$feature_flag_definitions_loaded_at = flagDefinitionsLoadedAt;
|
|
323
|
-
}
|
|
324
|
-
if (featureFlagError) properties.$feature_flag_error = featureFlagError;
|
|
325
|
-
this.capture({
|
|
326
|
-
distinctId,
|
|
327
|
-
event: '$feature_flag_called',
|
|
328
|
-
properties,
|
|
329
|
-
groups,
|
|
330
|
-
disableGeoip
|
|
331
|
-
});
|
|
332
|
-
}
|
|
333
|
-
}
|
|
334
|
-
if (void 0 !== result && void 0 !== this._payloadOverrides && key in this._payloadOverrides) result = {
|
|
335
|
-
...result,
|
|
336
|
-
payload: this._payloadOverrides[key]
|
|
337
|
-
};
|
|
338
|
-
return result;
|
|
339
|
-
}
|
|
340
|
-
async getFeatureFlag(key, distinctId, options) {
|
|
341
|
-
const result = await this._getFeatureFlagResult(key, distinctId, {
|
|
342
|
-
...options,
|
|
343
|
-
sendFeatureFlagEvents: options?.sendFeatureFlagEvents ?? this.options.sendFeatureFlagEvent ?? true
|
|
344
|
-
});
|
|
345
|
-
if (void 0 === result) return;
|
|
346
|
-
if (false === result.enabled) return false;
|
|
347
|
-
return result.variant ?? true;
|
|
348
|
-
}
|
|
349
|
-
async getFeatureFlagPayload(key, distinctId, matchValue, options) {
|
|
350
|
-
if (void 0 !== this._payloadOverrides && key in this._payloadOverrides) return this._payloadOverrides[key];
|
|
351
|
-
const result = await this._getFeatureFlagResult(key, distinctId, {
|
|
352
|
-
...options,
|
|
353
|
-
sendFeatureFlagEvents: false
|
|
354
|
-
}, matchValue);
|
|
355
|
-
if (void 0 === result) return;
|
|
356
|
-
return result.payload ?? null;
|
|
357
|
-
}
|
|
358
|
-
async getFeatureFlagResult(key, distinctIdOrOptions, options) {
|
|
359
|
-
const { distinctId: resolvedDistinctId, options: resolvedOptions } = this._resolveDistinctId(distinctIdOrOptions, options);
|
|
360
|
-
if (!resolvedDistinctId) return void this._logger.warn("[PostHog] distinctId is required \u2014 pass it explicitly or use withContext()");
|
|
361
|
-
return this._getFeatureFlagResult(key, resolvedDistinctId, {
|
|
362
|
-
...resolvedOptions,
|
|
363
|
-
sendFeatureFlagEvents: resolvedOptions?.sendFeatureFlagEvents ?? this.options.sendFeatureFlagEvent ?? true
|
|
364
|
-
});
|
|
365
|
-
}
|
|
366
|
-
async getRemoteConfigPayload(flagKey) {
|
|
367
|
-
if (!this.options.personalApiKey) throw new Error('Personal API key is required for remote config payload decryption');
|
|
368
|
-
const response = await this._requestRemoteConfigPayload(flagKey);
|
|
369
|
-
if (!response) return;
|
|
370
|
-
const parsed = await response.json();
|
|
371
|
-
if ('string' == typeof parsed) try {
|
|
372
|
-
return JSON.parse(parsed);
|
|
373
|
-
} catch (e) {}
|
|
374
|
-
return parsed;
|
|
375
|
-
}
|
|
376
|
-
async isFeatureEnabled(key, distinctId, options) {
|
|
377
|
-
const feat = await this.getFeatureFlag(key, distinctId, options);
|
|
378
|
-
if (void 0 === feat) return;
|
|
379
|
-
return !!feat || false;
|
|
380
|
-
}
|
|
381
|
-
async getAllFlags(distinctIdOrOptions, options) {
|
|
382
|
-
const { distinctId: resolvedDistinctId, options: resolvedOptions } = this._resolveDistinctId(distinctIdOrOptions, options);
|
|
383
|
-
if (!resolvedDistinctId) {
|
|
384
|
-
this._logger.warn("[PostHog] distinctId is required to get feature flags \u2014 pass it explicitly or use withContext()");
|
|
385
|
-
return {};
|
|
386
|
-
}
|
|
387
|
-
const response = await this.getAllFlagsAndPayloads(resolvedDistinctId, resolvedOptions);
|
|
388
|
-
return response.featureFlags || {};
|
|
389
|
-
}
|
|
390
|
-
async getAllFlagsAndPayloads(distinctIdOrOptions, options) {
|
|
391
|
-
const { distinctId: resolvedDistinctId, options: resolvedOptions } = this._resolveDistinctId(distinctIdOrOptions, options);
|
|
392
|
-
if (!resolvedDistinctId) {
|
|
393
|
-
this._logger.warn("[PostHog] distinctId is required to get feature flags and payloads \u2014 pass it explicitly or use withContext()");
|
|
394
|
-
return {
|
|
395
|
-
featureFlags: {},
|
|
396
|
-
featureFlagPayloads: {}
|
|
397
|
-
};
|
|
398
|
-
}
|
|
399
|
-
const { groups, disableGeoip, flagKeys } = resolvedOptions || {};
|
|
400
|
-
let { onlyEvaluateLocally, personProperties, groupProperties } = resolvedOptions || {};
|
|
401
|
-
const adjustedProperties = this.addLocalPersonAndGroupProperties(resolvedDistinctId, groups, personProperties, groupProperties);
|
|
402
|
-
personProperties = adjustedProperties.allPersonProperties;
|
|
403
|
-
groupProperties = adjustedProperties.allGroupProperties;
|
|
404
|
-
const evaluationContext = this.createFeatureFlagEvaluationContext(resolvedDistinctId, groups, personProperties, groupProperties);
|
|
405
|
-
if (void 0 == onlyEvaluateLocally) onlyEvaluateLocally = this.options.strictLocalEvaluation ?? false;
|
|
406
|
-
const localEvaluationResult = await this.featureFlagsPoller?.getAllFlagsAndPayloads(evaluationContext, flagKeys);
|
|
407
|
-
let featureFlags = {};
|
|
408
|
-
let featureFlagPayloads = {};
|
|
409
|
-
let fallbackToFlags = true;
|
|
410
|
-
if (localEvaluationResult) {
|
|
411
|
-
featureFlags = localEvaluationResult.response;
|
|
412
|
-
featureFlagPayloads = localEvaluationResult.payloads;
|
|
413
|
-
fallbackToFlags = localEvaluationResult.fallbackToFlags;
|
|
414
|
-
}
|
|
415
|
-
if (fallbackToFlags && !onlyEvaluateLocally) {
|
|
416
|
-
const remoteEvaluationResult = await super.getFeatureFlagsAndPayloadsStateless(evaluationContext.distinctId, evaluationContext.groups, evaluationContext.personProperties, evaluationContext.groupProperties, disableGeoip, flagKeys);
|
|
417
|
-
featureFlags = {
|
|
418
|
-
...featureFlags,
|
|
419
|
-
...remoteEvaluationResult.flags || {}
|
|
420
|
-
};
|
|
421
|
-
featureFlagPayloads = {
|
|
422
|
-
...featureFlagPayloads,
|
|
423
|
-
...remoteEvaluationResult.payloads || {}
|
|
424
|
-
};
|
|
425
|
-
}
|
|
426
|
-
if (void 0 !== this._flagOverrides) featureFlags = {
|
|
427
|
-
...featureFlags,
|
|
428
|
-
...this._flagOverrides
|
|
429
|
-
};
|
|
430
|
-
if (void 0 !== this._payloadOverrides) featureFlagPayloads = {
|
|
431
|
-
...featureFlagPayloads,
|
|
432
|
-
...this._payloadOverrides
|
|
433
|
-
};
|
|
434
|
-
return {
|
|
435
|
-
featureFlags,
|
|
436
|
-
featureFlagPayloads
|
|
437
|
-
};
|
|
438
|
-
}
|
|
439
|
-
groupIdentify({ groupType, groupKey, properties, distinctId, disableGeoip }) {
|
|
440
|
-
super.groupIdentifyStateless(groupType, groupKey, properties, {
|
|
441
|
-
disableGeoip
|
|
442
|
-
}, distinctId);
|
|
443
|
-
}
|
|
444
|
-
async reloadFeatureFlags() {
|
|
445
|
-
await this.featureFlagsPoller?.loadFeatureFlags(true);
|
|
446
|
-
}
|
|
447
|
-
overrideFeatureFlags(overrides) {
|
|
448
|
-
const flagArrayToRecord = (flags)=>Object.fromEntries(flags.map((f)=>[
|
|
449
|
-
f,
|
|
450
|
-
true
|
|
451
|
-
]));
|
|
452
|
-
if (false === overrides) {
|
|
453
|
-
this._flagOverrides = void 0;
|
|
454
|
-
this._payloadOverrides = void 0;
|
|
455
|
-
return;
|
|
456
|
-
}
|
|
457
|
-
if (Array.isArray(overrides)) {
|
|
458
|
-
this._flagOverrides = flagArrayToRecord(overrides);
|
|
459
|
-
return;
|
|
460
|
-
}
|
|
461
|
-
if (this._isFeatureFlagOverrideOptions(overrides)) {
|
|
462
|
-
if ('flags' in overrides) {
|
|
463
|
-
if (false === overrides.flags) this._flagOverrides = void 0;
|
|
464
|
-
else if (Array.isArray(overrides.flags)) this._flagOverrides = flagArrayToRecord(overrides.flags);
|
|
465
|
-
else if (void 0 !== overrides.flags) this._flagOverrides = {
|
|
466
|
-
...overrides.flags
|
|
467
|
-
};
|
|
468
|
-
}
|
|
469
|
-
if ('payloads' in overrides) {
|
|
470
|
-
if (false === overrides.payloads) this._payloadOverrides = void 0;
|
|
471
|
-
else if (void 0 !== overrides.payloads) this._payloadOverrides = {
|
|
472
|
-
...overrides.payloads
|
|
473
|
-
};
|
|
474
|
-
}
|
|
475
|
-
return;
|
|
476
|
-
}
|
|
477
|
-
this._flagOverrides = {
|
|
478
|
-
...overrides
|
|
479
|
-
};
|
|
480
|
-
}
|
|
481
|
-
_isFeatureFlagOverrideOptions(overrides) {
|
|
482
|
-
if ('object' != typeof overrides || null === overrides || Array.isArray(overrides)) return false;
|
|
483
|
-
const obj = overrides;
|
|
484
|
-
if ('flags' in obj) {
|
|
485
|
-
const flagsValue = obj['flags'];
|
|
486
|
-
if (false === flagsValue || Array.isArray(flagsValue) || 'object' == typeof flagsValue && null !== flagsValue) return true;
|
|
487
|
-
}
|
|
488
|
-
if ('payloads' in obj) {
|
|
489
|
-
const payloadsValue = obj['payloads'];
|
|
490
|
-
if (false === payloadsValue || 'object' == typeof payloadsValue && null !== payloadsValue) return true;
|
|
491
|
-
}
|
|
492
|
-
return false;
|
|
493
|
-
}
|
|
494
|
-
withContext(data, fn, options) {
|
|
495
|
-
if (!this.context) return fn();
|
|
496
|
-
return this.context.run(data, fn, options);
|
|
497
|
-
}
|
|
498
|
-
getContext() {
|
|
499
|
-
return this.context?.get();
|
|
500
|
-
}
|
|
501
|
-
enterContext(data, options) {
|
|
502
|
-
this.context?.enter(data, options);
|
|
503
|
-
}
|
|
504
|
-
async _shutdown(shutdownTimeoutMs) {
|
|
505
|
-
const resolve = this._consumeWaitUntilCycle();
|
|
506
|
-
this.featureFlagsPoller?.stopPoller(shutdownTimeoutMs);
|
|
507
|
-
this.errorTracking.shutdown();
|
|
508
|
-
try {
|
|
509
|
-
return await super._shutdown(shutdownTimeoutMs);
|
|
510
|
-
} finally{
|
|
511
|
-
resolve?.();
|
|
512
|
-
}
|
|
513
|
-
}
|
|
514
|
-
async _requestRemoteConfigPayload(flagKey) {
|
|
515
|
-
if (!this.options.personalApiKey) return;
|
|
516
|
-
const url = `${this.host}/api/projects/@current/feature_flags/${flagKey}/remote_config?token=${encodeURIComponent(this.apiKey)}`;
|
|
517
|
-
const options = {
|
|
518
|
-
method: 'GET',
|
|
519
|
-
headers: {
|
|
520
|
-
...this.getCustomHeaders(),
|
|
521
|
-
'Content-Type': 'application/json',
|
|
522
|
-
Authorization: `Bearer ${this.options.personalApiKey}`
|
|
523
|
-
}
|
|
524
|
-
};
|
|
525
|
-
let abortTimeout = null;
|
|
526
|
-
if (this.options.requestTimeout && 'number' == typeof this.options.requestTimeout) {
|
|
527
|
-
const controller = new AbortController();
|
|
528
|
-
abortTimeout = safeSetTimeout(()=>{
|
|
529
|
-
controller.abort();
|
|
530
|
-
}, this.options.requestTimeout);
|
|
531
|
-
options.signal = controller.signal;
|
|
532
|
-
}
|
|
533
|
-
try {
|
|
534
|
-
return await this.fetch(url, options);
|
|
535
|
-
} catch (error) {
|
|
536
|
-
this._events.emit('error', error);
|
|
537
|
-
return;
|
|
538
|
-
} finally{
|
|
539
|
-
if (abortTimeout) clearTimeout(abortTimeout);
|
|
540
|
-
}
|
|
541
|
-
}
|
|
542
|
-
extractPropertiesFromEvent(eventProperties, groups) {
|
|
543
|
-
if (!eventProperties) return {
|
|
544
|
-
personProperties: {},
|
|
545
|
-
groupProperties: {}
|
|
546
|
-
};
|
|
547
|
-
const personProperties = {};
|
|
548
|
-
const groupProperties = {};
|
|
549
|
-
for (const [key, value] of Object.entries(eventProperties))if (isPlainObject(value) && groups && key in groups) {
|
|
550
|
-
const groupProps = {};
|
|
551
|
-
for (const [groupKey, groupValue] of Object.entries(value))groupProps[String(groupKey)] = String(groupValue);
|
|
552
|
-
groupProperties[String(key)] = groupProps;
|
|
553
|
-
} else personProperties[String(key)] = String(value);
|
|
554
|
-
return {
|
|
555
|
-
personProperties,
|
|
556
|
-
groupProperties
|
|
557
|
-
};
|
|
558
|
-
}
|
|
559
|
-
async getFeatureFlagsForEvent(distinctId, groups, disableGeoip, sendFeatureFlagsOptions) {
|
|
560
|
-
const finalPersonProperties = sendFeatureFlagsOptions?.personProperties || {};
|
|
561
|
-
const finalGroupProperties = sendFeatureFlagsOptions?.groupProperties || {};
|
|
562
|
-
const flagKeys = sendFeatureFlagsOptions?.flagKeys;
|
|
563
|
-
const onlyEvaluateLocally = sendFeatureFlagsOptions?.onlyEvaluateLocally ?? this.options.strictLocalEvaluation ?? false;
|
|
564
|
-
if (onlyEvaluateLocally) if (!((this.featureFlagsPoller?.featureFlags?.length || 0) > 0)) return {};
|
|
565
|
-
else {
|
|
566
|
-
const groupsWithStringValues = {};
|
|
567
|
-
for (const [key, value] of Object.entries(groups || {}))groupsWithStringValues[key] = String(value);
|
|
568
|
-
return await this.getAllFlags(distinctId, {
|
|
569
|
-
groups: groupsWithStringValues,
|
|
570
|
-
personProperties: finalPersonProperties,
|
|
571
|
-
groupProperties: finalGroupProperties,
|
|
572
|
-
disableGeoip,
|
|
573
|
-
onlyEvaluateLocally: true,
|
|
574
|
-
flagKeys
|
|
575
|
-
});
|
|
576
|
-
}
|
|
577
|
-
if ((this.featureFlagsPoller?.featureFlags?.length || 0) > 0) {
|
|
578
|
-
const groupsWithStringValues = {};
|
|
579
|
-
for (const [key, value] of Object.entries(groups || {}))groupsWithStringValues[key] = String(value);
|
|
580
|
-
return await this.getAllFlags(distinctId, {
|
|
581
|
-
groups: groupsWithStringValues,
|
|
582
|
-
personProperties: finalPersonProperties,
|
|
583
|
-
groupProperties: finalGroupProperties,
|
|
584
|
-
disableGeoip,
|
|
585
|
-
onlyEvaluateLocally: true,
|
|
586
|
-
flagKeys
|
|
587
|
-
});
|
|
588
|
-
}
|
|
589
|
-
return (await super.getFeatureFlagsStateless(distinctId, groups, finalPersonProperties, finalGroupProperties, disableGeoip)).flags;
|
|
590
|
-
}
|
|
591
|
-
addLocalPersonAndGroupProperties(distinctId, groups, personProperties, groupProperties) {
|
|
592
|
-
const allPersonProperties = {
|
|
593
|
-
distinct_id: distinctId,
|
|
594
|
-
...personProperties || {}
|
|
595
|
-
};
|
|
596
|
-
const allGroupProperties = {};
|
|
597
|
-
if (groups) for (const groupName of Object.keys(groups))allGroupProperties[groupName] = {
|
|
598
|
-
$group_key: groups[groupName],
|
|
599
|
-
...groupProperties?.[groupName] || {}
|
|
600
|
-
};
|
|
601
|
-
return {
|
|
602
|
-
allPersonProperties,
|
|
603
|
-
allGroupProperties
|
|
604
|
-
};
|
|
605
|
-
}
|
|
606
|
-
createFeatureFlagEvaluationContext(distinctId, groups, personProperties, groupProperties) {
|
|
607
|
-
return {
|
|
608
|
-
distinctId,
|
|
609
|
-
groups: groups || {},
|
|
610
|
-
personProperties: personProperties || {},
|
|
611
|
-
groupProperties: groupProperties || {},
|
|
612
|
-
evaluationCache: {}
|
|
613
|
-
};
|
|
614
|
-
}
|
|
615
|
-
captureException(error, distinctId, additionalProperties, uuid) {
|
|
616
|
-
if (!error_tracking.isPreviouslyCapturedError(error)) {
|
|
617
|
-
const syntheticException = new Error('PostHog syntheticException');
|
|
618
|
-
this.addPendingPromise(error_tracking.buildEventMessage(error, {
|
|
619
|
-
syntheticException
|
|
620
|
-
}, distinctId, additionalProperties).then((msg)=>this.capture({
|
|
621
|
-
...msg,
|
|
622
|
-
uuid
|
|
623
|
-
})));
|
|
624
|
-
}
|
|
625
|
-
}
|
|
626
|
-
async captureExceptionImmediate(error, distinctId, additionalProperties) {
|
|
627
|
-
if (!error_tracking.isPreviouslyCapturedError(error)) {
|
|
628
|
-
const syntheticException = new Error('PostHog syntheticException');
|
|
629
|
-
this.addPendingPromise(error_tracking.buildEventMessage(error, {
|
|
630
|
-
syntheticException
|
|
631
|
-
}, distinctId, additionalProperties).then((msg)=>this.captureImmediate(msg)));
|
|
632
|
-
}
|
|
633
|
-
}
|
|
634
|
-
async prepareEventMessage(props) {
|
|
635
|
-
const { distinctId, event, properties, groups, sendFeatureFlags, timestamp, disableGeoip, uuid } = props;
|
|
636
|
-
const contextData = this.context?.get();
|
|
637
|
-
let mergedDistinctId = distinctId || contextData?.distinctId;
|
|
638
|
-
const mergedProperties = {
|
|
639
|
-
...this.props,
|
|
640
|
-
...contextData?.properties || {},
|
|
641
|
-
...properties || {}
|
|
642
|
-
};
|
|
643
|
-
if (!mergedDistinctId) {
|
|
644
|
-
mergedDistinctId = uuidv7();
|
|
645
|
-
mergedProperties.$process_person_profile = false;
|
|
646
|
-
}
|
|
647
|
-
if (contextData?.sessionId && !mergedProperties.$session_id) mergedProperties.$session_id = contextData.sessionId;
|
|
648
|
-
const eventMessage = this._runBeforeSend({
|
|
649
|
-
distinctId: mergedDistinctId,
|
|
650
|
-
event,
|
|
651
|
-
properties: mergedProperties,
|
|
652
|
-
groups,
|
|
653
|
-
sendFeatureFlags,
|
|
654
|
-
timestamp,
|
|
655
|
-
disableGeoip,
|
|
656
|
-
uuid
|
|
657
|
-
});
|
|
658
|
-
if (!eventMessage) return Promise.reject(null);
|
|
659
|
-
const eventProperties = await Promise.resolve().then(async ()=>{
|
|
660
|
-
if (sendFeatureFlags) {
|
|
661
|
-
const sendFeatureFlagsOptions = 'object' == typeof sendFeatureFlags ? sendFeatureFlags : void 0;
|
|
662
|
-
return await this.getFeatureFlagsForEvent(eventMessage.distinctId, groups, disableGeoip, sendFeatureFlagsOptions);
|
|
663
|
-
}
|
|
664
|
-
eventMessage.event;
|
|
665
|
-
return {};
|
|
666
|
-
}).then((flags)=>{
|
|
667
|
-
const additionalProperties = {};
|
|
668
|
-
if (flags) for (const [feature, variant] of Object.entries(flags))additionalProperties[`$feature/${feature}`] = variant;
|
|
669
|
-
const activeFlags = Object.keys(flags || {}).filter((flag)=>flags?.[flag] !== false).sort();
|
|
670
|
-
if (activeFlags.length > 0) additionalProperties['$active_feature_flags'] = activeFlags;
|
|
671
|
-
return additionalProperties;
|
|
672
|
-
}).catch(()=>({})).then((additionalProperties)=>{
|
|
673
|
-
const props = {
|
|
674
|
-
...additionalProperties,
|
|
675
|
-
...eventMessage.properties || {},
|
|
676
|
-
$groups: eventMessage.groups || groups
|
|
677
|
-
};
|
|
678
|
-
return props;
|
|
679
|
-
});
|
|
680
|
-
if ('$pageview' === eventMessage.event && this.options.__preview_capture_bot_pageviews && 'string' == typeof eventProperties.$raw_user_agent) {
|
|
681
|
-
if (isBlockedUA(eventProperties.$raw_user_agent, this.options.custom_blocked_useragents || [])) {
|
|
682
|
-
eventMessage.event = '$bot_pageview';
|
|
683
|
-
eventProperties.$browser_type = 'bot';
|
|
684
|
-
}
|
|
685
|
-
}
|
|
686
|
-
return {
|
|
687
|
-
distinctId: eventMessage.distinctId,
|
|
688
|
-
event: eventMessage.event,
|
|
689
|
-
properties: eventProperties,
|
|
690
|
-
options: {
|
|
691
|
-
timestamp: eventMessage.timestamp,
|
|
692
|
-
disableGeoip: eventMessage.disableGeoip,
|
|
693
|
-
uuid: eventMessage.uuid
|
|
694
|
-
}
|
|
695
|
-
};
|
|
696
|
-
}
|
|
697
|
-
_runBeforeSend(eventMessage) {
|
|
698
|
-
const beforeSend = this.options.before_send;
|
|
699
|
-
if (!beforeSend) return eventMessage;
|
|
700
|
-
const fns = Array.isArray(beforeSend) ? beforeSend : [
|
|
701
|
-
beforeSend
|
|
702
|
-
];
|
|
703
|
-
let result = eventMessage;
|
|
704
|
-
for (const fn of fns){
|
|
705
|
-
result = fn(result);
|
|
706
|
-
if (!result) {
|
|
707
|
-
this._logger.info(`Event '${eventMessage.event}' was rejected in beforeSend function`);
|
|
708
|
-
return null;
|
|
709
|
-
}
|
|
710
|
-
if (!result.properties || 0 === Object.keys(result.properties).length) {
|
|
711
|
-
const message = `Event '${result.event}' has no properties after beforeSend function, this is likely an error.`;
|
|
712
|
-
this._logger.warn(message);
|
|
713
|
-
}
|
|
714
|
-
}
|
|
715
|
-
return result;
|
|
716
|
-
}
|
|
717
|
-
}
|
|
718
|
-
export { PostHogBackendClient };
|