oh-my-opencode 5.0.0-beta.11 → 5.0.0-beta.13
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/.agents/skills/senpi-qa/SKILL.md +80 -0
- package/.agents/skills/senpi-qa/scripts/resolve-evidence-dir.mjs +65 -0
- package/.agents/skills/senpi-qa/scripts/resolve-evidence-dir.test.mjs +171 -0
- package/dist/cli/index.js +6784 -4321
- package/dist/cli-node/index.js +6784 -4321
- package/dist/create-hooks.d.ts +1 -0
- package/dist/features/btw-side/btw-command-draft.d.ts +7 -0
- package/dist/features/btw-side/context-injector.d.ts +15 -0
- package/dist/features/btw-side/index.d.ts +8 -0
- package/dist/features/btw-side/metadata.d.ts +15 -0
- package/dist/features/btw-side/parent-context-budget.d.ts +9 -0
- package/dist/features/btw-side/server-session-registry.d.ts +8 -0
- package/dist/features/btw-side/tui-adoption-cache.d.ts +13 -0
- package/dist/features/btw-side/tui-adoption-guard.d.ts +5 -0
- package/dist/features/btw-side/tui-controller-types.d.ts +63 -0
- package/dist/features/btw-side/tui-controller.d.ts +14 -0
- package/dist/features/btw-side/tui-keymap.d.ts +10 -0
- package/dist/features/btw-side/tui-parent-validator.d.ts +6 -0
- package/dist/features/btw-side/tui-prompt-queue.d.ts +8 -0
- package/dist/features/btw-side/tui-session-bridge.d.ts +11 -0
- package/dist/features/btw-side/tui-side-removal.d.ts +11 -0
- package/dist/features/btw-side/tui-side-start.d.ts +9 -0
- package/dist/features/btw-side/tui-wiring.d.ts +8 -0
- package/dist/hooks/runtime-fallback/chat-message-handler.d.ts +2 -0
- package/dist/hooks/runtime-fallback/retry-model-payload.d.ts +1 -0
- package/dist/hooks/runtime-fallback/runtime-model-settings.d.ts +6 -0
- package/dist/hooks/runtime-fallback/session-status-handler.d.ts +1 -1
- package/dist/hooks/runtime-fallback/types.d.ts +3 -1
- package/dist/index.js +6512 -3851
- package/dist/plugin/event-session-lifecycle.d.ts +1 -0
- package/dist/plugin/hooks/create-core-hooks.d.ts +1 -0
- package/dist/plugin/hooks/create-transform-hooks.d.ts +2 -0
- package/dist/plugin/messages-transform.d.ts +1 -0
- package/dist/shared/index.d.ts +1 -0
- package/dist/shared/runtime-fallback-retry-marker.d.ts +16 -0
- package/dist/tui.js +8102 -6793
- package/package.json +24 -23
- package/packages/git-bash-mcp/dist/cli.js +5 -1
- package/packages/lsp-daemon/dist/cli.js +5 -1
- package/packages/lsp-daemon/dist/client.js +5 -1
- package/packages/lsp-daemon/dist/index.js +5 -1
- package/packages/lsp-tools-mcp/dist/cli.js +5 -1
- package/packages/lsp-tools-mcp/dist/mcp.js +5 -1
- package/packages/omo-codex/plugin/.codex-plugin/plugin.json +1 -1
- package/packages/omo-codex/plugin/components/bootstrap/hooks/hooks.json +1 -1
- package/packages/omo-codex/plugin/components/bootstrap/package.json +1 -1
- package/packages/omo-codex/plugin/components/codegraph/dist/cli.js +14 -1
- package/packages/omo-codex/plugin/components/codegraph/dist/serve.js +14 -1
- package/packages/omo-codex/plugin/components/codegraph/package.json +1 -1
- package/packages/omo-codex/plugin/components/comment-checker/hooks/hooks.json +1 -1
- package/packages/omo-codex/plugin/components/comment-checker/package.json +1 -1
- package/packages/omo-codex/plugin/components/git-bash/hooks/hooks.json +2 -2
- package/packages/omo-codex/plugin/components/git-bash/package.json +1 -1
- package/packages/omo-codex/plugin/components/lazycodex-executor-verify/hooks/hooks.json +1 -1
- package/packages/omo-codex/plugin/components/lazycodex-executor-verify/package.json +1 -1
- package/packages/omo-codex/plugin/components/lsp/dist/.omo-runtime-manifest.json +2 -2
- package/packages/omo-codex/plugin/components/lsp/hooks/hooks.json +2 -2
- package/packages/omo-codex/plugin/components/lsp/package.json +1 -1
- package/packages/omo-codex/plugin/components/rules/hooks/hooks.json +4 -4
- package/packages/omo-codex/plugin/components/rules/package.json +1 -1
- package/packages/omo-codex/plugin/components/start-work-continuation/hooks/hooks.json +2 -2
- package/packages/omo-codex/plugin/components/start-work-continuation/package.json +1 -1
- package/packages/omo-codex/plugin/components/teammode/hooks/hooks.json +1 -1
- package/packages/omo-codex/plugin/components/teammode/package.json +1 -1
- package/packages/omo-codex/plugin/components/telemetry/dist/cli.js +2242 -381
- package/packages/omo-codex/plugin/components/telemetry/dist/posthog.js +2247 -386
- package/packages/omo-codex/plugin/components/telemetry/hooks/hooks.json +1 -1
- package/packages/omo-codex/plugin/components/telemetry/package.json +1 -1
- package/packages/omo-codex/plugin/components/ultrawork/hooks/hooks.json +1 -1
- package/packages/omo-codex/plugin/components/ultrawork/package.json +1 -1
- package/packages/omo-codex/plugin/components/ulw-loop/hooks/hooks.json +4 -4
- package/packages/omo-codex/plugin/components/ulw-loop/package.json +1 -1
- package/packages/omo-codex/plugin/hooks/post-compact-resetting-git-bash-mcp-reminder.json +1 -1
- package/packages/omo-codex/plugin/hooks/post-compact-resetting-lsp-diagnostics-cache.json +1 -1
- package/packages/omo-codex/plugin/hooks/post-compact-resetting-project-rule-cache.json +1 -1
- package/packages/omo-codex/plugin/hooks/post-tool-use-checking-codegraph-init-guidance.json +1 -1
- package/packages/omo-codex/plugin/hooks/post-tool-use-checking-comments.json +1 -1
- package/packages/omo-codex/plugin/hooks/post-tool-use-checking-lsp-diagnostics.json +1 -1
- package/packages/omo-codex/plugin/hooks/post-tool-use-checking-thread-title-hygiene.json +1 -1
- package/packages/omo-codex/plugin/hooks/post-tool-use-matching-project-rules.json +1 -1
- package/packages/omo-codex/plugin/hooks/pre-tool-use-enforcing-unlimited-goal-budget.json +1 -1
- package/packages/omo-codex/plugin/hooks/pre-tool-use-guarding-ulw-loop-spawns.json +1 -1
- package/packages/omo-codex/plugin/hooks/pre-tool-use-recommending-git-bash-mcp.json +1 -1
- package/packages/omo-codex/plugin/hooks/session-start-checking-auto-update.json +1 -1
- package/packages/omo-codex/plugin/hooks/session-start-checking-bootstrap-provisioning.json +1 -1
- package/packages/omo-codex/plugin/hooks/session-start-checking-codegraph-bootstrap.json +1 -1
- package/packages/omo-codex/plugin/hooks/session-start-loading-project-rules.json +1 -1
- package/packages/omo-codex/plugin/hooks/session-start-recording-session-telemetry.json +1 -1
- package/packages/omo-codex/plugin/hooks/stop-checking-start-work-continuation.json +1 -1
- package/packages/omo-codex/plugin/hooks/stop-checking-ulw-loop-resume.json +1 -1
- package/packages/omo-codex/plugin/hooks/subagent-stop-checking-start-work-continuation.json +1 -1
- package/packages/omo-codex/plugin/hooks/subagent-stop-verifying-lazycodex-executor-evidence.json +1 -1
- package/packages/omo-codex/plugin/hooks/user-prompt-submit-checking-ultrawork-trigger.json +1 -1
- package/packages/omo-codex/plugin/hooks/user-prompt-submit-checking-ulw-loop-steering.json +1 -1
- package/packages/omo-codex/plugin/hooks/user-prompt-submit-loading-project-rules.json +1 -1
- package/packages/omo-codex/plugin/package-lock.json +13 -13
- package/packages/omo-codex/plugin/package.json +1 -1
- package/packages/omo-codex/scripts/install-dist/install-local.mjs +2307 -401
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
// omo-codex-install:1d8359e77ebe41655f091cd2e455f320cde2f9c681f0651797c47d8fdfa2dd76:
|
|
2
|
+
// omo-codex-install:1d8359e77ebe41655f091cd2e455f320cde2f9c681f0651797c47d8fdfa2dd76:e371cebae43ce34744106a00682784be6e1b1e8d819d26ccfadaa11eb3dc22b9
|
|
3
3
|
var __defProp = Object.defineProperty;
|
|
4
4
|
var __returnValue = (v) => v;
|
|
5
5
|
function __exportSetter(name, newValue) {
|
|
@@ -347,7 +347,7 @@ var init_env = __esm(() => {
|
|
|
347
347
|
SEND_OPT_OUT_VALUES = ["0", "false", "no", "yes"];
|
|
348
348
|
});
|
|
349
349
|
|
|
350
|
-
// node_modules/.bun/posthog-node@5.
|
|
350
|
+
// node_modules/.bun/posthog-node@5.49.2/node_modules/posthog-node/dist/extensions/error-tracking/modifiers/module.node.mjs
|
|
351
351
|
import { dirname as dirname10, posix as posix2, sep as sep7 } from "node:path";
|
|
352
352
|
function createModulerModifier() {
|
|
353
353
|
const getModuleFromFileName = createGetModuleFromFilename();
|
|
@@ -384,7 +384,7 @@ function normalizeWindowsPath(path2) {
|
|
|
384
384
|
}
|
|
385
385
|
var init_module_node = () => {};
|
|
386
386
|
|
|
387
|
-
// node_modules/.bun/@posthog+core@1.
|
|
387
|
+
// node_modules/.bun/@posthog+core@1.48.6/node_modules/@posthog/core/dist/featureFlagUtils.mjs
|
|
388
388
|
function getFlagDetailFromFlagAndPayload(key, value, payload) {
|
|
389
389
|
return {
|
|
390
390
|
key,
|
|
@@ -449,10 +449,71 @@ var normalizeFlagsResponse = (flagsResponse) => {
|
|
|
449
449
|
} catch {
|
|
450
450
|
return response;
|
|
451
451
|
}
|
|
452
|
+
}, MINIMAL_FLAG_CALLED_EVENT_CAMPAIGN_PROPERTIES, MINIMAL_FLAG_CALLED_EVENT_PROPERTIES, minimizeFlagCalledEventProperties = (properties, transportKeys = []) => {
|
|
453
|
+
const minimal = {};
|
|
454
|
+
const copyKey = (key) => {
|
|
455
|
+
if (properties[key] !== undefined)
|
|
456
|
+
minimal[key] = properties[key];
|
|
457
|
+
};
|
|
458
|
+
MINIMAL_FLAG_CALLED_EVENT_PROPERTIES.forEach(copyKey);
|
|
459
|
+
transportKeys.forEach(copyKey);
|
|
460
|
+
return minimal;
|
|
452
461
|
};
|
|
453
|
-
var init_featureFlagUtils = () => {
|
|
462
|
+
var init_featureFlagUtils = __esm(() => {
|
|
463
|
+
MINIMAL_FLAG_CALLED_EVENT_CAMPAIGN_PROPERTIES = [
|
|
464
|
+
"utm_source",
|
|
465
|
+
"utm_medium",
|
|
466
|
+
"utm_campaign",
|
|
467
|
+
"utm_content",
|
|
468
|
+
"utm_term",
|
|
469
|
+
"gad_source",
|
|
470
|
+
"mc_cid",
|
|
471
|
+
"gclid",
|
|
472
|
+
"gclsrc",
|
|
473
|
+
"dclid",
|
|
474
|
+
"gbraid",
|
|
475
|
+
"wbraid",
|
|
476
|
+
"fbclid",
|
|
477
|
+
"msclkid",
|
|
478
|
+
"twclid",
|
|
479
|
+
"li_fat_id",
|
|
480
|
+
"igshid",
|
|
481
|
+
"ttclid",
|
|
482
|
+
"rdt_cid",
|
|
483
|
+
"epik",
|
|
484
|
+
"qclid",
|
|
485
|
+
"sccid",
|
|
486
|
+
"irclid",
|
|
487
|
+
"_kx"
|
|
488
|
+
];
|
|
489
|
+
MINIMAL_FLAG_CALLED_EVENT_PROPERTIES = [
|
|
490
|
+
"$feature_flag",
|
|
491
|
+
"$feature_flag_response",
|
|
492
|
+
"$feature_flag_has_experiment",
|
|
493
|
+
"$feature_flag_id",
|
|
494
|
+
"$feature_flag_version",
|
|
495
|
+
"$feature_flag_reason",
|
|
496
|
+
"$feature_flag_request_id",
|
|
497
|
+
"$feature_flag_evaluated_at",
|
|
498
|
+
"$feature_flag_error",
|
|
499
|
+
"locally_evaluated",
|
|
500
|
+
"$groups",
|
|
501
|
+
"$process_person_profile",
|
|
502
|
+
"$geoip_disable",
|
|
503
|
+
"$current_url",
|
|
504
|
+
"$pathname",
|
|
505
|
+
"$referring_domain",
|
|
506
|
+
...MINIMAL_FLAG_CALLED_EVENT_CAMPAIGN_PROPERTIES,
|
|
507
|
+
"$session_id",
|
|
508
|
+
"$window_id",
|
|
509
|
+
"$lib",
|
|
510
|
+
"$lib_version",
|
|
511
|
+
"$device_id",
|
|
512
|
+
"$is_server"
|
|
513
|
+
];
|
|
514
|
+
});
|
|
454
515
|
|
|
455
|
-
// node_modules/.bun/@posthog+core@1.
|
|
516
|
+
// node_modules/.bun/@posthog+core@1.48.6/node_modules/@posthog/core/dist/types.mjs
|
|
456
517
|
var types_PostHogPersistedProperty;
|
|
457
518
|
var init_types = __esm(() => {
|
|
458
519
|
types_PostHogPersistedProperty = /* @__PURE__ */ function(PostHogPersistedProperty) {
|
|
@@ -469,6 +530,8 @@ var init_types = __esm(() => {
|
|
|
469
530
|
PostHogPersistedProperty["BootstrapFeatureFlagPayloads"] = "bootstrap_feature_flag_payloads";
|
|
470
531
|
PostHogPersistedProperty["OverrideFeatureFlags"] = "override_feature_flags";
|
|
471
532
|
PostHogPersistedProperty["Queue"] = "queue";
|
|
533
|
+
PostHogPersistedProperty["AiQueue"] = "ai_queue";
|
|
534
|
+
PostHogPersistedProperty["AiCaptureQueue"] = "ai_capture_queue";
|
|
472
535
|
PostHogPersistedProperty["LogsQueue"] = "logs_queue";
|
|
473
536
|
PostHogPersistedProperty["OptedOut"] = "opted_out";
|
|
474
537
|
PostHogPersistedProperty["SessionId"] = "session_id";
|
|
@@ -479,6 +542,8 @@ var init_types = __esm(() => {
|
|
|
479
542
|
PostHogPersistedProperty["InstalledAppBuild"] = "installed_app_build";
|
|
480
543
|
PostHogPersistedProperty["InstalledAppVersion"] = "installed_app_version";
|
|
481
544
|
PostHogPersistedProperty["SessionReplay"] = "session_replay";
|
|
545
|
+
PostHogPersistedProperty["PushRegistered"] = "push_registered";
|
|
546
|
+
PostHogPersistedProperty["SessionReplayEventTriggerActivatedSession"] = "session_replay_event_trigger_activated_session";
|
|
482
547
|
PostHogPersistedProperty["SurveyLastSeenDate"] = "survey_last_seen_date";
|
|
483
548
|
PostHogPersistedProperty["SurveysSeen"] = "surveys_seen";
|
|
484
549
|
PostHogPersistedProperty["Surveys"] = "surveys";
|
|
@@ -489,14 +554,14 @@ var init_types = __esm(() => {
|
|
|
489
554
|
}({});
|
|
490
555
|
});
|
|
491
556
|
|
|
492
|
-
// node_modules/.bun/@posthog+core@1.
|
|
557
|
+
// node_modules/.bun/@posthog+core@1.48.6/node_modules/@posthog/core/dist/gzip.mjs
|
|
493
558
|
function isGzipSupported() {
|
|
494
559
|
return "CompressionStream" in globalThis && "TextEncoder" in globalThis && "Response" in globalThis && typeof Response.prototype.blob == "function";
|
|
495
560
|
}
|
|
496
561
|
async function gzipCompress(input, isDebug = true, options) {
|
|
497
562
|
try {
|
|
498
563
|
const inputBytes = new TextEncoder().encode(input);
|
|
499
|
-
const compressedStream = new CompressionStream("gzip");
|
|
564
|
+
const compressedStream = new globalThis.CompressionStream("gzip");
|
|
500
565
|
const writer = compressedStream.writable.getWriter();
|
|
501
566
|
const writePromise = writer.write(inputBytes).then(() => writer.close()).catch(async (err) => {
|
|
502
567
|
try {
|
|
@@ -557,7 +622,7 @@ var init_gzip = __esm(() => {
|
|
|
557
622
|
init_types();
|
|
558
623
|
});
|
|
559
624
|
|
|
560
|
-
// node_modules/.bun/@posthog+core@1.
|
|
625
|
+
// node_modules/.bun/@posthog+core@1.48.6/node_modules/@posthog/core/dist/utils/bot-detection.mjs
|
|
561
626
|
var DEFAULT_BLOCKED_UA_STRS, isBlockedUA = function(ua, customBlockedUserAgents = []) {
|
|
562
627
|
if (!ua)
|
|
563
628
|
return false;
|
|
@@ -649,16 +714,56 @@ var init_bot_detection = __esm(() => {
|
|
|
649
714
|
];
|
|
650
715
|
});
|
|
651
716
|
|
|
652
|
-
// node_modules/.bun/@posthog+core@1.
|
|
717
|
+
// node_modules/.bun/@posthog+core@1.48.6/node_modules/@posthog/core/dist/utils/string-utils.mjs
|
|
718
|
+
function safeJsonStringify(value) {
|
|
719
|
+
const ancestors = [];
|
|
720
|
+
return JSON.stringify(value, function(_key, replacementValue) {
|
|
721
|
+
if (typeof replacementValue == "bigint")
|
|
722
|
+
return replacementValue.toString();
|
|
723
|
+
if (typeof replacementValue == "function" || typeof replacementValue == "symbol")
|
|
724
|
+
return;
|
|
725
|
+
if (replacementValue instanceof Error)
|
|
726
|
+
return {
|
|
727
|
+
name: replacementValue.name,
|
|
728
|
+
message: replacementValue.message,
|
|
729
|
+
stack: replacementValue.stack
|
|
730
|
+
};
|
|
731
|
+
if (replacementValue && typeof replacementValue == "object") {
|
|
732
|
+
while (ancestors.length > 0 && ancestors[ancestors.length - 1] !== this)
|
|
733
|
+
ancestors.pop();
|
|
734
|
+
if (ancestors.includes(replacementValue))
|
|
735
|
+
return "[Circular]";
|
|
736
|
+
ancestors.push(replacementValue);
|
|
737
|
+
}
|
|
738
|
+
return replacementValue;
|
|
739
|
+
}) ?? "null";
|
|
740
|
+
}
|
|
653
741
|
var init_string_utils = () => {};
|
|
654
742
|
|
|
655
|
-
// node_modules/.bun/@posthog+core@1.
|
|
743
|
+
// node_modules/.bun/@posthog+core@1.48.6/node_modules/@posthog/core/dist/utils/browser-utils.mjs
|
|
744
|
+
var init_browser_utils = __esm(() => {
|
|
745
|
+
init_string_utils();
|
|
746
|
+
});
|
|
747
|
+
|
|
748
|
+
// node_modules/.bun/@posthog+core@1.48.6/node_modules/@posthog/core/dist/utils/type-utils.mjs
|
|
656
749
|
function isPrimitive(value) {
|
|
657
750
|
return value === null || typeof value != "object";
|
|
658
751
|
}
|
|
659
752
|
function isBuiltin(candidate, className) {
|
|
660
753
|
return Object.prototype.toString.call(candidate) === `[object ${className}]`;
|
|
661
754
|
}
|
|
755
|
+
function isError(candidate) {
|
|
756
|
+
switch (Object.prototype.toString.call(candidate)) {
|
|
757
|
+
case "[object Error]":
|
|
758
|
+
case "[object Exception]":
|
|
759
|
+
case "[object DOMException]":
|
|
760
|
+
case "[object DOMError]":
|
|
761
|
+
case "[object WebAssembly.Exception]":
|
|
762
|
+
return true;
|
|
763
|
+
default:
|
|
764
|
+
return isInstanceOf(candidate, Error);
|
|
765
|
+
}
|
|
766
|
+
}
|
|
662
767
|
function isErrorEvent(event) {
|
|
663
768
|
return isBuiltin(event, "ErrorEvent");
|
|
664
769
|
}
|
|
@@ -675,7 +780,7 @@ function isInstanceOf(candidate, base) {
|
|
|
675
780
|
return false;
|
|
676
781
|
}
|
|
677
782
|
}
|
|
678
|
-
var nativeIsArray, ObjProto, type_utils_hasOwnProperty, type_utils_toString, isArray, isObject = (x) => x === Object(x) && !isArray(x), isUndefined = (x) => x === undefined, isString = (x) => type_utils_toString.call(x) == "[object String]", isEmptyString = (x) => isString(x) && x.trim().length === 0, isNumber = (x) => type_utils_toString.call(x) == "[object Number]" && x === x,
|
|
783
|
+
var nativeIsArray, ObjProto, type_utils_hasOwnProperty, type_utils_toString, isArray, isObject = (x) => x === Object(x) && !isArray(x), isUndefined = (x) => x === undefined, isString = (x) => type_utils_toString.call(x) == "[object String]", isEmptyString = (x) => isString(x) && x.trim().length === 0, isNull = (x) => x === null, isNumber = (x) => type_utils_toString.call(x) == "[object Number]" && x === x, isBoolean = (x) => type_utils_toString.call(x) === "[object Boolean]";
|
|
679
784
|
var init_type_utils = __esm(() => {
|
|
680
785
|
init_types();
|
|
681
786
|
init_string_utils();
|
|
@@ -688,7 +793,7 @@ var init_type_utils = __esm(() => {
|
|
|
688
793
|
};
|
|
689
794
|
});
|
|
690
795
|
|
|
691
|
-
// node_modules/.bun/@posthog+core@1.
|
|
796
|
+
// node_modules/.bun/@posthog+core@1.48.6/node_modules/@posthog/core/dist/utils/number-utils.mjs
|
|
692
797
|
function clampToRange(value, min, max, logger, fallbackValue) {
|
|
693
798
|
if (min > max) {
|
|
694
799
|
logger.warn("min cannot be greater than max.");
|
|
@@ -711,7 +816,14 @@ var init_number_utils = __esm(() => {
|
|
|
711
816
|
init_type_utils();
|
|
712
817
|
});
|
|
713
818
|
|
|
714
|
-
// node_modules/.bun/@posthog+core@1.
|
|
819
|
+
// node_modules/.bun/@posthog+core@1.48.6/node_modules/@posthog/core/dist/utils/bucketed-rate-limiter.mjs
|
|
820
|
+
function resolveExceptionRateLimiterConfig(config = {}) {
|
|
821
|
+
return {
|
|
822
|
+
refillRate: config.exceptionRateLimiterRefillRate ?? config.__exceptionRateLimiterRefillRate ?? DEFAULT_EXCEPTION_RATE_LIMITER_REFILL_RATE,
|
|
823
|
+
bucketSize: config.exceptionRateLimiterBucketSize ?? config.__exceptionRateLimiterBucketSize ?? DEFAULT_EXCEPTION_RATE_LIMITER_BUCKET_SIZE
|
|
824
|
+
};
|
|
825
|
+
}
|
|
826
|
+
|
|
715
827
|
class BucketedRateLimiter {
|
|
716
828
|
constructor(options) {
|
|
717
829
|
this._buckets = {};
|
|
@@ -753,12 +865,19 @@ class BucketedRateLimiter {
|
|
|
753
865
|
this._buckets = {};
|
|
754
866
|
}
|
|
755
867
|
}
|
|
756
|
-
var ONE_DAY_IN_MS = 86400000;
|
|
868
|
+
var ONE_DAY_IN_MS = 86400000, DEFAULT_EXCEPTION_RATE_LIMITER_REFILL_RATE = 1, DEFAULT_EXCEPTION_RATE_LIMITER_BUCKET_SIZE = 10;
|
|
757
869
|
var init_bucketed_rate_limiter = __esm(() => {
|
|
758
870
|
init_number_utils();
|
|
759
871
|
});
|
|
760
872
|
|
|
761
|
-
// node_modules/.bun/@posthog+core@1.
|
|
873
|
+
// node_modules/.bun/@posthog+core@1.48.6/node_modules/@posthog/core/dist/utils/json-utils.mjs
|
|
874
|
+
var dateGetTime, dateToISOString;
|
|
875
|
+
var init_json_utils = __esm(() => {
|
|
876
|
+
dateGetTime = Date.prototype.getTime;
|
|
877
|
+
dateToISOString = Date.prototype.toISOString;
|
|
878
|
+
});
|
|
879
|
+
|
|
880
|
+
// node_modules/.bun/@posthog+core@1.48.6/node_modules/@posthog/core/dist/vendor/uuidv7.mjs
|
|
762
881
|
class UUID {
|
|
763
882
|
constructor(bytes) {
|
|
764
883
|
this.bytes = bytes;
|
|
@@ -933,37 +1052,49 @@ var init_uuidv7 = __esm(() => {
|
|
|
933
1052
|
/*! For license information please see uuidv7.mjs.LICENSE.txt */
|
|
934
1053
|
});
|
|
935
1054
|
|
|
936
|
-
// node_modules/.bun/@posthog+core@1.
|
|
1055
|
+
// node_modules/.bun/@posthog+core@1.48.6/node_modules/@posthog/core/dist/utils/promise-queue.mjs
|
|
937
1056
|
class PromiseQueue {
|
|
938
1057
|
add(promise) {
|
|
939
1058
|
const promiseUUID = uuidv7();
|
|
940
|
-
|
|
1059
|
+
const id = ++this.nextId;
|
|
1060
|
+
this.promiseByIds[promiseUUID] = {
|
|
1061
|
+
id,
|
|
1062
|
+
promise
|
|
1063
|
+
};
|
|
941
1064
|
promise.catch(() => {}).finally(() => {
|
|
942
1065
|
delete this.promiseByIds[promiseUUID];
|
|
943
1066
|
});
|
|
944
1067
|
return promise;
|
|
945
1068
|
}
|
|
946
1069
|
async join() {
|
|
947
|
-
let promises = Object.values(this.promiseByIds);
|
|
1070
|
+
let promises = Object.values(this.promiseByIds).map((item) => item.promise);
|
|
948
1071
|
let length = promises.length;
|
|
949
1072
|
while (length > 0) {
|
|
950
1073
|
await Promise.all(promises);
|
|
951
|
-
promises = Object.values(this.promiseByIds);
|
|
1074
|
+
promises = Object.values(this.promiseByIds).map((item) => item.promise);
|
|
952
1075
|
length = promises.length;
|
|
953
1076
|
}
|
|
954
1077
|
}
|
|
1078
|
+
getPromises(ignoredPromises = [], maxId = this.nextId) {
|
|
1079
|
+
const ignoredPromiseSet = new Set(ignoredPromises);
|
|
1080
|
+
return Object.values(this.promiseByIds).filter((item) => item.id <= maxId && !ignoredPromiseSet.has(item.promise)).map((item) => item.promise);
|
|
1081
|
+
}
|
|
1082
|
+
get maxId() {
|
|
1083
|
+
return this.nextId;
|
|
1084
|
+
}
|
|
955
1085
|
get length() {
|
|
956
1086
|
return Object.keys(this.promiseByIds).length;
|
|
957
1087
|
}
|
|
958
1088
|
constructor() {
|
|
959
1089
|
this.promiseByIds = {};
|
|
1090
|
+
this.nextId = 0;
|
|
960
1091
|
}
|
|
961
1092
|
}
|
|
962
1093
|
var init_promise_queue = __esm(() => {
|
|
963
1094
|
init_uuidv7();
|
|
964
1095
|
});
|
|
965
1096
|
|
|
966
|
-
// node_modules/.bun/@posthog+core@1.
|
|
1097
|
+
// node_modules/.bun/@posthog+core@1.48.6/node_modules/@posthog/core/dist/utils/logger.mjs
|
|
967
1098
|
function createConsole(consoleLike = console) {
|
|
968
1099
|
const lockedMethods = {
|
|
969
1100
|
log: consoleLike.log.bind(consoleLike),
|
|
@@ -1005,8 +1136,8 @@ var _createLogger = (prefix, maybeCall, consoleLike) => {
|
|
|
1005
1136
|
}, passThrough = (fn) => fn();
|
|
1006
1137
|
var init_logger = () => {};
|
|
1007
1138
|
|
|
1008
|
-
// node_modules/.bun/@posthog+core@1.
|
|
1009
|
-
var MOBILE = "Mobile", IOS = "iOS", ANDROID = "Android", TABLET = "Tablet", ANDROID_TABLET, APPLE = "Apple", APPLE_WATCH, SAFARI = "Safari", BLACKBERRY = "BlackBerry", SAMSUNG = "Samsung", SAMSUNG_BROWSER, SAMSUNG_INTERNET, CHROME = "Chrome", CHROME_OS, CHROME_IOS, INTERNET_EXPLORER = "Internet Explorer", INTERNET_EXPLORER_MOBILE, OPERA = "Opera", OPERA_MINI, EDGE = "Edge", MICROSOFT_EDGE, FIREFOX = "Firefox", FIREFOX_IOS, NINTENDO = "Nintendo", PLAYSTATION = "PlayStation", XBOX = "Xbox", ANDROID_MOBILE, MOBILE_SAFARI, WINDOWS = "Windows", WINDOWS_PHONE, GENERIC = "Generic", GENERIC_MOBILE, GENERIC_TABLET, KONQUEROR = "Konqueror", OCULUS_BROWSER = "Oculus Browser", VIVALDI = "Vivaldi", YANDEX = "Yandex", WHALE = "Whale", DUCKDUCKGO = "DuckDuckGo", PALE_MOON = "Pale Moon", WATERFOX = "Waterfox", BRAVE = "Brave", BROWSER_VERSION_REGEX_SUFFIX = "(\\d+(\\.\\d+)?)", DEFAULT_BROWSER_VERSION_REGEX, XBOX_REGEX, PLAYSTATION_REGEX, NINTENDO_REGEX, BLACKBERRY_REGEX, windowsVersionMap, versionRegexes, osMatchers;
|
|
1139
|
+
// node_modules/.bun/@posthog+core@1.48.6/node_modules/@posthog/core/dist/utils/user-agent-utils.mjs
|
|
1140
|
+
var MOBILE = "Mobile", IOS = "iOS", ANDROID = "Android", TABLET = "Tablet", ANDROID_TABLET, APPLE = "Apple", APPLE_WATCH, SAFARI = "Safari", BLACKBERRY = "BlackBerry", SAMSUNG = "Samsung", SAMSUNG_BROWSER, SAMSUNG_INTERNET, CHROME = "Chrome", CHROME_OS, CHROME_IOS, INTERNET_EXPLORER = "Internet Explorer", INTERNET_EXPLORER_MOBILE, OPERA = "Opera", OPERA_MINI, EDGE = "Edge", MICROSOFT_EDGE, FIREFOX = "Firefox", FIREFOX_IOS, NINTENDO = "Nintendo", PLAYSTATION = "PlayStation", XBOX = "Xbox", ANDROID_MOBILE, MOBILE_SAFARI, WINDOWS = "Windows", WINDOWS_PHONE, GENERIC = "Generic", GENERIC_MOBILE, GENERIC_TABLET, KONQUEROR = "Konqueror", OCULUS_BROWSER = "Oculus Browser", VIVALDI = "Vivaldi", YANDEX = "Yandex", WHALE = "Whale", DUCKDUCKGO = "DuckDuckGo", PALE_MOON = "Pale Moon", WATERFOX = "Waterfox", BRAVE = "Brave", GOOGLE_SEARCH_APP = "Google Search App", BROWSER_VERSION_REGEX_SUFFIX = "(\\d+(\\.\\d+)?)", DEFAULT_BROWSER_VERSION_REGEX, XBOX_REGEX, PLAYSTATION_REGEX, NINTENDO_REGEX, BLACKBERRY_REGEX, windowsVersionMap, versionRegexes, osMatchers;
|
|
1010
1141
|
var init_user_agent_utils = __esm(() => {
|
|
1011
1142
|
init_string_utils();
|
|
1012
1143
|
init_type_utils();
|
|
@@ -1111,6 +1242,9 @@ var init_user_agent_utils = __esm(() => {
|
|
|
1111
1242
|
[WATERFOX]: [
|
|
1112
1243
|
new RegExp(WATERFOX + "\\/" + BROWSER_VERSION_REGEX_SUFFIX)
|
|
1113
1244
|
],
|
|
1245
|
+
[GOOGLE_SEARCH_APP]: [
|
|
1246
|
+
new RegExp("GSA\\/" + BROWSER_VERSION_REGEX_SUFFIX)
|
|
1247
|
+
],
|
|
1114
1248
|
[INTERNET_EXPLORER]: [
|
|
1115
1249
|
new RegExp("(rv:|MSIE )" + BROWSER_VERSION_REGEX_SUFFIX)
|
|
1116
1250
|
],
|
|
@@ -1271,7 +1405,13 @@ var init_user_agent_utils = __esm(() => {
|
|
|
1271
1405
|
];
|
|
1272
1406
|
});
|
|
1273
1407
|
|
|
1274
|
-
// node_modules/.bun/@posthog+core@1.
|
|
1408
|
+
// node_modules/.bun/@posthog+core@1.48.6/node_modules/@posthog/core/dist/utils/index.mjs
|
|
1409
|
+
function isValidUUID(value) {
|
|
1410
|
+
return typeof value == "string" && UUID_REGEX.test(value);
|
|
1411
|
+
}
|
|
1412
|
+
function getEventUuid(uuid, generateUuid) {
|
|
1413
|
+
return isValidUUID(uuid) ? uuid : generateUuid();
|
|
1414
|
+
}
|
|
1275
1415
|
function removeTrailingSlash(url) {
|
|
1276
1416
|
return url?.replace(/\/+$/, "");
|
|
1277
1417
|
}
|
|
@@ -1299,6 +1439,26 @@ function safeSetTimeout(fn, timeout) {
|
|
|
1299
1439
|
t?.unref && t?.unref();
|
|
1300
1440
|
return t;
|
|
1301
1441
|
}
|
|
1442
|
+
async function raceWithTimeout(promise, timeoutMs, onTimeout) {
|
|
1443
|
+
let timeoutHandle;
|
|
1444
|
+
try {
|
|
1445
|
+
return await Promise.race([
|
|
1446
|
+
promise,
|
|
1447
|
+
new Promise((resolve9, reject) => {
|
|
1448
|
+
timeoutHandle = safeSetTimeout(() => {
|
|
1449
|
+
try {
|
|
1450
|
+
onTimeout?.();
|
|
1451
|
+
resolve9();
|
|
1452
|
+
} catch (error) {
|
|
1453
|
+
reject(error);
|
|
1454
|
+
}
|
|
1455
|
+
}, timeoutMs);
|
|
1456
|
+
})
|
|
1457
|
+
]);
|
|
1458
|
+
} finally {
|
|
1459
|
+
clearTimeout(timeoutHandle);
|
|
1460
|
+
}
|
|
1461
|
+
}
|
|
1302
1462
|
function allSettled(promises) {
|
|
1303
1463
|
return Promise.all(promises.map((p) => (p ?? Promise.resolve()).then((value) => ({
|
|
1304
1464
|
status: "fulfilled",
|
|
@@ -1308,19 +1468,72 @@ function allSettled(promises) {
|
|
|
1308
1468
|
reason
|
|
1309
1469
|
}))));
|
|
1310
1470
|
}
|
|
1311
|
-
var STRING_FORMAT = "utf8",
|
|
1471
|
+
var STRING_FORMAT = "utf8", UUID_REGEX;
|
|
1312
1472
|
var init_utils = __esm(() => {
|
|
1313
1473
|
init_bot_detection();
|
|
1474
|
+
init_browser_utils();
|
|
1314
1475
|
init_bucketed_rate_limiter();
|
|
1476
|
+
init_json_utils();
|
|
1315
1477
|
init_number_utils();
|
|
1316
1478
|
init_string_utils();
|
|
1317
1479
|
init_type_utils();
|
|
1318
1480
|
init_promise_queue();
|
|
1319
1481
|
init_logger();
|
|
1320
1482
|
init_user_agent_utils();
|
|
1483
|
+
UUID_REGEX = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
1321
1484
|
});
|
|
1322
1485
|
|
|
1323
|
-
// node_modules/.bun/@posthog+core@1.
|
|
1486
|
+
// node_modules/.bun/@posthog+core@1.48.6/node_modules/@posthog/core/dist/logs/logs-utils.mjs
|
|
1487
|
+
function toOtlpAnyValue(value) {
|
|
1488
|
+
if (isBoolean(value))
|
|
1489
|
+
return {
|
|
1490
|
+
boolValue: value
|
|
1491
|
+
};
|
|
1492
|
+
if (typeof value == "number") {
|
|
1493
|
+
if (!Number.isFinite(value))
|
|
1494
|
+
return {
|
|
1495
|
+
stringValue: String(value)
|
|
1496
|
+
};
|
|
1497
|
+
if (Number.isInteger(value))
|
|
1498
|
+
return {
|
|
1499
|
+
intValue: value
|
|
1500
|
+
};
|
|
1501
|
+
return {
|
|
1502
|
+
doubleValue: value
|
|
1503
|
+
};
|
|
1504
|
+
}
|
|
1505
|
+
if (typeof value == "string")
|
|
1506
|
+
return {
|
|
1507
|
+
stringValue: value
|
|
1508
|
+
};
|
|
1509
|
+
if (isArray(value))
|
|
1510
|
+
return {
|
|
1511
|
+
arrayValue: {
|
|
1512
|
+
values: value.map((v) => toOtlpAnyValue(v))
|
|
1513
|
+
}
|
|
1514
|
+
};
|
|
1515
|
+
try {
|
|
1516
|
+
return {
|
|
1517
|
+
stringValue: JSON.stringify(value)
|
|
1518
|
+
};
|
|
1519
|
+
} catch {
|
|
1520
|
+
return {
|
|
1521
|
+
stringValue: String(value)
|
|
1522
|
+
};
|
|
1523
|
+
}
|
|
1524
|
+
}
|
|
1525
|
+
function toOtlpKeyValueList(attrs) {
|
|
1526
|
+
const result = [];
|
|
1527
|
+
for (const key in attrs) {
|
|
1528
|
+
const value = attrs[key];
|
|
1529
|
+
if (!(isNull(value) || isUndefined(value)))
|
|
1530
|
+
result.push({
|
|
1531
|
+
key,
|
|
1532
|
+
value: toOtlpAnyValue(value)
|
|
1533
|
+
});
|
|
1534
|
+
}
|
|
1535
|
+
return result;
|
|
1536
|
+
}
|
|
1324
1537
|
var OTLP_SEVERITY_MAP, DEFAULT_OTLP_SEVERITY;
|
|
1325
1538
|
var init_logs_utils = __esm(() => {
|
|
1326
1539
|
init_utils();
|
|
@@ -1353,25 +1566,441 @@ var init_logs_utils = __esm(() => {
|
|
|
1353
1566
|
DEFAULT_OTLP_SEVERITY = OTLP_SEVERITY_MAP.info;
|
|
1354
1567
|
});
|
|
1355
1568
|
|
|
1356
|
-
// node_modules/.bun/@posthog+core@1.
|
|
1569
|
+
// node_modules/.bun/@posthog+core@1.48.6/node_modules/@posthog/core/dist/logs/index.mjs
|
|
1357
1570
|
var init_logs = __esm(() => {
|
|
1358
1571
|
init_logs_utils();
|
|
1359
1572
|
init_types();
|
|
1360
1573
|
init_utils();
|
|
1361
1574
|
});
|
|
1362
1575
|
|
|
1363
|
-
// node_modules/.bun/@posthog+core@1.
|
|
1576
|
+
// node_modules/.bun/@posthog+core@1.48.6/node_modules/@posthog/core/dist/metrics/metrics-utils.mjs
|
|
1577
|
+
function msToUnixNano(ms) {
|
|
1578
|
+
return String(ms) + "000000";
|
|
1579
|
+
}
|
|
1580
|
+
function seriesKey(type, name, unit, attributes) {
|
|
1581
|
+
let attrsKey = "";
|
|
1582
|
+
if (attributes) {
|
|
1583
|
+
const keys = Object.keys(attributes).sort();
|
|
1584
|
+
attrsKey = keys.map((k) => `${JSON.stringify(k)}:${JSON.stringify(attributes[k])}`).join(",");
|
|
1585
|
+
}
|
|
1586
|
+
return `${type}\x00${name}\x00${unit ?? ""}\x00${attrsKey}`;
|
|
1587
|
+
}
|
|
1588
|
+
function bucketIndexFor(value, bounds) {
|
|
1589
|
+
for (let i = 0;i < bounds.length; i++)
|
|
1590
|
+
if (value <= bounds[i])
|
|
1591
|
+
return i;
|
|
1592
|
+
return bounds.length;
|
|
1593
|
+
}
|
|
1594
|
+
function buildMetricsResourceAttributes(config, scopeName, scopeVersion) {
|
|
1595
|
+
return {
|
|
1596
|
+
...config.resourceAttributes,
|
|
1597
|
+
"service.name": config.serviceName || "unknown_service",
|
|
1598
|
+
...config.environment && {
|
|
1599
|
+
"deployment.environment": config.environment
|
|
1600
|
+
},
|
|
1601
|
+
...config.serviceVersion && {
|
|
1602
|
+
"service.version": config.serviceVersion
|
|
1603
|
+
},
|
|
1604
|
+
"telemetry.sdk.name": scopeName,
|
|
1605
|
+
"telemetry.sdk.version": scopeVersion
|
|
1606
|
+
};
|
|
1607
|
+
}
|
|
1608
|
+
function buildOtlpMetricsPayload(metrics, resourceAttributes, scopeName, scopeVersion) {
|
|
1609
|
+
return {
|
|
1610
|
+
resourceMetrics: [
|
|
1611
|
+
{
|
|
1612
|
+
resource: {
|
|
1613
|
+
attributes: toOtlpKeyValueList(resourceAttributes)
|
|
1614
|
+
},
|
|
1615
|
+
scopeMetrics: [
|
|
1616
|
+
{
|
|
1617
|
+
scope: {
|
|
1618
|
+
name: scopeName,
|
|
1619
|
+
version: scopeVersion
|
|
1620
|
+
},
|
|
1621
|
+
metrics
|
|
1622
|
+
}
|
|
1623
|
+
]
|
|
1624
|
+
}
|
|
1625
|
+
]
|
|
1626
|
+
};
|
|
1627
|
+
}
|
|
1628
|
+
var DEFAULT_HISTOGRAM_BOUNDS;
|
|
1629
|
+
var init_metrics_utils = __esm(() => {
|
|
1630
|
+
init_logs_utils();
|
|
1631
|
+
DEFAULT_HISTOGRAM_BOUNDS = [
|
|
1632
|
+
0,
|
|
1633
|
+
5,
|
|
1634
|
+
10,
|
|
1635
|
+
25,
|
|
1636
|
+
50,
|
|
1637
|
+
75,
|
|
1638
|
+
100,
|
|
1639
|
+
250,
|
|
1640
|
+
500,
|
|
1641
|
+
750,
|
|
1642
|
+
1000,
|
|
1643
|
+
2500,
|
|
1644
|
+
5000,
|
|
1645
|
+
7500,
|
|
1646
|
+
1e4
|
|
1647
|
+
];
|
|
1648
|
+
});
|
|
1649
|
+
|
|
1650
|
+
// node_modules/.bun/@posthog+core@1.48.6/node_modules/@posthog/core/dist/metrics/config.mjs
|
|
1651
|
+
function resolveMetricsConfig(config) {
|
|
1652
|
+
const resourceAttributes = config?.resourceAttributes;
|
|
1653
|
+
return {
|
|
1654
|
+
serviceName: resourceAttributes?.["service.name"] ?? config?.serviceName,
|
|
1655
|
+
serviceVersion: resourceAttributes?.["service.version"] ?? config?.serviceVersion,
|
|
1656
|
+
environment: resourceAttributes?.["deployment.environment"] ?? config?.environment,
|
|
1657
|
+
resourceAttributes,
|
|
1658
|
+
beforeSend: config?.beforeSend,
|
|
1659
|
+
flushIntervalMs: config?.flushIntervalMs ?? DEFAULT_FLUSH_INTERVAL_MS,
|
|
1660
|
+
maxSeriesPerFlush: config?.maxSeriesPerFlush ?? DEFAULT_MAX_SERIES_PER_FLUSH
|
|
1661
|
+
};
|
|
1662
|
+
}
|
|
1663
|
+
var DEFAULT_FLUSH_INTERVAL_MS = 1e4, DEFAULT_MAX_SERIES_PER_FLUSH = 1000;
|
|
1664
|
+
var init_config = () => {};
|
|
1665
|
+
|
|
1666
|
+
// node_modules/.bun/@posthog+core@1.48.6/node_modules/@posthog/core/dist/metrics/index.mjs
|
|
1667
|
+
class PostHogMetrics {
|
|
1668
|
+
constructor(_instance, _config, _logger) {
|
|
1669
|
+
this._instance = _instance;
|
|
1670
|
+
this._config = _config;
|
|
1671
|
+
this._logger = _logger;
|
|
1672
|
+
this._series = new Map;
|
|
1673
|
+
this._flushPromise = null;
|
|
1674
|
+
this._seriesCapWarned = false;
|
|
1675
|
+
this._typeByName = new Map;
|
|
1676
|
+
this._typeCollisionWarned = new Set;
|
|
1677
|
+
this._generation = 0;
|
|
1678
|
+
}
|
|
1679
|
+
count(name, value = 1, options) {
|
|
1680
|
+
this._capture({
|
|
1681
|
+
name,
|
|
1682
|
+
type: "count",
|
|
1683
|
+
value,
|
|
1684
|
+
unit: options?.unit,
|
|
1685
|
+
attributes: options?.attributes
|
|
1686
|
+
});
|
|
1687
|
+
}
|
|
1688
|
+
gauge(name, value, options) {
|
|
1689
|
+
this._capture({
|
|
1690
|
+
name,
|
|
1691
|
+
type: "gauge",
|
|
1692
|
+
value,
|
|
1693
|
+
unit: options?.unit,
|
|
1694
|
+
attributes: options?.attributes
|
|
1695
|
+
});
|
|
1696
|
+
}
|
|
1697
|
+
histogram(name, value, options) {
|
|
1698
|
+
this._capture({
|
|
1699
|
+
name,
|
|
1700
|
+
type: "histogram",
|
|
1701
|
+
value,
|
|
1702
|
+
unit: options?.unit,
|
|
1703
|
+
attributes: options?.attributes
|
|
1704
|
+
});
|
|
1705
|
+
}
|
|
1706
|
+
flush() {
|
|
1707
|
+
const prev = this._flushPromise;
|
|
1708
|
+
const run = async () => {
|
|
1709
|
+
if (prev)
|
|
1710
|
+
await prev.catch(() => {});
|
|
1711
|
+
await this._doFlush();
|
|
1712
|
+
};
|
|
1713
|
+
const p = run().finally(() => {
|
|
1714
|
+
if (this._flushPromise === p)
|
|
1715
|
+
this._flushPromise = null;
|
|
1716
|
+
});
|
|
1717
|
+
this._flushPromise = p;
|
|
1718
|
+
return p;
|
|
1719
|
+
}
|
|
1720
|
+
drainWindow() {
|
|
1721
|
+
if (this._series.size === 0)
|
|
1722
|
+
return null;
|
|
1723
|
+
const window = this._series;
|
|
1724
|
+
this._series = new Map;
|
|
1725
|
+
this._seriesCapWarned = false;
|
|
1726
|
+
this._typeByName = new Map;
|
|
1727
|
+
this._typeCollisionWarned = new Set;
|
|
1728
|
+
return this._buildPayload(window);
|
|
1729
|
+
}
|
|
1730
|
+
reset() {
|
|
1731
|
+
this._generation++;
|
|
1732
|
+
this._clearFlushTimer();
|
|
1733
|
+
this._series = new Map;
|
|
1734
|
+
this._flushPromise = null;
|
|
1735
|
+
this._seriesCapWarned = false;
|
|
1736
|
+
this._typeByName = new Map;
|
|
1737
|
+
this._typeCollisionWarned = new Set;
|
|
1738
|
+
}
|
|
1739
|
+
_capture(sample) {
|
|
1740
|
+
if (this._instance.isDisabled || this._instance.optedOut)
|
|
1741
|
+
return;
|
|
1742
|
+
const filtered = this._runBeforeSend(sample);
|
|
1743
|
+
if (filtered === null)
|
|
1744
|
+
return;
|
|
1745
|
+
if (!filtered.name || typeof filtered.name != "string")
|
|
1746
|
+
return void this._logger.warn("Dropping metric with empty name");
|
|
1747
|
+
if (typeof filtered.value != "number" || !Number.isFinite(filtered.value))
|
|
1748
|
+
return void this._logger.warn(`Dropping metric '${filtered.name}': value must be a finite number`);
|
|
1749
|
+
if (filtered.type === "count" && filtered.value < 0)
|
|
1750
|
+
return void this._logger.warn(`Dropping count '${filtered.name}': counters are monotonic, value must be >= 0`);
|
|
1751
|
+
let attributes;
|
|
1752
|
+
let key;
|
|
1753
|
+
try {
|
|
1754
|
+
attributes = filtered.attributes ? {
|
|
1755
|
+
...filtered.attributes
|
|
1756
|
+
} : undefined;
|
|
1757
|
+
key = seriesKey(filtered.type, filtered.name, filtered.unit, attributes);
|
|
1758
|
+
} catch (e) {
|
|
1759
|
+
this._logger.warn(`Dropping metric '${filtered.name}': attributes could not be serialized`, e);
|
|
1760
|
+
return;
|
|
1761
|
+
}
|
|
1762
|
+
let state = this._series.get(key);
|
|
1763
|
+
if (!state) {
|
|
1764
|
+
if (!this._admitNewSeries())
|
|
1765
|
+
return;
|
|
1766
|
+
state = {
|
|
1767
|
+
name: filtered.name,
|
|
1768
|
+
type: filtered.type,
|
|
1769
|
+
unit: filtered.unit,
|
|
1770
|
+
attributes,
|
|
1771
|
+
windowStartMs: Date.now()
|
|
1772
|
+
};
|
|
1773
|
+
this._series.set(key, state);
|
|
1774
|
+
}
|
|
1775
|
+
const seenType = this._typeByName.get(filtered.name);
|
|
1776
|
+
if (seenType === undefined)
|
|
1777
|
+
this._typeByName.set(filtered.name, filtered.type);
|
|
1778
|
+
else if (seenType !== filtered.type && !this._typeCollisionWarned.has(filtered.name)) {
|
|
1779
|
+
this._typeCollisionWarned.add(filtered.name);
|
|
1780
|
+
this._logger.warn(`Metric name '${filtered.name}' is already used as a ${seenType}; recording it as a ${filtered.type} too will blend both series in charts. Use a distinct name.`);
|
|
1781
|
+
}
|
|
1782
|
+
this._fold(state, filtered.value);
|
|
1783
|
+
this._armFlushTimer();
|
|
1784
|
+
}
|
|
1785
|
+
_admitNewSeries() {
|
|
1786
|
+
if (this._series.size < this._config.maxSeriesPerFlush)
|
|
1787
|
+
return true;
|
|
1788
|
+
if (!this._seriesCapWarned) {
|
|
1789
|
+
this._seriesCapWarned = true;
|
|
1790
|
+
this._logger.warn(`Metric series cap reached (${this._config.maxSeriesPerFlush} per flush window); dropping new series until the next flush. Reduce attribute cardinality.`);
|
|
1791
|
+
}
|
|
1792
|
+
return false;
|
|
1793
|
+
}
|
|
1794
|
+
_fold(state, value) {
|
|
1795
|
+
switch (state.type) {
|
|
1796
|
+
case "count":
|
|
1797
|
+
state.total = (state.total ?? 0) + value;
|
|
1798
|
+
break;
|
|
1799
|
+
case "gauge":
|
|
1800
|
+
state.last = value;
|
|
1801
|
+
break;
|
|
1802
|
+
case "histogram": {
|
|
1803
|
+
if (!state.hist)
|
|
1804
|
+
state.hist = {
|
|
1805
|
+
count: 0,
|
|
1806
|
+
sum: 0,
|
|
1807
|
+
min: value,
|
|
1808
|
+
max: value,
|
|
1809
|
+
bucketCounts: new Array(DEFAULT_HISTOGRAM_BOUNDS.length + 1).fill(0)
|
|
1810
|
+
};
|
|
1811
|
+
const hist = state.hist;
|
|
1812
|
+
hist.count += 1;
|
|
1813
|
+
hist.sum += value;
|
|
1814
|
+
hist.min = Math.min(hist.min, value);
|
|
1815
|
+
hist.max = Math.max(hist.max, value);
|
|
1816
|
+
hist.bucketCounts[bucketIndexFor(value, DEFAULT_HISTOGRAM_BOUNDS)] += 1;
|
|
1817
|
+
break;
|
|
1818
|
+
}
|
|
1819
|
+
}
|
|
1820
|
+
}
|
|
1821
|
+
_runBeforeSend(sample) {
|
|
1822
|
+
const beforeSend = this._config.beforeSend;
|
|
1823
|
+
if (!beforeSend)
|
|
1824
|
+
return sample;
|
|
1825
|
+
const fns = isArray(beforeSend) ? beforeSend : [
|
|
1826
|
+
beforeSend
|
|
1827
|
+
];
|
|
1828
|
+
let result = sample;
|
|
1829
|
+
for (const fn of fns)
|
|
1830
|
+
try {
|
|
1831
|
+
const next = fn(result);
|
|
1832
|
+
if (!next) {
|
|
1833
|
+
this._logger.info("Metric was rejected in beforeSend function");
|
|
1834
|
+
return null;
|
|
1835
|
+
}
|
|
1836
|
+
result = next;
|
|
1837
|
+
} catch (e) {
|
|
1838
|
+
this._logger.error("Error in beforeSend function for metric:", e);
|
|
1839
|
+
return null;
|
|
1840
|
+
}
|
|
1841
|
+
return result;
|
|
1842
|
+
}
|
|
1843
|
+
_armFlushTimer() {
|
|
1844
|
+
if (this._flushTimer)
|
|
1845
|
+
return;
|
|
1846
|
+
this._flushTimer = safeSetTimeout(() => {
|
|
1847
|
+
this._flushTimer = undefined;
|
|
1848
|
+
this.flush().catch((e) => {
|
|
1849
|
+
this._logger.error("Metrics flush failed:", e);
|
|
1850
|
+
});
|
|
1851
|
+
}, this._config.flushIntervalMs);
|
|
1852
|
+
}
|
|
1853
|
+
_clearFlushTimer() {
|
|
1854
|
+
if (this._flushTimer) {
|
|
1855
|
+
clearTimeout(this._flushTimer);
|
|
1856
|
+
this._flushTimer = undefined;
|
|
1857
|
+
}
|
|
1858
|
+
}
|
|
1859
|
+
async _doFlush() {
|
|
1860
|
+
if (this._series.size === 0)
|
|
1861
|
+
return;
|
|
1862
|
+
const window = this._series;
|
|
1863
|
+
this._series = new Map;
|
|
1864
|
+
this._seriesCapWarned = false;
|
|
1865
|
+
this._typeByName = new Map;
|
|
1866
|
+
this._typeCollisionWarned = new Set;
|
|
1867
|
+
const generation = this._generation;
|
|
1868
|
+
const outcome = await this._instance._sendMetricsBatch(this._buildPayload(window));
|
|
1869
|
+
if (generation !== this._generation)
|
|
1870
|
+
return;
|
|
1871
|
+
switch (outcome.kind) {
|
|
1872
|
+
case "ok":
|
|
1873
|
+
return;
|
|
1874
|
+
case "retry-later":
|
|
1875
|
+
this._mergeWindowBack(window);
|
|
1876
|
+
this._armFlushTimer();
|
|
1877
|
+
return;
|
|
1878
|
+
case "too-large":
|
|
1879
|
+
this._logger.warn("Metrics batch exceeded the server size limit and was dropped");
|
|
1880
|
+
return;
|
|
1881
|
+
case "fatal":
|
|
1882
|
+
this._logger.error("Failed to send metrics batch:", outcome.error);
|
|
1883
|
+
return;
|
|
1884
|
+
}
|
|
1885
|
+
}
|
|
1886
|
+
_buildPayload(window) {
|
|
1887
|
+
return buildOtlpMetricsPayload(this._buildMetrics(window), buildMetricsResourceAttributes(this._config, this._instance.getLibraryId(), this._instance.getLibraryVersion()), this._instance.getLibraryId(), this._instance.getLibraryVersion());
|
|
1888
|
+
}
|
|
1889
|
+
_buildMetrics(window) {
|
|
1890
|
+
const nowNano = msToUnixNano(Date.now());
|
|
1891
|
+
const byMetric = new Map;
|
|
1892
|
+
for (const state of window.values()) {
|
|
1893
|
+
const metricKey = seriesKey(state.type, state.name, state.unit, undefined);
|
|
1894
|
+
let metric = byMetric.get(metricKey);
|
|
1895
|
+
if (!metric) {
|
|
1896
|
+
metric = {
|
|
1897
|
+
name: state.name,
|
|
1898
|
+
...state.unit && {
|
|
1899
|
+
unit: state.unit
|
|
1900
|
+
}
|
|
1901
|
+
};
|
|
1902
|
+
if (state.type === "count")
|
|
1903
|
+
metric.sum = {
|
|
1904
|
+
aggregationTemporality: OTLP_TEMPORALITY_DELTA,
|
|
1905
|
+
isMonotonic: true,
|
|
1906
|
+
dataPoints: []
|
|
1907
|
+
};
|
|
1908
|
+
else if (state.type === "gauge")
|
|
1909
|
+
metric.gauge = {
|
|
1910
|
+
dataPoints: []
|
|
1911
|
+
};
|
|
1912
|
+
else
|
|
1913
|
+
metric.histogram = {
|
|
1914
|
+
aggregationTemporality: OTLP_TEMPORALITY_DELTA,
|
|
1915
|
+
dataPoints: []
|
|
1916
|
+
};
|
|
1917
|
+
byMetric.set(metricKey, metric);
|
|
1918
|
+
}
|
|
1919
|
+
const attributes = toOtlpKeyValueList(state.attributes ?? {});
|
|
1920
|
+
const startNano = msToUnixNano(state.windowStartMs);
|
|
1921
|
+
if (state.type === "count") {
|
|
1922
|
+
const dp = {
|
|
1923
|
+
attributes,
|
|
1924
|
+
startTimeUnixNano: startNano,
|
|
1925
|
+
timeUnixNano: nowNano,
|
|
1926
|
+
asDouble: state.total ?? 0
|
|
1927
|
+
};
|
|
1928
|
+
metric.sum.dataPoints.push(dp);
|
|
1929
|
+
} else if (state.type === "gauge") {
|
|
1930
|
+
const dp = {
|
|
1931
|
+
attributes,
|
|
1932
|
+
timeUnixNano: nowNano,
|
|
1933
|
+
asDouble: state.last ?? 0
|
|
1934
|
+
};
|
|
1935
|
+
metric.gauge.dataPoints.push(dp);
|
|
1936
|
+
} else if (state.hist) {
|
|
1937
|
+
const dp = {
|
|
1938
|
+
attributes,
|
|
1939
|
+
startTimeUnixNano: startNano,
|
|
1940
|
+
timeUnixNano: nowNano,
|
|
1941
|
+
count: state.hist.count,
|
|
1942
|
+
sum: state.hist.sum,
|
|
1943
|
+
min: state.hist.min,
|
|
1944
|
+
max: state.hist.max,
|
|
1945
|
+
bucketCounts: state.hist.bucketCounts,
|
|
1946
|
+
explicitBounds: DEFAULT_HISTOGRAM_BOUNDS
|
|
1947
|
+
};
|
|
1948
|
+
metric.histogram.dataPoints.push(dp);
|
|
1949
|
+
}
|
|
1950
|
+
}
|
|
1951
|
+
return Array.from(byMetric.values());
|
|
1952
|
+
}
|
|
1953
|
+
_mergeWindowBack(window) {
|
|
1954
|
+
for (const [key, old] of window) {
|
|
1955
|
+
const current = this._series.get(key);
|
|
1956
|
+
if (!current) {
|
|
1957
|
+
if (this._admitNewSeries())
|
|
1958
|
+
this._series.set(key, old);
|
|
1959
|
+
continue;
|
|
1960
|
+
}
|
|
1961
|
+
current.windowStartMs = Math.min(current.windowStartMs, old.windowStartMs);
|
|
1962
|
+
switch (current.type) {
|
|
1963
|
+
case "count":
|
|
1964
|
+
current.total = (current.total ?? 0) + (old.total ?? 0);
|
|
1965
|
+
break;
|
|
1966
|
+
case "gauge":
|
|
1967
|
+
break;
|
|
1968
|
+
case "histogram":
|
|
1969
|
+
if (old.hist)
|
|
1970
|
+
if (current.hist) {
|
|
1971
|
+
current.hist.count += old.hist.count;
|
|
1972
|
+
current.hist.sum += old.hist.sum;
|
|
1973
|
+
current.hist.min = Math.min(current.hist.min, old.hist.min);
|
|
1974
|
+
current.hist.max = Math.max(current.hist.max, old.hist.max);
|
|
1975
|
+
for (let i = 0;i < current.hist.bucketCounts.length; i++)
|
|
1976
|
+
current.hist.bucketCounts[i] += old.hist.bucketCounts[i];
|
|
1977
|
+
} else
|
|
1978
|
+
current.hist = old.hist;
|
|
1979
|
+
break;
|
|
1980
|
+
}
|
|
1981
|
+
}
|
|
1982
|
+
}
|
|
1983
|
+
}
|
|
1984
|
+
var OTLP_TEMPORALITY_DELTA = 1;
|
|
1985
|
+
var init_metrics = __esm(() => {
|
|
1986
|
+
init_utils();
|
|
1987
|
+
init_logs_utils();
|
|
1988
|
+
init_metrics_utils();
|
|
1989
|
+
init_config();
|
|
1990
|
+
});
|
|
1991
|
+
|
|
1992
|
+
// node_modules/.bun/@posthog+core@1.48.6/node_modules/@posthog/core/dist/surveys/validation.mjs
|
|
1364
1993
|
var init_validation = __esm(() => {
|
|
1365
1994
|
init_types();
|
|
1366
1995
|
});
|
|
1367
1996
|
|
|
1368
|
-
// node_modules/.bun/@posthog+core@1.
|
|
1997
|
+
// node_modules/.bun/@posthog+core@1.48.6/node_modules/@posthog/core/dist/cookie.mjs
|
|
1369
1998
|
var init_cookie = __esm(() => {
|
|
1370
1999
|
init_utils();
|
|
1371
2000
|
init_uuidv7();
|
|
1372
2001
|
});
|
|
1373
2002
|
|
|
1374
|
-
// node_modules/.bun/@posthog+core@1.
|
|
2003
|
+
// node_modules/.bun/@posthog+core@1.48.6/node_modules/@posthog/core/dist/eventemitter.mjs
|
|
1375
2004
|
class SimpleEventEmitter {
|
|
1376
2005
|
constructor() {
|
|
1377
2006
|
this.events = {};
|
|
@@ -1394,7 +2023,7 @@ class SimpleEventEmitter {
|
|
|
1394
2023
|
}
|
|
1395
2024
|
var init_eventemitter = () => {};
|
|
1396
2025
|
|
|
1397
|
-
// node_modules/.bun/@posthog+core@1.
|
|
2026
|
+
// node_modules/.bun/@posthog+core@1.48.6/node_modules/@posthog/core/dist/error-tracking/chunk-ids.mjs
|
|
1398
2027
|
function getFilenameToChunkIdMap(stackParser) {
|
|
1399
2028
|
const chunkIdMap = globalThis._posthogChunkIds;
|
|
1400
2029
|
if (!chunkIdMap)
|
|
@@ -1432,7 +2061,7 @@ function getFilenameToChunkIdMap(stackParser) {
|
|
|
1432
2061
|
var parsedStackResults, lastKeysCount, cachedFilenameChunkIds;
|
|
1433
2062
|
var init_chunk_ids = () => {};
|
|
1434
2063
|
|
|
1435
|
-
// node_modules/.bun/@posthog+core@1.
|
|
2064
|
+
// node_modules/.bun/@posthog+core@1.48.6/node_modules/@posthog/core/dist/error-tracking/error-properties-builder.mjs
|
|
1436
2065
|
class ErrorPropertiesBuilder {
|
|
1437
2066
|
constructor(coercers, stackParser, modifiers = []) {
|
|
1438
2067
|
this.coercers = coercers;
|
|
@@ -1558,13 +2187,13 @@ var init_error_properties_builder = __esm(() => {
|
|
|
1558
2187
|
init_chunk_ids();
|
|
1559
2188
|
});
|
|
1560
2189
|
|
|
1561
|
-
// node_modules/.bun/@posthog+core@1.
|
|
2190
|
+
// node_modules/.bun/@posthog+core@1.48.6/node_modules/@posthog/core/dist/error-tracking/parsers/base.mjs
|
|
1562
2191
|
function createFrame(platform, filename, func, lineno, colno) {
|
|
1563
2192
|
const frame = {
|
|
1564
2193
|
platform,
|
|
1565
2194
|
filename,
|
|
1566
2195
|
function: func === "<anonymous>" ? UNKNOWN_FUNCTION : func,
|
|
1567
|
-
in_app:
|
|
2196
|
+
in_app: !filename?.startsWith(MASKED_URL_PREFIX) && filename !== ANONYMOUS_FILENAME
|
|
1568
2197
|
};
|
|
1569
2198
|
if (!isUndefined(lineno))
|
|
1570
2199
|
frame.lineno = lineno;
|
|
@@ -1572,12 +2201,12 @@ function createFrame(platform, filename, func, lineno, colno) {
|
|
|
1572
2201
|
frame.colno = colno;
|
|
1573
2202
|
return frame;
|
|
1574
2203
|
}
|
|
1575
|
-
var UNKNOWN_FUNCTION = "?";
|
|
2204
|
+
var UNKNOWN_FUNCTION = "?", MASKED_URL_PREFIX = "webkit-masked-url://", ANONYMOUS_FILENAME = "<anonymous>";
|
|
1576
2205
|
var init_base = __esm(() => {
|
|
1577
2206
|
init_utils();
|
|
1578
2207
|
});
|
|
1579
2208
|
|
|
1580
|
-
// node_modules/.bun/@posthog+core@1.
|
|
2209
|
+
// node_modules/.bun/@posthog+core@1.48.6/node_modules/@posthog/core/dist/error-tracking/parsers/safari.mjs
|
|
1581
2210
|
var extractSafariExtensionDetails = (func, filename) => {
|
|
1582
2211
|
const isSafariExtension = func.indexOf("safari-extension") !== -1;
|
|
1583
2212
|
const isSafariWebExtension = func.indexOf("safari-web-extension") !== -1;
|
|
@@ -1593,7 +2222,7 @@ var init_safari = __esm(() => {
|
|
|
1593
2222
|
init_base();
|
|
1594
2223
|
});
|
|
1595
2224
|
|
|
1596
|
-
// node_modules/.bun/@posthog+core@1.
|
|
2225
|
+
// node_modules/.bun/@posthog+core@1.48.6/node_modules/@posthog/core/dist/error-tracking/parsers/chrome.mjs
|
|
1597
2226
|
var chromeRegexNoFnName, chromeRegex, chromeEvalRegex, chromeStackLineParser = (line, platform) => {
|
|
1598
2227
|
const noFnParts = chromeRegexNoFnName.exec(line);
|
|
1599
2228
|
if (noFnParts) {
|
|
@@ -1623,7 +2252,7 @@ var init_chrome = __esm(() => {
|
|
|
1623
2252
|
chromeEvalRegex = /\((\S*)(?::(\d+))(?::(\d+))\)/;
|
|
1624
2253
|
});
|
|
1625
2254
|
|
|
1626
|
-
// node_modules/.bun/@posthog+core@1.
|
|
2255
|
+
// node_modules/.bun/@posthog+core@1.48.6/node_modules/@posthog/core/dist/error-tracking/parsers/gecko.mjs
|
|
1627
2256
|
var geckoREgex, geckoEvalRegex, geckoStackLineParser = (line, platform) => {
|
|
1628
2257
|
const parts = geckoREgex.exec(line);
|
|
1629
2258
|
if (parts) {
|
|
@@ -1650,7 +2279,7 @@ var init_gecko = __esm(() => {
|
|
|
1650
2279
|
geckoEvalRegex = /(\S+) line (\d+)(?: > eval line \d+)* > eval/i;
|
|
1651
2280
|
});
|
|
1652
2281
|
|
|
1653
|
-
// node_modules/.bun/@posthog+core@1.
|
|
2282
|
+
// node_modules/.bun/@posthog+core@1.48.6/node_modules/@posthog/core/dist/error-tracking/parsers/winjs.mjs
|
|
1654
2283
|
var winjsRegex, winjsStackLineParser = (line, platform) => {
|
|
1655
2284
|
const parts = winjsRegex.exec(line);
|
|
1656
2285
|
return parts ? createFrame(platform, parts[2], parts[1] || UNKNOWN_FUNCTION, +parts[3], parts[4] ? +parts[4] : undefined) : undefined;
|
|
@@ -1660,7 +2289,7 @@ var init_winjs = __esm(() => {
|
|
|
1660
2289
|
winjsRegex = /^\s*at (?:((?:\[object object\])?.+) )?\(?((?:[-a-z]+):.*?):(\d+)(?::(\d+))?\)?\s*$/i;
|
|
1661
2290
|
});
|
|
1662
2291
|
|
|
1663
|
-
// node_modules/.bun/@posthog+core@1.
|
|
2292
|
+
// node_modules/.bun/@posthog+core@1.48.6/node_modules/@posthog/core/dist/error-tracking/parsers/opera.mjs
|
|
1664
2293
|
var opera10Regex, opera10StackLineParser = (line, platform) => {
|
|
1665
2294
|
const parts = opera10Regex.exec(line);
|
|
1666
2295
|
return parts ? createFrame(platform, parts[2], parts[3] || UNKNOWN_FUNCTION, +parts[1]) : undefined;
|
|
@@ -1674,7 +2303,7 @@ var init_opera = __esm(() => {
|
|
|
1674
2303
|
opera11Regex = / line (\d+), column (\d+)\s*(?:in (?:<anonymous function: ([^>]+)>|([^)]+))\(.*\))? in (.*):\s*$/i;
|
|
1675
2304
|
});
|
|
1676
2305
|
|
|
1677
|
-
// node_modules/.bun/@posthog+core@1.
|
|
2306
|
+
// node_modules/.bun/@posthog+core@1.48.6/node_modules/@posthog/core/dist/error-tracking/parsers/node.mjs
|
|
1678
2307
|
function filenameIsInApp(filename, isNative = false) {
|
|
1679
2308
|
const isInternal = isNative || filename && !filename.startsWith("/") && !filename.match(/^[A-Z]:/) && !filename.startsWith(".") && !filename.match(/^[a-zA-Z]([a-zA-Z0-9.\-+])*:\/\//);
|
|
1680
2309
|
return !isInternal && filename !== undefined && !filename.includes("node_modules/");
|
|
@@ -1682,7 +2311,7 @@ function filenameIsInApp(filename, isNative = false) {
|
|
|
1682
2311
|
function _parseIntOrUndefined(input) {
|
|
1683
2312
|
return parseInt(input || "", 10) || undefined;
|
|
1684
2313
|
}
|
|
1685
|
-
var FILENAME_MATCH, FULL_MATCH, nodeStackLineParser = (line, platform) => {
|
|
2314
|
+
var FILENAME_MATCH, FULL_MATCH, PROMISE_COMBINATOR, PROMISE_INDEX, PROMISE_FRAME_FILENAME = "node:internal/promise", nodeStackLineParser = (line, platform) => {
|
|
1686
2315
|
const lineMatch = line.match(FULL_MATCH);
|
|
1687
2316
|
if (lineMatch) {
|
|
1688
2317
|
let object;
|
|
@@ -1724,6 +2353,8 @@ var FILENAME_MATCH, FULL_MATCH, nodeStackLineParser = (line, platform) => {
|
|
|
1724
2353
|
filename = filename.slice(1);
|
|
1725
2354
|
if (!filename && lineMatch[5] && !isNative)
|
|
1726
2355
|
filename = lineMatch[5];
|
|
2356
|
+
if (PROMISE_COMBINATOR.test(functionName) && PROMISE_INDEX.test(filename || ""))
|
|
2357
|
+
filename = PROMISE_FRAME_FILENAME;
|
|
1727
2358
|
return {
|
|
1728
2359
|
filename: filename ? decodeURI(filename) : undefined,
|
|
1729
2360
|
module: undefined,
|
|
@@ -1744,9 +2375,11 @@ var init_node = __esm(() => {
|
|
|
1744
2375
|
init_base();
|
|
1745
2376
|
FILENAME_MATCH = /^\s*[-]{4,}$/;
|
|
1746
2377
|
FULL_MATCH = /at (?:async )?(?:(.+?)\s+\()?(?:(.+):(\d+):(\d+)?|([^)]+))\)?/;
|
|
2378
|
+
PROMISE_COMBINATOR = /^Promise\.(?:all|any)$/;
|
|
2379
|
+
PROMISE_INDEX = /^index \d+$/;
|
|
1747
2380
|
});
|
|
1748
2381
|
|
|
1749
|
-
// node_modules/.bun/@posthog+core@1.
|
|
2382
|
+
// node_modules/.bun/@posthog+core@1.48.6/node_modules/@posthog/core/dist/error-tracking/parsers/index.mjs
|
|
1750
2383
|
function reverseAndStripFrames(stack) {
|
|
1751
2384
|
if (!stack.length)
|
|
1752
2385
|
return [];
|
|
@@ -1800,7 +2433,7 @@ var init_parsers = __esm(() => {
|
|
|
1800
2433
|
WEBPACK_ERROR_REGEXP = /\(error: (.*)\)/;
|
|
1801
2434
|
});
|
|
1802
2435
|
|
|
1803
|
-
// node_modules/.bun/@posthog+core@1.
|
|
2436
|
+
// node_modules/.bun/@posthog+core@1.48.6/node_modules/@posthog/core/dist/error-tracking/coercers/dom-exception-coercer.mjs
|
|
1804
2437
|
class DOMExceptionCoercer {
|
|
1805
2438
|
match(err) {
|
|
1806
2439
|
return this.isDOMException(err) || this.isDOMError(err);
|
|
@@ -1834,18 +2467,20 @@ var init_dom_exception_coercer = __esm(() => {
|
|
|
1834
2467
|
init_utils();
|
|
1835
2468
|
});
|
|
1836
2469
|
|
|
1837
|
-
// node_modules/.bun/@posthog+core@1.
|
|
2470
|
+
// node_modules/.bun/@posthog+core@1.48.6/node_modules/@posthog/core/dist/error-tracking/coercers/error-coercer.mjs
|
|
1838
2471
|
class ErrorCoercer {
|
|
1839
2472
|
match(err) {
|
|
1840
|
-
return
|
|
2473
|
+
return isError(err);
|
|
1841
2474
|
}
|
|
1842
2475
|
coerce(err, ctx) {
|
|
2476
|
+
const stack = this.getStack(err);
|
|
2477
|
+
const synthetic = stack === undefined;
|
|
1843
2478
|
return {
|
|
1844
2479
|
type: this.getType(err),
|
|
1845
2480
|
value: this.getMessage(err, ctx),
|
|
1846
|
-
stack:
|
|
2481
|
+
stack: stack ?? ctx.syntheticException?.stack,
|
|
1847
2482
|
cause: err.cause ? ctx.next(err.cause) : undefined,
|
|
1848
|
-
synthetic
|
|
2483
|
+
synthetic
|
|
1849
2484
|
};
|
|
1850
2485
|
}
|
|
1851
2486
|
getType(err) {
|
|
@@ -1862,32 +2497,48 @@ class ErrorCoercer {
|
|
|
1862
2497
|
}
|
|
1863
2498
|
}
|
|
1864
2499
|
var init_error_coercer = __esm(() => {
|
|
1865
|
-
|
|
2500
|
+
init_type_utils();
|
|
1866
2501
|
});
|
|
1867
2502
|
|
|
1868
|
-
// node_modules/.bun/@posthog+core@1.
|
|
2503
|
+
// node_modules/.bun/@posthog+core@1.48.6/node_modules/@posthog/core/dist/error-tracking/coercers/error-event-coercer.mjs
|
|
1869
2504
|
class ErrorEventCoercer {
|
|
1870
2505
|
constructor() {}
|
|
1871
2506
|
match(err) {
|
|
1872
|
-
|
|
2507
|
+
if (!isErrorEvent(err))
|
|
2508
|
+
return false;
|
|
2509
|
+
const errorEvent = err;
|
|
2510
|
+
return errorEvent.error != null || this._hasUsableMessage(errorEvent);
|
|
1873
2511
|
}
|
|
1874
2512
|
coerce(err, ctx) {
|
|
1875
|
-
|
|
1876
|
-
|
|
1877
|
-
|
|
1878
|
-
|
|
1879
|
-
|
|
1880
|
-
|
|
1881
|
-
|
|
1882
|
-
|
|
1883
|
-
|
|
2513
|
+
if (err.error != null)
|
|
2514
|
+
return ctx.apply(err.error);
|
|
2515
|
+
const exceptionLike = ctx.apply(err.message);
|
|
2516
|
+
return {
|
|
2517
|
+
...exceptionLike,
|
|
2518
|
+
stack: this._buildLocationStack(err) ?? exceptionLike.stack,
|
|
2519
|
+
synthetic: true
|
|
2520
|
+
};
|
|
2521
|
+
}
|
|
2522
|
+
_hasUsableMessage(err) {
|
|
2523
|
+
return isString(err.message) && err.message.length > 0;
|
|
2524
|
+
}
|
|
2525
|
+
_buildLocationStack(err) {
|
|
2526
|
+
const location = err;
|
|
2527
|
+
const lineno = location.lineno ?? 0;
|
|
2528
|
+
const colno = location.colno ?? 0;
|
|
2529
|
+
if (!isString(location.filename) || location.filename.length === 0)
|
|
2530
|
+
return;
|
|
2531
|
+
if (lineno === 0)
|
|
2532
|
+
return;
|
|
2533
|
+
return `Error
|
|
2534
|
+
at ${location.filename}:${lineno}:${colno}`;
|
|
1884
2535
|
}
|
|
1885
2536
|
}
|
|
1886
2537
|
var init_error_event_coercer = __esm(() => {
|
|
1887
2538
|
init_utils();
|
|
1888
2539
|
});
|
|
1889
2540
|
|
|
1890
|
-
// node_modules/.bun/@posthog+core@1.
|
|
2541
|
+
// node_modules/.bun/@posthog+core@1.48.6/node_modules/@posthog/core/dist/error-tracking/coercers/string-coercer.mjs
|
|
1891
2542
|
class StringCoercer {
|
|
1892
2543
|
match(input) {
|
|
1893
2544
|
return typeof input == "string";
|
|
@@ -1920,7 +2571,7 @@ var init_string_coercer = __esm(() => {
|
|
|
1920
2571
|
ERROR_TYPES_PATTERN = /^(?:[Uu]ncaught (?:exception: )?)?(?:((?:Eval|Internal|Range|Reference|Syntax|Type|URI|)Error): )?(.*)$/i;
|
|
1921
2572
|
});
|
|
1922
2573
|
|
|
1923
|
-
// node_modules/.bun/@posthog+core@1.
|
|
2574
|
+
// node_modules/.bun/@posthog+core@1.48.6/node_modules/@posthog/core/dist/error-tracking/types.mjs
|
|
1924
2575
|
var severityLevels;
|
|
1925
2576
|
var init_types2 = __esm(() => {
|
|
1926
2577
|
severityLevels = [
|
|
@@ -1933,7 +2584,7 @@ var init_types2 = __esm(() => {
|
|
|
1933
2584
|
];
|
|
1934
2585
|
});
|
|
1935
2586
|
|
|
1936
|
-
// node_modules/.bun/@posthog+core@1.
|
|
2587
|
+
// node_modules/.bun/@posthog+core@1.48.6/node_modules/@posthog/core/dist/error-tracking/coercers/utils.mjs
|
|
1937
2588
|
function extractExceptionKeysForMessage(err, maxLength = 40) {
|
|
1938
2589
|
const keys = Object.keys(err);
|
|
1939
2590
|
keys.sort();
|
|
@@ -1951,7 +2602,7 @@ function extractExceptionKeysForMessage(err, maxLength = 40) {
|
|
|
1951
2602
|
}
|
|
1952
2603
|
var init_utils2 = () => {};
|
|
1953
2604
|
|
|
1954
|
-
// node_modules/.bun/@posthog+core@1.
|
|
2605
|
+
// node_modules/.bun/@posthog+core@1.48.6/node_modules/@posthog/core/dist/error-tracking/coercers/object-coercer.mjs
|
|
1955
2606
|
class ObjectCoercer {
|
|
1956
2607
|
match(candidate) {
|
|
1957
2608
|
return typeof candidate == "object" && candidate !== null;
|
|
@@ -1963,13 +2614,16 @@ class ObjectCoercer {
|
|
|
1963
2614
|
return {
|
|
1964
2615
|
type: this.getType(candidate),
|
|
1965
2616
|
value: this.getValue(candidate),
|
|
1966
|
-
stack: ctx.syntheticException?.stack,
|
|
2617
|
+
stack: this.getStack(candidate) ?? ctx.syntheticException?.stack,
|
|
1967
2618
|
level: this.isSeverityLevel(candidate.level) ? candidate.level : "error",
|
|
1968
2619
|
synthetic: true
|
|
1969
2620
|
};
|
|
1970
2621
|
}
|
|
1971
2622
|
getType(err) {
|
|
1972
|
-
|
|
2623
|
+
if (isEvent(err))
|
|
2624
|
+
return err.constructor.name;
|
|
2625
|
+
const name = "name" in err ? err.name : undefined;
|
|
2626
|
+
return isString(name) && !isEmptyString(name) ? name : "Error";
|
|
1973
2627
|
}
|
|
1974
2628
|
getValue(err) {
|
|
1975
2629
|
if ("name" in err && typeof err.name == "string") {
|
|
@@ -1987,6 +2641,15 @@ class ObjectCoercer {
|
|
|
1987
2641
|
isSeverityLevel(x) {
|
|
1988
2642
|
return isString(x) && !isEmptyString(x) && severityLevels.indexOf(x) >= 0;
|
|
1989
2643
|
}
|
|
2644
|
+
getStack(candidate) {
|
|
2645
|
+
try {
|
|
2646
|
+
if (isString(candidate.stacktrace) && candidate.stacktrace.length > 0)
|
|
2647
|
+
return candidate.stacktrace;
|
|
2648
|
+
return isString(candidate.stack) && candidate.stack.length > 0 ? candidate.stack : undefined;
|
|
2649
|
+
} catch {
|
|
2650
|
+
return;
|
|
2651
|
+
}
|
|
2652
|
+
}
|
|
1990
2653
|
getErrorPropertyFromObject(obj) {
|
|
1991
2654
|
for (const prop in obj)
|
|
1992
2655
|
if (Object.prototype.hasOwnProperty.call(obj, prop)) {
|
|
@@ -2010,7 +2673,7 @@ var init_object_coercer = __esm(() => {
|
|
|
2010
2673
|
init_utils2();
|
|
2011
2674
|
});
|
|
2012
2675
|
|
|
2013
|
-
// node_modules/.bun/@posthog+core@1.
|
|
2676
|
+
// node_modules/.bun/@posthog+core@1.48.6/node_modules/@posthog/core/dist/error-tracking/coercers/event-coercer.mjs
|
|
2014
2677
|
class EventCoercer {
|
|
2015
2678
|
match(err) {
|
|
2016
2679
|
return isEvent(err);
|
|
@@ -2030,7 +2693,7 @@ var init_event_coercer = __esm(() => {
|
|
|
2030
2693
|
init_utils2();
|
|
2031
2694
|
});
|
|
2032
2695
|
|
|
2033
|
-
// node_modules/.bun/@posthog+core@1.
|
|
2696
|
+
// node_modules/.bun/@posthog+core@1.48.6/node_modules/@posthog/core/dist/error-tracking/coercers/primitive-coercer.mjs
|
|
2034
2697
|
class PrimitiveCoercer {
|
|
2035
2698
|
match(candidate) {
|
|
2036
2699
|
return isPrimitive(candidate);
|
|
@@ -2048,7 +2711,7 @@ var init_primitive_coercer = __esm(() => {
|
|
|
2048
2711
|
init_utils();
|
|
2049
2712
|
});
|
|
2050
2713
|
|
|
2051
|
-
// node_modules/.bun/@posthog+core@1.
|
|
2714
|
+
// node_modules/.bun/@posthog+core@1.48.6/node_modules/@posthog/core/dist/error-tracking/coercers/promise-rejection-event.mjs
|
|
2052
2715
|
class PromiseRejectionEventCoercer {
|
|
2053
2716
|
match(err) {
|
|
2054
2717
|
return isBuiltin(err, "PromiseRejectionEvent") || this.isCustomEventWrappingRejection(err);
|
|
@@ -2088,7 +2751,7 @@ var init_promise_rejection_event = __esm(() => {
|
|
|
2088
2751
|
init_utils();
|
|
2089
2752
|
});
|
|
2090
2753
|
|
|
2091
|
-
// node_modules/.bun/@posthog+core@1.
|
|
2754
|
+
// node_modules/.bun/@posthog+core@1.48.6/node_modules/@posthog/core/dist/error-tracking/coercers/index.mjs
|
|
2092
2755
|
var init_coercers = __esm(() => {
|
|
2093
2756
|
init_dom_exception_coercer();
|
|
2094
2757
|
init_error_coercer();
|
|
@@ -2100,7 +2763,7 @@ var init_coercers = __esm(() => {
|
|
|
2100
2763
|
init_promise_rejection_event();
|
|
2101
2764
|
});
|
|
2102
2765
|
|
|
2103
|
-
// node_modules/.bun/@posthog+core@1.
|
|
2766
|
+
// node_modules/.bun/@posthog+core@1.48.6/node_modules/@posthog/core/dist/error-tracking/utils.mjs
|
|
2104
2767
|
class ReduceableCache {
|
|
2105
2768
|
constructor(_maxSize) {
|
|
2106
2769
|
this._maxSize = _maxSize;
|
|
@@ -2127,7 +2790,7 @@ class ReduceableCache {
|
|
|
2127
2790
|
}
|
|
2128
2791
|
var init_utils3 = () => {};
|
|
2129
2792
|
|
|
2130
|
-
// node_modules/.bun/@posthog+core@1.
|
|
2793
|
+
// node_modules/.bun/@posthog+core@1.48.6/node_modules/@posthog/core/dist/error-tracking/exception-steps.mjs
|
|
2131
2794
|
function resolveExceptionStepsConfig(config) {
|
|
2132
2795
|
if (!config)
|
|
2133
2796
|
return {
|
|
@@ -2210,9 +2873,12 @@ function normalizePositiveInteger(input, fallback) {
|
|
|
2210
2873
|
return normalized;
|
|
2211
2874
|
}
|
|
2212
2875
|
function normalizeAndSerializeStep(step) {
|
|
2213
|
-
|
|
2214
|
-
|
|
2876
|
+
let json;
|
|
2877
|
+
try {
|
|
2878
|
+
json = safeJsonStringify(step);
|
|
2879
|
+
} catch {
|
|
2215
2880
|
return;
|
|
2881
|
+
}
|
|
2216
2882
|
try {
|
|
2217
2883
|
const parsed = JSON.parse(json);
|
|
2218
2884
|
if (!isObject(parsed))
|
|
@@ -2232,33 +2898,6 @@ function normalizeAndSerializeStep(step) {
|
|
|
2232
2898
|
return;
|
|
2233
2899
|
}
|
|
2234
2900
|
}
|
|
2235
|
-
function safeStringify(value) {
|
|
2236
|
-
const seen = new WeakSet;
|
|
2237
|
-
try {
|
|
2238
|
-
return JSON.stringify(value, (_key, replacementValue) => {
|
|
2239
|
-
if (typeof replacementValue == "bigint")
|
|
2240
|
-
return replacementValue.toString();
|
|
2241
|
-
if (typeof replacementValue == "function" || typeof replacementValue == "symbol")
|
|
2242
|
-
return;
|
|
2243
|
-
if (replacementValue instanceof Date)
|
|
2244
|
-
return replacementValue.toISOString();
|
|
2245
|
-
if (replacementValue instanceof Error)
|
|
2246
|
-
return {
|
|
2247
|
-
name: replacementValue.name,
|
|
2248
|
-
message: replacementValue.message,
|
|
2249
|
-
stack: replacementValue.stack
|
|
2250
|
-
};
|
|
2251
|
-
if (replacementValue && typeof replacementValue == "object") {
|
|
2252
|
-
if (seen.has(replacementValue))
|
|
2253
|
-
return "[Circular]";
|
|
2254
|
-
seen.add(replacementValue);
|
|
2255
|
-
}
|
|
2256
|
-
return replacementValue;
|
|
2257
|
-
});
|
|
2258
|
-
} catch {
|
|
2259
|
-
return;
|
|
2260
|
-
}
|
|
2261
|
-
}
|
|
2262
2901
|
function getUtf8ByteLength(value) {
|
|
2263
2902
|
if (typeof TextEncoder != "undefined")
|
|
2264
2903
|
return new TextEncoder().encode(value).length;
|
|
@@ -2289,7 +2928,14 @@ var init_exception_steps = __esm(() => {
|
|
|
2289
2928
|
};
|
|
2290
2929
|
});
|
|
2291
2930
|
|
|
2292
|
-
// node_modules/.bun/@posthog+core@1.
|
|
2931
|
+
// node_modules/.bun/@posthog+core@1.48.6/node_modules/@posthog/core/dist/error-tracking/release.mjs
|
|
2932
|
+
function getInjectedReleaseId() {
|
|
2933
|
+
const injected = globalThis._posthogReleaseId;
|
|
2934
|
+
return typeof injected == "string" && injected.length > 0 ? injected : undefined;
|
|
2935
|
+
}
|
|
2936
|
+
var init_release = () => {};
|
|
2937
|
+
|
|
2938
|
+
// node_modules/.bun/@posthog+core@1.48.6/node_modules/@posthog/core/dist/error-tracking/index.mjs
|
|
2293
2939
|
var exports_error_tracking = {};
|
|
2294
2940
|
__export(exports_error_tracking, {
|
|
2295
2941
|
winjsStackLineParser: () => winjsStackLineParser,
|
|
@@ -2300,6 +2946,7 @@ __export(exports_error_tracking, {
|
|
|
2300
2946
|
opera10StackLineParser: () => opera10StackLineParser,
|
|
2301
2947
|
nodeStackLineParser: () => nodeStackLineParser,
|
|
2302
2948
|
getUtf8ByteLength: () => getUtf8ByteLength,
|
|
2949
|
+
getInjectedReleaseId: () => getInjectedReleaseId,
|
|
2303
2950
|
geckoStackLineParser: () => geckoStackLineParser,
|
|
2304
2951
|
createStackParser: () => createStackParser,
|
|
2305
2952
|
createDefaultStackParser: () => createDefaultStackParser,
|
|
@@ -2324,15 +2971,19 @@ var init_error_tracking = __esm(() => {
|
|
|
2324
2971
|
init_coercers();
|
|
2325
2972
|
init_utils3();
|
|
2326
2973
|
init_exception_steps();
|
|
2974
|
+
init_release();
|
|
2327
2975
|
});
|
|
2328
2976
|
|
|
2329
|
-
// node_modules/.bun/@posthog+core@1.
|
|
2977
|
+
// node_modules/.bun/@posthog+core@1.48.6/node_modules/@posthog/core/dist/posthog-core-stateless.mjs
|
|
2330
2978
|
async function logFlushError(err) {
|
|
2331
2979
|
if (err instanceof PostHogFetchHttpError) {
|
|
2332
2980
|
let text = "";
|
|
2333
2981
|
try {
|
|
2334
2982
|
text = await err.text;
|
|
2335
|
-
} catch {
|
|
2983
|
+
} catch {
|
|
2984
|
+
if (err.bodyReadTimedOut)
|
|
2985
|
+
text = "<response body read timed out>";
|
|
2986
|
+
}
|
|
2336
2987
|
console.error(`Error while flushing PostHog: message=${err.message}, response body=${text}`, err);
|
|
2337
2988
|
} else
|
|
2338
2989
|
console.error("Error while flushing PostHog", err);
|
|
@@ -2344,9 +2995,26 @@ function isPostHogFetchError(err) {
|
|
|
2344
2995
|
function isPostHogFetchNetworkError(err) {
|
|
2345
2996
|
return err instanceof PostHogFetchNetworkError;
|
|
2346
2997
|
}
|
|
2998
|
+
function isRetryableFlagsFetchError(err) {
|
|
2999
|
+
if (err instanceof PostHogFetchHttpError)
|
|
3000
|
+
return err.status === 502 || err.status === 504;
|
|
3001
|
+
if (!(err instanceof PostHogFetchNetworkError))
|
|
3002
|
+
return false;
|
|
3003
|
+
const cause = err.error;
|
|
3004
|
+
const code = cause?.code ?? cause?.cause?.code;
|
|
3005
|
+
return code !== "ECONNREFUSED";
|
|
3006
|
+
}
|
|
2347
3007
|
function isPostHogFetchContentTooLargeError(err) {
|
|
2348
3008
|
return typeof err == "object" && err instanceof PostHogFetchHttpError && err.status === 413;
|
|
2349
3009
|
}
|
|
3010
|
+
function isPostHogFetchRetryableError(err) {
|
|
3011
|
+
if (err instanceof PostHogFetchHttpError)
|
|
3012
|
+
return err.status === 408 || err.status === 429 || err.status >= 500;
|
|
3013
|
+
return isPostHogFetchNetworkError(err);
|
|
3014
|
+
}
|
|
3015
|
+
function isPostHogEventProperties(value) {
|
|
3016
|
+
return value !== null && typeof value == "object" && !Array.isArray(value);
|
|
3017
|
+
}
|
|
2350
3018
|
|
|
2351
3019
|
class PostHogCoreStateless {
|
|
2352
3020
|
getErrorPropertiesBuilder() {
|
|
@@ -2364,6 +3032,9 @@ class PostHogCoreStateless {
|
|
|
2364
3032
|
}
|
|
2365
3033
|
constructor(apiKey, options = {}) {
|
|
2366
3034
|
this.flushPromise = null;
|
|
3035
|
+
this.pendingFlushPromise = null;
|
|
3036
|
+
this.flushPromises = new Set;
|
|
3037
|
+
this._dequeuedMessagesCount = 0;
|
|
2367
3038
|
this.shutdownPromise = null;
|
|
2368
3039
|
this.promiseQueue = new PromiseQueue;
|
|
2369
3040
|
this._events = new SimpleEventEmitter;
|
|
@@ -2386,10 +3057,11 @@ class PostHogCoreStateless {
|
|
|
2386
3057
|
this._retryOptions = {
|
|
2387
3058
|
retryCount: options.fetchRetryCount ?? 3,
|
|
2388
3059
|
retryDelay: options.fetchRetryDelay ?? 3000,
|
|
2389
|
-
retryCheck:
|
|
3060
|
+
retryCheck: isPostHogFetchRetryableError
|
|
2390
3061
|
};
|
|
2391
3062
|
this.requestTimeout = options.requestTimeout ?? 1e4;
|
|
2392
3063
|
this.featureFlagsRequestTimeoutMs = options.featureFlagsRequestTimeoutMs ?? 3000;
|
|
3064
|
+
this.featureFlagsRequestMaxRetries = options.featureFlagsRequestMaxRetries ?? 1;
|
|
2393
3065
|
this.remoteConfigRequestTimeoutMs = options.remoteConfigRequestTimeoutMs ?? 3000;
|
|
2394
3066
|
this.disableGeoip = options.disableGeoip ?? true;
|
|
2395
3067
|
this.disabled = (options.disabled ?? false) || missingApiKey;
|
|
@@ -2451,15 +3123,23 @@ class PostHogCoreStateless {
|
|
|
2451
3123
|
return this.disabled;
|
|
2452
3124
|
}
|
|
2453
3125
|
buildPayload(payload) {
|
|
3126
|
+
const userProperties = payload.properties || {};
|
|
3127
|
+
let properties = {
|
|
3128
|
+
...userProperties,
|
|
3129
|
+
...this.getCommonEventProperties()
|
|
3130
|
+
};
|
|
3131
|
+
applyCallerFeatureFlagOverrides(properties, userProperties);
|
|
3132
|
+
if (payload.event === "$feature_flag_called" && properties.$feature_flag_has_experiment === false && this.isMinimalFlagCalledEventsEnabled())
|
|
3133
|
+
properties = minimizeFlagCalledEventProperties(properties);
|
|
2454
3134
|
return {
|
|
2455
3135
|
distinct_id: payload.distinct_id,
|
|
2456
3136
|
event: payload.event,
|
|
2457
|
-
properties
|
|
2458
|
-
...payload.properties || {},
|
|
2459
|
-
...this.getCommonEventProperties()
|
|
2460
|
-
}
|
|
3137
|
+
properties
|
|
2461
3138
|
};
|
|
2462
3139
|
}
|
|
3140
|
+
isMinimalFlagCalledEventsEnabled() {
|
|
3141
|
+
return false;
|
|
3142
|
+
}
|
|
2463
3143
|
addPendingPromise(promise) {
|
|
2464
3144
|
return this.promiseQueue.add(promise);
|
|
2465
3145
|
}
|
|
@@ -2544,6 +3224,19 @@ class PostHogCoreStateless {
|
|
|
2544
3224
|
this.enqueue("capture", payload, options);
|
|
2545
3225
|
});
|
|
2546
3226
|
}
|
|
3227
|
+
async groupIdentifyStatelessImmediate(groupType, groupKey, groupProperties, options, distinctId, eventProperties) {
|
|
3228
|
+
const payload = this.buildPayload({
|
|
3229
|
+
distinct_id: distinctId || `$${groupType}_${groupKey}`,
|
|
3230
|
+
event: "$groupidentify",
|
|
3231
|
+
properties: {
|
|
3232
|
+
$group_type: groupType,
|
|
3233
|
+
$group_key: groupKey,
|
|
3234
|
+
$group_set: groupProperties || {},
|
|
3235
|
+
...eventProperties || {}
|
|
3236
|
+
}
|
|
3237
|
+
});
|
|
3238
|
+
await this.sendImmediate("capture", payload, options);
|
|
3239
|
+
}
|
|
2547
3240
|
async getRemoteConfig() {
|
|
2548
3241
|
await this._initPromise;
|
|
2549
3242
|
let host = this.host;
|
|
@@ -2560,8 +3253,11 @@ class PostHogCoreStateless {
|
|
|
2560
3253
|
}
|
|
2561
3254
|
};
|
|
2562
3255
|
return this.fetchWithRetry(url, fetchOptions, {
|
|
3256
|
+
type: "required",
|
|
3257
|
+
consume: (response) => response.json()
|
|
3258
|
+
}, {
|
|
2563
3259
|
retryCount: 0
|
|
2564
|
-
}, this.remoteConfigRequestTimeoutMs).
|
|
3260
|
+
}, this.remoteConfigRequestTimeoutMs).catch((error) => {
|
|
2565
3261
|
this._logger.error("Remote config could not be loaded", error);
|
|
2566
3262
|
this._events.emit("error", error);
|
|
2567
3263
|
});
|
|
@@ -2592,8 +3288,12 @@ class PostHogCoreStateless {
|
|
|
2592
3288
|
};
|
|
2593
3289
|
this._logger.info("Flags URL", url);
|
|
2594
3290
|
return this.fetchWithRetry(url, fetchOptions, {
|
|
2595
|
-
|
|
2596
|
-
|
|
3291
|
+
type: "required",
|
|
3292
|
+
consume: (response) => response.json()
|
|
3293
|
+
}, {
|
|
3294
|
+
retryCount: this.featureFlagsRequestMaxRetries,
|
|
3295
|
+
retryCheck: isRetryableFlagsFetchError
|
|
3296
|
+
}, this.featureFlagsRequestTimeoutMs).then((response) => ({
|
|
2597
3297
|
success: true,
|
|
2598
3298
|
response: normalizeFlagsResponse(response)
|
|
2599
3299
|
})).catch((error) => {
|
|
@@ -2693,9 +3393,9 @@ class PostHogCoreStateless {
|
|
|
2693
3393
|
}
|
|
2694
3394
|
async getFeatureFlagDetailsStateless(distinctId, groups = {}, personProperties = {}, groupProperties = {}, disableGeoip, flagKeysToEvaluate) {
|
|
2695
3395
|
await this._initPromise;
|
|
2696
|
-
const extraPayload = {
|
|
2697
|
-
|
|
2698
|
-
|
|
3396
|
+
const extraPayload = {
|
|
3397
|
+
geoip_disable: disableGeoip ?? this.disableGeoip
|
|
3398
|
+
};
|
|
2699
3399
|
if (flagKeysToEvaluate)
|
|
2700
3400
|
extraPayload["flag_keys_to_evaluate"] = flagKeysToEvaluate;
|
|
2701
3401
|
const result = await this.getFlags(distinctId, groups, personProperties, groupProperties, extraPayload);
|
|
@@ -2732,15 +3432,18 @@ class PostHogCoreStateless {
|
|
|
2732
3432
|
"Content-Type": "application/json"
|
|
2733
3433
|
}
|
|
2734
3434
|
};
|
|
2735
|
-
const response = await this.fetchWithRetry(url, fetchOptions
|
|
2736
|
-
|
|
2737
|
-
|
|
2738
|
-
|
|
2739
|
-
|
|
2740
|
-
|
|
2741
|
-
|
|
3435
|
+
const response = await this.fetchWithRetry(url, fetchOptions, {
|
|
3436
|
+
type: "required",
|
|
3437
|
+
consume: (response2) => {
|
|
3438
|
+
if (response2.status !== 200 || !response2.json) {
|
|
3439
|
+
const msg = `Surveys API could not be loaded: ${response2.status}`;
|
|
3440
|
+
const error = new Error(msg);
|
|
3441
|
+
this._logger.error(error);
|
|
3442
|
+
this._events.emit("error", new Error(msg));
|
|
3443
|
+
return Promise.resolve(undefined);
|
|
3444
|
+
}
|
|
3445
|
+
return response2.json();
|
|
2742
3446
|
}
|
|
2743
|
-
return response2.json();
|
|
2744
3447
|
}).catch((error) => {
|
|
2745
3448
|
this._logger.error("Surveys API could not be loaded", error);
|
|
2746
3449
|
this._events.emit("error", error);
|
|
@@ -2777,23 +3480,39 @@ class PostHogCoreStateless {
|
|
|
2777
3480
|
return message;
|
|
2778
3481
|
}
|
|
2779
3482
|
async flushStorage() {}
|
|
2780
|
-
|
|
3483
|
+
getQueueRouteKey(_message) {
|
|
3484
|
+
return DEFAULT_QUEUE_ROUTE;
|
|
3485
|
+
}
|
|
3486
|
+
persistedQueueKeyForRoute(_route) {
|
|
3487
|
+
return types_PostHogPersistedProperty.Queue;
|
|
3488
|
+
}
|
|
3489
|
+
getActiveQueueRoutes() {
|
|
3490
|
+
return [
|
|
3491
|
+
DEFAULT_QUEUE_ROUTE
|
|
3492
|
+
];
|
|
3493
|
+
}
|
|
3494
|
+
getRouteQueue(route) {
|
|
3495
|
+
return this.getPersistedProperty(this.persistedQueueKeyForRoute(route)) || [];
|
|
3496
|
+
}
|
|
3497
|
+
enqueue(type, _message, options, explicitRoute) {
|
|
2781
3498
|
this.wrap(() => {
|
|
2782
3499
|
if (this.optedOut)
|
|
2783
3500
|
return void this._events.emit(type, "Library is disabled. Not sending event. To re-enable, call posthog.optIn()");
|
|
2784
|
-
let message = this.prepareMessage(
|
|
3501
|
+
let message = this.prepareMessage(_message, options);
|
|
2785
3502
|
message = this.processBeforeEnqueue(message);
|
|
2786
3503
|
if (message === null)
|
|
2787
3504
|
return;
|
|
2788
|
-
|
|
3505
|
+
message = this.normalizeMessage(message);
|
|
3506
|
+
const queueKey = this.persistedQueueKeyForRoute(explicitRoute ?? this.getQueueRouteKey(message));
|
|
3507
|
+
const queue = this.getPersistedProperty(queueKey) || [];
|
|
2789
3508
|
if (queue.length >= this.maxQueueSize) {
|
|
2790
3509
|
queue.shift();
|
|
2791
|
-
this._logger.
|
|
3510
|
+
this._logger.warn("Queue is full, the oldest event is dropped.");
|
|
2792
3511
|
}
|
|
2793
3512
|
queue.push({
|
|
2794
3513
|
message
|
|
2795
3514
|
});
|
|
2796
|
-
this.setPersistedProperty(
|
|
3515
|
+
this.setPersistedProperty(queueKey, queue);
|
|
2797
3516
|
this._events.emit(type, message);
|
|
2798
3517
|
if (queue.length >= this.flushAt)
|
|
2799
3518
|
this.flushBackground();
|
|
@@ -2801,61 +3520,63 @@ class PostHogCoreStateless {
|
|
|
2801
3520
|
this._flushTimer = safeSetTimeout(() => this.flushBackground(), this.flushInterval);
|
|
2802
3521
|
});
|
|
2803
3522
|
}
|
|
2804
|
-
async sendImmediate(type, _message, options) {
|
|
3523
|
+
async sendImmediate(type, _message, options, explicitRoute) {
|
|
2805
3524
|
if (this.disabled)
|
|
2806
3525
|
return void this._logger.warn("The client is disabled");
|
|
2807
3526
|
if (!this._isInitialized)
|
|
2808
3527
|
await this._initPromise;
|
|
2809
3528
|
if (this.optedOut)
|
|
2810
3529
|
return void this._events.emit(type, "Library is disabled. Not sending event. To re-enable, call posthog.optIn()");
|
|
2811
|
-
let message = this.prepareMessage(
|
|
3530
|
+
let message = this.prepareMessage(_message, options);
|
|
2812
3531
|
message = this.processBeforeEnqueue(message);
|
|
2813
3532
|
if (message === null)
|
|
2814
3533
|
return;
|
|
2815
|
-
|
|
2816
|
-
|
|
2817
|
-
|
|
3534
|
+
message = this.normalizeMessage(message);
|
|
3535
|
+
try {
|
|
3536
|
+
await this.sendBatch([
|
|
2818
3537
|
message
|
|
2819
|
-
],
|
|
2820
|
-
sent_at: currentISOTime()
|
|
2821
|
-
};
|
|
2822
|
-
if (this.historicalMigration)
|
|
2823
|
-
data.historical_migration = true;
|
|
2824
|
-
const payload = JSON.stringify(data);
|
|
2825
|
-
const url = `${this.host}/batch/`;
|
|
2826
|
-
const gzippedPayload = this.disableCompression ? null : await gzipCompress(payload, this.isDebug);
|
|
2827
|
-
const fetchOptions = {
|
|
2828
|
-
method: "POST",
|
|
2829
|
-
headers: {
|
|
2830
|
-
...this.getCustomHeaders(),
|
|
2831
|
-
"Content-Type": "application/json",
|
|
2832
|
-
...gzippedPayload !== null && {
|
|
2833
|
-
"Content-Encoding": "gzip"
|
|
2834
|
-
}
|
|
2835
|
-
},
|
|
2836
|
-
body: gzippedPayload || payload
|
|
2837
|
-
};
|
|
2838
|
-
try {
|
|
2839
|
-
const response = await this.fetchWithRetry(url, fetchOptions);
|
|
2840
|
-
await response.body?.cancel()?.catch(() => {});
|
|
3538
|
+
], undefined, explicitRoute ?? this.getQueueRouteKey(message));
|
|
2841
3539
|
} catch (err) {
|
|
2842
3540
|
this._events.emit("error", err);
|
|
2843
3541
|
}
|
|
2844
3542
|
}
|
|
2845
|
-
|
|
3543
|
+
normalizeMessage(message) {
|
|
3544
|
+
const { type: _type, library, library_version, ...sanitizedMessage } = message;
|
|
3545
|
+
let properties = isPostHogEventProperties(sanitizedMessage.properties) ? sanitizedMessage.properties : undefined;
|
|
3546
|
+
if (library !== undefined && properties?.$lib === undefined)
|
|
3547
|
+
properties = {
|
|
3548
|
+
...properties || {},
|
|
3549
|
+
$lib: library
|
|
3550
|
+
};
|
|
3551
|
+
if (library_version !== undefined && properties?.$lib_version === undefined)
|
|
3552
|
+
properties = {
|
|
3553
|
+
...properties || {},
|
|
3554
|
+
$lib_version: library_version
|
|
3555
|
+
};
|
|
3556
|
+
if (properties)
|
|
3557
|
+
sanitizedMessage.properties = properties;
|
|
3558
|
+
sanitizedMessage.uuid = getEventUuid(sanitizedMessage.uuid, uuidv7);
|
|
3559
|
+
return sanitizedMessage;
|
|
3560
|
+
}
|
|
3561
|
+
normalizeTimestampForWire(timestamp) {
|
|
3562
|
+
const parsedTimestamp = timestamp instanceof Date ? timestamp : typeof timestamp == "string" ? new Date(timestamp) : null;
|
|
3563
|
+
if (!parsedTimestamp || Number.isNaN(parsedTimestamp.getTime()))
|
|
3564
|
+
return timestamp;
|
|
3565
|
+
const normalized = parsedTimestamp.toISOString();
|
|
3566
|
+
const fractionalSeconds = typeof timestamp == "string" ? timestamp.match(/\.(\d+)(?:Z|[+-]\d{2}:?\d{2})?$/i)?.[1] : undefined;
|
|
3567
|
+
return fractionalSeconds && fractionalSeconds.length > 3 ? normalized.replace(/\.\d{3}Z$/, `.${fractionalSeconds}Z`) : normalized;
|
|
3568
|
+
}
|
|
3569
|
+
prepareMessage(_message, options) {
|
|
2846
3570
|
const message = {
|
|
2847
3571
|
..._message,
|
|
2848
|
-
type,
|
|
2849
|
-
library: this.getLibraryId(),
|
|
2850
|
-
library_version: this.getLibraryVersion(),
|
|
2851
3572
|
timestamp: options?.timestamp ? options?.timestamp : currentISOTime(),
|
|
2852
|
-
uuid: options?.uuid
|
|
3573
|
+
uuid: getEventUuid(options?.uuid, uuidv7)
|
|
2853
3574
|
};
|
|
2854
3575
|
const addGeoipDisableProperty = options?.disableGeoip ?? this.disableGeoip;
|
|
2855
3576
|
if (addGeoipDisableProperty) {
|
|
2856
|
-
if (!message.properties)
|
|
3577
|
+
if (!isPostHogEventProperties(message.properties))
|
|
2857
3578
|
message.properties = {};
|
|
2858
|
-
message
|
|
3579
|
+
message.properties["$geoip_disable"] = true;
|
|
2859
3580
|
}
|
|
2860
3581
|
if (message.distinctId) {
|
|
2861
3582
|
message.distinct_id = message.distinctId;
|
|
@@ -2870,21 +3591,64 @@ class PostHogCoreStateless {
|
|
|
2870
3591
|
}
|
|
2871
3592
|
}
|
|
2872
3593
|
flushBackground() {
|
|
3594
|
+
if (this.pendingFlushPromise)
|
|
3595
|
+
return;
|
|
2873
3596
|
this.flush().catch(async (err) => {
|
|
2874
3597
|
await logFlushError(err);
|
|
2875
3598
|
});
|
|
2876
3599
|
}
|
|
2877
|
-
async
|
|
3600
|
+
async waitForPendingPromises(maxPromiseId, ignoredPromises = []) {
|
|
3601
|
+
const ignoredPendingPromises = ignoredPromises.filter((promise) => !!promise);
|
|
3602
|
+
let iteration = 0;
|
|
3603
|
+
while (true) {
|
|
3604
|
+
const promises = this.promiseQueue.getPromises([
|
|
3605
|
+
...ignoredPendingPromises,
|
|
3606
|
+
...this.flushPromises
|
|
3607
|
+
], maxPromiseId);
|
|
3608
|
+
if (promises.length === 0)
|
|
3609
|
+
return;
|
|
3610
|
+
if (iteration > 0)
|
|
3611
|
+
this._logger.debug(`flush() re-checking ${promises.length} pending promise(s) before flushing`);
|
|
3612
|
+
await Promise.all(promises.map((promise) => promise.catch(() => {})));
|
|
3613
|
+
iteration++;
|
|
3614
|
+
}
|
|
3615
|
+
}
|
|
3616
|
+
flushWithPendingPromises() {
|
|
3617
|
+
return this.flushInternal(true);
|
|
3618
|
+
}
|
|
3619
|
+
flush() {
|
|
3620
|
+
return this.flushInternal(false);
|
|
3621
|
+
}
|
|
3622
|
+
flushInternal(waitForPendingPromises) {
|
|
2878
3623
|
if (this.disabled)
|
|
2879
|
-
return;
|
|
2880
|
-
|
|
2881
|
-
this.
|
|
2882
|
-
|
|
3624
|
+
return Promise.resolve();
|
|
3625
|
+
if (!waitForPendingPromises && this.pendingFlushPromise)
|
|
3626
|
+
return this.pendingFlushPromise;
|
|
3627
|
+
const previousFlushPromise = this.flushPromise;
|
|
3628
|
+
const maxPromiseId = this.promiseQueue.maxId;
|
|
3629
|
+
const nextFlushPromise = Promise.resolve().then(() => {
|
|
3630
|
+
if (waitForPendingPromises)
|
|
3631
|
+
return this.waitForPendingPromises(maxPromiseId, [
|
|
3632
|
+
previousFlushPromise,
|
|
3633
|
+
nextFlushPromise
|
|
3634
|
+
]);
|
|
3635
|
+
}).then(() => allSettled([
|
|
3636
|
+
previousFlushPromise
|
|
3637
|
+
])).then(() => {
|
|
3638
|
+
if (this.pendingFlushPromise === nextFlushPromise)
|
|
3639
|
+
this.pendingFlushPromise = null;
|
|
3640
|
+
return this._flush();
|
|
3641
|
+
});
|
|
3642
|
+
this.pendingFlushPromise = nextFlushPromise;
|
|
2883
3643
|
this.flushPromise = nextFlushPromise;
|
|
3644
|
+
this.flushPromises.add(nextFlushPromise);
|
|
2884
3645
|
this.addPendingPromise(nextFlushPromise);
|
|
2885
3646
|
allSettled([
|
|
2886
3647
|
nextFlushPromise
|
|
2887
3648
|
]).then(() => {
|
|
3649
|
+
this.flushPromises.delete(nextFlushPromise);
|
|
3650
|
+
if (this.pendingFlushPromise === nextFlushPromise)
|
|
3651
|
+
this.pendingFlushPromise = null;
|
|
2888
3652
|
if (this.flushPromise === nextFlushPromise)
|
|
2889
3653
|
this.flushPromise = null;
|
|
2890
3654
|
});
|
|
@@ -2897,55 +3661,102 @@ class PostHogCoreStateless {
|
|
|
2897
3661
|
headers["User-Agent"] = customUserAgent;
|
|
2898
3662
|
return headers;
|
|
2899
3663
|
}
|
|
3664
|
+
compressPayload(payload) {
|
|
3665
|
+
return gzipCompress(payload, this.isDebug);
|
|
3666
|
+
}
|
|
3667
|
+
getBatchEndpointPath(_route) {
|
|
3668
|
+
return "/batch/";
|
|
3669
|
+
}
|
|
3670
|
+
async sendBatch(batchMessages, retryOptions, route = DEFAULT_QUEUE_ROUTE) {
|
|
3671
|
+
const data = {
|
|
3672
|
+
api_key: this.apiKey,
|
|
3673
|
+
batch: batchMessages.map((message) => {
|
|
3674
|
+
if (!message)
|
|
3675
|
+
return message;
|
|
3676
|
+
const timestamp = this.normalizeTimestampForWire(message.timestamp);
|
|
3677
|
+
return timestamp === message.timestamp ? message : {
|
|
3678
|
+
...message,
|
|
3679
|
+
timestamp
|
|
3680
|
+
};
|
|
3681
|
+
}),
|
|
3682
|
+
sent_at: currentISOTime()
|
|
3683
|
+
};
|
|
3684
|
+
if (this.historicalMigration)
|
|
3685
|
+
data.historical_migration = true;
|
|
3686
|
+
const payload = safeJsonStringify(data);
|
|
3687
|
+
const url = `${this.host}${this.getBatchEndpointPath(route)}`;
|
|
3688
|
+
const gzippedPayload = this.disableCompression ? null : await this.compressPayload(payload);
|
|
3689
|
+
const fetchOptions = {
|
|
3690
|
+
method: "POST",
|
|
3691
|
+
headers: {
|
|
3692
|
+
...this.getCustomHeaders(),
|
|
3693
|
+
"Content-Type": "application/json",
|
|
3694
|
+
...gzippedPayload !== null && {
|
|
3695
|
+
"Content-Encoding": "gzip"
|
|
3696
|
+
}
|
|
3697
|
+
},
|
|
3698
|
+
body: gzippedPayload || payload
|
|
3699
|
+
};
|
|
3700
|
+
await this.fetchWithRetry(url, fetchOptions, {
|
|
3701
|
+
type: "successful-write"
|
|
3702
|
+
}, retryOptions);
|
|
3703
|
+
}
|
|
2900
3704
|
async _flush() {
|
|
2901
3705
|
this.clearFlushTimer();
|
|
2902
3706
|
await this._initPromise;
|
|
2903
|
-
|
|
2904
|
-
if (!
|
|
3707
|
+
const routes = this.getActiveQueueRoutes();
|
|
3708
|
+
if (!routes.some((route) => this.getRouteQueue(route).length > 0))
|
|
2905
3709
|
return;
|
|
2906
3710
|
const sentMessages = [];
|
|
3711
|
+
let firstError;
|
|
3712
|
+
for (const route of routes)
|
|
3713
|
+
try {
|
|
3714
|
+
await this._flushRoute(route, sentMessages);
|
|
3715
|
+
} catch (err) {
|
|
3716
|
+
if (firstError === undefined)
|
|
3717
|
+
firstError = err;
|
|
3718
|
+
}
|
|
3719
|
+
if (firstError !== undefined)
|
|
3720
|
+
throw firstError;
|
|
3721
|
+
this._events.emit("flush", sentMessages);
|
|
3722
|
+
}
|
|
3723
|
+
async _flushRoute(route, sentMessages) {
|
|
3724
|
+
const queueKey = this.persistedQueueKeyForRoute(route);
|
|
3725
|
+
let queue = this.getPersistedProperty(queueKey) || [];
|
|
3726
|
+
if (!queue.length)
|
|
3727
|
+
return;
|
|
2907
3728
|
const originalQueueLength = queue.length;
|
|
2908
|
-
|
|
3729
|
+
let sentFromRoute = 0;
|
|
3730
|
+
while (queue.length > 0 && sentFromRoute < originalQueueLength) {
|
|
2909
3731
|
const batchItems = queue.slice(0, this.maxBatchSize);
|
|
2910
|
-
const batchMessages = batchItems.map((item) => item.message);
|
|
3732
|
+
const batchMessages = batchItems.map((item) => item.message === undefined ? item.message : this.normalizeMessage(item.message));
|
|
2911
3733
|
const persistQueueChange = async () => {
|
|
2912
|
-
const refreshedQueue = this.getPersistedProperty(
|
|
2913
|
-
const
|
|
2914
|
-
|
|
3734
|
+
const refreshedQueue = this.getPersistedProperty(queueKey) || [];
|
|
3735
|
+
const remainingBatchItems = [
|
|
3736
|
+
...batchItems
|
|
3737
|
+
];
|
|
3738
|
+
const newQueue = refreshedQueue.filter((item) => {
|
|
3739
|
+
const itemUuid = item.message?.uuid;
|
|
3740
|
+
const batchItemIndex = remainingBatchItems.findIndex((batchItem) => batchItem === item || typeof itemUuid == "string" && itemUuid.length > 0 && batchItem.message?.uuid === itemUuid);
|
|
3741
|
+
if (batchItemIndex === -1)
|
|
3742
|
+
return true;
|
|
3743
|
+
remainingBatchItems.splice(batchItemIndex, 1);
|
|
3744
|
+
return false;
|
|
3745
|
+
});
|
|
3746
|
+
this.setPersistedProperty(queueKey, newQueue);
|
|
2915
3747
|
queue = newQueue;
|
|
3748
|
+
this._dequeuedMessagesCount += batchItems.length;
|
|
2916
3749
|
await this.flushStorage();
|
|
2917
3750
|
};
|
|
2918
|
-
const data = {
|
|
2919
|
-
api_key: this.apiKey,
|
|
2920
|
-
batch: batchMessages,
|
|
2921
|
-
sent_at: currentISOTime()
|
|
2922
|
-
};
|
|
2923
|
-
if (this.historicalMigration)
|
|
2924
|
-
data.historical_migration = true;
|
|
2925
|
-
const payload = JSON.stringify(data);
|
|
2926
|
-
const url = `${this.host}/batch/`;
|
|
2927
|
-
const gzippedPayload = this.disableCompression ? null : await gzipCompress(payload, this.isDebug);
|
|
2928
|
-
const fetchOptions = {
|
|
2929
|
-
method: "POST",
|
|
2930
|
-
headers: {
|
|
2931
|
-
...this.getCustomHeaders(),
|
|
2932
|
-
"Content-Type": "application/json",
|
|
2933
|
-
...gzippedPayload !== null && {
|
|
2934
|
-
"Content-Encoding": "gzip"
|
|
2935
|
-
}
|
|
2936
|
-
},
|
|
2937
|
-
body: gzippedPayload || payload
|
|
2938
|
-
};
|
|
2939
3751
|
const retryOptions = {
|
|
2940
3752
|
retryCheck: (err) => {
|
|
2941
3753
|
if (isPostHogFetchContentTooLargeError(err))
|
|
2942
3754
|
return false;
|
|
2943
|
-
return
|
|
3755
|
+
return isPostHogFetchRetryableError(err);
|
|
2944
3756
|
}
|
|
2945
3757
|
};
|
|
2946
3758
|
try {
|
|
2947
|
-
|
|
2948
|
-
await response.body?.cancel()?.catch(() => {});
|
|
3759
|
+
await this.sendBatch(batchMessages, retryOptions, route);
|
|
2949
3760
|
} catch (err) {
|
|
2950
3761
|
if (isPostHogFetchContentTooLargeError(err) && batchMessages.length > 1) {
|
|
2951
3762
|
this.maxBatchSize = Math.max(1, Math.floor(batchMessages.length / 2));
|
|
@@ -2959,8 +3770,8 @@ class PostHogCoreStateless {
|
|
|
2959
3770
|
}
|
|
2960
3771
|
await persistQueueChange();
|
|
2961
3772
|
sentMessages.push(...batchMessages);
|
|
3773
|
+
sentFromRoute += batchMessages.length;
|
|
2962
3774
|
}
|
|
2963
|
-
this._events.emit("flush", sentMessages);
|
|
2964
3775
|
}
|
|
2965
3776
|
async _sendLogsBatch(payload) {
|
|
2966
3777
|
if (this.disabled)
|
|
@@ -2970,7 +3781,7 @@ class PostHogCoreStateless {
|
|
|
2970
3781
|
};
|
|
2971
3782
|
const serialized = JSON.stringify(payload);
|
|
2972
3783
|
const url = `${this.host}/i/v1/logs?token=${encodeURIComponent(this.apiKey)}`;
|
|
2973
|
-
const gzippedPayload = this.disableCompression ? null : await
|
|
3784
|
+
const gzippedPayload = this.disableCompression ? null : await this.compressPayload(serialized);
|
|
2974
3785
|
const fetchOptions = {
|
|
2975
3786
|
method: "POST",
|
|
2976
3787
|
headers: {
|
|
@@ -2984,10 +3795,12 @@ class PostHogCoreStateless {
|
|
|
2984
3795
|
};
|
|
2985
3796
|
try {
|
|
2986
3797
|
await this.fetchWithRetry(url, fetchOptions, {
|
|
3798
|
+
type: "successful-write"
|
|
3799
|
+
}, {
|
|
2987
3800
|
retryCheck: (err) => {
|
|
2988
3801
|
if (isPostHogFetchContentTooLargeError(err))
|
|
2989
3802
|
return false;
|
|
2990
|
-
return
|
|
3803
|
+
return isPostHogFetchRetryableError(err);
|
|
2991
3804
|
}
|
|
2992
3805
|
});
|
|
2993
3806
|
return {
|
|
@@ -3009,7 +3822,56 @@ class PostHogCoreStateless {
|
|
|
3009
3822
|
};
|
|
3010
3823
|
}
|
|
3011
3824
|
}
|
|
3012
|
-
async
|
|
3825
|
+
async _sendMetricsBatch(payload) {
|
|
3826
|
+
if (this.disabled)
|
|
3827
|
+
return {
|
|
3828
|
+
kind: "fatal",
|
|
3829
|
+
error: new Error("The client is disabled")
|
|
3830
|
+
};
|
|
3831
|
+
const serialized = JSON.stringify(payload);
|
|
3832
|
+
const url = `${this.host}/i/v1/metrics?token=${encodeURIComponent(this.apiKey)}`;
|
|
3833
|
+
const gzippedPayload = this.disableCompression ? null : await this.compressPayload(serialized);
|
|
3834
|
+
const fetchOptions = {
|
|
3835
|
+
method: "POST",
|
|
3836
|
+
headers: {
|
|
3837
|
+
...this.getCustomHeaders(),
|
|
3838
|
+
"Content-Type": "application/json",
|
|
3839
|
+
...gzippedPayload !== null && {
|
|
3840
|
+
"Content-Encoding": "gzip"
|
|
3841
|
+
}
|
|
3842
|
+
},
|
|
3843
|
+
body: gzippedPayload || serialized
|
|
3844
|
+
};
|
|
3845
|
+
try {
|
|
3846
|
+
await this.fetchWithRetry(url, fetchOptions, {
|
|
3847
|
+
type: "successful-write"
|
|
3848
|
+
}, {
|
|
3849
|
+
retryCheck: (err) => {
|
|
3850
|
+
if (isPostHogFetchContentTooLargeError(err))
|
|
3851
|
+
return false;
|
|
3852
|
+
return isPostHogFetchRetryableError(err);
|
|
3853
|
+
}
|
|
3854
|
+
});
|
|
3855
|
+
return {
|
|
3856
|
+
kind: "ok"
|
|
3857
|
+
};
|
|
3858
|
+
} catch (err) {
|
|
3859
|
+
if (isPostHogFetchContentTooLargeError(err))
|
|
3860
|
+
return {
|
|
3861
|
+
kind: "too-large"
|
|
3862
|
+
};
|
|
3863
|
+
if (isPostHogFetchRetryableError(err))
|
|
3864
|
+
return {
|
|
3865
|
+
kind: "retry-later",
|
|
3866
|
+
error: err
|
|
3867
|
+
};
|
|
3868
|
+
return {
|
|
3869
|
+
kind: "fatal",
|
|
3870
|
+
error: err
|
|
3871
|
+
};
|
|
3872
|
+
}
|
|
3873
|
+
}
|
|
3874
|
+
async fetchWithRetry(url, options, responseHandling, retryOptions, requestTimeout) {
|
|
3013
3875
|
const body = options.body ? options.body : "";
|
|
3014
3876
|
let reqByteLength = -1;
|
|
3015
3877
|
try {
|
|
@@ -3022,28 +3884,91 @@ class PostHogCoreStateless {
|
|
|
3022
3884
|
reqByteLength = encoded.length;
|
|
3023
3885
|
}
|
|
3024
3886
|
}
|
|
3887
|
+
const retriableOptions = {
|
|
3888
|
+
...this._retryOptions,
|
|
3889
|
+
...retryOptions
|
|
3890
|
+
};
|
|
3891
|
+
let attempt = 0;
|
|
3025
3892
|
return await retriable(async () => {
|
|
3893
|
+
attempt++;
|
|
3026
3894
|
const ctrl = new AbortController;
|
|
3027
3895
|
const timeoutMs = requestTimeout ?? this.requestTimeout;
|
|
3028
|
-
const
|
|
3029
|
-
let
|
|
3896
|
+
const requestDeadline = Date.now() + timeoutMs;
|
|
3897
|
+
let timer;
|
|
3898
|
+
const deadline = new Promise((_resolve, reject) => {
|
|
3899
|
+
timer = safeSetTimeout(() => {
|
|
3900
|
+
const timeoutError = new Error(`Request timed out after ${timeoutMs}ms`);
|
|
3901
|
+
timeoutError.name = "AbortError";
|
|
3902
|
+
reject(timeoutError);
|
|
3903
|
+
ctrl.abort(timeoutError);
|
|
3904
|
+
}, timeoutMs);
|
|
3905
|
+
});
|
|
3906
|
+
let res;
|
|
3907
|
+
let responseAccepted = false;
|
|
3908
|
+
let cancellation;
|
|
3909
|
+
const cancelBody = () => cancellation ??= (async () => {
|
|
3910
|
+
try {
|
|
3911
|
+
await res?.body?.cancel();
|
|
3912
|
+
} catch {}
|
|
3913
|
+
})();
|
|
3030
3914
|
try {
|
|
3031
|
-
|
|
3032
|
-
|
|
3033
|
-
|
|
3034
|
-
|
|
3035
|
-
|
|
3036
|
-
|
|
3915
|
+
let fetchPromise;
|
|
3916
|
+
try {
|
|
3917
|
+
fetchPromise = this.fetch(url, {
|
|
3918
|
+
signal: ctrl.signal,
|
|
3919
|
+
...options
|
|
3920
|
+
});
|
|
3921
|
+
} catch (e) {
|
|
3922
|
+
throw new PostHogFetchNetworkError(e);
|
|
3923
|
+
}
|
|
3924
|
+
fetchPromise.then((lateResponse) => {
|
|
3925
|
+
if (ctrl.signal.aborted && !responseAccepted)
|
|
3926
|
+
Promise.resolve(lateResponse.body?.cancel()).catch(() => {});
|
|
3927
|
+
}).catch(() => {});
|
|
3928
|
+
try {
|
|
3929
|
+
res = await Promise.race([
|
|
3930
|
+
fetchPromise,
|
|
3931
|
+
deadline
|
|
3932
|
+
]);
|
|
3933
|
+
responseAccepted = true;
|
|
3934
|
+
} catch (e) {
|
|
3935
|
+
throw new PostHogFetchNetworkError(e);
|
|
3936
|
+
}
|
|
3937
|
+
const isNoCors = options.mode === "no-cors";
|
|
3938
|
+
if (!isNoCors && (res.status < 200 || res.status >= 400))
|
|
3939
|
+
throw new PostHogFetchHttpError(res, reqByteLength, requestDeadline, ctrl);
|
|
3940
|
+
if (responseHandling.type === "successful-write") {
|
|
3941
|
+
try {
|
|
3942
|
+
await Promise.race([
|
|
3943
|
+
cancelBody(),
|
|
3944
|
+
deadline
|
|
3945
|
+
]);
|
|
3946
|
+
} catch {}
|
|
3947
|
+
return;
|
|
3948
|
+
}
|
|
3949
|
+
try {
|
|
3950
|
+
return await Promise.race([
|
|
3951
|
+
responseHandling.consume(res),
|
|
3952
|
+
deadline
|
|
3953
|
+
]);
|
|
3954
|
+
} catch (e) {
|
|
3955
|
+
if (ctrl.signal.aborted)
|
|
3956
|
+
throw new PostHogFetchNetworkError(e);
|
|
3957
|
+
throw e;
|
|
3958
|
+
}
|
|
3037
3959
|
} finally {
|
|
3038
3960
|
clearTimeout(timer);
|
|
3961
|
+
if (ctrl.signal.aborted && res)
|
|
3962
|
+
cancelBody();
|
|
3039
3963
|
}
|
|
3040
|
-
const isNoCors = options.mode === "no-cors";
|
|
3041
|
-
if (!isNoCors && (res.status < 200 || res.status >= 400))
|
|
3042
|
-
throw new PostHogFetchHttpError(res, reqByteLength);
|
|
3043
|
-
return res;
|
|
3044
3964
|
}, {
|
|
3045
|
-
...
|
|
3046
|
-
|
|
3965
|
+
...retriableOptions,
|
|
3966
|
+
retryCheck: (error) => {
|
|
3967
|
+
const shouldRetry = retriableOptions.retryCheck(error);
|
|
3968
|
+
if (shouldRetry && attempt <= retriableOptions.retryCount && error instanceof PostHogFetchHttpError)
|
|
3969
|
+
error.cancelResponseBody();
|
|
3970
|
+
return shouldRetry;
|
|
3971
|
+
}
|
|
3047
3972
|
});
|
|
3048
3973
|
}
|
|
3049
3974
|
async _shutdown(shutdownTimeoutMs = 30000) {
|
|
@@ -3056,12 +3981,17 @@ class PostHogCoreStateless {
|
|
|
3056
3981
|
try {
|
|
3057
3982
|
await this.promiseQueue.join();
|
|
3058
3983
|
while (true) {
|
|
3059
|
-
const
|
|
3060
|
-
if (
|
|
3984
|
+
const hasQueuedEvents = this.getActiveQueueRoutes().some((route) => this.getRouteQueue(route).length > 0);
|
|
3985
|
+
if (!hasQueuedEvents)
|
|
3061
3986
|
break;
|
|
3987
|
+
const dequeuedBeforeFlush = this._dequeuedMessagesCount;
|
|
3062
3988
|
await this.flush();
|
|
3063
3989
|
if (hasTimedOut)
|
|
3064
3990
|
break;
|
|
3991
|
+
if (this._dequeuedMessagesCount === dequeuedBeforeFlush) {
|
|
3992
|
+
this._logger.warn("Shutdown flush completed but did not send any queued events. Stopping drain to avoid a loop.");
|
|
3993
|
+
break;
|
|
3994
|
+
}
|
|
3065
3995
|
}
|
|
3066
3996
|
} catch (e) {
|
|
3067
3997
|
if (!isPostHogFetchError(e))
|
|
@@ -3069,21 +3999,12 @@ class PostHogCoreStateless {
|
|
|
3069
3999
|
await logFlushError(e);
|
|
3070
4000
|
}
|
|
3071
4001
|
};
|
|
3072
|
-
|
|
3073
|
-
|
|
3074
|
-
|
|
3075
|
-
|
|
3076
|
-
|
|
3077
|
-
|
|
3078
|
-
hasTimedOut = true;
|
|
3079
|
-
reject("Timeout while shutting down PostHog. Some events may not have been sent.");
|
|
3080
|
-
}, shutdownTimeoutMs);
|
|
3081
|
-
}),
|
|
3082
|
-
doShutdown()
|
|
3083
|
-
]);
|
|
3084
|
-
} finally {
|
|
3085
|
-
clearTimeout(timeoutHandle);
|
|
3086
|
-
}
|
|
4002
|
+
return raceWithTimeout(doShutdown(), shutdownTimeoutMs, () => {
|
|
4003
|
+
this._logger.critical("Timeout while shutting down PostHog. Some events may not have been sent.", {
|
|
4004
|
+
shutdownTimeoutMs
|
|
4005
|
+
});
|
|
4006
|
+
hasTimedOut = true;
|
|
4007
|
+
});
|
|
3087
4008
|
}
|
|
3088
4009
|
async shutdown(shutdownTimeoutMs = 30000) {
|
|
3089
4010
|
if (this.shutdownPromise)
|
|
@@ -3095,7 +4016,11 @@ class PostHogCoreStateless {
|
|
|
3095
4016
|
return this.shutdownPromise;
|
|
3096
4017
|
}
|
|
3097
4018
|
}
|
|
3098
|
-
var PostHogFetchHttpError, PostHogFetchNetworkError
|
|
4019
|
+
var PostHogFetchHttpError, PostHogFetchNetworkError, applyCallerFeatureFlagOverrides = (target, callerProperties) => {
|
|
4020
|
+
for (const key of Object.keys(callerProperties))
|
|
4021
|
+
if (key.startsWith("$feature/") || key === "$active_feature_flags")
|
|
4022
|
+
target[key] = callerProperties[key];
|
|
4023
|
+
}, DEFAULT_QUEUE_ROUTE = "default";
|
|
3099
4024
|
var init_posthog_core_stateless = __esm(() => {
|
|
3100
4025
|
init_eventemitter();
|
|
3101
4026
|
init_featureFlagUtils();
|
|
@@ -3105,17 +4030,58 @@ var init_posthog_core_stateless = __esm(() => {
|
|
|
3105
4030
|
init_uuidv7();
|
|
3106
4031
|
init_error_tracking();
|
|
3107
4032
|
PostHogFetchHttpError = class PostHogFetchHttpError extends Error {
|
|
3108
|
-
constructor(response, reqByteLength) {
|
|
3109
|
-
super("HTTP error while fetching PostHog: status=" + response.status + ", reqByteLength=" + reqByteLength), this.response = response, this.reqByteLength = reqByteLength, this.name = "PostHogFetchHttpError";
|
|
4033
|
+
constructor(response, reqByteLength, responseBodyDeadline, abortController) {
|
|
4034
|
+
super("HTTP error while fetching PostHog: status=" + response.status + ", reqByteLength=" + reqByteLength), this.response = response, this.reqByteLength = reqByteLength, this.responseBodyDeadline = responseBodyDeadline, this.abortController = abortController, this.name = "PostHogFetchHttpError", this._bodyReadTimedOut = false;
|
|
3110
4035
|
}
|
|
3111
4036
|
get status() {
|
|
3112
4037
|
return this.response.status;
|
|
3113
4038
|
}
|
|
4039
|
+
get bodyReadTimedOut() {
|
|
4040
|
+
return this._bodyReadTimedOut;
|
|
4041
|
+
}
|
|
3114
4042
|
get text() {
|
|
3115
|
-
|
|
4043
|
+
if (!this.responseBodyTextPromise)
|
|
4044
|
+
if (Date.now() >= this.responseBodyDeadline) {
|
|
4045
|
+
this._bodyReadTimedOut = true;
|
|
4046
|
+
const timeoutError = new Error("Response body read timed out");
|
|
4047
|
+
timeoutError.name = "AbortError";
|
|
4048
|
+
this.cancelResponseBody(timeoutError);
|
|
4049
|
+
this.responseBodyTextPromise = Promise.reject(timeoutError);
|
|
4050
|
+
} else {
|
|
4051
|
+
const responseBodyTimeout = new Promise((_resolve, reject) => {
|
|
4052
|
+
this.responseBodyTimer = safeSetTimeout(() => {
|
|
4053
|
+
this._bodyReadTimedOut = true;
|
|
4054
|
+
const timeoutError = new Error("Response body read timed out");
|
|
4055
|
+
timeoutError.name = "AbortError";
|
|
4056
|
+
reject(timeoutError);
|
|
4057
|
+
this.cancelResponseBody(timeoutError);
|
|
4058
|
+
}, this.responseBodyDeadline - Date.now());
|
|
4059
|
+
});
|
|
4060
|
+
let responseBodyText;
|
|
4061
|
+
try {
|
|
4062
|
+
responseBodyText = Promise.resolve(this.response.text());
|
|
4063
|
+
} catch (error) {
|
|
4064
|
+
responseBodyText = Promise.reject(error);
|
|
4065
|
+
}
|
|
4066
|
+
this.responseBodyTextPromise = Promise.race([
|
|
4067
|
+
responseBodyText,
|
|
4068
|
+
responseBodyTimeout
|
|
4069
|
+
]).finally(() => clearTimeout(this.responseBodyTimer));
|
|
4070
|
+
}
|
|
4071
|
+
return this.responseBodyTextPromise;
|
|
3116
4072
|
}
|
|
3117
4073
|
get json() {
|
|
3118
|
-
return this.
|
|
4074
|
+
return this.text.then((text) => JSON.parse(text));
|
|
4075
|
+
}
|
|
4076
|
+
cancelResponseBody(reason) {
|
|
4077
|
+
clearTimeout(this.responseBodyTimer);
|
|
4078
|
+
if (!this.abortController.signal.aborted)
|
|
4079
|
+
this.abortController.abort(reason);
|
|
4080
|
+
(async () => {
|
|
4081
|
+
try {
|
|
4082
|
+
await this.response.body?.cancel();
|
|
4083
|
+
} catch {}
|
|
4084
|
+
})();
|
|
3119
4085
|
}
|
|
3120
4086
|
};
|
|
3121
4087
|
PostHogFetchNetworkError = class PostHogFetchNetworkError extends Error {
|
|
@@ -3127,7 +4093,7 @@ var init_posthog_core_stateless = __esm(() => {
|
|
|
3127
4093
|
};
|
|
3128
4094
|
});
|
|
3129
4095
|
|
|
3130
|
-
// node_modules/.bun/@posthog+core@1.
|
|
4096
|
+
// node_modules/.bun/@posthog+core@1.48.6/node_modules/@posthog/core/dist/posthog-core.mjs
|
|
3131
4097
|
var init_posthog_core = __esm(() => {
|
|
3132
4098
|
init_featureFlagUtils();
|
|
3133
4099
|
init_types();
|
|
@@ -3136,17 +4102,18 @@ var init_posthog_core = __esm(() => {
|
|
|
3136
4102
|
init_utils();
|
|
3137
4103
|
});
|
|
3138
4104
|
|
|
3139
|
-
// node_modules/.bun/@posthog+core@1.
|
|
4105
|
+
// node_modules/.bun/@posthog+core@1.48.6/node_modules/@posthog/core/dist/tracing-headers.mjs
|
|
3140
4106
|
var init_tracing_headers = __esm(() => {
|
|
3141
4107
|
init_type_utils();
|
|
3142
4108
|
});
|
|
3143
4109
|
|
|
3144
|
-
// node_modules/.bun/@posthog+core@1.
|
|
4110
|
+
// node_modules/.bun/@posthog+core@1.48.6/node_modules/@posthog/core/dist/index.mjs
|
|
3145
4111
|
var init_dist = __esm(() => {
|
|
3146
4112
|
init_featureFlagUtils();
|
|
3147
4113
|
init_gzip();
|
|
3148
4114
|
init_logs_utils();
|
|
3149
4115
|
init_logs();
|
|
4116
|
+
init_metrics();
|
|
3150
4117
|
init_uuidv7();
|
|
3151
4118
|
init_validation();
|
|
3152
4119
|
init_error_tracking();
|
|
@@ -3158,16 +4125,24 @@ var init_dist = __esm(() => {
|
|
|
3158
4125
|
init_types();
|
|
3159
4126
|
});
|
|
3160
4127
|
|
|
3161
|
-
// node_modules/.bun/posthog-node@5.
|
|
3162
|
-
import {
|
|
4128
|
+
// node_modules/.bun/posthog-node@5.49.2/node_modules/posthog-node/dist/extensions/error-tracking/modifiers/context-lines.node.mjs
|
|
4129
|
+
import { constants as constants3 } from "node:fs";
|
|
4130
|
+
import { open as promises_open } from "node:fs/promises";
|
|
4131
|
+
import { isAbsolute as isAbsolute7 } from "node:path";
|
|
3163
4132
|
import { createInterface } from "node:readline";
|
|
3164
|
-
async function addSourceContext(frames) {
|
|
4133
|
+
async function addSourceContext(frames, openSourceFile = promises_open, logger2) {
|
|
3165
4134
|
const filesToLines = {};
|
|
4135
|
+
let basePath;
|
|
4136
|
+
try {
|
|
4137
|
+
basePath = process.cwd();
|
|
4138
|
+
} catch {}
|
|
3166
4139
|
for (let i = frames.length - 1;i >= 0; i--) {
|
|
3167
4140
|
const frame = frames[i];
|
|
3168
4141
|
const filename = frame?.filename;
|
|
3169
4142
|
if (!frame || typeof filename != "string" || typeof frame.lineno != "number" || shouldSkipContextLinesForFile(filename) || shouldSkipContextLinesForFrame(frame))
|
|
3170
4143
|
continue;
|
|
4144
|
+
if (!isAbsolute7(filename) && basePath === undefined)
|
|
4145
|
+
continue;
|
|
3171
4146
|
const filesToLinesOutput = filesToLines[filename];
|
|
3172
4147
|
if (!filesToLinesOutput)
|
|
3173
4148
|
filesToLines[filename] = [];
|
|
@@ -3178,50 +4153,98 @@ async function addSourceContext(frames) {
|
|
|
3178
4153
|
return frames;
|
|
3179
4154
|
const readlinePromises = [];
|
|
3180
4155
|
for (const file of files) {
|
|
3181
|
-
|
|
4156
|
+
const cacheKey = makeSourceCacheKey(file, basePath);
|
|
4157
|
+
if (cacheKey === undefined)
|
|
4158
|
+
continue;
|
|
4159
|
+
if (LRU_FILE_CONTENTS_FS_READ_FAILED.get(cacheKey))
|
|
3182
4160
|
continue;
|
|
3183
4161
|
const filesToLineRanges = filesToLines[file];
|
|
3184
4162
|
if (!filesToLineRanges)
|
|
3185
4163
|
continue;
|
|
3186
4164
|
filesToLineRanges.sort((a, b) => a - b);
|
|
3187
4165
|
const ranges = makeLineReaderRanges(filesToLineRanges);
|
|
3188
|
-
if (ranges.every((r) => rangeExistsInContentCache(
|
|
4166
|
+
if (ranges.every((r) => rangeExistsInContentCache(cacheKey, r)))
|
|
3189
4167
|
continue;
|
|
3190
|
-
const cache = emplace(LRU_FILE_CONTENTS_CACHE,
|
|
3191
|
-
readlinePromises.push(getContextLinesFromFile(file, ranges, cache));
|
|
4168
|
+
const cache = emplace(LRU_FILE_CONTENTS_CACHE, cacheKey, {});
|
|
4169
|
+
readlinePromises.push(getContextLinesFromFile(file, ranges, cache, cacheKey, openSourceFile, logger2));
|
|
3192
4170
|
}
|
|
3193
4171
|
await Promise.all(readlinePromises).catch(() => {});
|
|
3194
4172
|
if (frames && frames.length > 0)
|
|
3195
|
-
addSourceContextToFrames(frames, LRU_FILE_CONTENTS_CACHE);
|
|
4173
|
+
addSourceContextToFrames(frames, LRU_FILE_CONTENTS_CACHE, basePath);
|
|
3196
4174
|
LRU_FILE_CONTENTS_CACHE.reduce();
|
|
3197
4175
|
return frames;
|
|
3198
4176
|
}
|
|
3199
|
-
function
|
|
4177
|
+
async function openRegularSourceFile(path2, openSourceFile, logger2) {
|
|
4178
|
+
let fileHandle;
|
|
4179
|
+
let isValid = false;
|
|
4180
|
+
try {
|
|
4181
|
+
fileHandle = await openSourceFile(path2, constants3.O_RDONLY | constants3.O_NONBLOCK);
|
|
4182
|
+
const fileStat = await fileHandle.stat();
|
|
4183
|
+
if (!fileStat.isFile())
|
|
4184
|
+
return;
|
|
4185
|
+
if (fileStat.size > MAX_CONTEXTLINES_FILE_SIZE)
|
|
4186
|
+
return void logger2?.debug(`Skipping source context for oversized file ${path2}: ${fileStat.size} bytes exceeds ${MAX_CONTEXTLINES_FILE_SIZE}`);
|
|
4187
|
+
isValid = true;
|
|
4188
|
+
return fileHandle;
|
|
4189
|
+
} catch {
|
|
4190
|
+
return;
|
|
4191
|
+
} finally {
|
|
4192
|
+
if (fileHandle && !isValid)
|
|
4193
|
+
await fileHandle.close().catch(() => {});
|
|
4194
|
+
}
|
|
4195
|
+
}
|
|
4196
|
+
async function getContextLinesFromFile(path2, ranges, output, cacheKey, openSourceFile, logger2) {
|
|
4197
|
+
const fileHandle = await openRegularSourceFile(path2, openSourceFile, logger2);
|
|
4198
|
+
if (fileHandle === undefined)
|
|
4199
|
+
return void LRU_FILE_CONTENTS_FS_READ_FAILED.set(cacheKey, 1);
|
|
4200
|
+
const openedFileHandle = fileHandle;
|
|
3200
4201
|
return new Promise((resolve9) => {
|
|
3201
|
-
|
|
3202
|
-
|
|
3203
|
-
|
|
3204
|
-
|
|
3205
|
-
|
|
3206
|
-
|
|
3207
|
-
|
|
4202
|
+
let finished = false;
|
|
4203
|
+
function destroyStreamAndResolve(stream2) {
|
|
4204
|
+
if (finished)
|
|
4205
|
+
return;
|
|
4206
|
+
finished = true;
|
|
4207
|
+
stream2?.destroy();
|
|
4208
|
+
openedFileHandle.close().then(resolve9, resolve9);
|
|
4209
|
+
}
|
|
4210
|
+
let stream;
|
|
4211
|
+
try {
|
|
4212
|
+
stream = openedFileHandle.createReadStream({
|
|
4213
|
+
autoClose: false,
|
|
4214
|
+
start: 0,
|
|
4215
|
+
end: MAX_CONTEXTLINES_FILE_SIZE - 1
|
|
4216
|
+
});
|
|
4217
|
+
} catch {
|
|
4218
|
+
LRU_FILE_CONTENTS_FS_READ_FAILED.set(cacheKey, 1);
|
|
4219
|
+
destroyStreamAndResolve();
|
|
4220
|
+
return;
|
|
4221
|
+
}
|
|
4222
|
+
let lineReaded;
|
|
4223
|
+
try {
|
|
4224
|
+
lineReaded = createInterface({
|
|
4225
|
+
input: stream
|
|
4226
|
+
});
|
|
4227
|
+
} catch {
|
|
4228
|
+
LRU_FILE_CONTENTS_FS_READ_FAILED.set(cacheKey, 1);
|
|
4229
|
+
destroyStreamAndResolve(stream);
|
|
4230
|
+
return;
|
|
3208
4231
|
}
|
|
3209
4232
|
let lineNumber = 0;
|
|
3210
4233
|
let currentRangeIndex = 0;
|
|
3211
4234
|
const range = ranges[currentRangeIndex];
|
|
3212
4235
|
if (range === undefined)
|
|
3213
|
-
return void destroyStreamAndResolve();
|
|
4236
|
+
return void destroyStreamAndResolve(stream);
|
|
3214
4237
|
let rangeStart = range[0];
|
|
3215
4238
|
let rangeEnd = range[1];
|
|
3216
4239
|
function onStreamError() {
|
|
3217
|
-
LRU_FILE_CONTENTS_FS_READ_FAILED.set(
|
|
4240
|
+
LRU_FILE_CONTENTS_FS_READ_FAILED.set(cacheKey, 1);
|
|
3218
4241
|
lineReaded.close();
|
|
3219
4242
|
lineReaded.removeAllListeners();
|
|
3220
|
-
destroyStreamAndResolve();
|
|
4243
|
+
destroyStreamAndResolve(stream);
|
|
3221
4244
|
}
|
|
3222
4245
|
stream.on("error", onStreamError);
|
|
3223
4246
|
lineReaded.on("error", onStreamError);
|
|
3224
|
-
lineReaded.on("close", destroyStreamAndResolve);
|
|
4247
|
+
lineReaded.on("close", () => destroyStreamAndResolve(stream));
|
|
3225
4248
|
lineReaded.on("line", (line) => {
|
|
3226
4249
|
lineNumber++;
|
|
3227
4250
|
if (lineNumber < rangeStart)
|
|
@@ -3246,10 +4269,11 @@ function getContextLinesFromFile(path2, ranges, output) {
|
|
|
3246
4269
|
});
|
|
3247
4270
|
});
|
|
3248
4271
|
}
|
|
3249
|
-
function addSourceContextToFrames(frames, cache) {
|
|
4272
|
+
function addSourceContextToFrames(frames, cache, basePath) {
|
|
3250
4273
|
for (const frame of frames)
|
|
3251
4274
|
if (frame.filename && frame.context_line === undefined && typeof frame.lineno == "number") {
|
|
3252
|
-
const
|
|
4275
|
+
const cacheKey = makeSourceCacheKey(frame.filename, basePath);
|
|
4276
|
+
const contents = cacheKey === undefined ? undefined : cache.get(cacheKey);
|
|
3253
4277
|
if (contents === undefined)
|
|
3254
4278
|
continue;
|
|
3255
4279
|
addContextToFrame(frame.lineno, frame, contents);
|
|
@@ -3292,8 +4316,19 @@ function shouldSkipContextLinesForFrame(frame) {
|
|
|
3292
4316
|
return true;
|
|
3293
4317
|
return false;
|
|
3294
4318
|
}
|
|
3295
|
-
function
|
|
3296
|
-
|
|
4319
|
+
function makeSourceCacheKey(path2, basePath) {
|
|
4320
|
+
if (isAbsolute7(path2))
|
|
4321
|
+
return JSON.stringify([
|
|
4322
|
+
null,
|
|
4323
|
+
path2
|
|
4324
|
+
]);
|
|
4325
|
+
return basePath === undefined ? undefined : JSON.stringify([
|
|
4326
|
+
basePath,
|
|
4327
|
+
path2
|
|
4328
|
+
]);
|
|
4329
|
+
}
|
|
4330
|
+
function rangeExistsInContentCache(cacheKey, range) {
|
|
4331
|
+
const contents = LRU_FILE_CONTENTS_CACHE.get(cacheKey);
|
|
3297
4332
|
if (contents === undefined)
|
|
3298
4333
|
return false;
|
|
3299
4334
|
for (let i = range[0];i <= range[1]; i++)
|
|
@@ -3370,15 +4405,15 @@ function snipLine(line, colno) {
|
|
|
3370
4405
|
newLine += "...";
|
|
3371
4406
|
return newLine;
|
|
3372
4407
|
}
|
|
3373
|
-
var LRU_FILE_CONTENTS_CACHE, LRU_FILE_CONTENTS_FS_READ_FAILED, DEFAULT_LINES_OF_CONTEXT = 7, MAX_CONTEXTLINES_COLNO = 1000, MAX_CONTEXTLINES_LINENO = 1e4;
|
|
4408
|
+
var LRU_FILE_CONTENTS_CACHE, LRU_FILE_CONTENTS_FS_READ_FAILED, DEFAULT_LINES_OF_CONTEXT = 7, MAX_CONTEXTLINES_COLNO = 1000, MAX_CONTEXTLINES_LINENO = 1e4, MAX_CONTEXTLINES_FILE_SIZE = 10485760;
|
|
3374
4409
|
var init_context_lines_node = __esm(() => {
|
|
3375
4410
|
init_dist();
|
|
3376
4411
|
LRU_FILE_CONTENTS_CACHE = new exports_error_tracking.ReduceableCache(25);
|
|
3377
4412
|
LRU_FILE_CONTENTS_FS_READ_FAILED = new exports_error_tracking.ReduceableCache(20);
|
|
3378
4413
|
});
|
|
3379
4414
|
|
|
3380
|
-
// node_modules/.bun/posthog-node@5.
|
|
3381
|
-
import { isAbsolute as
|
|
4415
|
+
// node_modules/.bun/posthog-node@5.49.2/node_modules/posthog-node/dist/extensions/error-tracking/modifiers/relative-path.node.mjs
|
|
4416
|
+
import { isAbsolute as isAbsolute8, relative as relative4, sep as sep8 } from "node:path";
|
|
3382
4417
|
function createRelativePathModifier(basePath = process.cwd()) {
|
|
3383
4418
|
const isWindows = sep8 === "\\";
|
|
3384
4419
|
const toUnix = (p) => isWindows ? p.replace(/\\/g, "/") : p;
|
|
@@ -3386,7 +4421,7 @@ function createRelativePathModifier(basePath = process.cwd()) {
|
|
|
3386
4421
|
return async (frames) => {
|
|
3387
4422
|
for (const frame of frames)
|
|
3388
4423
|
if (!(!frame.filename || frame.filename.startsWith("node:") || frame.filename.startsWith("data:"))) {
|
|
3389
|
-
if (
|
|
4424
|
+
if (isAbsolute8(frame.filename))
|
|
3390
4425
|
frame.filename = toUnix(relative4(normalizedBase, toUnix(frame.filename)));
|
|
3391
4426
|
}
|
|
3392
4427
|
return frames;
|
|
@@ -3394,11 +4429,11 @@ function createRelativePathModifier(basePath = process.cwd()) {
|
|
|
3394
4429
|
}
|
|
3395
4430
|
var init_relative_path_node = () => {};
|
|
3396
4431
|
|
|
3397
|
-
// node_modules/.bun/posthog-node@5.
|
|
3398
|
-
var version = "5.
|
|
4432
|
+
// node_modules/.bun/posthog-node@5.49.2/node_modules/posthog-node/dist/version.mjs
|
|
4433
|
+
var version = "5.49.2";
|
|
3399
4434
|
var init_version = () => {};
|
|
3400
4435
|
|
|
3401
|
-
// node_modules/.bun/posthog-node@5.
|
|
4436
|
+
// node_modules/.bun/posthog-node@5.49.2/node_modules/posthog-node/dist/types.mjs
|
|
3402
4437
|
var FeatureFlagError2;
|
|
3403
4438
|
var init_types3 = __esm(() => {
|
|
3404
4439
|
FeatureFlagError2 = {
|
|
@@ -3409,7 +4444,7 @@ var init_types3 = __esm(() => {
|
|
|
3409
4444
|
};
|
|
3410
4445
|
});
|
|
3411
4446
|
|
|
3412
|
-
// node_modules/.bun/posthog-node@5.
|
|
4447
|
+
// node_modules/.bun/posthog-node@5.49.2/node_modules/posthog-node/dist/feature-flag-evaluations.mjs
|
|
3413
4448
|
class FeatureFlagEvaluations {
|
|
3414
4449
|
constructor(init) {
|
|
3415
4450
|
this._host = init.host;
|
|
@@ -3518,6 +4553,8 @@ class FeatureFlagEvaluations {
|
|
|
3518
4553
|
$feature_flag_request_id: this._requestId,
|
|
3519
4554
|
$feature_flag_evaluated_at: flag?.locallyEvaluated ? Date.now() : this._evaluatedAt
|
|
3520
4555
|
};
|
|
4556
|
+
if (flag?.hasExperiment !== undefined)
|
|
4557
|
+
properties.$feature_flag_has_experiment = flag.hasExperiment;
|
|
3521
4558
|
if (flag?.locallyEvaluated && this._flagDefinitionsLoadedAt !== undefined)
|
|
3522
4559
|
properties.$feature_flag_definitions_loaded_at = this._flagDefinitionsLoadedAt;
|
|
3523
4560
|
const errors = [];
|
|
@@ -3543,7 +4580,7 @@ var init_feature_flag_evaluations = __esm(() => {
|
|
|
3543
4580
|
init_types3();
|
|
3544
4581
|
});
|
|
3545
4582
|
|
|
3546
|
-
// node_modules/.bun/posthog-node@5.
|
|
4583
|
+
// node_modules/.bun/posthog-node@5.49.2/node_modules/posthog-node/dist/extensions/feature-flags/crypto.mjs
|
|
3547
4584
|
async function hashSHA1(text) {
|
|
3548
4585
|
const subtle = globalThis.crypto?.subtle;
|
|
3549
4586
|
if (!subtle)
|
|
@@ -3554,12 +4591,19 @@ async function hashSHA1(text) {
|
|
|
3554
4591
|
}
|
|
3555
4592
|
var init_crypto = () => {};
|
|
3556
4593
|
|
|
3557
|
-
// node_modules/.bun/posthog-node@5.
|
|
4594
|
+
// node_modules/.bun/posthog-node@5.49.2/node_modules/posthog-node/dist/extensions/feature-flags/feature-flags.mjs
|
|
4595
|
+
function setCustomErrorPrototype(error, constructor) {
|
|
4596
|
+
error.name = constructor.name;
|
|
4597
|
+
Error.captureStackTrace(error, constructor);
|
|
4598
|
+
Object.setPrototypeOf(error, constructor.prototype);
|
|
4599
|
+
}
|
|
4600
|
+
|
|
3558
4601
|
class FeatureFlagsPoller {
|
|
3559
4602
|
constructor({ pollingInterval, personalApiKey, projectApiKey, timeout, host, customHeaders, ...options }) {
|
|
3560
4603
|
this.debugMode = false;
|
|
3561
4604
|
this.shouldBeginExponentialBackoff = false;
|
|
3562
4605
|
this.backOffCount = 0;
|
|
4606
|
+
this.pollerStopped = false;
|
|
3563
4607
|
this.pollingInterval = pollingInterval;
|
|
3564
4608
|
this.personalApiKey = personalApiKey;
|
|
3565
4609
|
this.featureFlags = [];
|
|
@@ -3575,6 +4619,7 @@ class FeatureFlagsPoller {
|
|
|
3575
4619
|
this.onError = options.onError;
|
|
3576
4620
|
this.customHeaders = customHeaders;
|
|
3577
4621
|
this.onLoad = options.onLoad;
|
|
4622
|
+
this.onMinimalFlagCalledEvents = options.onMinimalFlagCalledEvents;
|
|
3578
4623
|
this.cacheProvider = options.cacheProvider;
|
|
3579
4624
|
this.strictLocalEvaluation = options.strictLocalEvaluation ?? false;
|
|
3580
4625
|
this.loadFeatureFlags();
|
|
@@ -3772,6 +4817,7 @@ class FeatureFlagsPoller {
|
|
|
3772
4817
|
const flagFilters = flag.filters || {};
|
|
3773
4818
|
const flagConditions = flagFilters.groups || [];
|
|
3774
4819
|
const flagAggregation = flagFilters.aggregation_group_type_index;
|
|
4820
|
+
const earlyExitEnabled = flagFilters.early_exit ?? false;
|
|
3775
4821
|
const { groups, groupProperties } = evaluationContext;
|
|
3776
4822
|
let isInconclusive = false;
|
|
3777
4823
|
let result;
|
|
@@ -3795,12 +4841,15 @@ class FeatureFlagsPoller {
|
|
|
3795
4841
|
effectiveBucketingValue = groups[groupName];
|
|
3796
4842
|
}
|
|
3797
4843
|
}
|
|
3798
|
-
|
|
4844
|
+
const matchResult = await this.isConditionMatch(flag, effectiveBucketingValue, condition, effectiveProperties, evaluationContext);
|
|
4845
|
+
if (matchResult === "match") {
|
|
3799
4846
|
const variantOverride = condition.variant;
|
|
3800
4847
|
const flagVariants = flagFilters.multivariate?.variants || [];
|
|
3801
4848
|
result = variantOverride && flagVariants.some((variant) => variant.key === variantOverride) ? variantOverride : await this.getMatchingVariant(flag, effectiveBucketingValue) || true;
|
|
3802
4849
|
break;
|
|
3803
4850
|
}
|
|
4851
|
+
if (earlyExitEnabled && matchResult === "out_of_rollout_bound")
|
|
4852
|
+
return false;
|
|
3804
4853
|
} catch (e) {
|
|
3805
4854
|
if (e instanceof RequiresServerEvaluation)
|
|
3806
4855
|
throw e;
|
|
@@ -3824,16 +4873,20 @@ class FeatureFlagsPoller {
|
|
|
3824
4873
|
for (const prop of condition.properties) {
|
|
3825
4874
|
const propertyType = prop.type;
|
|
3826
4875
|
let matches = false;
|
|
3827
|
-
|
|
4876
|
+
if (propertyType === "cohort") {
|
|
4877
|
+
const inCohort = await matchCohort(prop, properties, this.cohorts, this.debugMode, (depProp) => this.evaluateFlagDependency(depProp, properties, evaluationContext));
|
|
4878
|
+
matches = prop.operator === "not_in" ? !inCohort : inCohort;
|
|
4879
|
+
} else
|
|
4880
|
+
matches = propertyType === "flag" ? await this.evaluateFlagDependency(prop, properties, evaluationContext) : matchProperty(prop, properties, warnFunction);
|
|
3828
4881
|
if (!matches)
|
|
3829
|
-
return
|
|
4882
|
+
return "no_match";
|
|
3830
4883
|
}
|
|
3831
4884
|
if (rolloutPercentage == undefined)
|
|
3832
|
-
return
|
|
4885
|
+
return "match";
|
|
3833
4886
|
}
|
|
3834
4887
|
if (rolloutPercentage != null && await _hash(flag.key, bucketingValue) > rolloutPercentage / 100)
|
|
3835
|
-
return
|
|
3836
|
-
return
|
|
4888
|
+
return "out_of_rollout_bound";
|
|
4889
|
+
return "match";
|
|
3837
4890
|
}
|
|
3838
4891
|
async getMatchingVariant(flag, bucketingValue) {
|
|
3839
4892
|
const hashValue = await _hash(flag.key, bucketingValue, "variant");
|
|
@@ -3864,6 +4917,7 @@ class FeatureFlagsPoller {
|
|
|
3864
4917
|
this.groupTypeMapping = flagData.groupTypeMapping;
|
|
3865
4918
|
this.cohorts = flagData.cohorts;
|
|
3866
4919
|
this.loadedSuccessfullyOnce = true;
|
|
4920
|
+
this.onMinimalFlagCalledEvents?.(flagData.minimalFlagCalledEvents === true);
|
|
3867
4921
|
}
|
|
3868
4922
|
warnAboutExperienceContinuityFlags(flags) {
|
|
3869
4923
|
if (this.strictLocalEvaluation)
|
|
@@ -3927,7 +4981,6 @@ class FeatureFlagsPoller {
|
|
|
3927
4981
|
clearTimeout(this.poller);
|
|
3928
4982
|
this.poller = undefined;
|
|
3929
4983
|
}
|
|
3930
|
-
this.poller = setTimeout(() => this.loadFeatureFlags(true), this.getPollingInterval());
|
|
3931
4984
|
try {
|
|
3932
4985
|
let shouldFetch = true;
|
|
3933
4986
|
if (this.cacheProvider)
|
|
@@ -3955,17 +5008,18 @@ class FeatureFlagsPoller {
|
|
|
3955
5008
|
return;
|
|
3956
5009
|
case 401:
|
|
3957
5010
|
this.beginBackoff();
|
|
3958
|
-
throw new ClientError(`Your project key or
|
|
5011
|
+
throw new ClientError(`Your project key or secret key is invalid. Setting next polling interval to ${this.getPollingInterval()}ms. More information: https://posthog.com/docs/api#rate-limiting`);
|
|
3959
5012
|
case 402:
|
|
3960
5013
|
console.warn("[FEATURE FLAGS] Feature flags quota limit exceeded - unsetting all local flags. Learn more about billing limits at https://posthog.com/docs/billing/limits-alerts");
|
|
3961
5014
|
this.featureFlags = [];
|
|
3962
5015
|
this.featureFlagsByKey = {};
|
|
3963
5016
|
this.groupTypeMapping = {};
|
|
3964
5017
|
this.cohorts = {};
|
|
5018
|
+
this.onMinimalFlagCalledEvents?.(false);
|
|
3965
5019
|
return;
|
|
3966
5020
|
case 403:
|
|
3967
5021
|
this.beginBackoff();
|
|
3968
|
-
throw new ClientError(`Your
|
|
5022
|
+
throw new ClientError(`Your secret key does not have permission to fetch feature flag definitions for local evaluation. Setting next polling interval to ${this.getPollingInterval()}ms. Are you sure you're using the correct secret and Project API key pair? More information: https://posthog.com/docs/api/overview`);
|
|
3969
5023
|
case 429:
|
|
3970
5024
|
this.beginBackoff();
|
|
3971
5025
|
throw new ClientError(`You are being rate limited. Setting next polling interval to ${this.getPollingInterval()}ms. More information: https://posthog.com/docs/api#rate-limiting`);
|
|
@@ -3977,7 +5031,8 @@ class FeatureFlagsPoller {
|
|
|
3977
5031
|
const flagData = {
|
|
3978
5032
|
flags: responseJson.flags ?? [],
|
|
3979
5033
|
groupTypeMapping: responseJson.group_type_mapping || {},
|
|
3980
|
-
cohorts: responseJson.cohorts || {}
|
|
5034
|
+
cohorts: responseJson.cohorts || {},
|
|
5035
|
+
minimalFlagCalledEvents: responseJson.minimal_flag_called_events === true
|
|
3981
5036
|
};
|
|
3982
5037
|
this.updateFlagState(flagData);
|
|
3983
5038
|
this.flagDefinitionsLoadedAt = Date.now();
|
|
@@ -3998,6 +5053,9 @@ class FeatureFlagsPoller {
|
|
|
3998
5053
|
} catch (err) {
|
|
3999
5054
|
if (err instanceof ClientError)
|
|
4000
5055
|
this.onError?.(err);
|
|
5056
|
+
} finally {
|
|
5057
|
+
if (!this.pollerStopped)
|
|
5058
|
+
this.poller = setTimeout(() => this.loadFeatureFlags(true), this.getPollingInterval());
|
|
4001
5059
|
}
|
|
4002
5060
|
}
|
|
4003
5061
|
getPersonalApiKeyRequestOptions(method = "GET", etag) {
|
|
@@ -4013,7 +5071,7 @@ class FeatureFlagsPoller {
|
|
|
4013
5071
|
headers
|
|
4014
5072
|
};
|
|
4015
5073
|
}
|
|
4016
|
-
_requestFeatureFlagDefinitions() {
|
|
5074
|
+
async _requestFeatureFlagDefinitions() {
|
|
4017
5075
|
const url = `${this.host}/flags/definitions?token=${this.projectApiKey}&send_cohorts`;
|
|
4018
5076
|
const options = this.getPersonalApiKeyRequestOptions("GET", this.flagsEtag);
|
|
4019
5077
|
let abortTimeout = null;
|
|
@@ -4024,23 +5082,49 @@ class FeatureFlagsPoller {
|
|
|
4024
5082
|
}, this.timeout);
|
|
4025
5083
|
options.signal = controller.signal;
|
|
4026
5084
|
}
|
|
5085
|
+
const clearAbortTimeout = () => clearTimeout(abortTimeout);
|
|
4027
5086
|
try {
|
|
4028
5087
|
const fetch1 = this.fetch;
|
|
4029
|
-
|
|
4030
|
-
|
|
4031
|
-
|
|
5088
|
+
const res = await fetch1(url, options);
|
|
5089
|
+
if (res.status !== 200) {
|
|
5090
|
+
clearAbortTimeout();
|
|
5091
|
+
return res;
|
|
5092
|
+
}
|
|
5093
|
+
return {
|
|
5094
|
+
status: res.status,
|
|
5095
|
+
headers: res.headers,
|
|
5096
|
+
body: res.body,
|
|
5097
|
+
text: async () => {
|
|
5098
|
+
try {
|
|
5099
|
+
return await res.text();
|
|
5100
|
+
} finally {
|
|
5101
|
+
clearAbortTimeout();
|
|
5102
|
+
}
|
|
5103
|
+
},
|
|
5104
|
+
json: async () => {
|
|
5105
|
+
try {
|
|
5106
|
+
return await res.json();
|
|
5107
|
+
} finally {
|
|
5108
|
+
clearAbortTimeout();
|
|
5109
|
+
}
|
|
5110
|
+
}
|
|
5111
|
+
};
|
|
5112
|
+
} catch (err) {
|
|
5113
|
+
clearAbortTimeout();
|
|
5114
|
+
throw err;
|
|
4032
5115
|
}
|
|
4033
5116
|
}
|
|
4034
5117
|
async stopPoller(timeoutMs = 30000) {
|
|
5118
|
+
this.pollerStopped = true;
|
|
4035
5119
|
clearTimeout(this.poller);
|
|
5120
|
+
this.poller = undefined;
|
|
4036
5121
|
if (this.cacheProvider)
|
|
4037
5122
|
try {
|
|
4038
5123
|
const shutdownResult = this.cacheProvider.shutdown();
|
|
4039
5124
|
if (shutdownResult instanceof Promise)
|
|
4040
|
-
await
|
|
4041
|
-
|
|
4042
|
-
|
|
4043
|
-
]);
|
|
5125
|
+
await raceWithTimeout(shutdownResult, timeoutMs, () => {
|
|
5126
|
+
throw new Error(`Cache shutdown timeout after ${timeoutMs}ms`);
|
|
5127
|
+
});
|
|
4044
5128
|
} catch (err) {
|
|
4045
5129
|
this.onError?.(new Error(`Error during cache shutdown: ${err}`));
|
|
4046
5130
|
}
|
|
@@ -4095,6 +5179,14 @@ function matchProperty(property, propertyValues, warnFunction) {
|
|
|
4095
5179
|
return String(overrideValue).toLowerCase().includes(String(value).toLowerCase());
|
|
4096
5180
|
case "not_icontains":
|
|
4097
5181
|
return !String(overrideValue).toLowerCase().includes(String(value).toLowerCase());
|
|
5182
|
+
case "starts_with":
|
|
5183
|
+
return String(overrideValue).toLowerCase().startsWith(String(value).toLowerCase());
|
|
5184
|
+
case "not_starts_with":
|
|
5185
|
+
return !String(overrideValue).toLowerCase().startsWith(String(value).toLowerCase());
|
|
5186
|
+
case "ends_with":
|
|
5187
|
+
return String(overrideValue).toLowerCase().endsWith(String(value).toLowerCase());
|
|
5188
|
+
case "not_ends_with":
|
|
5189
|
+
return !String(overrideValue).toLowerCase().endsWith(String(value).toLowerCase());
|
|
4098
5190
|
case "regex":
|
|
4099
5191
|
return isValidRegex(String(value)) && String(overrideValue).match(String(value)) !== null;
|
|
4100
5192
|
case "not_regex":
|
|
@@ -4440,34 +5532,70 @@ var init_feature_flags = __esm(() => {
|
|
|
4440
5532
|
InconclusiveMatchError = class InconclusiveMatchError extends Error {
|
|
4441
5533
|
constructor(message) {
|
|
4442
5534
|
super(message);
|
|
4443
|
-
this
|
|
4444
|
-
Error.captureStackTrace(this, this.constructor);
|
|
4445
|
-
Object.setPrototypeOf(this, InconclusiveMatchError.prototype);
|
|
5535
|
+
setCustomErrorPrototype(this, InconclusiveMatchError);
|
|
4446
5536
|
}
|
|
4447
5537
|
};
|
|
4448
5538
|
RequiresServerEvaluation = class RequiresServerEvaluation extends Error {
|
|
4449
5539
|
constructor(message) {
|
|
4450
5540
|
super(message);
|
|
4451
|
-
this
|
|
4452
|
-
Error.captureStackTrace(this, this.constructor);
|
|
4453
|
-
Object.setPrototypeOf(this, RequiresServerEvaluation.prototype);
|
|
5541
|
+
setCustomErrorPrototype(this, RequiresServerEvaluation);
|
|
4454
5542
|
}
|
|
4455
5543
|
};
|
|
4456
5544
|
});
|
|
4457
5545
|
|
|
4458
|
-
// node_modules/.bun/posthog-node@5.
|
|
5546
|
+
// node_modules/.bun/posthog-node@5.49.2/node_modules/posthog-node/dist/extensions/error-tracking/autocapture.mjs
|
|
5547
|
+
function splitNodeOptions(nodeOptions) {
|
|
5548
|
+
const args = [];
|
|
5549
|
+
let current = "";
|
|
5550
|
+
let isInString = false;
|
|
5551
|
+
for (let index = 0;index < nodeOptions.length; index++) {
|
|
5552
|
+
const character = nodeOptions[index];
|
|
5553
|
+
if (character === "\\" && isInString && index + 1 < nodeOptions.length)
|
|
5554
|
+
current += nodeOptions[++index];
|
|
5555
|
+
else if (character !== " " || isInString)
|
|
5556
|
+
if (character === '"')
|
|
5557
|
+
isInString = !isInString;
|
|
5558
|
+
else
|
|
5559
|
+
current += character;
|
|
5560
|
+
else if (current) {
|
|
5561
|
+
args.push(current);
|
|
5562
|
+
current = "";
|
|
5563
|
+
}
|
|
5564
|
+
}
|
|
5565
|
+
if (current)
|
|
5566
|
+
args.push(current);
|
|
5567
|
+
return args;
|
|
5568
|
+
}
|
|
5569
|
+
function findUnhandledRejectionMode(args) {
|
|
5570
|
+
let mode;
|
|
5571
|
+
for (let index = 0;index < args.length; index++) {
|
|
5572
|
+
const argument = args[index];
|
|
5573
|
+
const optionName = UNHANDLED_REJECTION_OPTION_NAMES.find((name) => argument === name || argument.startsWith(`${name}=`));
|
|
5574
|
+
if (!optionName)
|
|
5575
|
+
continue;
|
|
5576
|
+
const value = argument === optionName ? args[++index] : argument.slice(optionName.length + 1);
|
|
5577
|
+
if (UNHANDLED_REJECTION_MODES.has(value))
|
|
5578
|
+
mode = value;
|
|
5579
|
+
}
|
|
5580
|
+
return mode;
|
|
5581
|
+
}
|
|
5582
|
+
function getUnhandledRejectionMode(execArgv = STARTUP_EXEC_ARGV, nodeOptions = STARTUP_NODE_OPTIONS) {
|
|
5583
|
+
return findUnhandledRejectionMode(execArgv) ?? findUnhandledRejectionMode(splitNodeOptions(nodeOptions ?? "")) ?? "throw";
|
|
5584
|
+
}
|
|
5585
|
+
function captureUncaughtException(captureFn, error, origin) {
|
|
5586
|
+
captureFn(error, {
|
|
5587
|
+
mechanism: {
|
|
5588
|
+
type: origin === "unhandledRejection" ? "onunhandledrejection" : "onuncaughtexception",
|
|
5589
|
+
handled: false
|
|
5590
|
+
}
|
|
5591
|
+
});
|
|
5592
|
+
}
|
|
4459
5593
|
function makeUncaughtExceptionHandler(captureFn, onFatalFn) {
|
|
4460
5594
|
let calledFatalError = false;
|
|
4461
|
-
return Object.assign((error) => {
|
|
5595
|
+
return Object.assign((error, origin) => {
|
|
4462
5596
|
const userProvidedListenersCount = global.process.listeners("uncaughtException").filter((listener) => listener.name !== "domainUncaughtExceptionClear" && listener._posthogErrorHandler !== true).length;
|
|
4463
|
-
|
|
4464
|
-
|
|
4465
|
-
mechanism: {
|
|
4466
|
-
type: "onuncaughtexception",
|
|
4467
|
-
handled: false
|
|
4468
|
-
}
|
|
4469
|
-
});
|
|
4470
|
-
if (!calledFatalError && processWouldExit) {
|
|
5597
|
+
captureUncaughtException(captureFn, error, origin);
|
|
5598
|
+
if (!calledFatalError && userProvidedListenersCount === 0) {
|
|
4471
5599
|
calledFatalError = true;
|
|
4472
5600
|
onFatalFn(error);
|
|
4473
5601
|
}
|
|
@@ -4475,28 +5603,55 @@ function makeUncaughtExceptionHandler(captureFn, onFatalFn) {
|
|
|
4475
5603
|
_posthogErrorHandler: true
|
|
4476
5604
|
});
|
|
4477
5605
|
}
|
|
4478
|
-
function addUncaughtExceptionListener(captureFn, onFatalFn) {
|
|
4479
|
-
globalThis.process
|
|
5606
|
+
function addUncaughtExceptionListener(captureFn, onFatalFn, mode = STARTUP_UNHANDLED_REJECTION_MODE) {
|
|
5607
|
+
const process2 = globalThis.process;
|
|
5608
|
+
if (!process2)
|
|
5609
|
+
return;
|
|
5610
|
+
if (mode === "strict")
|
|
5611
|
+
return void process2.on("uncaughtExceptionMonitor", (error, origin) => captureUncaughtException(captureFn, error, origin));
|
|
5612
|
+
process2.on("uncaughtException", makeUncaughtExceptionHandler(captureFn, onFatalFn));
|
|
4480
5613
|
}
|
|
4481
|
-
function addUnhandledRejectionListener(captureFn) {
|
|
4482
|
-
globalThis.process
|
|
4483
|
-
|
|
4484
|
-
|
|
4485
|
-
|
|
4486
|
-
|
|
4487
|
-
|
|
5614
|
+
function addUnhandledRejectionListener(captureFn, mode = STARTUP_UNHANDLED_REJECTION_MODE) {
|
|
5615
|
+
const process2 = globalThis.process;
|
|
5616
|
+
if (!process2 || mode === "throw" || mode === "strict" || mode === "warn-with-error-code")
|
|
5617
|
+
return;
|
|
5618
|
+
process2.on("unhandledRejection", (reason) => {
|
|
5619
|
+
captureFn(reason, {
|
|
5620
|
+
mechanism: {
|
|
5621
|
+
type: "onunhandledrejection",
|
|
5622
|
+
handled: false
|
|
5623
|
+
}
|
|
5624
|
+
});
|
|
5625
|
+
});
|
|
4488
5626
|
}
|
|
4489
|
-
var
|
|
5627
|
+
var UNHANDLED_REJECTION_OPTION_NAMES, UNHANDLED_REJECTION_MODES, STARTUP_EXEC_ARGV, STARTUP_NODE_OPTIONS, STARTUP_UNHANDLED_REJECTION_MODE;
|
|
5628
|
+
var init_autocapture = __esm(() => {
|
|
5629
|
+
UNHANDLED_REJECTION_OPTION_NAMES = [
|
|
5630
|
+
"--unhandled-rejections",
|
|
5631
|
+
"--unhandled_rejections"
|
|
5632
|
+
];
|
|
5633
|
+
UNHANDLED_REJECTION_MODES = new Set([
|
|
5634
|
+
"throw",
|
|
5635
|
+
"strict",
|
|
5636
|
+
"warn",
|
|
5637
|
+
"warn-with-error-code",
|
|
5638
|
+
"none"
|
|
5639
|
+
]);
|
|
5640
|
+
STARTUP_EXEC_ARGV = [
|
|
5641
|
+
...globalThis.process?.execArgv ?? []
|
|
5642
|
+
];
|
|
5643
|
+
STARTUP_NODE_OPTIONS = globalThis.process?.env?.NODE_OPTIONS;
|
|
5644
|
+
STARTUP_UNHANDLED_REJECTION_MODE = getUnhandledRejectionMode();
|
|
5645
|
+
});
|
|
4490
5646
|
|
|
4491
|
-
// node_modules/.bun/posthog-node@5.
|
|
4492
|
-
class
|
|
5647
|
+
// node_modules/.bun/posthog-node@5.49.2/node_modules/posthog-node/dist/extensions/error-tracking/index.mjs
|
|
5648
|
+
class error_tracking_ErrorTracking {
|
|
4493
5649
|
constructor(client, options, _logger) {
|
|
4494
5650
|
this.client = client;
|
|
4495
5651
|
this._exceptionAutocaptureEnabled = options.enableExceptionAutocapture || false;
|
|
4496
5652
|
this._logger = _logger;
|
|
4497
5653
|
this._rateLimiter = new BucketedRateLimiter({
|
|
4498
|
-
|
|
4499
|
-
bucketSize: 10,
|
|
5654
|
+
...resolveExceptionRateLimiterConfig(options),
|
|
4500
5655
|
refillInterval: 1e4,
|
|
4501
5656
|
_logger: this._logger
|
|
4502
5657
|
});
|
|
@@ -4511,6 +5666,9 @@ class ErrorTracking {
|
|
|
4511
5666
|
};
|
|
4512
5667
|
const exceptionProperties = builder.buildFromUnknown(error, hint);
|
|
4513
5668
|
exceptionProperties.$exception_list = await builder.modifyFrames(exceptionProperties.$exception_list);
|
|
5669
|
+
const injectedReleaseId = exports_error_tracking.getInjectedReleaseId();
|
|
5670
|
+
if (injectedReleaseId)
|
|
5671
|
+
properties.$release_id = injectedReleaseId;
|
|
4514
5672
|
return {
|
|
4515
5673
|
event: "$exception",
|
|
4516
5674
|
distinctId,
|
|
@@ -4529,8 +5687,8 @@ class ErrorTracking {
|
|
|
4529
5687
|
}
|
|
4530
5688
|
onException(exception, hint) {
|
|
4531
5689
|
this.client.addPendingPromise((async () => {
|
|
4532
|
-
if (!
|
|
4533
|
-
const eventMessage = await
|
|
5690
|
+
if (!error_tracking_ErrorTracking.isPreviouslyCapturedError(exception)) {
|
|
5691
|
+
const eventMessage = await error_tracking_ErrorTracking.buildEventMessage(this.client.getErrorPropertiesBuilder(), exception, hint);
|
|
4534
5692
|
const exceptionProperties = eventMessage.properties;
|
|
4535
5693
|
const exceptionType = exceptionProperties?.$exception_list[0]?.type ?? "Exception";
|
|
4536
5694
|
const isRateLimited = this._rateLimiter.consumeRateLimit(exceptionType);
|
|
@@ -4538,14 +5696,14 @@ class ErrorTracking {
|
|
|
4538
5696
|
return void this._logger.info("Skipping exception capture because of client rate limiting.", {
|
|
4539
5697
|
exception: exceptionType
|
|
4540
5698
|
});
|
|
4541
|
-
return this.client.
|
|
5699
|
+
return this.client._capturePreparedEvent(eventMessage, false);
|
|
4542
5700
|
}
|
|
4543
5701
|
})());
|
|
4544
5702
|
}
|
|
4545
5703
|
async onFatalError(exception) {
|
|
4546
5704
|
console.error(exception);
|
|
4547
5705
|
await this.client.shutdown(SHUTDOWN_TIMEOUT);
|
|
4548
|
-
process.exit(1);
|
|
5706
|
+
globalThis.process.exit(1);
|
|
4549
5707
|
}
|
|
4550
5708
|
isEnabled() {
|
|
4551
5709
|
return !this.client.isDisabled && this._exceptionAutocaptureEnabled;
|
|
@@ -4560,7 +5718,7 @@ var init_error_tracking2 = __esm(() => {
|
|
|
4560
5718
|
init_dist();
|
|
4561
5719
|
});
|
|
4562
5720
|
|
|
4563
|
-
// node_modules/.bun/posthog-node@5.
|
|
5721
|
+
// node_modules/.bun/posthog-node@5.49.2/node_modules/posthog-node/dist/storage-memory.mjs
|
|
4564
5722
|
class PostHogMemoryStorage {
|
|
4565
5723
|
getProperty(key) {
|
|
4566
5724
|
return this._memoryStorage[key];
|
|
@@ -4574,7 +5732,464 @@ class PostHogMemoryStorage {
|
|
|
4574
5732
|
}
|
|
4575
5733
|
var init_storage_memory = () => {};
|
|
4576
5734
|
|
|
4577
|
-
// node_modules/.bun/posthog-node@5.
|
|
5735
|
+
// node_modules/.bun/posthog-node@5.49.2/node_modules/posthog-node/dist/capture-v1/config.mjs
|
|
5736
|
+
function isCaptureMode(value) {
|
|
5737
|
+
return value === "v0" || value === "v1";
|
|
5738
|
+
}
|
|
5739
|
+
function resolveCaptureMode() {
|
|
5740
|
+
const envMode = typeof process != "undefined" ? process.env?.POSTHOG_CAPTURE_MODE : undefined;
|
|
5741
|
+
return isCaptureMode(envMode) ? envMode : "v0";
|
|
5742
|
+
}
|
|
5743
|
+
var init_config2 = () => {};
|
|
5744
|
+
|
|
5745
|
+
// node_modules/.bun/posthog-node@5.49.2/node_modules/posthog-node/dist/capture-v1/routing.mjs
|
|
5746
|
+
function isLegacyOnlyEvent(message) {
|
|
5747
|
+
return typeof message.event == "string" && message.event.startsWith(AI_EVENT_PREFIX);
|
|
5748
|
+
}
|
|
5749
|
+
var AI_EVENT_PREFIX = "$ai_", ANALYTICS_ROUTE = "analytics", AI_ROUTE = "ai";
|
|
5750
|
+
var init_routing = () => {};
|
|
5751
|
+
|
|
5752
|
+
// node_modules/.bun/posthog-node@5.49.2/node_modules/posthog-node/dist/capture-v1/errors.mjs
|
|
5753
|
+
var CaptureV1Error;
|
|
5754
|
+
var init_errors = __esm(() => {
|
|
5755
|
+
CaptureV1Error = class CaptureV1Error extends Error {
|
|
5756
|
+
constructor({ requestId, drops, retryExhausted, cause }) {
|
|
5757
|
+
super(CaptureV1Error.buildMessage(requestId, drops, retryExhausted, cause)), this.name = "CaptureV1Error";
|
|
5758
|
+
this.requestId = requestId;
|
|
5759
|
+
this.drops = drops;
|
|
5760
|
+
this.retryExhausted = retryExhausted;
|
|
5761
|
+
this.cause = cause;
|
|
5762
|
+
}
|
|
5763
|
+
static buildMessage(requestId, drops, retryExhausted, cause) {
|
|
5764
|
+
let message = `Capture V1 batch ${requestId} did not fully deliver: ${drops.length} dropped, ${retryExhausted.length} undelivered`;
|
|
5765
|
+
if (cause instanceof Error)
|
|
5766
|
+
message += ` (${cause.message})`;
|
|
5767
|
+
return message;
|
|
5768
|
+
}
|
|
5769
|
+
};
|
|
5770
|
+
});
|
|
5771
|
+
|
|
5772
|
+
// node_modules/.bun/posthog-node@5.49.2/node_modules/posthog-node/dist/capture-v1/transform.mjs
|
|
5773
|
+
function coerceBool(value) {
|
|
5774
|
+
if (typeof value == "boolean")
|
|
5775
|
+
return value;
|
|
5776
|
+
if (typeof value == "number")
|
|
5777
|
+
return value !== 0;
|
|
5778
|
+
if (typeof value == "string") {
|
|
5779
|
+
const normalized = value.trim().toLowerCase();
|
|
5780
|
+
if (normalized === "true" || normalized === "1")
|
|
5781
|
+
return true;
|
|
5782
|
+
if (normalized === "false" || normalized === "0")
|
|
5783
|
+
return false;
|
|
5784
|
+
}
|
|
5785
|
+
}
|
|
5786
|
+
function coerceString(value) {
|
|
5787
|
+
return typeof value == "string" ? value : undefined;
|
|
5788
|
+
}
|
|
5789
|
+
function isRecord3(value) {
|
|
5790
|
+
return typeof value == "object" && value !== null && !Array.isArray(value);
|
|
5791
|
+
}
|
|
5792
|
+
function toRfc3339(timestamp) {
|
|
5793
|
+
if (typeof timestamp == "string") {
|
|
5794
|
+
const asDate2 = new Date(timestamp);
|
|
5795
|
+
if (Number.isNaN(asDate2.getTime()))
|
|
5796
|
+
return new Date().toISOString();
|
|
5797
|
+
const normalized = asDate2.toISOString();
|
|
5798
|
+
const fractionalSeconds = timestamp.match(/\.(\d+)(?:Z|[+-]\d{2}:?\d{2})?$/i)?.[1];
|
|
5799
|
+
return fractionalSeconds && fractionalSeconds.length > 3 ? normalized.replace(/\.\d{3}Z$/, `.${fractionalSeconds}Z`) : normalized;
|
|
5800
|
+
}
|
|
5801
|
+
if (timestamp instanceof Date)
|
|
5802
|
+
return Number.isNaN(timestamp.getTime()) ? new Date().toISOString() : timestamp.toISOString();
|
|
5803
|
+
const asDate = timestamp == null ? new Date : new Date(timestamp);
|
|
5804
|
+
return Number.isNaN(asDate.getTime()) ? new Date().toISOString() : asDate.toISOString();
|
|
5805
|
+
}
|
|
5806
|
+
function relocateInto(properties, key, value) {
|
|
5807
|
+
if (value !== undefined && !(key in properties))
|
|
5808
|
+
properties[key] = value;
|
|
5809
|
+
}
|
|
5810
|
+
function buildV1Event(message) {
|
|
5811
|
+
const sourceProperties = isRecord3(message.properties) ? message.properties : {};
|
|
5812
|
+
const properties = {
|
|
5813
|
+
...sourceProperties
|
|
5814
|
+
};
|
|
5815
|
+
const options = {};
|
|
5816
|
+
for (const { property, optionKey, coerce } of OPTION_SENTINELS)
|
|
5817
|
+
if (property in properties) {
|
|
5818
|
+
const coerced = coerce(properties[property]);
|
|
5819
|
+
if (coerced !== undefined)
|
|
5820
|
+
options[optionKey] = coerced;
|
|
5821
|
+
delete properties[property];
|
|
5822
|
+
}
|
|
5823
|
+
const topLevel = {};
|
|
5824
|
+
for (const { property, field } of TOPLEVEL_SENTINELS)
|
|
5825
|
+
if (property in properties) {
|
|
5826
|
+
const value = properties[property];
|
|
5827
|
+
if (typeof value == "string")
|
|
5828
|
+
topLevel[field] = value;
|
|
5829
|
+
delete properties[property];
|
|
5830
|
+
}
|
|
5831
|
+
delete properties.$lib;
|
|
5832
|
+
delete properties.$lib_version;
|
|
5833
|
+
relocateInto(properties, "$set", message.$set);
|
|
5834
|
+
relocateInto(properties, "$set_once", message.$set_once);
|
|
5835
|
+
return {
|
|
5836
|
+
event: String(message.event ?? ""),
|
|
5837
|
+
uuid: String(message.uuid ?? ""),
|
|
5838
|
+
distinct_id: String(message.distinct_id ?? ""),
|
|
5839
|
+
timestamp: toRfc3339(message.timestamp),
|
|
5840
|
+
...topLevel,
|
|
5841
|
+
options,
|
|
5842
|
+
properties
|
|
5843
|
+
};
|
|
5844
|
+
}
|
|
5845
|
+
function buildV1Batch(messages, { createdAt, historicalMigration }) {
|
|
5846
|
+
const batch = {
|
|
5847
|
+
created_at: createdAt,
|
|
5848
|
+
batch: messages.map(buildV1Event)
|
|
5849
|
+
};
|
|
5850
|
+
if (historicalMigration)
|
|
5851
|
+
batch.historical_migration = true;
|
|
5852
|
+
return batch;
|
|
5853
|
+
}
|
|
5854
|
+
var OPTION_SENTINELS, TOPLEVEL_SENTINELS;
|
|
5855
|
+
var init_transform = __esm(() => {
|
|
5856
|
+
OPTION_SENTINELS = [
|
|
5857
|
+
{
|
|
5858
|
+
property: "$cookieless_mode",
|
|
5859
|
+
optionKey: "cookieless_mode",
|
|
5860
|
+
coerce: coerceBool
|
|
5861
|
+
},
|
|
5862
|
+
{
|
|
5863
|
+
property: "$ignore_sent_at",
|
|
5864
|
+
optionKey: "disable_skew_correction",
|
|
5865
|
+
coerce: coerceBool
|
|
5866
|
+
},
|
|
5867
|
+
{
|
|
5868
|
+
property: "$process_person_profile",
|
|
5869
|
+
optionKey: "process_person_profile",
|
|
5870
|
+
coerce: coerceBool
|
|
5871
|
+
},
|
|
5872
|
+
{
|
|
5873
|
+
property: "$product_tour_id",
|
|
5874
|
+
optionKey: "product_tour_id",
|
|
5875
|
+
coerce: coerceString
|
|
5876
|
+
}
|
|
5877
|
+
];
|
|
5878
|
+
TOPLEVEL_SENTINELS = [
|
|
5879
|
+
{
|
|
5880
|
+
property: "$session_id",
|
|
5881
|
+
field: "session_id"
|
|
5882
|
+
},
|
|
5883
|
+
{
|
|
5884
|
+
property: "$window_id",
|
|
5885
|
+
field: "window_id"
|
|
5886
|
+
}
|
|
5887
|
+
];
|
|
5888
|
+
});
|
|
5889
|
+
|
|
5890
|
+
// node_modules/.bun/posthog-node@5.49.2/node_modules/posthog-node/dist/capture-v1/sender.mjs
|
|
5891
|
+
class V1CaptureSender {
|
|
5892
|
+
constructor(config, hooks) {
|
|
5893
|
+
this.config = config;
|
|
5894
|
+
this.maxBackoffMs = config.maxBackoffMs ?? DEFAULT_MAX_BACKOFF_MS;
|
|
5895
|
+
this.fetchFn = hooks.fetch;
|
|
5896
|
+
this.onError = hooks.onError;
|
|
5897
|
+
this.now = hooks.now ?? Date.now;
|
|
5898
|
+
this.sleep = hooks.sleep ?? ((ms) => new Promise((resolve9) => safeSetTimeout(resolve9, ms)));
|
|
5899
|
+
this.generateRequestId = hooks.generateRequestId ?? uuidv7;
|
|
5900
|
+
this.compress = hooks.compress ?? gzipCompress;
|
|
5901
|
+
}
|
|
5902
|
+
async sendV1Batch(messages) {
|
|
5903
|
+
if (messages.length === 0)
|
|
5904
|
+
return;
|
|
5905
|
+
const requestId = this.generateRequestId();
|
|
5906
|
+
const createdAt = new Date(this.now()).toISOString();
|
|
5907
|
+
const { batch } = buildV1Batch(messages, {
|
|
5908
|
+
createdAt,
|
|
5909
|
+
historicalMigration: this.config.historicalMigration
|
|
5910
|
+
});
|
|
5911
|
+
const url = `${this.config.host}${V1_ANALYTICS_PATH}`;
|
|
5912
|
+
const drops = [];
|
|
5913
|
+
let pending = batch;
|
|
5914
|
+
const maxAttempts = Math.max(1, this.config.maxAttempts);
|
|
5915
|
+
for (let attempt = 1;attempt <= maxAttempts; attempt++) {
|
|
5916
|
+
const isLastAttempt = attempt === maxAttempts;
|
|
5917
|
+
const payload = safeJsonStringify({
|
|
5918
|
+
created_at: createdAt,
|
|
5919
|
+
...this.config.historicalMigration ? {
|
|
5920
|
+
historical_migration: true
|
|
5921
|
+
} : {},
|
|
5922
|
+
batch: pending
|
|
5923
|
+
});
|
|
5924
|
+
let captureAttempt;
|
|
5925
|
+
let retryDelayMs;
|
|
5926
|
+
try {
|
|
5927
|
+
captureAttempt = await this.sendOnce(url, payload, attempt, requestId);
|
|
5928
|
+
const { response, signal } = captureAttempt;
|
|
5929
|
+
const { status } = response;
|
|
5930
|
+
if (status < 200 || status >= 300)
|
|
5931
|
+
if (!isLastAttempt && RETRYABLE_STATUSES.has(status)) {
|
|
5932
|
+
const retryAfterMs = this.parseRetryAfter(response);
|
|
5933
|
+
await captureAttempt.waitFor(captureAttempt.cancelBody()).catch(() => {});
|
|
5934
|
+
retryDelayMs = this.backoffDelay(attempt, retryAfterMs);
|
|
5935
|
+
} else {
|
|
5936
|
+
const httpError = await this.buildHttpError(response, status, captureAttempt.waitFor);
|
|
5937
|
+
return this.surfaceBatchFailure(requestId, drops, pending, httpError);
|
|
5938
|
+
}
|
|
5939
|
+
else {
|
|
5940
|
+
let parsed;
|
|
5941
|
+
try {
|
|
5942
|
+
parsed = await captureAttempt.waitFor(this.parseResponse(response));
|
|
5943
|
+
} catch (error) {
|
|
5944
|
+
if (signal.aborted)
|
|
5945
|
+
throw error;
|
|
5946
|
+
return this.surfaceBatchFailure(requestId, drops, pending, new Error(`Capture V1 returned an unparseable ${status} response body`));
|
|
5947
|
+
}
|
|
5948
|
+
const retryable = this.classify(pending, parsed, drops);
|
|
5949
|
+
if (retryable.length === 0)
|
|
5950
|
+
return this.surfacePartialDrops(requestId, drops);
|
|
5951
|
+
if (isLastAttempt)
|
|
5952
|
+
return void this.onError(new CaptureV1Error({
|
|
5953
|
+
requestId,
|
|
5954
|
+
drops,
|
|
5955
|
+
retryExhausted: retryable.map((event) => event.uuid)
|
|
5956
|
+
}));
|
|
5957
|
+
pending = retryable;
|
|
5958
|
+
const retryAfterMs = this.parseRetryAfter(response);
|
|
5959
|
+
retryDelayMs = this.backoffDelay(attempt, retryAfterMs);
|
|
5960
|
+
}
|
|
5961
|
+
} catch (transportError) {
|
|
5962
|
+
if (captureAttempt && !captureAttempt.signal.aborted)
|
|
5963
|
+
throw transportError;
|
|
5964
|
+
if (isLastAttempt)
|
|
5965
|
+
return this.surfaceBatchFailure(requestId, drops, pending, transportError);
|
|
5966
|
+
retryDelayMs = this.backoffDelay(attempt);
|
|
5967
|
+
} finally {
|
|
5968
|
+
captureAttempt?.cleanup();
|
|
5969
|
+
}
|
|
5970
|
+
if (retryDelayMs !== undefined)
|
|
5971
|
+
await this.sleep(retryDelayMs);
|
|
5972
|
+
}
|
|
5973
|
+
}
|
|
5974
|
+
async sendOnce(url, payload, attempt, requestId) {
|
|
5975
|
+
const headers = this.buildHeaders(attempt, requestId);
|
|
5976
|
+
let body = payload;
|
|
5977
|
+
if (this.config.compressionEnabled) {
|
|
5978
|
+
const compressed = await this.compress(payload, this.config.isDebug);
|
|
5979
|
+
if (compressed !== null) {
|
|
5980
|
+
body = compressed;
|
|
5981
|
+
headers["Content-Encoding"] = "gzip";
|
|
5982
|
+
}
|
|
5983
|
+
}
|
|
5984
|
+
const controller = new AbortController;
|
|
5985
|
+
let timeoutPhase = "waiting for response headers";
|
|
5986
|
+
let timer;
|
|
5987
|
+
const deadline = new Promise((_resolve, reject) => {
|
|
5988
|
+
timer = safeSetTimeout(() => {
|
|
5989
|
+
const timeoutError = new Error(`Capture V1 request timed out ${timeoutPhase} after ${this.config.requestTimeoutMs}ms`);
|
|
5990
|
+
timeoutError.name = "AbortError";
|
|
5991
|
+
reject(timeoutError);
|
|
5992
|
+
controller.abort(timeoutError);
|
|
5993
|
+
}, this.config.requestTimeoutMs);
|
|
5994
|
+
});
|
|
5995
|
+
try {
|
|
5996
|
+
const fetchPromise = this.fetchFn(url, {
|
|
5997
|
+
method: "POST",
|
|
5998
|
+
headers,
|
|
5999
|
+
body,
|
|
6000
|
+
signal: controller.signal
|
|
6001
|
+
});
|
|
6002
|
+
let responseAccepted = false;
|
|
6003
|
+
fetchPromise.then((lateResponse) => {
|
|
6004
|
+
if (controller.signal.aborted && !responseAccepted)
|
|
6005
|
+
this.cancelBody(lateResponse);
|
|
6006
|
+
}).catch(() => {});
|
|
6007
|
+
const response = await Promise.race([
|
|
6008
|
+
fetchPromise,
|
|
6009
|
+
deadline
|
|
6010
|
+
]);
|
|
6011
|
+
responseAccepted = true;
|
|
6012
|
+
timeoutPhase = "while reading the response body";
|
|
6013
|
+
let cleanedUp = false;
|
|
6014
|
+
let cancellation;
|
|
6015
|
+
const cancelBody = () => cancellation ??= this.cancelBody(response);
|
|
6016
|
+
return {
|
|
6017
|
+
response,
|
|
6018
|
+
signal: controller.signal,
|
|
6019
|
+
waitFor: (operation) => Promise.race([
|
|
6020
|
+
operation,
|
|
6021
|
+
deadline
|
|
6022
|
+
]),
|
|
6023
|
+
cancelBody,
|
|
6024
|
+
cleanup: () => {
|
|
6025
|
+
if (cleanedUp)
|
|
6026
|
+
return;
|
|
6027
|
+
cleanedUp = true;
|
|
6028
|
+
clearTimeout(timer);
|
|
6029
|
+
if (controller.signal.aborted)
|
|
6030
|
+
cancelBody();
|
|
6031
|
+
}
|
|
6032
|
+
};
|
|
6033
|
+
} catch (error) {
|
|
6034
|
+
clearTimeout(timer);
|
|
6035
|
+
throw error;
|
|
6036
|
+
}
|
|
6037
|
+
}
|
|
6038
|
+
buildHeaders(attempt, requestId) {
|
|
6039
|
+
const sdkInfo = `${this.config.libraryId}/${this.config.libraryVersion}`;
|
|
6040
|
+
const headers = {
|
|
6041
|
+
"Content-Type": "application/json",
|
|
6042
|
+
Authorization: `Bearer ${this.config.apiKey}`,
|
|
6043
|
+
"PostHog-Sdk-Info": sdkInfo,
|
|
6044
|
+
"PostHog-Attempt": String(attempt),
|
|
6045
|
+
"PostHog-Request-Id": requestId,
|
|
6046
|
+
"PostHog-Request-Timestamp": new Date(this.now()).toISOString()
|
|
6047
|
+
};
|
|
6048
|
+
if (this.config.userAgent)
|
|
6049
|
+
headers["User-Agent"] = this.config.userAgent;
|
|
6050
|
+
return headers;
|
|
6051
|
+
}
|
|
6052
|
+
classify(pending, parsed, drops) {
|
|
6053
|
+
const results = parsed.results ?? {};
|
|
6054
|
+
const retryable = [];
|
|
6055
|
+
for (const event of pending) {
|
|
6056
|
+
const result = results[event.uuid];
|
|
6057
|
+
if (result) {
|
|
6058
|
+
if (result.result === "drop")
|
|
6059
|
+
drops.push({
|
|
6060
|
+
uuid: event.uuid,
|
|
6061
|
+
details: result.details ?? undefined
|
|
6062
|
+
});
|
|
6063
|
+
else if (result.result === "retry")
|
|
6064
|
+
retryable.push(event);
|
|
6065
|
+
}
|
|
6066
|
+
}
|
|
6067
|
+
return retryable;
|
|
6068
|
+
}
|
|
6069
|
+
backoffDelay(attempt, retryAfterMs) {
|
|
6070
|
+
const exponential = Math.min(this.config.initialRetryDelayMs * 2 ** (attempt - 1), this.maxBackoffMs);
|
|
6071
|
+
if (retryAfterMs === undefined)
|
|
6072
|
+
return exponential;
|
|
6073
|
+
return Math.max(exponential, Math.min(retryAfterMs, this.maxBackoffMs));
|
|
6074
|
+
}
|
|
6075
|
+
parseRetryAfter(response) {
|
|
6076
|
+
const raw = response.headers?.get("Retry-After");
|
|
6077
|
+
if (!raw)
|
|
6078
|
+
return;
|
|
6079
|
+
const trimmed = raw.trim();
|
|
6080
|
+
if (/^\d+$/.test(trimmed)) {
|
|
6081
|
+
const seconds = parseInt(trimmed, 10);
|
|
6082
|
+
return Number.isFinite(seconds) && seconds > 0 ? 1000 * seconds : undefined;
|
|
6083
|
+
}
|
|
6084
|
+
const dateMs = Date.parse(trimmed);
|
|
6085
|
+
if (Number.isNaN(dateMs))
|
|
6086
|
+
return;
|
|
6087
|
+
const delta = dateMs - this.now();
|
|
6088
|
+
return delta > 0 ? delta : undefined;
|
|
6089
|
+
}
|
|
6090
|
+
async parseResponse(response) {
|
|
6091
|
+
const text = await response.text();
|
|
6092
|
+
const parsed = JSON.parse(text);
|
|
6093
|
+
if (typeof parsed != "object" || parsed === null || Array.isArray(parsed))
|
|
6094
|
+
throw new Error("unexpected response shape");
|
|
6095
|
+
const results = parsed.results;
|
|
6096
|
+
if (results !== undefined && (typeof results != "object" || results === null || Array.isArray(results)))
|
|
6097
|
+
throw new Error("unexpected results shape");
|
|
6098
|
+
return {
|
|
6099
|
+
results: results ?? {}
|
|
6100
|
+
};
|
|
6101
|
+
}
|
|
6102
|
+
async buildHttpError(response, status, waitFor) {
|
|
6103
|
+
let bodyText = "";
|
|
6104
|
+
try {
|
|
6105
|
+
bodyText = (await waitFor(response.text())).slice(0, 512);
|
|
6106
|
+
} catch {}
|
|
6107
|
+
const suffix = bodyText ? `: ${bodyText}` : "";
|
|
6108
|
+
return new Error(`Capture V1 request failed with HTTP ${status}${suffix}`);
|
|
6109
|
+
}
|
|
6110
|
+
surfaceBatchFailure(requestId, drops, pending, cause) {
|
|
6111
|
+
this.onError(new CaptureV1Error({
|
|
6112
|
+
requestId,
|
|
6113
|
+
drops,
|
|
6114
|
+
retryExhausted: pending.map((event) => event.uuid),
|
|
6115
|
+
cause
|
|
6116
|
+
}));
|
|
6117
|
+
}
|
|
6118
|
+
surfacePartialDrops(requestId, drops) {
|
|
6119
|
+
if (drops.length > 0)
|
|
6120
|
+
this.onError(new CaptureV1Error({
|
|
6121
|
+
requestId,
|
|
6122
|
+
drops,
|
|
6123
|
+
retryExhausted: []
|
|
6124
|
+
}));
|
|
6125
|
+
}
|
|
6126
|
+
async cancelBody(response) {
|
|
6127
|
+
try {
|
|
6128
|
+
await response.body?.cancel();
|
|
6129
|
+
} catch {}
|
|
6130
|
+
}
|
|
6131
|
+
}
|
|
6132
|
+
var V1_ANALYTICS_PATH = "/i/v1/analytics/events", DEFAULT_MAX_BACKOFF_MS = 30000, RETRYABLE_STATUSES;
|
|
6133
|
+
var init_sender = __esm(() => {
|
|
6134
|
+
init_dist();
|
|
6135
|
+
init_errors();
|
|
6136
|
+
init_transform();
|
|
6137
|
+
RETRYABLE_STATUSES = new Set([
|
|
6138
|
+
408,
|
|
6139
|
+
500,
|
|
6140
|
+
502,
|
|
6141
|
+
503,
|
|
6142
|
+
504
|
|
6143
|
+
]);
|
|
6144
|
+
});
|
|
6145
|
+
|
|
6146
|
+
// node_modules/.bun/posthog-node@5.49.2/node_modules/posthog-node/dist/ai-capture/routing.mjs
|
|
6147
|
+
var AI_CAPTURE_ROUTE = "ai-capture", AI_CAPTURE_ENDPOINT_PATH = "/i/v0/ai/batch/", AI_MAX_EVENT_BYTES = 8388608, AI_BATCH_TARGET_BYTES = 5242880;
|
|
6148
|
+
var init_routing2 = () => {};
|
|
6149
|
+
|
|
6150
|
+
// node_modules/.bun/posthog-node@5.49.2/node_modules/posthog-node/dist/ai-capture/batching.mjs
|
|
6151
|
+
function eventByteSize(message) {
|
|
6152
|
+
return encoder.encode(safeJsonStringify(message)).length;
|
|
6153
|
+
}
|
|
6154
|
+
function partitionAiBatch(messages, maxEventBytes = AI_MAX_EVENT_BYTES, targetBatchBytes = AI_BATCH_TARGET_BYTES) {
|
|
6155
|
+
const batches = [];
|
|
6156
|
+
const dropped = [];
|
|
6157
|
+
let current = [];
|
|
6158
|
+
let currentBytes = 0;
|
|
6159
|
+
for (const message of messages) {
|
|
6160
|
+
if (message === undefined)
|
|
6161
|
+
continue;
|
|
6162
|
+
const bytes = eventByteSize(message);
|
|
6163
|
+
if (bytes > maxEventBytes) {
|
|
6164
|
+
dropped.push({
|
|
6165
|
+
event: typeof message.event == "string" ? message.event : "unknown",
|
|
6166
|
+
bytes
|
|
6167
|
+
});
|
|
6168
|
+
continue;
|
|
6169
|
+
}
|
|
6170
|
+
if (current.length > 0 && currentBytes + bytes > targetBatchBytes) {
|
|
6171
|
+
batches.push(current);
|
|
6172
|
+
current = [];
|
|
6173
|
+
currentBytes = 0;
|
|
6174
|
+
}
|
|
6175
|
+
current.push(message);
|
|
6176
|
+
currentBytes += bytes;
|
|
6177
|
+
}
|
|
6178
|
+
if (current.length > 0)
|
|
6179
|
+
batches.push(current);
|
|
6180
|
+
return {
|
|
6181
|
+
batches,
|
|
6182
|
+
dropped
|
|
6183
|
+
};
|
|
6184
|
+
}
|
|
6185
|
+
var encoder;
|
|
6186
|
+
var init_batching = __esm(() => {
|
|
6187
|
+
init_dist();
|
|
6188
|
+
init_routing2();
|
|
6189
|
+
encoder = new TextEncoder;
|
|
6190
|
+
});
|
|
6191
|
+
|
|
6192
|
+
// node_modules/.bun/posthog-node@5.49.2/node_modules/posthog-node/dist/client.mjs
|
|
4578
6193
|
function emitDeprecationWarningOnce(id, message) {
|
|
4579
6194
|
if (_emittedDeprecations.has(id))
|
|
4580
6195
|
return;
|
|
@@ -4592,6 +6207,12 @@ function normalizeHost(value) {
|
|
|
4592
6207
|
const normalizedValue = typeof value == "string" ? value.trim() : "";
|
|
4593
6208
|
return normalizedValue || DEFAULT_NODE_HOST;
|
|
4594
6209
|
}
|
|
6210
|
+
function normalizeUnsetPersonProperties(value) {
|
|
6211
|
+
const propertyNames = Array.isArray(value) ? value : [
|
|
6212
|
+
value
|
|
6213
|
+
];
|
|
6214
|
+
return propertyNames.filter((propertyName) => typeof propertyName == "string" && propertyName.trim().length > 0);
|
|
6215
|
+
}
|
|
4595
6216
|
function buildFlagEventProperties(flagValues) {
|
|
4596
6217
|
if (!flagValues)
|
|
4597
6218
|
return {};
|
|
@@ -4612,17 +6233,26 @@ var init_client = __esm(() => {
|
|
|
4612
6233
|
init_feature_flags();
|
|
4613
6234
|
init_error_tracking2();
|
|
4614
6235
|
init_storage_memory();
|
|
6236
|
+
init_config2();
|
|
6237
|
+
init_routing();
|
|
6238
|
+
init_sender();
|
|
6239
|
+
init_batching();
|
|
6240
|
+
init_routing2();
|
|
4615
6241
|
_emittedDeprecations = new Set;
|
|
4616
6242
|
PostHogBackendClient = class PostHogBackendClient extends PostHogCoreStateless {
|
|
4617
6243
|
constructor(apiKey, options = {}) {
|
|
4618
6244
|
const normalizedApiKey = normalizeApiKey(apiKey);
|
|
4619
6245
|
const normalizedOptions = {
|
|
4620
6246
|
...options,
|
|
6247
|
+
maxQueueSize: options.maxQueueSize ?? 1e4,
|
|
6248
|
+
flushInterval: options.flushInterval ?? 5000,
|
|
4621
6249
|
host: normalizeHost(options.host),
|
|
4622
|
-
personalApiKey: normalizePersonalApiKey(options.personalApiKey)
|
|
6250
|
+
personalApiKey: normalizePersonalApiKey(options.secretKey ?? options.personalApiKey)
|
|
4623
6251
|
};
|
|
4624
|
-
super(normalizedApiKey, normalizedOptions), this._memoryStorage = new PostHogMemoryStorage;
|
|
6252
|
+
super(normalizedApiKey, normalizedOptions), this._memoryStorage = new PostHogMemoryStorage, this._aiCaptureRouteActive = false, this._minimalFlagCalledEvents = false;
|
|
4625
6253
|
this.options = normalizedOptions;
|
|
6254
|
+
this.captureMode = resolveCaptureMode();
|
|
6255
|
+
this.enableFullAiCapture = normalizedOptions.enableFullAiCapture === true;
|
|
4626
6256
|
this.context = this.initializeContext();
|
|
4627
6257
|
this.options.featureFlagsPollingInterval = typeof normalizedOptions.featureFlagsPollingInterval == "number" ? Math.max(normalizedOptions.featureFlagsPollingInterval, MINIMUM_POLLING_INTERVAL) : THIRTY_SECONDS;
|
|
4628
6258
|
if (typeof normalizedOptions.waitUntilDebounceMs == "number")
|
|
@@ -4647,21 +6277,24 @@ var init_client = __esm(() => {
|
|
|
4647
6277
|
onLoad: (count) => {
|
|
4648
6278
|
this._events.emit("localEvaluationFlagsLoaded", count);
|
|
4649
6279
|
},
|
|
6280
|
+
onMinimalFlagCalledEvents: (enabled) => {
|
|
6281
|
+
this._minimalFlagCalledEvents = enabled;
|
|
6282
|
+
},
|
|
4650
6283
|
customHeaders: this.getCustomHeaders(),
|
|
4651
6284
|
cacheProvider: normalizedOptions.flagDefinitionCacheProvider,
|
|
4652
6285
|
strictLocalEvaluation: normalizedOptions.strictLocalEvaluation
|
|
4653
6286
|
});
|
|
4654
6287
|
}
|
|
4655
|
-
this.errorTracking = new
|
|
6288
|
+
this.errorTracking = new error_tracking_ErrorTracking(this, normalizedOptions, this._logger);
|
|
4656
6289
|
this.distinctIdHasSentFlagCalls = {};
|
|
4657
6290
|
this.maxCacheSize = normalizedOptions.maxCacheSize || MAX_CACHE_SIZE;
|
|
4658
6291
|
}
|
|
4659
|
-
enqueue(type, message, options) {
|
|
4660
|
-
super.enqueue(type, message, options);
|
|
6292
|
+
enqueue(type, message, options, explicitRoute) {
|
|
6293
|
+
super.enqueue(type, message, options, explicitRoute);
|
|
4661
6294
|
this.scheduleDebouncedFlush();
|
|
4662
6295
|
}
|
|
4663
6296
|
async flush() {
|
|
4664
|
-
const flushPromise =
|
|
6297
|
+
const flushPromise = this.flushWithPendingPromises();
|
|
4665
6298
|
const waitUntil = this.options.waitUntil;
|
|
4666
6299
|
if (waitUntil && !this._waitUntilCycle)
|
|
4667
6300
|
try {
|
|
@@ -4714,7 +6347,7 @@ var init_client = __esm(() => {
|
|
|
4714
6347
|
async resolveWaitUntilFlush() {
|
|
4715
6348
|
const resolve9 = this._consumeWaitUntilCycle();
|
|
4716
6349
|
try {
|
|
4717
|
-
await
|
|
6350
|
+
await this.flushWithPendingPromises();
|
|
4718
6351
|
} catch {} finally {
|
|
4719
6352
|
resolve9?.();
|
|
4720
6353
|
}
|
|
@@ -4728,12 +6361,103 @@ var init_client = __esm(() => {
|
|
|
4728
6361
|
fetch(url, options) {
|
|
4729
6362
|
return this.options.fetch ? this.options.fetch(url, options) : fetch(url, options);
|
|
4730
6363
|
}
|
|
6364
|
+
getQueueRouteKey(message) {
|
|
6365
|
+
return this.captureMode === "v1" && isLegacyOnlyEvent(message) ? AI_ROUTE : ANALYTICS_ROUTE;
|
|
6366
|
+
}
|
|
6367
|
+
persistedQueueKeyForRoute(route) {
|
|
6368
|
+
if (route === AI_CAPTURE_ROUTE)
|
|
6369
|
+
return types_PostHogPersistedProperty.AiCaptureQueue;
|
|
6370
|
+
return route === AI_ROUTE ? types_PostHogPersistedProperty.AiQueue : types_PostHogPersistedProperty.Queue;
|
|
6371
|
+
}
|
|
6372
|
+
getActiveQueueRoutes() {
|
|
6373
|
+
const routes = this.captureMode === "v1" ? [
|
|
6374
|
+
ANALYTICS_ROUTE,
|
|
6375
|
+
AI_ROUTE
|
|
6376
|
+
] : [
|
|
6377
|
+
ANALYTICS_ROUTE
|
|
6378
|
+
];
|
|
6379
|
+
if (this._aiCaptureRouteActive)
|
|
6380
|
+
routes.push(AI_CAPTURE_ROUTE);
|
|
6381
|
+
return routes;
|
|
6382
|
+
}
|
|
6383
|
+
getBatchEndpointPath(route) {
|
|
6384
|
+
return route === AI_CAPTURE_ROUTE ? AI_CAPTURE_ENDPOINT_PATH : super.getBatchEndpointPath(route);
|
|
6385
|
+
}
|
|
6386
|
+
async sendBatch(batchMessages, retryOptions, route = ANALYTICS_ROUTE) {
|
|
6387
|
+
if (route === AI_CAPTURE_ROUTE)
|
|
6388
|
+
return this.sendAiCaptureBatch(batchMessages, retryOptions);
|
|
6389
|
+
if (this.captureMode !== "v1" || route === AI_ROUTE)
|
|
6390
|
+
return super.sendBatch(batchMessages, retryOptions, route);
|
|
6391
|
+
const v1Events = batchMessages.filter((message) => message !== undefined);
|
|
6392
|
+
await this.getV1Sender().sendV1Batch(v1Events);
|
|
6393
|
+
}
|
|
6394
|
+
async sendAiCaptureBatch(batchMessages, retryOptions) {
|
|
6395
|
+
const { batches, dropped } = partitionAiBatch(batchMessages);
|
|
6396
|
+
for (const { event, bytes } of dropped) {
|
|
6397
|
+
const message = `Event ${event} (${bytes} bytes) exceeds the ${AI_MAX_EVENT_BYTES / 1048576}MiB limit for ${AI_CAPTURE_ENDPOINT_PATH}, dropping.`;
|
|
6398
|
+
this._logger.error(message);
|
|
6399
|
+
this._events.emit("error", new Error(message));
|
|
6400
|
+
}
|
|
6401
|
+
for (const batch of batches)
|
|
6402
|
+
await this.sendAiSubBatch(batch, retryOptions);
|
|
6403
|
+
}
|
|
6404
|
+
async sendAiSubBatch(batch, retryOptions) {
|
|
6405
|
+
try {
|
|
6406
|
+
await super.sendBatch(batch, retryOptions, AI_CAPTURE_ROUTE);
|
|
6407
|
+
} catch (err) {
|
|
6408
|
+
if (!isPostHogFetchContentTooLargeError(err))
|
|
6409
|
+
throw err;
|
|
6410
|
+
if (batch.length === 1) {
|
|
6411
|
+
const [event] = batch;
|
|
6412
|
+
const eventName = typeof event.event == "string" ? event.event : "unknown";
|
|
6413
|
+
const message = `Event ${eventName} (${eventByteSize(event)} bytes) was rejected with 413 by ${AI_CAPTURE_ENDPOINT_PATH} on its own, dropping.`;
|
|
6414
|
+
this._logger.error(message);
|
|
6415
|
+
this._events.emit("error", new Error(message));
|
|
6416
|
+
return;
|
|
6417
|
+
}
|
|
6418
|
+
const mid = Math.ceil(batch.length / 2);
|
|
6419
|
+
await this.sendAiSubBatch(batch.slice(0, mid), retryOptions);
|
|
6420
|
+
await this.sendAiSubBatch(batch.slice(mid), retryOptions);
|
|
6421
|
+
}
|
|
6422
|
+
}
|
|
6423
|
+
getV1Sender() {
|
|
6424
|
+
if (!this._v1Sender)
|
|
6425
|
+
this._v1Sender = new V1CaptureSender({
|
|
6426
|
+
host: this.host,
|
|
6427
|
+
apiKey: this.apiKey,
|
|
6428
|
+
libraryId: this.getLibraryId(),
|
|
6429
|
+
libraryVersion: this.getLibraryVersion(),
|
|
6430
|
+
userAgent: this.getCustomUserAgent() || undefined,
|
|
6431
|
+
historicalMigration: this.historicalMigration,
|
|
6432
|
+
compressionEnabled: !this.disableCompression,
|
|
6433
|
+
requestTimeoutMs: this.requestTimeout,
|
|
6434
|
+
maxAttempts: (this.options.fetchRetryCount ?? 3) + 1,
|
|
6435
|
+
initialRetryDelayMs: this.options.fetchRetryDelay ?? 3000,
|
|
6436
|
+
isDebug: this.isDebug
|
|
6437
|
+
}, {
|
|
6438
|
+
fetch: (url, fetchOptions) => this.fetch(url, fetchOptions),
|
|
6439
|
+
onError: (error) => this._events.emit("error", error),
|
|
6440
|
+
compress: (payload) => this.compressPayload(payload)
|
|
6441
|
+
});
|
|
6442
|
+
return this._v1Sender;
|
|
6443
|
+
}
|
|
4731
6444
|
getLibraryVersion() {
|
|
4732
6445
|
return version;
|
|
4733
6446
|
}
|
|
6447
|
+
get metrics() {
|
|
6448
|
+
if (!this._metrics)
|
|
6449
|
+
this._metrics = new PostHogMetrics(this, resolveMetricsConfig(this.options.metrics), this._logger);
|
|
6450
|
+
return this._metrics;
|
|
6451
|
+
}
|
|
4734
6452
|
getCustomUserAgent() {
|
|
4735
6453
|
return `${this.getLibraryId()}/${this.getLibraryVersion()}`;
|
|
4736
6454
|
}
|
|
6455
|
+
getCommonEventProperties() {
|
|
6456
|
+
const commonProperties = super.getCommonEventProperties();
|
|
6457
|
+
if (this.options.isServer ?? true)
|
|
6458
|
+
commonProperties.$is_server = true;
|
|
6459
|
+
return commonProperties;
|
|
6460
|
+
}
|
|
4737
6461
|
enable() {
|
|
4738
6462
|
return super.optIn();
|
|
4739
6463
|
}
|
|
@@ -4744,33 +6468,69 @@ var init_client = __esm(() => {
|
|
|
4744
6468
|
super.debug(enabled);
|
|
4745
6469
|
this.featureFlagsPoller?.debug(enabled);
|
|
4746
6470
|
}
|
|
4747
|
-
|
|
6471
|
+
_warnIfInvalidCapture(props, stringArgumentWarning, exceptionCaptureWarning) {
|
|
4748
6472
|
if (typeof props == "string")
|
|
4749
|
-
this._logger.warn(
|
|
6473
|
+
this._logger.warn(stringArgumentWarning);
|
|
4750
6474
|
if (props.event === "$exception" && !props._originatedFromCaptureException)
|
|
4751
|
-
this._logger.warn(
|
|
4752
|
-
|
|
4753
|
-
|
|
4754
|
-
|
|
4755
|
-
|
|
4756
|
-
|
|
6475
|
+
this._logger.warn(exceptionCaptureWarning);
|
|
6476
|
+
}
|
|
6477
|
+
_sendPreparedEvent(type, props, immediate, prepareOptions, explicitRoute) {
|
|
6478
|
+
return this.addPendingPromise(this._prepareEventMessage(props, prepareOptions).then(({ distinctId, event, properties, options }) => {
|
|
6479
|
+
const captureOptions = {
|
|
6480
|
+
timestamp: options.timestamp,
|
|
6481
|
+
disableGeoip: options.disableGeoip,
|
|
6482
|
+
uuid: options.uuid
|
|
6483
|
+
};
|
|
6484
|
+
const message = {
|
|
6485
|
+
distinctId,
|
|
6486
|
+
event,
|
|
6487
|
+
properties: {
|
|
6488
|
+
...properties,
|
|
6489
|
+
...this.getCommonEventProperties()
|
|
6490
|
+
}
|
|
6491
|
+
};
|
|
6492
|
+
return immediate ? this.sendImmediate(type, message, captureOptions, explicitRoute) : this.enqueue(type, message, captureOptions, explicitRoute);
|
|
6493
|
+
}).catch((err) => {
|
|
4757
6494
|
if (err)
|
|
4758
6495
|
console.error(err);
|
|
4759
6496
|
}));
|
|
4760
6497
|
}
|
|
6498
|
+
_capturePreparedEvent(props, immediate) {
|
|
6499
|
+
return this._sendPreparedEvent("capture", props, immediate);
|
|
6500
|
+
}
|
|
6501
|
+
capture(props) {
|
|
6502
|
+
this._warnIfInvalidCapture(props, "Called capture() with a string as the first argument when an object was expected.", "Using `posthog.capture('$exception')` is unreliable because it does not attach required metadata. Use `posthog.captureException(error)` instead, which attaches required metadata automatically.");
|
|
6503
|
+
this._capturePreparedEvent(props, false);
|
|
6504
|
+
}
|
|
4761
6505
|
async captureImmediate(props) {
|
|
4762
|
-
|
|
4763
|
-
|
|
4764
|
-
|
|
4765
|
-
|
|
4766
|
-
|
|
4767
|
-
|
|
4768
|
-
|
|
4769
|
-
|
|
4770
|
-
|
|
4771
|
-
|
|
4772
|
-
|
|
4773
|
-
|
|
6506
|
+
this._warnIfInvalidCapture(props, "Called captureImmediate() with a string as the first argument when an object was expected.", "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.");
|
|
6507
|
+
return this._capturePreparedEvent(props, true);
|
|
6508
|
+
}
|
|
6509
|
+
captureAi(props) {
|
|
6510
|
+
if (this.disabled)
|
|
6511
|
+
return;
|
|
6512
|
+
const uuid = getEventUuid(props.uuid, uuidv7);
|
|
6513
|
+
this._sendPreparedAiEvent({
|
|
6514
|
+
...props,
|
|
6515
|
+
uuid
|
|
6516
|
+
}, false);
|
|
6517
|
+
return uuid;
|
|
6518
|
+
}
|
|
6519
|
+
async captureAiImmediate(props) {
|
|
6520
|
+
if (this.disabled)
|
|
6521
|
+
return;
|
|
6522
|
+
const uuid = getEventUuid(props.uuid, uuidv7);
|
|
6523
|
+
await this._sendPreparedAiEvent({
|
|
6524
|
+
...props,
|
|
6525
|
+
uuid
|
|
6526
|
+
}, true);
|
|
6527
|
+
return uuid;
|
|
6528
|
+
}
|
|
6529
|
+
_sendPreparedAiEvent(props, immediate) {
|
|
6530
|
+
if (typeof props?.event == "string" && !props.event.startsWith("$ai_"))
|
|
6531
|
+
this._logger.debug(`captureAi called with non-AI event ${props.event}; routing it to the AI endpoint anyway.`);
|
|
6532
|
+
this._aiCaptureRouteActive = true;
|
|
6533
|
+
return this._sendPreparedEvent("capture", props, immediate, undefined, AI_CAPTURE_ROUTE);
|
|
4774
6534
|
}
|
|
4775
6535
|
identify({ distinctId, properties = {}, disableGeoip }) {
|
|
4776
6536
|
const { $set, $set_once, $anon_distinct_id, ...rest } = properties;
|
|
@@ -4781,8 +6541,13 @@ var init_client = __esm(() => {
|
|
|
4781
6541
|
$set_once: setOnceProps,
|
|
4782
6542
|
$anon_distinct_id: $anon_distinct_id ?? undefined
|
|
4783
6543
|
};
|
|
4784
|
-
|
|
6544
|
+
this._sendPreparedEvent("identify", {
|
|
6545
|
+
distinctId,
|
|
6546
|
+
event: "$identify",
|
|
6547
|
+
properties: eventProperties,
|
|
4785
6548
|
disableGeoip
|
|
6549
|
+
}, false, {
|
|
6550
|
+
includeContextProperties: false
|
|
4786
6551
|
});
|
|
4787
6552
|
}
|
|
4788
6553
|
async identifyImmediate({ distinctId, properties = {}, disableGeoip }) {
|
|
@@ -4794,18 +6559,65 @@ var init_client = __esm(() => {
|
|
|
4794
6559
|
$set_once: setOnceProps,
|
|
4795
6560
|
$anon_distinct_id: $anon_distinct_id ?? undefined
|
|
4796
6561
|
};
|
|
4797
|
-
await
|
|
6562
|
+
await this._sendPreparedEvent("identify", {
|
|
6563
|
+
distinctId,
|
|
6564
|
+
event: "$identify",
|
|
6565
|
+
properties: eventProperties,
|
|
4798
6566
|
disableGeoip
|
|
6567
|
+
}, true, {
|
|
6568
|
+
includeContextProperties: false
|
|
6569
|
+
});
|
|
6570
|
+
}
|
|
6571
|
+
setPersonProperties({ distinctId, properties = {}, propertiesOnce = {} }) {
|
|
6572
|
+
if (Object.keys(properties).length === 0 && Object.keys(propertiesOnce).length === 0)
|
|
6573
|
+
return;
|
|
6574
|
+
const eventProperties = {};
|
|
6575
|
+
if (Object.keys(properties).length > 0)
|
|
6576
|
+
eventProperties.$set = properties;
|
|
6577
|
+
if (Object.keys(propertiesOnce).length > 0)
|
|
6578
|
+
eventProperties.$set_once = propertiesOnce;
|
|
6579
|
+
this.capture({
|
|
6580
|
+
distinctId,
|
|
6581
|
+
event: "$set",
|
|
6582
|
+
properties: eventProperties
|
|
6583
|
+
});
|
|
6584
|
+
}
|
|
6585
|
+
unsetPersonProperties({ distinctId, properties }) {
|
|
6586
|
+
const propertyNames = normalizeUnsetPersonProperties(properties);
|
|
6587
|
+
if (propertyNames.length === 0)
|
|
6588
|
+
return;
|
|
6589
|
+
this.capture({
|
|
6590
|
+
distinctId,
|
|
6591
|
+
event: "$set",
|
|
6592
|
+
properties: {
|
|
6593
|
+
$unset: propertyNames
|
|
6594
|
+
}
|
|
4799
6595
|
});
|
|
4800
6596
|
}
|
|
4801
6597
|
alias(data) {
|
|
4802
|
-
|
|
6598
|
+
this._sendPreparedEvent("alias", {
|
|
6599
|
+
distinctId: data.distinctId,
|
|
6600
|
+
event: "$create_alias",
|
|
6601
|
+
properties: {
|
|
6602
|
+
distinct_id: data.distinctId,
|
|
6603
|
+
alias: data.alias
|
|
6604
|
+
},
|
|
4803
6605
|
disableGeoip: data.disableGeoip
|
|
6606
|
+
}, false, {
|
|
6607
|
+
includeContextProperties: false
|
|
4804
6608
|
});
|
|
4805
6609
|
}
|
|
4806
6610
|
async aliasImmediate(data) {
|
|
4807
|
-
await
|
|
6611
|
+
await this._sendPreparedEvent("alias", {
|
|
6612
|
+
distinctId: data.distinctId,
|
|
6613
|
+
event: "$create_alias",
|
|
6614
|
+
properties: {
|
|
6615
|
+
distinct_id: data.distinctId,
|
|
6616
|
+
alias: data.alias
|
|
6617
|
+
},
|
|
4808
6618
|
disableGeoip: data.disableGeoip
|
|
6619
|
+
}, true, {
|
|
6620
|
+
includeContextProperties: false
|
|
4809
6621
|
});
|
|
4810
6622
|
}
|
|
4811
6623
|
isLocalEvaluationReady() {
|
|
@@ -4860,7 +6672,7 @@ var init_client = __esm(() => {
|
|
|
4860
6672
|
const adjustedProperties = this.addLocalPersonAndGroupProperties(distinctId, groups, personProperties, groupProperties);
|
|
4861
6673
|
personProperties = adjustedProperties.allPersonProperties;
|
|
4862
6674
|
groupProperties = adjustedProperties.allGroupProperties;
|
|
4863
|
-
const evaluationContext = this.createFeatureFlagEvaluationContext(distinctId, groups, personProperties, groupProperties);
|
|
6675
|
+
const evaluationContext = this.createFeatureFlagEvaluationContext(distinctId, groups, this.personPropertiesForLocalEvaluation(distinctId, personProperties), groupProperties);
|
|
4864
6676
|
if (onlyEvaluateLocally == undefined)
|
|
4865
6677
|
onlyEvaluateLocally = this.options.strictLocalEvaluation ?? false;
|
|
4866
6678
|
let result;
|
|
@@ -4871,6 +6683,7 @@ var init_client = __esm(() => {
|
|
|
4871
6683
|
let flagId;
|
|
4872
6684
|
let flagVersion;
|
|
4873
6685
|
let flagReason;
|
|
6686
|
+
let flagHasExperiment;
|
|
4874
6687
|
const localEvaluationEnabled = this.featureFlagsPoller !== undefined;
|
|
4875
6688
|
if (localEvaluationEnabled) {
|
|
4876
6689
|
await this.featureFlagsPoller?.loadFeatureFlags();
|
|
@@ -4885,6 +6698,7 @@ var init_client = __esm(() => {
|
|
|
4885
6698
|
const value = localResult.value;
|
|
4886
6699
|
flagId = flag.id;
|
|
4887
6700
|
flagReason = "Evaluated locally";
|
|
6701
|
+
flagHasExperiment = flag.has_experiment;
|
|
4888
6702
|
result = {
|
|
4889
6703
|
key,
|
|
4890
6704
|
enabled: value !== false,
|
|
@@ -4900,12 +6714,13 @@ var init_client = __esm(() => {
|
|
|
4900
6714
|
}
|
|
4901
6715
|
}
|
|
4902
6716
|
if (!flagWasLocallyEvaluated && !onlyEvaluateLocally) {
|
|
4903
|
-
const flagsResponse = await super.getFeatureFlagDetailsStateless(evaluationContext.distinctId, evaluationContext.groups,
|
|
6717
|
+
const flagsResponse = await super.getFeatureFlagDetailsStateless(evaluationContext.distinctId, evaluationContext.groups, personProperties, groupProperties, disableGeoip, [
|
|
4904
6718
|
key
|
|
4905
6719
|
]);
|
|
4906
6720
|
if (flagsResponse === undefined)
|
|
4907
6721
|
featureFlagError = FeatureFlagError2.UNKNOWN_ERROR;
|
|
4908
6722
|
else {
|
|
6723
|
+
this._minimalFlagCalledEvents = flagsResponse.minimalFlagCalledEvents === true;
|
|
4909
6724
|
requestId = flagsResponse.requestId;
|
|
4910
6725
|
evaluatedAt = flagsResponse.evaluatedAt;
|
|
4911
6726
|
const errors = [];
|
|
@@ -4920,6 +6735,7 @@ var init_client = __esm(() => {
|
|
|
4920
6735
|
flagId = flagDetail.metadata?.id;
|
|
4921
6736
|
flagVersion = flagDetail.metadata?.version;
|
|
4922
6737
|
flagReason = flagDetail.reason?.description ?? flagDetail.reason?.code;
|
|
6738
|
+
flagHasExperiment = flagDetail.metadata?.has_experiment;
|
|
4923
6739
|
let parsedPayload;
|
|
4924
6740
|
if (flagDetail.metadata?.payload !== undefined)
|
|
4925
6741
|
try {
|
|
@@ -4951,6 +6767,8 @@ var init_client = __esm(() => {
|
|
|
4951
6767
|
$feature_flag_request_id: requestId,
|
|
4952
6768
|
$feature_flag_evaluated_at: flagWasLocallyEvaluated ? Date.now() : evaluatedAt
|
|
4953
6769
|
};
|
|
6770
|
+
if (flagHasExperiment !== undefined)
|
|
6771
|
+
properties.$feature_flag_has_experiment = flagHasExperiment;
|
|
4954
6772
|
if (flagWasLocallyEvaluated && this.featureFlagsPoller) {
|
|
4955
6773
|
const flagDefinitionsLoadedAt = this.featureFlagsPoller.getFlagDefinitionsLoadedAt();
|
|
4956
6774
|
if (flagDefinitionsLoadedAt !== undefined)
|
|
@@ -5065,7 +6883,7 @@ var init_client = __esm(() => {
|
|
|
5065
6883
|
const adjustedProperties = this.addLocalPersonAndGroupProperties(resolvedDistinctId, groups, personProperties, groupProperties);
|
|
5066
6884
|
personProperties = adjustedProperties.allPersonProperties;
|
|
5067
6885
|
groupProperties = adjustedProperties.allGroupProperties;
|
|
5068
|
-
const evaluationContext = this.createFeatureFlagEvaluationContext(resolvedDistinctId, groups, personProperties, groupProperties);
|
|
6886
|
+
const evaluationContext = this.createFeatureFlagEvaluationContext(resolvedDistinctId, groups, this.personPropertiesForLocalEvaluation(resolvedDistinctId, personProperties), groupProperties);
|
|
5069
6887
|
if (onlyEvaluateLocally == undefined)
|
|
5070
6888
|
onlyEvaluateLocally = this.options.strictLocalEvaluation ?? false;
|
|
5071
6889
|
const localEvaluationResult = await this.featureFlagsPoller?.getAllFlagsAndPayloads(evaluationContext, flagKeys);
|
|
@@ -5078,7 +6896,7 @@ var init_client = __esm(() => {
|
|
|
5078
6896
|
fallbackToFlags = localEvaluationResult.fallbackToFlags;
|
|
5079
6897
|
}
|
|
5080
6898
|
if (fallbackToFlags && !onlyEvaluateLocally) {
|
|
5081
|
-
const remoteEvaluationResult = await super.getFeatureFlagsAndPayloadsStateless(evaluationContext.distinctId, evaluationContext.groups,
|
|
6899
|
+
const remoteEvaluationResult = await super.getFeatureFlagsAndPayloadsStateless(evaluationContext.distinctId, evaluationContext.groups, personProperties, groupProperties, disableGeoip, flagKeys);
|
|
5082
6900
|
featureFlags = {
|
|
5083
6901
|
...featureFlags,
|
|
5084
6902
|
...remoteEvaluationResult.flags || {}
|
|
@@ -5126,7 +6944,7 @@ var init_client = __esm(() => {
|
|
|
5126
6944
|
const adjustedProperties = this.addLocalPersonAndGroupProperties(resolvedDistinctId, groups, personProperties, groupProperties);
|
|
5127
6945
|
personProperties = adjustedProperties.allPersonProperties;
|
|
5128
6946
|
groupProperties = adjustedProperties.allGroupProperties;
|
|
5129
|
-
const evaluationContext = this.createFeatureFlagEvaluationContext(resolvedDistinctId, groups, personProperties, groupProperties);
|
|
6947
|
+
const evaluationContext = this.createFeatureFlagEvaluationContext(resolvedDistinctId, groups, this.personPropertiesForLocalEvaluation(resolvedDistinctId, personProperties), groupProperties);
|
|
5130
6948
|
if (onlyEvaluateLocally == undefined)
|
|
5131
6949
|
onlyEvaluateLocally = this.options.strictLocalEvaluation ?? false;
|
|
5132
6950
|
const records = {};
|
|
@@ -5147,14 +6965,16 @@ var init_client = __esm(() => {
|
|
|
5147
6965
|
id: flagDef?.id,
|
|
5148
6966
|
version: undefined,
|
|
5149
6967
|
reason: "Evaluated locally",
|
|
5150
|
-
locallyEvaluated: true
|
|
6968
|
+
locallyEvaluated: true,
|
|
6969
|
+
hasExperiment: flagDef?.has_experiment
|
|
5151
6970
|
};
|
|
5152
6971
|
locallyEvaluatedKeys.add(key);
|
|
5153
6972
|
}
|
|
5154
6973
|
const fallbackToFlags = localResult ? localResult.fallbackToFlags : true;
|
|
5155
6974
|
if (fallbackToFlags && !onlyEvaluateLocally) {
|
|
5156
|
-
const details = await super.getFeatureFlagDetailsStateless(evaluationContext.distinctId, evaluationContext.groups,
|
|
6975
|
+
const details = await super.getFeatureFlagDetailsStateless(evaluationContext.distinctId, evaluationContext.groups, personProperties, groupProperties, disableGeoip, flagKeys);
|
|
5157
6976
|
if (details) {
|
|
6977
|
+
this._minimalFlagCalledEvents = details.minimalFlagCalledEvents === true;
|
|
5158
6978
|
requestId = details.requestId;
|
|
5159
6979
|
evaluatedAt = details.evaluatedAt;
|
|
5160
6980
|
errorsWhileComputing = Boolean(details.errorsWhileComputingFlags);
|
|
@@ -5177,7 +6997,8 @@ var init_client = __esm(() => {
|
|
|
5177
6997
|
id: detail.metadata?.id,
|
|
5178
6998
|
version: detail.metadata?.version,
|
|
5179
6999
|
reason: detail.reason?.description ?? detail.reason?.code,
|
|
5180
|
-
locallyEvaluated: false
|
|
7000
|
+
locallyEvaluated: false,
|
|
7001
|
+
hasExperiment: detail.metadata?.has_experiment
|
|
5181
7002
|
};
|
|
5182
7003
|
}
|
|
5183
7004
|
}
|
|
@@ -5197,7 +7018,8 @@ var init_client = __esm(() => {
|
|
|
5197
7018
|
id: existing?.id,
|
|
5198
7019
|
version: existing?.version,
|
|
5199
7020
|
reason: existing?.reason,
|
|
5200
|
-
locallyEvaluated: existing?.locallyEvaluated ?? false
|
|
7021
|
+
locallyEvaluated: existing?.locallyEvaluated ?? false,
|
|
7022
|
+
hasExperiment: existing?.hasExperiment
|
|
5201
7023
|
};
|
|
5202
7024
|
}
|
|
5203
7025
|
if (this._payloadOverrides !== undefined)
|
|
@@ -5222,6 +7044,9 @@ var init_client = __esm(() => {
|
|
|
5222
7044
|
quotaLimited
|
|
5223
7045
|
});
|
|
5224
7046
|
}
|
|
7047
|
+
_shouldSendMinimalFlagCalledEvent(event, properties) {
|
|
7048
|
+
return event === "$feature_flag_called" && this._minimalFlagCalledEvents && properties.$feature_flag_has_experiment === false;
|
|
7049
|
+
}
|
|
5225
7050
|
_captureFlagCalledEventIfNeeded(params) {
|
|
5226
7051
|
const { distinctId, key, response, groups, disableGeoip, properties } = params;
|
|
5227
7052
|
const groupSuffix = groups && Object.keys(groups).length > 0 ? `_${JSON.stringify(Object.entries(groups).sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0))}` : "";
|
|
@@ -5256,9 +7081,32 @@ var init_client = __esm(() => {
|
|
|
5256
7081
|
return this._featureFlagEvaluationsHost;
|
|
5257
7082
|
}
|
|
5258
7083
|
groupIdentify({ groupType, groupKey, properties, distinctId, disableGeoip }) {
|
|
5259
|
-
|
|
7084
|
+
this._sendPreparedEvent("capture", {
|
|
7085
|
+
distinctId: distinctId || `$${groupType}_${groupKey}`,
|
|
7086
|
+
event: "$groupidentify",
|
|
7087
|
+
properties: {
|
|
7088
|
+
$group_type: groupType,
|
|
7089
|
+
$group_key: groupKey,
|
|
7090
|
+
$group_set: properties || {}
|
|
7091
|
+
},
|
|
7092
|
+
disableGeoip
|
|
7093
|
+
}, false, {
|
|
7094
|
+
includeContextProperties: false
|
|
7095
|
+
});
|
|
7096
|
+
}
|
|
7097
|
+
async groupIdentifyImmediate({ groupType, groupKey, properties, distinctId, disableGeoip }) {
|
|
7098
|
+
await this._sendPreparedEvent("capture", {
|
|
7099
|
+
distinctId: distinctId || `$${groupType}_${groupKey}`,
|
|
7100
|
+
event: "$groupidentify",
|
|
7101
|
+
properties: {
|
|
7102
|
+
$group_type: groupType,
|
|
7103
|
+
$group_key: groupKey,
|
|
7104
|
+
$group_set: properties || {}
|
|
7105
|
+
},
|
|
5260
7106
|
disableGeoip
|
|
5261
|
-
},
|
|
7107
|
+
}, true, {
|
|
7108
|
+
includeContextProperties: false
|
|
7109
|
+
});
|
|
5262
7110
|
}
|
|
5263
7111
|
async reloadFeatureFlags() {
|
|
5264
7112
|
await this.featureFlagsPoller?.loadFeatureFlags(true);
|
|
@@ -5330,12 +7178,18 @@ var init_client = __esm(() => {
|
|
|
5330
7178
|
this.context?.enter(data, options);
|
|
5331
7179
|
}
|
|
5332
7180
|
async _shutdown(shutdownTimeoutMs) {
|
|
7181
|
+
const shutdownDeadlineMs = Date.now() + (shutdownTimeoutMs ?? 30000);
|
|
5333
7182
|
const resolve9 = this._consumeWaitUntilCycle();
|
|
5334
7183
|
await this.featureFlagsPoller?.stopPoller(shutdownTimeoutMs);
|
|
5335
7184
|
this.errorTracking.shutdown();
|
|
7185
|
+
if (this._metrics) {
|
|
7186
|
+
await raceWithTimeout(this._metrics.flush().catch(() => {}), Math.max(0, shutdownDeadlineMs - Date.now()));
|
|
7187
|
+
this._metrics.reset();
|
|
7188
|
+
}
|
|
5336
7189
|
try {
|
|
5337
|
-
return await super._shutdown(
|
|
7190
|
+
return await super._shutdown(Math.max(0, shutdownDeadlineMs - Date.now()));
|
|
5338
7191
|
} finally {
|
|
7192
|
+
this.distinctIdHasSentFlagCalls = {};
|
|
5339
7193
|
resolve9?.();
|
|
5340
7194
|
}
|
|
5341
7195
|
}
|
|
@@ -5430,7 +7284,6 @@ var init_client = __esm(() => {
|
|
|
5430
7284
|
}
|
|
5431
7285
|
addLocalPersonAndGroupProperties(distinctId, groups, personProperties, groupProperties) {
|
|
5432
7286
|
const allPersonProperties = {
|
|
5433
|
-
distinct_id: distinctId,
|
|
5434
7287
|
...personProperties || {}
|
|
5435
7288
|
};
|
|
5436
7289
|
const allGroupProperties = {};
|
|
@@ -5445,6 +7298,12 @@ var init_client = __esm(() => {
|
|
|
5445
7298
|
allGroupProperties
|
|
5446
7299
|
};
|
|
5447
7300
|
}
|
|
7301
|
+
personPropertiesForLocalEvaluation(distinctId, personProperties) {
|
|
7302
|
+
return {
|
|
7303
|
+
distinct_id: distinctId,
|
|
7304
|
+
...personProperties || {}
|
|
7305
|
+
};
|
|
7306
|
+
}
|
|
5448
7307
|
createFeatureFlagEvaluationContext(distinctId, groups, personProperties, groupProperties) {
|
|
5449
7308
|
return {
|
|
5450
7309
|
distinctId,
|
|
@@ -5455,21 +7314,21 @@ var init_client = __esm(() => {
|
|
|
5455
7314
|
};
|
|
5456
7315
|
}
|
|
5457
7316
|
captureException(error, distinctId, additionalProperties, uuid, flags) {
|
|
5458
|
-
if (!
|
|
7317
|
+
if (!error_tracking_ErrorTracking.isPreviouslyCapturedError(error)) {
|
|
5459
7318
|
const syntheticException = new Error("PostHog syntheticException");
|
|
5460
|
-
this.addPendingPromise(
|
|
7319
|
+
this.addPendingPromise(error_tracking_ErrorTracking.buildEventMessage(this.getErrorPropertiesBuilder(), error, {
|
|
5461
7320
|
syntheticException
|
|
5462
|
-
}, distinctId, additionalProperties).then((msg) => this.
|
|
7321
|
+
}, distinctId, additionalProperties).then((msg) => this._capturePreparedEvent({
|
|
5463
7322
|
...msg,
|
|
5464
7323
|
uuid,
|
|
5465
7324
|
flags
|
|
5466
|
-
})));
|
|
7325
|
+
}, false)));
|
|
5467
7326
|
}
|
|
5468
7327
|
}
|
|
5469
7328
|
async captureExceptionImmediate(error, distinctId, additionalProperties, flags) {
|
|
5470
|
-
if (!
|
|
7329
|
+
if (!error_tracking_ErrorTracking.isPreviouslyCapturedError(error)) {
|
|
5471
7330
|
const syntheticException = new Error("PostHog syntheticException");
|
|
5472
|
-
return this.addPendingPromise(
|
|
7331
|
+
return this.addPendingPromise(error_tracking_ErrorTracking.buildEventMessage(this.getErrorPropertiesBuilder(), error, {
|
|
5473
7332
|
syntheticException
|
|
5474
7333
|
}, distinctId, additionalProperties).then((msg) => this.captureImmediate({
|
|
5475
7334
|
...msg,
|
|
@@ -5478,24 +7337,31 @@ var init_client = __esm(() => {
|
|
|
5478
7337
|
}
|
|
5479
7338
|
}
|
|
5480
7339
|
async prepareEventMessage(props) {
|
|
7340
|
+
return this._prepareEventMessage(props);
|
|
7341
|
+
}
|
|
7342
|
+
async _prepareEventMessage(props, options = {}) {
|
|
5481
7343
|
const { distinctId, event, properties, groups, flags, sendFeatureFlags, timestamp, disableGeoip, uuid } = props;
|
|
5482
7344
|
const contextData = this.context?.get();
|
|
7345
|
+
const includeContextProperties = options.includeContextProperties ?? true;
|
|
5483
7346
|
let mergedDistinctId = distinctId || contextData?.distinctId;
|
|
5484
|
-
const mergedProperties = {
|
|
7347
|
+
const mergedProperties = includeContextProperties ? {
|
|
5485
7348
|
...this.props,
|
|
5486
7349
|
...contextData?.properties || {},
|
|
5487
7350
|
...properties || {}
|
|
7351
|
+
} : {
|
|
7352
|
+
...properties || {}
|
|
5488
7353
|
};
|
|
5489
7354
|
if (!mergedDistinctId) {
|
|
5490
7355
|
mergedDistinctId = uuidv7();
|
|
5491
7356
|
mergedProperties.$process_person_profile = false;
|
|
5492
7357
|
}
|
|
5493
|
-
if (contextData?.sessionId && !mergedProperties.$session_id)
|
|
7358
|
+
if (includeContextProperties && contextData?.sessionId && !mergedProperties.$session_id)
|
|
5494
7359
|
mergedProperties.$session_id = contextData.sessionId;
|
|
7360
|
+
const finalProperties = this._shouldSendMinimalFlagCalledEvent(event, mergedProperties) ? minimizeFlagCalledEventProperties(mergedProperties) : mergedProperties;
|
|
5495
7361
|
const eventMessage = this._runBeforeSend({
|
|
5496
7362
|
distinctId: mergedDistinctId,
|
|
5497
7363
|
event,
|
|
5498
|
-
properties:
|
|
7364
|
+
properties: finalProperties,
|
|
5499
7365
|
groups,
|
|
5500
7366
|
flags,
|
|
5501
7367
|
sendFeatureFlags,
|
|
@@ -5519,12 +7385,14 @@ var init_client = __esm(() => {
|
|
|
5519
7385
|
}
|
|
5520
7386
|
return {};
|
|
5521
7387
|
}).catch(() => ({})).then((additionalProperties) => {
|
|
5522
|
-
const
|
|
7388
|
+
const resolvedGroups = eventMessage.groups || groups;
|
|
7389
|
+
return {
|
|
5523
7390
|
...additionalProperties,
|
|
5524
7391
|
...eventMessage.properties || {},
|
|
5525
|
-
|
|
7392
|
+
...resolvedGroups !== undefined && Object.keys(resolvedGroups).length > 0 ? {
|
|
7393
|
+
$groups: resolvedGroups
|
|
7394
|
+
} : {}
|
|
5526
7395
|
};
|
|
5527
|
-
return props2;
|
|
5528
7396
|
});
|
|
5529
7397
|
if (eventMessage.event === "$pageview" && this.options.__preview_capture_bot_pageviews && typeof eventProperties.$raw_user_agent == "string") {
|
|
5530
7398
|
if (isBlockedUA(eventProperties.$raw_user_agent, this.options.custom_blocked_useragents || [])) {
|
|
@@ -5551,23 +7419,27 @@ var init_client = __esm(() => {
|
|
|
5551
7419
|
beforeSend
|
|
5552
7420
|
];
|
|
5553
7421
|
let result = eventMessage;
|
|
5554
|
-
for (const fn of fns)
|
|
5555
|
-
|
|
5556
|
-
|
|
5557
|
-
|
|
7422
|
+
for (const fn of fns)
|
|
7423
|
+
try {
|
|
7424
|
+
result = fn(result);
|
|
7425
|
+
if (!result) {
|
|
7426
|
+
this._logger.info(`Event '${eventMessage.event}' was rejected in beforeSend function`);
|
|
7427
|
+
return null;
|
|
7428
|
+
}
|
|
7429
|
+
if (!result.properties || Object.keys(result.properties).length === 0) {
|
|
7430
|
+
const message = `Event '${result.event}' has no properties after beforeSend function, this is likely an error.`;
|
|
7431
|
+
this._logger.warn(message);
|
|
7432
|
+
}
|
|
7433
|
+
} catch (error) {
|
|
7434
|
+
this._logger.error(`Error in before_send function for event '${eventMessage.event}':`, error);
|
|
5558
7435
|
return null;
|
|
5559
7436
|
}
|
|
5560
|
-
if (!result.properties || Object.keys(result.properties).length === 0) {
|
|
5561
|
-
const message = `Event '${result.event}' has no properties after beforeSend function, this is likely an error.`;
|
|
5562
|
-
this._logger.warn(message);
|
|
5563
|
-
}
|
|
5564
|
-
}
|
|
5565
7437
|
return result;
|
|
5566
7438
|
}
|
|
5567
7439
|
};
|
|
5568
7440
|
});
|
|
5569
7441
|
|
|
5570
|
-
// node_modules/.bun/posthog-node@5.
|
|
7442
|
+
// node_modules/.bun/posthog-node@5.49.2/node_modules/posthog-node/dist/extensions/context/context.mjs
|
|
5571
7443
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
5572
7444
|
|
|
5573
7445
|
class PostHogContext {
|
|
@@ -5599,7 +7471,27 @@ class PostHogContext {
|
|
|
5599
7471
|
}
|
|
5600
7472
|
var init_context = () => {};
|
|
5601
7473
|
|
|
5602
|
-
// node_modules/.bun/posthog-node@5.
|
|
7474
|
+
// node_modules/.bun/posthog-node@5.49.2/node_modules/posthog-node/dist/gzip.node.mjs
|
|
7475
|
+
import { gzip } from "node:zlib";
|
|
7476
|
+
import { promisify } from "node:util";
|
|
7477
|
+
async function gzipCompress2(input, isDebug = true) {
|
|
7478
|
+
try {
|
|
7479
|
+
const compressed = await gzipAsync(input);
|
|
7480
|
+
return new Blob([
|
|
7481
|
+
new Uint8Array(compressed)
|
|
7482
|
+
]);
|
|
7483
|
+
} catch (error) {
|
|
7484
|
+
if (isDebug)
|
|
7485
|
+
console.error("Failed to gzip compress data", error);
|
|
7486
|
+
return null;
|
|
7487
|
+
}
|
|
7488
|
+
}
|
|
7489
|
+
var gzipAsync;
|
|
7490
|
+
var init_gzip_node = __esm(() => {
|
|
7491
|
+
gzipAsync = promisify(gzip);
|
|
7492
|
+
});
|
|
7493
|
+
|
|
7494
|
+
// node_modules/.bun/posthog-node@5.49.2/node_modules/posthog-node/dist/extensions/sentry-integration.mjs
|
|
5603
7495
|
function createEventProcessor(_posthog, { organization, projectId, prefix, severityAllowList = [
|
|
5604
7496
|
"error"
|
|
5605
7497
|
], sendExceptionsToPostHog = true } = {}) {
|
|
@@ -5638,6 +7530,9 @@ function createEventProcessor(_posthog, { organization, projectId, prefix, sever
|
|
|
5638
7530
|
$sentry_exception_type: exceptions[0]?.type,
|
|
5639
7531
|
$sentry_tags: event.tags
|
|
5640
7532
|
};
|
|
7533
|
+
const injectedReleaseId = exports_error_tracking.getInjectedReleaseId();
|
|
7534
|
+
if (injectedReleaseId)
|
|
7535
|
+
properties.$release_id = injectedReleaseId;
|
|
5641
7536
|
if (organization && projectId)
|
|
5642
7537
|
properties["$sentry_url"] = (prefix || "https://sentry.io/organizations/") + organization + "/issues/?project=" + projectId + "&query=" + event.event_id;
|
|
5643
7538
|
if (sendExceptionsToPostHog)
|
|
@@ -5651,6 +7546,7 @@ function createEventProcessor(_posthog, { organization, projectId, prefix, sever
|
|
|
5651
7546
|
}
|
|
5652
7547
|
var NAME = "posthog-node", PostHogSentryIntegration;
|
|
5653
7548
|
var init_sentry_integration = __esm(() => {
|
|
7549
|
+
init_dist();
|
|
5654
7550
|
PostHogSentryIntegration = class PostHogSentryIntegration {
|
|
5655
7551
|
static #_ = this.POSTHOG_ID_TAG = "posthog_distinct_id";
|
|
5656
7552
|
constructor(_posthog, organization, prefix, severityAllowList, sendExceptionsToPostHog) {
|
|
@@ -5670,16 +7566,22 @@ var init_sentry_integration = __esm(() => {
|
|
|
5670
7566
|
};
|
|
5671
7567
|
});
|
|
5672
7568
|
|
|
5673
|
-
// node_modules/.bun/posthog-node@5.
|
|
7569
|
+
// node_modules/.bun/posthog-node@5.49.2/node_modules/posthog-node/dist/extensions/tracing-headers.mjs
|
|
5674
7570
|
var init_tracing_headers2 = () => {};
|
|
5675
7571
|
|
|
5676
|
-
// node_modules/.bun/posthog-node@5.
|
|
7572
|
+
// node_modules/.bun/posthog-node@5.49.2/node_modules/posthog-node/dist/extensions/url-utils.mjs
|
|
7573
|
+
var init_url_utils = __esm(() => {
|
|
7574
|
+
init_dist();
|
|
7575
|
+
});
|
|
7576
|
+
|
|
7577
|
+
// node_modules/.bun/posthog-node@5.49.2/node_modules/posthog-node/dist/extensions/express.mjs
|
|
5677
7578
|
var init_express = __esm(() => {
|
|
5678
7579
|
init_error_tracking2();
|
|
5679
7580
|
init_tracing_headers2();
|
|
7581
|
+
init_url_utils();
|
|
5680
7582
|
});
|
|
5681
7583
|
|
|
5682
|
-
// node_modules/.bun/posthog-node@5.
|
|
7584
|
+
// node_modules/.bun/posthog-node@5.49.2/node_modules/posthog-node/dist/exports.mjs
|
|
5683
7585
|
var init_exports = __esm(() => {
|
|
5684
7586
|
init_feature_flag_evaluations();
|
|
5685
7587
|
init_dist();
|
|
@@ -5688,7 +7590,7 @@ var init_exports = __esm(() => {
|
|
|
5688
7590
|
init_types3();
|
|
5689
7591
|
});
|
|
5690
7592
|
|
|
5691
|
-
// node_modules/.bun/posthog-node@5.
|
|
7593
|
+
// node_modules/.bun/posthog-node@5.49.2/node_modules/posthog-node/dist/entrypoints/index.node.mjs
|
|
5692
7594
|
var PostHog;
|
|
5693
7595
|
var init_index_node = __esm(() => {
|
|
5694
7596
|
init_module_node();
|
|
@@ -5697,11 +7599,15 @@ var init_index_node = __esm(() => {
|
|
|
5697
7599
|
init_client();
|
|
5698
7600
|
init_dist();
|
|
5699
7601
|
init_context();
|
|
7602
|
+
init_gzip_node();
|
|
5700
7603
|
init_exports();
|
|
5701
7604
|
PostHog = class PostHog extends PostHogBackendClient {
|
|
5702
7605
|
getLibraryId() {
|
|
5703
7606
|
return "posthog-node";
|
|
5704
7607
|
}
|
|
7608
|
+
compressPayload(payload) {
|
|
7609
|
+
return gzipCompress2(payload, this.isDebug);
|
|
7610
|
+
}
|
|
5705
7611
|
initializeContext() {
|
|
5706
7612
|
return new PostHogContext;
|
|
5707
7613
|
}
|
|
@@ -5714,7 +7620,7 @@ var init_index_node = __esm(() => {
|
|
|
5714
7620
|
new exports_error_tracking.PrimitiveCoercer
|
|
5715
7621
|
], exports_error_tracking.createStackParser("node:javascript", exports_error_tracking.nodeStackLineParser), [
|
|
5716
7622
|
createModulerModifier(),
|
|
5717
|
-
addSourceContext,
|
|
7623
|
+
(frames) => addSourceContext(frames, undefined, this._logger),
|
|
5718
7624
|
createRelativePathModifier()
|
|
5719
7625
|
]);
|
|
5720
7626
|
}
|
|
@@ -5927,7 +7833,7 @@ var package_default;
|
|
|
5927
7833
|
var init_package = __esm(() => {
|
|
5928
7834
|
package_default = {
|
|
5929
7835
|
name: "@oh-my-opencode/omo-codex",
|
|
5930
|
-
version: "5.0.0-beta.
|
|
7836
|
+
version: "5.0.0-beta.13",
|
|
5931
7837
|
type: "module",
|
|
5932
7838
|
private: true,
|
|
5933
7839
|
description: "Codex harness adapter for oh-my-openagent. Vendored Codex plugin namespace (omo) + TypeScript installer + telemetry.",
|