oh-my-opencode 5.0.0-beta.2 → 5.0.0-beta.21
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/command/publish.md +44 -16
- package/.agents/skills/publish/SKILL.md +44 -16
- 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/.agents/skills/work-with-pr/SKILL.md +37 -23
- package/.opencode/command/publish.md +44 -16
- package/.opencode/skills/work-with-pr/SKILL.md +37 -23
- package/README.ja.md +25 -21
- package/README.ko.md +25 -21
- package/README.md +38 -23
- package/README.ru.md +24 -20
- package/README.zh-cn.md +25 -21
- package/dist/agents/atlas/agent.d.ts +0 -1
- package/dist/agents/sisyphus/grok-4.d.ts +20 -0
- package/dist/agents/sisyphus/index.d.ts +2 -0
- package/dist/agents/sisyphus-agent-config.d.ts +6 -0
- package/dist/agents/sisyphus-agent-factory.d.ts +1 -1
- package/dist/agents/sisyphus-runtime-prompt-reconciler.d.ts +15 -4
- package/dist/agents/types.d.ts +2 -2
- package/dist/cli/fallback-lane-policy.d.ts +1 -0
- package/dist/cli/index.js +23057 -20893
- package/dist/cli/install-codex/install-codex-test-fixtures.d.ts +1 -1
- package/dist/cli/run/on-complete-hook.d.ts +2 -0
- package/dist/cli/runtime-commands.d.ts +1 -1
- package/dist/cli/worktree-sweep/classify.d.ts +16 -0
- package/dist/cli/worktree-sweep/format.d.ts +8 -0
- package/dist/cli/worktree-sweep/git.d.ts +19 -0
- package/dist/cli/worktree-sweep/index.d.ts +7 -0
- package/dist/cli/worktree-sweep/options.d.ts +2 -0
- package/dist/cli/worktree-sweep/parse-worktree-list.d.ts +8 -0
- package/dist/cli/worktree-sweep/sweep.d.ts +2 -0
- package/dist/cli/worktree-sweep/types.d.ts +65 -0
- package/dist/cli/worktree-sweep/worktree-sweep.d.ts +2 -0
- package/dist/cli-node/index.js +23093 -20929
- package/dist/config/schema/commands.d.ts +1 -1
- package/dist/config/schema/hooks.d.ts +1 -1
- package/dist/config/schema/oh-my-opencode-config.d.ts +4 -1
- package/dist/config/schema/ulw-execute.d.ts +5 -0
- package/dist/config/validate.d.ts +2 -0
- package/dist/create-hooks.d.ts +3 -1
- 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 +68 -0
- package/dist/features/btw-side/tui-controller.d.ts +19 -0
- package/dist/features/btw-side/tui-escape-return.d.ts +12 -0
- package/dist/features/btw-side/tui-keymap.d.ts +17 -0
- package/dist/features/btw-side/tui-parent-validator.d.ts +6 -0
- package/dist/features/btw-side/tui-picker-options.d.ts +20 -0
- package/dist/features/btw-side/tui-picker.d.ts +9 -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-session-catalog.d.ts +35 -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/features/builtin-commands/templates/ulw-execute.d.ts +1 -0
- package/dist/features/builtin-commands/types.d.ts +1 -1
- package/dist/features/opengateway-provider/index.d.ts +13 -0
- package/dist/hooks/atlas/atlas-hook.d.ts +1 -0
- package/dist/hooks/atlas/atlas-lifecycle-store.d.ts +50 -0
- package/dist/hooks/atlas/event-handler.d.ts +1 -0
- package/dist/hooks/atlas/final-wave-approval-gate.test-support.d.ts +50 -0
- package/dist/hooks/atlas/system-reminder-templates.d.ts +0 -1
- package/dist/hooks/atlas/tool-execute-before.d.ts +3 -0
- package/dist/hooks/atlas/types.d.ts +1 -0
- package/dist/hooks/index.d.ts +1 -1
- package/dist/hooks/prometheus-md-only/agent-resolution.d.ts +2 -2
- 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/hooks/sisyphus-junior-notepad/constants.d.ts +1 -1
- package/dist/hooks/{start-work → ulw-execute}/context-info-builder.d.ts +1 -1
- package/dist/hooks/{start-work → ulw-execute}/index.d.ts +1 -1
- package/dist/hooks/ulw-execute/ulw-execute-hook.d.ts +23 -0
- package/dist/index.js +11724 -6355
- package/dist/oh-my-opencode.schema.json +15 -2
- package/dist/plugin/chat-message/types.d.ts +3 -3
- package/dist/plugin/chat-message/ulw-execute-message.d.ts +5 -0
- package/dist/plugin/event-session-lifecycle.d.ts +1 -0
- package/dist/plugin/hooks/create-core-hooks.d.ts +2 -1
- package/dist/plugin/hooks/create-session-hooks.d.ts +2 -2
- 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/normalize-sdk-response.d.ts +1 -0
- package/dist/shared/runtime-fallback-retry-marker.d.ts +16 -0
- package/dist/shared/shell-env.d.ts +1 -1
- package/dist/skills/ast-grep/AGENTS.md +51 -0
- package/dist/skills/coding-agent-sessions/AGENTS.md +62 -0
- package/dist/skills/coding-agent-sessions/SKILL.md +3 -2
- package/dist/skills/coding-agent-sessions/references/all-platforms.md +1 -1
- package/dist/skills/coding-agent-sessions/references/senpi.md +4 -4
- package/dist/skills/coding-agent-sessions/scripts/agent_sessions/pi_family.py +1 -1
- package/dist/skills/frontend/SKILL.md +11 -7
- package/dist/skills/frontend/references/design/_INDEX.md +1 -0
- package/dist/skills/frontend/references/design/print-paged-media.md +76 -0
- package/dist/skills/frontend/references/design/stylegallery.md +80 -0
- package/dist/skills/frontend/references/designpowers/README.md +1 -1
- package/dist/skills/frontend/references/designpowers/lane-a-direction.md +1 -1
- package/dist/skills/frontend/references/designpowers/lane-b-execution.md +11 -11
- package/dist/skills/frontend/references/designpowers/lane-d-memory.md +3 -3
- package/dist/skills/frontend/references/designpowers/orchestration.md +1 -1
- package/dist/skills/frontend/references/designpowers/routing.md +5 -5
- package/dist/skills/review-work/SKILL.md +3 -3
- package/dist/skills/ultimate-browsing/ATTRIBUTION.md +37 -10
- package/dist/skills/ultimate-browsing/SKILL.md +2 -0
- package/dist/skills/ultimate-browsing/engine/AGENTS.md +179 -0
- package/dist/skills/ultimate-browsing/engine/templates/package.json +1 -1
- package/dist/skills/ultimate-browsing/references/chrome-stealth.md +13 -11
- package/dist/skills/{start-work → ulw-execute}/SKILL.md +9 -8
- package/dist/skills/ulw-plan/SKILL.md +6 -6
- package/dist/skills/ulw-plan/references/full-workflow.md +31 -7
- package/dist/skills/ulw-plan/references/intent-clear.md +2 -1
- package/dist/skills/ulw-plan/references/intent-unclear.md +5 -5
- package/dist/skills/ulw-research/SKILL.md +1 -1
- package/dist/skills/visual-qa/AGENTS.md +58 -0
- package/dist/skills/visual-qa/SKILL.md +3 -2
- package/dist/tools/delegate-task/builtin-categories.d.ts +1 -0
- package/dist/tools/delegate-task/builtin-category-definition.d.ts +1 -0
- package/dist/tools/delegate-task/tool-description.d.ts +3 -1
- package/dist/tui.js +8824 -8906
- package/package.json +38 -35
- package/packages/git-bash-mcp/dist/cli.js +5 -1
- package/packages/git-bash-mcp/package.json +1 -1
- package/packages/lsp-core/src/lsp/client-diagnostics-concurrency.integration.test.ts +44 -0
- package/packages/lsp-core/src/lsp/client-diagnostics-freshness.integration.test.ts +0 -28
- package/packages/lsp-core/src/lsp/client-wrapper-outside-cwd.test.ts +78 -0
- package/packages/lsp-core/src/lsp/client-wrapper.test.ts +66 -13
- package/packages/lsp-core/src/lsp/client-wrapper.ts +70 -18
- package/packages/lsp-core/src/lsp/outside-context-workspace.ts +33 -0
- package/packages/lsp-core/src/lsp/workspace-edit-adversarial.test.ts +20 -1
- package/packages/lsp-core/src/lsp/workspace-markers.ts +1 -0
- package/packages/lsp-core/src/tools/diagnostics.ts +3 -3
- package/packages/lsp-core/src/tools/navigation.ts +4 -2
- package/packages/lsp-core/src/tools/rename.ts +4 -2
- package/packages/lsp-core/src/tools/symbols.ts +1 -1
- package/packages/lsp-daemon/dist/cli.js +246 -185
- package/packages/lsp-daemon/dist/client.js +222 -164
- package/packages/lsp-daemon/dist/ensure-daemon.js +1 -0
- package/packages/lsp-daemon/dist/index.js +236 -177
- package/packages/lsp-daemon/dist/version-reap.js +1 -1
- package/packages/lsp-tools-mcp/dist/cli.js +198 -136
- package/packages/lsp-tools-mcp/dist/lsp/manager.js +62 -92
- package/packages/lsp-tools-mcp/dist/mcp.js +200 -138
- package/packages/lsp-tools-mcp/dist/request-context.js +11 -12
- package/packages/lsp-tools-mcp/dist/tools.js +204 -146
- package/packages/omo-codex/THIRD-PARTY-NOTICES.md +4 -4
- package/packages/omo-codex/plugin/.codex-plugin/plugin.json +4 -4
- package/packages/omo-codex/plugin/AGENTS.md +47 -0
- package/packages/omo-codex/plugin/README.md +1 -1
- package/packages/omo-codex/plugin/components/bootstrap/dist/cli.js +32 -31
- 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/bootstrap/src/hook.ts +1 -0
- package/packages/omo-codex/plugin/components/codegraph/dist/cli.js +224 -81
- package/packages/omo-codex/plugin/components/codegraph/dist/serve.js +224 -82
- package/packages/omo-codex/plugin/components/codegraph/package.json +4 -4
- package/packages/omo-codex/plugin/components/codegraph/src/mcp-bridge.ts +1 -0
- package/packages/omo-codex/plugin/components/codegraph/src/session-start-hook-runtime.ts +1 -0
- package/packages/omo-codex/plugin/components/comment-checker/AGENTS.md +9 -0
- package/packages/omo-codex/plugin/components/comment-checker/biome.json +2 -2
- package/packages/omo-codex/plugin/components/comment-checker/dist/cli.js +2 -1
- package/packages/omo-codex/plugin/components/comment-checker/hooks/hooks.json +1 -1
- package/packages/omo-codex/plugin/components/comment-checker/package.json +5 -5
- package/packages/omo-codex/plugin/components/comment-checker/src/apply-patch.ts +2 -8
- package/packages/omo-codex/plugin/components/comment-checker/src/core.ts +1 -2
- package/packages/omo-codex/plugin/components/comment-checker/src/request-extractor.ts +1 -1
- package/packages/omo-codex/plugin/components/comment-checker/src/runner.ts +1 -0
- package/packages/omo-codex/plugin/components/git-bash/AGENTS.md +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 +3 -4
- package/packages/omo-codex/plugin/components/lazycodex-executor-verify/biome.json +2 -2
- package/packages/omo-codex/plugin/components/lazycodex-executor-verify/dist/cli.js +1 -5
- package/packages/omo-codex/plugin/components/lazycodex-executor-verify/dist/codex-hook.js +1 -5
- 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 +5 -5
- package/packages/omo-codex/plugin/components/lazycodex-executor-verify/src/codex-hook.ts +1 -5
- package/packages/omo-codex/plugin/components/lazycodex-executor-verify/test/codex-hook.test.ts +4 -21
- package/packages/omo-codex/plugin/components/lsp/AGENTS.md +30 -15
- package/packages/omo-codex/plugin/components/lsp/biome.json +2 -2
- package/packages/omo-codex/plugin/components/lsp/dist/.omo-runtime-manifest.json +4 -4
- package/packages/omo-codex/plugin/components/lsp/dist/cli.js +217 -171
- package/packages/omo-codex/plugin/components/lsp/dist/daemon-cli-path.js +1 -1
- package/packages/omo-codex/plugin/components/lsp/hooks/hooks.json +2 -2
- package/packages/omo-codex/plugin/components/lsp/package.json +5 -5
- package/packages/omo-codex/plugin/components/lsp/src/cli.ts +1 -1
- package/packages/omo-codex/plugin/components/lsp/src/codex-hook.ts +1 -1
- package/packages/omo-codex/plugin/components/lsp/src/daemon-cli-path.ts +1 -5
- package/packages/omo-codex/plugin/components/lsp/test/codex-hook-unavailable.test.ts +6 -7
- package/packages/omo-codex/plugin/components/lsp/test/codex-hook.test.ts +1 -2
- package/packages/omo-codex/plugin/components/lsp/test/package-smoke.test.ts +11 -1
- package/packages/omo-codex/plugin/components/rules/AGENTS.md +12 -0
- package/packages/omo-codex/plugin/components/rules/biome.json +2 -2
- package/packages/omo-codex/plugin/components/rules/dist/cli.js +57 -42
- package/packages/omo-codex/plugin/components/rules/hooks/hooks.json +4 -4
- package/packages/omo-codex/plugin/components/rules/package.json +7 -7
- package/packages/omo-codex/plugin/components/rules/src/config.ts +1 -2
- package/packages/omo-codex/plugin/components/rules/src/persistent-cache.ts +1 -2
- package/packages/omo-codex/plugin/components/rules/src/post-compact-budget.ts +6 -2
- package/packages/omo-codex/plugin/components/rules/src/rules-engine-factory.ts +1 -4
- package/packages/omo-codex/plugin/components/rules/src/static-injection.ts +4 -9
- package/packages/omo-codex/plugin/components/rules/test/bundled-rules-priority.test.ts +11 -16
- package/packages/omo-codex/plugin/components/rules/test/bundled-rules.test.ts +17 -25
- package/packages/omo-codex/plugin/components/rules/test/codex-hook-post-compact-budget.test.ts +9 -7
- package/packages/omo-codex/plugin/components/rules/test/codex-hook-post-compact-context.test.ts +0 -6
- package/packages/omo-codex/plugin/components/rules/test/codex-hook-post-compact-dedup.test.ts +6 -4
- package/packages/omo-codex/plugin/components/rules/test/codex-hook-post-compact-directive.test.ts +12 -9
- package/packages/omo-codex/plugin/components/rules/test/codex-hook.test.ts +28 -37
- package/packages/omo-codex/plugin/components/rules/test/dynamic-target-fingerprints.test.ts +1 -2
- package/packages/omo-codex/plugin/components/rules/test/engine.test.ts +7 -4
- package/packages/omo-codex/plugin/components/rules/test/finder.test.ts +2 -3
- package/packages/omo-codex/plugin/components/rules/test/formatter.test.ts +39 -72
- package/packages/omo-codex/plugin/components/rules/test/hephaestus-model-variant.test.ts +1 -2
- package/packages/omo-codex/plugin/components/rules/test/hook-output.test.ts +2 -3
- package/packages/omo-codex/plugin/components/rules/test/matcher.test.ts +2 -3
- package/packages/omo-codex/plugin/components/rules/test/package-smoke.test.ts +1 -1
- package/packages/omo-codex/plugin/components/rules/test/parser.test.ts +1 -2
- package/packages/omo-codex/plugin/components/rules/test/post-compact-budget.test.ts +1 -2
- package/packages/omo-codex/plugin/components/rules/test/rules-engine-consumption.test.ts +3 -6
- package/packages/omo-codex/plugin/components/rules/test/scanner.test.ts +1 -2
- package/packages/omo-codex/plugin/components/rules/test/sources.test.ts +2 -5
- package/packages/omo-codex/plugin/components/rules/test/windows-git-bash-bundled-rule.test.ts +2 -17
- package/packages/omo-codex/plugin/components/teammode/hooks/hooks.json +1 -1
- package/packages/omo-codex/plugin/components/teammode/package.json +5 -5
- package/packages/omo-codex/plugin/components/teammode/test/thread-title-hook.test.ts +3 -9
- package/packages/omo-codex/plugin/components/telemetry/AGENTS.md +8 -0
- package/packages/omo-codex/plugin/components/telemetry/biome.json +2 -2
- package/packages/omo-codex/plugin/components/telemetry/dist/cli.js +2433 -422
- package/packages/omo-codex/plugin/components/telemetry/dist/posthog.js +2437 -426
- package/packages/omo-codex/plugin/components/telemetry/hooks/hooks.json +1 -1
- package/packages/omo-codex/plugin/components/telemetry/package.json +5 -5
- package/packages/omo-codex/plugin/components/telemetry/src/codex-hook.ts +1 -4
- package/packages/omo-codex/plugin/components/telemetry/src/posthog.ts +4 -14
- package/packages/omo-codex/plugin/components/telemetry/src/product-identity.ts +1 -1
- package/packages/omo-codex/plugin/components/telemetry/test/diagnostics.test.ts +2 -5
- package/packages/omo-codex/plugin/components/ultrawork/AGENTS.md +5 -0
- package/packages/omo-codex/plugin/components/ultrawork/biome.json +2 -2
- package/packages/omo-codex/plugin/components/ultrawork/directive.md +13 -1
- package/packages/omo-codex/plugin/components/ultrawork/hooks/hooks.json +1 -1
- package/packages/omo-codex/plugin/components/ultrawork/package.json +5 -5
- package/packages/omo-codex/plugin/components/ultrawork/skills/ultrawork/SKILL.md +13 -1
- package/packages/omo-codex/plugin/components/ultrawork/skills/ulw-plan/SKILL.md +6 -6
- package/packages/omo-codex/plugin/components/ultrawork/skills/ulw-plan/references/full-workflow.md +31 -7
- package/packages/omo-codex/plugin/components/ultrawork/skills/ulw-plan/references/intent-clear.md +2 -1
- package/packages/omo-codex/plugin/components/ultrawork/skills/ulw-plan/references/intent-unclear.md +5 -5
- package/packages/omo-codex/plugin/components/ultrawork/test/codex-hook-trigger-policy.test.ts +9 -1
- package/packages/omo-codex/plugin/components/ultrawork/test/codex-hook.test.ts +0 -136
- package/packages/omo-codex/plugin/components/ultrawork/test/skill-pointer.test.ts +0 -2
- package/packages/omo-codex/plugin/components/{start-work-continuation → ulw-execute-continuation}/AGENTS.md +5 -4
- package/packages/omo-codex/plugin/components/{start-work-continuation → ulw-execute-continuation}/NOTICE +1 -1
- package/packages/omo-codex/plugin/components/{start-work-continuation → ulw-execute-continuation}/README.md +5 -5
- package/packages/omo-codex/plugin/components/{start-work-continuation → ulw-execute-continuation}/biome.json +2 -2
- package/packages/omo-codex/plugin/components/{start-work-continuation → ulw-execute-continuation}/directive.md +6 -6
- package/packages/omo-codex/plugin/components/{start-work-continuation → ulw-execute-continuation}/dist/cli.js +12 -12
- package/packages/omo-codex/plugin/components/ulw-execute-continuation/hooks/hooks.json +28 -0
- package/packages/omo-codex/plugin/components/{start-work-continuation → ulw-execute-continuation}/package.json +12 -12
- package/packages/omo-codex/plugin/components/{start-work-continuation → ulw-execute-continuation}/src/boulder-reader.ts +1 -1
- package/packages/omo-codex/plugin/components/{start-work-continuation → ulw-execute-continuation}/src/cli.ts +1 -1
- package/packages/omo-codex/plugin/components/{start-work-continuation → ulw-execute-continuation}/src/codex-hook.ts +3 -3
- package/packages/omo-codex/plugin/components/{start-work-continuation → ulw-execute-continuation}/src/directive.ts +1 -1
- package/packages/omo-codex/plugin/components/{start-work-continuation → ulw-execute-continuation}/src/index.ts +1 -1
- package/packages/omo-codex/plugin/components/{start-work-continuation → ulw-execute-continuation}/test/boulder-reader.test.ts +3 -3
- package/packages/omo-codex/plugin/components/{start-work-continuation → ulw-execute-continuation}/test/cli.test.ts +1 -4
- package/packages/omo-codex/plugin/components/{start-work-continuation → ulw-execute-continuation}/test/codex-hook.test.ts +8 -22
- package/packages/omo-codex/plugin/components/ulw-loop/AGENTS.md +16 -0
- package/packages/omo-codex/plugin/components/ulw-loop/CHANGELOG.md +1 -1
- package/packages/omo-codex/plugin/components/ulw-loop/biome.json +2 -2
- package/packages/omo-codex/plugin/components/ulw-loop/directive.md +13 -1
- package/packages/omo-codex/plugin/components/ulw-loop/dist/cli.js +2 -4
- package/packages/omo-codex/plugin/components/ulw-loop/dist/codex-goal-snapshot.js +1 -1
- package/packages/omo-codex/plugin/components/ulw-loop/dist/paths.js +1 -1
- package/packages/omo-codex/plugin/components/ulw-loop/dist/stop-resume-hook.js +3 -3
- package/packages/omo-codex/plugin/components/ulw-loop/hooks/hooks.json +4 -4
- package/packages/omo-codex/plugin/components/ulw-loop/package.json +5 -5
- package/packages/omo-codex/plugin/components/ulw-loop/skills/ulw-loop/SKILL.md +3 -2
- package/packages/omo-codex/plugin/components/ulw-loop/skills/ulw-loop/references/define-goal.md +108 -0
- package/packages/omo-codex/plugin/components/ulw-loop/skills/ulw-loop/references/full-workflow.md +1 -0
- package/packages/omo-codex/plugin/components/ulw-loop/src/codex-goal-snapshot.ts +3 -1
- package/packages/omo-codex/plugin/components/ulw-loop/src/codex-hook.ts +3 -1
- package/packages/omo-codex/plugin/components/ulw-loop/src/paths.ts +1 -1
- package/packages/omo-codex/plugin/components/ulw-loop/src/stop-resume-hook.ts +3 -3
- package/packages/omo-codex/plugin/components/ulw-loop/test/checkpoint-continuation.test.ts +0 -1
- package/packages/omo-codex/plugin/components/ulw-loop/test/cli-create-goals.test.ts +25 -0
- package/packages/omo-codex/plugin/components/ulw-loop/test/codex-goal-instruction.test.ts +2 -2
- package/packages/omo-codex/plugin/components/ulw-loop/test/codex-goal-snapshot.test.ts +18 -0
- package/packages/omo-codex/plugin/components/ulw-loop/test/codex-hook.test.ts +0 -3
- package/packages/omo-codex/plugin/components/ulw-loop/test/package-smoke.test.ts +5 -37
- package/packages/omo-codex/plugin/components/ulw-loop/test/paths.test.ts +9 -0
- package/packages/omo-codex/plugin/components/ulw-loop/test/steering.test.ts +8 -5
- package/packages/omo-codex/plugin/components/ulw-loop/test/stop-resume-hook.test.ts +1 -1
- package/packages/omo-codex/plugin/components/ulw-loop/test/ultrawork-directive.test.ts +4 -5
- package/packages/omo-codex/plugin/components/ulw-loop/vitest.config.ts +1 -0
- 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-ulw-execute-continuation.json +17 -0
- package/packages/omo-codex/plugin/hooks/stop-checking-ulw-loop-resume.json +1 -1
- package/packages/omo-codex/plugin/hooks/subagent-stop-checking-ulw-execute-continuation.json +17 -0
- 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 +681 -395
- package/packages/omo-codex/plugin/package.json +2 -2
- package/packages/omo-codex/plugin/scripts/AGENTS.md +40 -0
- package/packages/omo-codex/plugin/scripts/auto-update-plan.mjs +1 -1
- package/packages/omo-codex/plugin/scripts/sync-skills.mjs +11 -11
- package/packages/omo-codex/plugin/shared/package.json +3 -4
- package/packages/omo-codex/plugin/skills/ast-grep/AGENTS.md +51 -0
- package/packages/omo-codex/plugin/skills/coding-agent-sessions/AGENTS.md +62 -0
- package/packages/omo-codex/plugin/skills/coding-agent-sessions/SKILL.md +3 -2
- package/packages/omo-codex/plugin/skills/coding-agent-sessions/references/all-platforms.md +1 -1
- package/packages/omo-codex/plugin/skills/coding-agent-sessions/references/senpi.md +4 -4
- package/packages/omo-codex/plugin/skills/coding-agent-sessions/scripts/agent_sessions/pi_family.py +1 -1
- package/packages/omo-codex/plugin/skills/frontend/SKILL.md +11 -7
- package/packages/omo-codex/plugin/skills/frontend/references/design/_INDEX.md +1 -0
- package/packages/omo-codex/plugin/skills/frontend/references/design/print-paged-media.md +76 -0
- package/packages/omo-codex/plugin/skills/frontend/references/design/stylegallery.md +80 -0
- package/packages/omo-codex/plugin/skills/frontend/references/designpowers/README.md +1 -1
- package/packages/omo-codex/plugin/skills/frontend/references/designpowers/lane-a-direction.md +1 -1
- package/packages/omo-codex/plugin/skills/frontend/references/designpowers/lane-b-execution.md +11 -11
- package/packages/omo-codex/plugin/skills/frontend/references/designpowers/lane-d-memory.md +3 -3
- package/packages/omo-codex/plugin/skills/frontend/references/designpowers/orchestration.md +1 -1
- package/packages/omo-codex/plugin/skills/frontend/references/designpowers/routing.md +5 -5
- package/packages/omo-codex/plugin/skills/review-work/SKILL.md +4 -4
- package/packages/omo-codex/plugin/skills/ultimate-browsing/ATTRIBUTION.md +37 -10
- package/packages/omo-codex/plugin/skills/ultimate-browsing/SKILL.md +2 -0
- package/packages/omo-codex/plugin/skills/ultimate-browsing/engine/AGENTS.md +179 -0
- package/packages/omo-codex/plugin/skills/ultimate-browsing/engine/templates/package.json +1 -1
- package/packages/omo-codex/plugin/skills/ultimate-browsing/references/chrome-stealth.md +13 -11
- package/packages/omo-codex/plugin/skills/ultrawork/SKILL.md +13 -1
- package/packages/omo-codex/plugin/skills/{start-work → ulw-execute}/SKILL.md +12 -11
- package/packages/omo-codex/plugin/skills/ulw-execute/agents/openai.yaml +2 -0
- package/packages/omo-codex/plugin/skills/ulw-loop/SKILL.md +3 -2
- package/packages/omo-codex/plugin/skills/ulw-loop/references/define-goal.md +108 -0
- package/packages/omo-codex/plugin/skills/ulw-loop/references/full-workflow.md +1 -0
- package/packages/omo-codex/plugin/skills/ulw-plan/SKILL.md +6 -6
- package/packages/omo-codex/plugin/skills/ulw-plan/references/full-workflow.md +31 -7
- package/packages/omo-codex/plugin/skills/ulw-plan/references/intent-clear.md +2 -1
- package/packages/omo-codex/plugin/skills/ulw-plan/references/intent-unclear.md +5 -5
- package/packages/omo-codex/plugin/skills/ulw-research/SKILL.md +1 -1
- package/packages/omo-codex/plugin/skills/visual-qa/AGENTS.md +58 -0
- package/packages/omo-codex/plugin/skills/visual-qa/SKILL.md +3 -2
- package/packages/omo-codex/plugin/test/AGENTS.md +47 -0
- package/packages/omo-codex/plugin/test/aggregate-agents.test.mjs +19 -173
- package/packages/omo-codex/plugin/test/aggregate-hooks.test.mjs +8 -28
- package/packages/omo-codex/plugin/test/aggregate-manifest.test.mjs +1 -1
- package/packages/omo-codex/plugin/test/aggregate-plugin-fixture.mjs +175 -13
- package/packages/omo-codex/plugin/test/aggregate.test.mjs +78 -2
- package/packages/omo-codex/plugin/test/auto-update-release-notes.test.mjs +19 -33
- package/packages/omo-codex/plugin/test/component-bin-names.test.mjs +2 -2
- package/packages/omo-codex/plugin/test/component-bundled-cli.test.mjs +1 -1
- package/packages/omo-codex/plugin/test/component-hook-contract-cases.mjs +2 -2
- package/packages/omo-codex/plugin/test/hook-status-message.test.mjs +4 -4
- package/packages/omo-codex/plugin/test/lcx-contribute-bug-fix-template.test.mjs +21 -27
- package/packages/omo-codex/plugin/test/scaffold-plan.test.mjs +0 -36
- package/packages/omo-codex/plugin/test/sync-skills-codex-compatibility.test.mjs +101 -0
- package/packages/omo-codex/plugin/test/sync-skills-test-support.mjs +12 -12
- package/packages/omo-codex/plugin/test/sync-skills.test.mjs +1 -119
- package/packages/omo-codex/plugin/test/teammode-archive-ambiguity.test.mjs +0 -40
- package/packages/omo-codex/plugin/test/teammode-communication.test.mjs +6 -62
- package/packages/omo-codex/plugin/test/teammode-thread-links.test.mjs +3 -36
- package/packages/omo-codex/plugin/test/teammode-transport.test.mjs +0 -44
- package/packages/omo-codex/plugin/test/teammode-worktree.test.mjs +2 -6
- package/packages/omo-codex/plugin/test/ultrawork-skill-pointer.test.mjs +0 -3
- package/packages/omo-codex/plugin/test/ulw-plan-review-state-contract.test.mjs +0 -3
- package/packages/omo-codex/scripts/AGENTS.md +36 -0
- package/packages/omo-codex/scripts/install-dist/install-local.mjs +2601 -528
- package/packages/omo-codex/scripts/install-lazycodex-version-stamp.test.mjs +7 -2
- package/packages/shared-skills/skills/ast-grep/AGENTS.md +51 -0
- package/packages/shared-skills/skills/coding-agent-sessions/AGENTS.md +62 -0
- package/packages/shared-skills/skills/coding-agent-sessions/SKILL.md +3 -2
- package/packages/shared-skills/skills/coding-agent-sessions/references/all-platforms.md +1 -1
- package/packages/shared-skills/skills/coding-agent-sessions/references/senpi.md +4 -4
- package/packages/shared-skills/skills/coding-agent-sessions/scripts/agent_sessions/pi_family.py +1 -1
- package/packages/shared-skills/skills/frontend/SKILL.md +11 -7
- package/packages/shared-skills/skills/frontend/references/design/_INDEX.md +1 -0
- package/packages/shared-skills/skills/frontend/references/design/print-paged-media.md +76 -0
- package/packages/shared-skills/skills/frontend/references/design/stylegallery.md +80 -0
- package/packages/shared-skills/skills/frontend/references/designpowers/README.md +1 -1
- package/packages/shared-skills/skills/frontend/references/designpowers/lane-a-direction.md +1 -1
- package/packages/shared-skills/skills/frontend/references/designpowers/lane-b-execution.md +11 -11
- package/packages/shared-skills/skills/frontend/references/designpowers/lane-d-memory.md +3 -3
- package/packages/shared-skills/skills/frontend/references/designpowers/orchestration.md +1 -1
- package/packages/shared-skills/skills/frontend/references/designpowers/routing.md +5 -5
- package/packages/shared-skills/skills/review-work/SKILL.md +3 -3
- package/packages/shared-skills/skills/ultimate-browsing/ATTRIBUTION.md +37 -10
- package/packages/shared-skills/skills/ultimate-browsing/SKILL.md +2 -0
- package/packages/shared-skills/skills/ultimate-browsing/engine/AGENTS.md +179 -0
- package/packages/shared-skills/skills/ultimate-browsing/engine/templates/package.json +1 -1
- package/packages/shared-skills/skills/ultimate-browsing/references/chrome-stealth.md +13 -11
- package/packages/shared-skills/skills/{start-work → ulw-execute}/SKILL.md +9 -8
- package/packages/shared-skills/skills/ulw-plan/SKILL.md +6 -6
- package/packages/shared-skills/skills/ulw-plan/references/full-workflow.md +31 -7
- package/packages/shared-skills/skills/ulw-plan/references/intent-clear.md +2 -1
- package/packages/shared-skills/skills/ulw-plan/references/intent-unclear.md +5 -5
- package/packages/shared-skills/skills/ulw-research/SKILL.md +1 -1
- package/packages/shared-skills/skills/visual-qa/AGENTS.md +58 -0
- package/packages/shared-skills/skills/visual-qa/SKILL.md +3 -2
- package/script/qa/web-terminal-visual-qa.mjs +2 -0
- package/script/qa/xterm-live-terminal.mjs +18 -2
- package/dist/config/schema/start-work.d.ts +0 -5
- package/dist/features/builtin-commands/templates/start-work.d.ts +0 -1
- package/dist/hooks/start-work/start-work-hook.d.ts +0 -23
- package/dist/plugin/chat-message/start-work-message.d.ts +0 -5
- package/dist/tools/call-omo-agent/background-agent-executor.d.ts +0 -5
- package/packages/omo-codex/plugin/components/start-work-continuation/hooks/hooks.json +0 -28
- package/packages/omo-codex/plugin/hooks/stop-checking-start-work-continuation.json +0 -17
- package/packages/omo-codex/plugin/hooks/subagent-stop-checking-start-work-continuation.json +0 -17
- package/packages/omo-codex/plugin/skills/start-work/agents/openai.yaml +0 -2
- package/packages/omo-codex/plugin/test/aggregate-skills.test.mjs +0 -92
- package/packages/omo-codex/plugin/test/sync-skills-orchestration.test.mjs +0 -314
- package/packages/omo-codex/plugin/test/ulw-plan-scope-contract.test.mjs +0 -24
- /package/dist/hooks/{start-work → ulw-execute}/context-info-formatters.d.ts +0 -0
- /package/dist/hooks/{start-work → ulw-execute}/explicit-plan-context.d.ts +0 -0
- /package/dist/hooks/{start-work → ulw-execute}/notepad-scaffold.d.ts +0 -0
- /package/dist/hooks/{start-work → ulw-execute}/parse-user-request.d.ts +0 -0
- /package/dist/hooks/{start-work → ulw-execute}/plan-discovery-context.d.ts +0 -0
- /package/dist/hooks/{start-work → ulw-execute}/plan-selection.d.ts +0 -0
- /package/dist/hooks/{start-work → ulw-execute}/session-plan-affinity.d.ts +0 -0
- /package/dist/hooks/{start-work → ulw-execute}/work-initializer.d.ts +0 -0
- /package/dist/hooks/{start-work → ulw-execute}/worktree-block.d.ts +0 -0
- /package/dist/hooks/{start-work → ulw-execute}/worktree-detector.d.ts +0 -0
- /package/packages/omo-codex/plugin/components/{start-work-continuation → ulw-execute-continuation}/.gitattributes +0 -0
- /package/packages/omo-codex/plugin/components/{start-work-continuation → ulw-execute-continuation}/CHANGELOG.md +0 -0
- /package/packages/omo-codex/plugin/components/{start-work-continuation → ulw-execute-continuation}/LICENSE +0 -0
- /package/packages/omo-codex/plugin/components/{start-work-continuation → ulw-execute-continuation}/src/plan-checklist.ts +0 -0
- /package/packages/omo-codex/plugin/components/{start-work-continuation → ulw-execute-continuation}/src/types.ts +0 -0
- /package/packages/omo-codex/plugin/components/{start-work-continuation → ulw-execute-continuation}/test/fixtures/boulder-completed.json +0 -0
- /package/packages/omo-codex/plugin/components/{start-work-continuation → ulw-execute-continuation}/test/fixtures/boulder-mixed-platforms.json +0 -0
- /package/packages/omo-codex/plugin/components/{start-work-continuation → ulw-execute-continuation}/test/fixtures/boulder-single-codex-work.json +0 -0
- /package/packages/omo-codex/plugin/components/{start-work-continuation → ulw-execute-continuation}/test/fixtures/plan-all-done.md +0 -0
- /package/packages/omo-codex/plugin/components/{start-work-continuation → ulw-execute-continuation}/test/fixtures/plan-scaffold.md +0 -0
- /package/packages/omo-codex/plugin/components/{start-work-continuation → ulw-execute-continuation}/test/fixtures/plan-with-nested-checkboxes.md +0 -0
- /package/packages/omo-codex/plugin/components/{start-work-continuation → ulw-execute-continuation}/test/fixtures/plan-with-unchecked.md +0 -0
- /package/packages/omo-codex/plugin/components/{start-work-continuation → ulw-execute-continuation}/tsconfig.build.json +0 -0
- /package/packages/omo-codex/plugin/components/{start-work-continuation → ulw-execute-continuation}/tsconfig.json +0 -0
- /package/packages/omo-codex/plugin/components/{start-work-continuation → ulw-execute-continuation}/vitest.config.ts +0 -0
|
@@ -170,6 +170,7 @@ function writePostHogActivityState(stateDir, nextState, diagnostics) {
|
|
|
170
170
|
// ../../../../telemetry-core/src/constants.ts
|
|
171
171
|
var DEFAULT_POSTHOG_HOST = "https://us.i.posthog.com";
|
|
172
172
|
var DEFAULT_POSTHOG_API_KEY = "phc_CFJhj5HyvA62QPhvyaUCtaq23aUfznnijg5VaaGkNk74";
|
|
173
|
+
var UNCONFIGURED_POSTHOG_API_KEY = "phc_REPLACE_ME_OMO_NATIVE";
|
|
173
174
|
|
|
174
175
|
// ../../../../telemetry-core/src/diagnostics.ts
|
|
175
176
|
import { appendFileSync, existsSync as existsSync2, mkdirSync as mkdirSync3, readFileSync as readFileSync2 } from "node:fs";
|
|
@@ -306,6 +307,9 @@ function shouldDisableTelemetry(input) {
|
|
|
306
307
|
const env = input.env ?? process.env;
|
|
307
308
|
const globalPrefix = input.globalEnvPrefix ?? "OMO";
|
|
308
309
|
const prefixes = Array.from(new Set([globalPrefix, input.productEnvPrefix]));
|
|
310
|
+
if (isDisableFlag(env["DO_NOT_TRACK"])) {
|
|
311
|
+
return true;
|
|
312
|
+
}
|
|
309
313
|
for (const prefix of prefixes) {
|
|
310
314
|
if (isDisableFlag(env[`${prefix}_DISABLE_POSTHOG`])) {
|
|
311
315
|
return true;
|
|
@@ -319,21 +323,18 @@ function shouldDisableTelemetry(input) {
|
|
|
319
323
|
function getTelemetryApiKey(env = process.env, defaultApiKey = DEFAULT_POSTHOG_API_KEY) {
|
|
320
324
|
return env["POSTHOG_API_KEY"]?.trim() ?? defaultApiKey;
|
|
321
325
|
}
|
|
322
|
-
function
|
|
323
|
-
|
|
326
|
+
function isConfiguredTelemetryApiKey(apiKey) {
|
|
327
|
+
const normalized = apiKey.trim();
|
|
328
|
+
return normalized.length > 0 && normalized !== UNCONFIGURED_POSTHOG_API_KEY;
|
|
324
329
|
}
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
import { createHash } from "node:crypto";
|
|
328
|
-
import os2 from "node:os";
|
|
329
|
-
function getDefaultTelemetryOsProvider() {
|
|
330
|
-
return os2;
|
|
330
|
+
function hasTelemetryApiKey(env, defaultApiKey) {
|
|
331
|
+
return isConfiguredTelemetryApiKey(getTelemetryApiKey(env, defaultApiKey));
|
|
331
332
|
}
|
|
332
|
-
function
|
|
333
|
-
return
|
|
333
|
+
function getTelemetryHost(env = process.env, defaultHost = DEFAULT_POSTHOG_HOST) {
|
|
334
|
+
return env["POSTHOG_HOST"]?.trim() || defaultHost;
|
|
334
335
|
}
|
|
335
336
|
|
|
336
|
-
// ../../../../../node_modules/.bun/posthog-node@5.
|
|
337
|
+
// ../../../../../node_modules/.bun/posthog-node@5.51.1/node_modules/posthog-node/dist/extensions/error-tracking/modifiers/module.node.mjs
|
|
337
338
|
import { dirname, posix, sep } from "path";
|
|
338
339
|
function createModulerModifier() {
|
|
339
340
|
const getModuleFromFileName = createGetModuleFromFilename();
|
|
@@ -369,7 +370,7 @@ function normalizeWindowsPath(path2) {
|
|
|
369
370
|
return path2.replace(/^[A-Z]:/, "").replace(/\\/g, "/");
|
|
370
371
|
}
|
|
371
372
|
|
|
372
|
-
// ../../../../../node_modules/.bun/@posthog+core@1.
|
|
373
|
+
// ../../../../../node_modules/.bun/@posthog+core@1.48.9/node_modules/@posthog/core/dist/featureFlagUtils.mjs
|
|
373
374
|
var normalizeFlagsResponse = (flagsResponse) => {
|
|
374
375
|
if ("flags" in flagsResponse) {
|
|
375
376
|
const featureFlags = getFlagValuesFromFlags(flagsResponse.flags);
|
|
@@ -439,8 +440,69 @@ var parsePayload = (response) => {
|
|
|
439
440
|
return response;
|
|
440
441
|
}
|
|
441
442
|
};
|
|
443
|
+
var MINIMAL_FLAG_CALLED_EVENT_CAMPAIGN_PROPERTIES = [
|
|
444
|
+
"utm_source",
|
|
445
|
+
"utm_medium",
|
|
446
|
+
"utm_campaign",
|
|
447
|
+
"utm_content",
|
|
448
|
+
"utm_term",
|
|
449
|
+
"gad_source",
|
|
450
|
+
"mc_cid",
|
|
451
|
+
"gclid",
|
|
452
|
+
"gclsrc",
|
|
453
|
+
"dclid",
|
|
454
|
+
"gbraid",
|
|
455
|
+
"wbraid",
|
|
456
|
+
"fbclid",
|
|
457
|
+
"msclkid",
|
|
458
|
+
"twclid",
|
|
459
|
+
"li_fat_id",
|
|
460
|
+
"igshid",
|
|
461
|
+
"ttclid",
|
|
462
|
+
"rdt_cid",
|
|
463
|
+
"epik",
|
|
464
|
+
"qclid",
|
|
465
|
+
"sccid",
|
|
466
|
+
"irclid",
|
|
467
|
+
"_kx"
|
|
468
|
+
];
|
|
469
|
+
var MINIMAL_FLAG_CALLED_EVENT_PROPERTIES = [
|
|
470
|
+
"$feature_flag",
|
|
471
|
+
"$feature_flag_response",
|
|
472
|
+
"$feature_flag_has_experiment",
|
|
473
|
+
"$feature_flag_id",
|
|
474
|
+
"$feature_flag_version",
|
|
475
|
+
"$feature_flag_reason",
|
|
476
|
+
"$feature_flag_request_id",
|
|
477
|
+
"$feature_flag_evaluated_at",
|
|
478
|
+
"$feature_flag_error",
|
|
479
|
+
"locally_evaluated",
|
|
480
|
+
"$groups",
|
|
481
|
+
"$process_person_profile",
|
|
482
|
+
"$geoip_disable",
|
|
483
|
+
"$current_url",
|
|
484
|
+
"$pathname",
|
|
485
|
+
"$referring_domain",
|
|
486
|
+
...MINIMAL_FLAG_CALLED_EVENT_CAMPAIGN_PROPERTIES,
|
|
487
|
+
"$session_id",
|
|
488
|
+
"$window_id",
|
|
489
|
+
"$lib",
|
|
490
|
+
"$lib_version",
|
|
491
|
+
"$device_id",
|
|
492
|
+
"$is_server"
|
|
493
|
+
];
|
|
494
|
+
var minimizeFlagCalledEventProperties = (properties, transportKeys = []) => {
|
|
495
|
+
const minimal = {};
|
|
496
|
+
const copyKey = (key) => {
|
|
497
|
+
if (properties[key] !== undefined)
|
|
498
|
+
minimal[key] = properties[key];
|
|
499
|
+
};
|
|
500
|
+
MINIMAL_FLAG_CALLED_EVENT_PROPERTIES.forEach(copyKey);
|
|
501
|
+
transportKeys.forEach(copyKey);
|
|
502
|
+
return minimal;
|
|
503
|
+
};
|
|
442
504
|
|
|
443
|
-
// ../../../../../node_modules/.bun/@posthog+core@1.
|
|
505
|
+
// ../../../../../node_modules/.bun/@posthog+core@1.48.9/node_modules/@posthog/core/dist/types.mjs
|
|
444
506
|
var types_PostHogPersistedProperty = /* @__PURE__ */ function(PostHogPersistedProperty) {
|
|
445
507
|
PostHogPersistedProperty["AnonymousId"] = "anonymous_id";
|
|
446
508
|
PostHogPersistedProperty["DistinctId"] = "distinct_id";
|
|
@@ -455,6 +517,8 @@ var types_PostHogPersistedProperty = /* @__PURE__ */ function(PostHogPersistedPr
|
|
|
455
517
|
PostHogPersistedProperty["BootstrapFeatureFlagPayloads"] = "bootstrap_feature_flag_payloads";
|
|
456
518
|
PostHogPersistedProperty["OverrideFeatureFlags"] = "override_feature_flags";
|
|
457
519
|
PostHogPersistedProperty["Queue"] = "queue";
|
|
520
|
+
PostHogPersistedProperty["AiQueue"] = "ai_queue";
|
|
521
|
+
PostHogPersistedProperty["AiCaptureQueue"] = "ai_capture_queue";
|
|
458
522
|
PostHogPersistedProperty["LogsQueue"] = "logs_queue";
|
|
459
523
|
PostHogPersistedProperty["OptedOut"] = "opted_out";
|
|
460
524
|
PostHogPersistedProperty["SessionId"] = "session_id";
|
|
@@ -465,6 +529,8 @@ var types_PostHogPersistedProperty = /* @__PURE__ */ function(PostHogPersistedPr
|
|
|
465
529
|
PostHogPersistedProperty["InstalledAppBuild"] = "installed_app_build";
|
|
466
530
|
PostHogPersistedProperty["InstalledAppVersion"] = "installed_app_version";
|
|
467
531
|
PostHogPersistedProperty["SessionReplay"] = "session_replay";
|
|
532
|
+
PostHogPersistedProperty["PushRegistered"] = "push_registered";
|
|
533
|
+
PostHogPersistedProperty["SessionReplayEventTriggerActivatedSession"] = "session_replay_event_trigger_activated_session";
|
|
468
534
|
PostHogPersistedProperty["SurveyLastSeenDate"] = "survey_last_seen_date";
|
|
469
535
|
PostHogPersistedProperty["SurveysSeen"] = "surveys_seen";
|
|
470
536
|
PostHogPersistedProperty["Surveys"] = "surveys";
|
|
@@ -474,7 +540,7 @@ var types_PostHogPersistedProperty = /* @__PURE__ */ function(PostHogPersistedPr
|
|
|
474
540
|
return PostHogPersistedProperty;
|
|
475
541
|
}({});
|
|
476
542
|
|
|
477
|
-
// ../../../../../node_modules/.bun/@posthog+core@1.
|
|
543
|
+
// ../../../../../node_modules/.bun/@posthog+core@1.48.9/node_modules/@posthog/core/dist/gzip.mjs
|
|
478
544
|
function isGzipSupported() {
|
|
479
545
|
return "CompressionStream" in globalThis && "TextEncoder" in globalThis && "Response" in globalThis && typeof Response.prototype.blob == "function";
|
|
480
546
|
}
|
|
@@ -524,7 +590,7 @@ var validateNativeGzip = async (compressed, inputBytes) => {
|
|
|
524
590
|
async function gzipCompress(input, isDebug = true, options) {
|
|
525
591
|
try {
|
|
526
592
|
const inputBytes = new TextEncoder().encode(input);
|
|
527
|
-
const compressedStream = new CompressionStream("gzip");
|
|
593
|
+
const compressedStream = new globalThis.CompressionStream("gzip");
|
|
528
594
|
const writer = compressedStream.writable.getWriter();
|
|
529
595
|
const writePromise = writer.write(inputBytes).then(() => writer.close()).catch(async (err) => {
|
|
530
596
|
try {
|
|
@@ -548,7 +614,34 @@ async function gzipCompress(input, isDebug = true, options) {
|
|
|
548
614
|
}
|
|
549
615
|
}
|
|
550
616
|
|
|
551
|
-
// ../../../../../node_modules/.bun/@posthog+core@1.
|
|
617
|
+
// ../../../../../node_modules/.bun/@posthog+core@1.48.9/node_modules/@posthog/core/dist/utils/json-utils.mjs
|
|
618
|
+
var MAX_JSON_SAFE_VALUE_DEPTH = 20;
|
|
619
|
+
var MAX_JSON_SAFE_VALUE_ITEMS = 1000;
|
|
620
|
+
var MAX_JSON_SAFE_VALUE_NODES = 1e4;
|
|
621
|
+
var CIRCULAR_VALUE = "[Circular]";
|
|
622
|
+
var TRUNCATED_VALUE = "[Truncated]";
|
|
623
|
+
var UNSERIALIZABLE_VALUE = "[Unserializable]";
|
|
624
|
+
var FUNCTION_VALUE = "[Function]";
|
|
625
|
+
var dateGetTime = Date.prototype.getTime;
|
|
626
|
+
var dateToISOString = Date.prototype.toISOString;
|
|
627
|
+
function sanitizeString(value) {
|
|
628
|
+
let output = "";
|
|
629
|
+
for (let index = 0;index < value.length; index++) {
|
|
630
|
+
const codeUnit = value.charCodeAt(index);
|
|
631
|
+
if (codeUnit >= 55296 && codeUnit <= 56319) {
|
|
632
|
+
const nextCodeUnit = value.charCodeAt(index + 1);
|
|
633
|
+
if (nextCodeUnit >= 56320 && nextCodeUnit <= 57343) {
|
|
634
|
+
output += value[index] + value[index + 1];
|
|
635
|
+
index++;
|
|
636
|
+
} else
|
|
637
|
+
output += "�";
|
|
638
|
+
} else
|
|
639
|
+
output += codeUnit >= 56320 && codeUnit <= 57343 ? "�" : value[index];
|
|
640
|
+
}
|
|
641
|
+
return output;
|
|
642
|
+
}
|
|
643
|
+
|
|
644
|
+
// ../../../../../node_modules/.bun/@posthog+core@1.48.9/node_modules/@posthog/core/dist/utils/bot-detection.mjs
|
|
552
645
|
var DEFAULT_BLOCKED_UA_STRS = [
|
|
553
646
|
"amazonbot",
|
|
554
647
|
"amazonproductbot",
|
|
@@ -637,7 +730,31 @@ var isBlockedUA = function(ua, customBlockedUserAgents = []) {
|
|
|
637
730
|
return uaLower.indexOf(blockedUaLower) !== -1;
|
|
638
731
|
});
|
|
639
732
|
};
|
|
640
|
-
// ../../../../../node_modules/.bun/@posthog+core@1.
|
|
733
|
+
// ../../../../../node_modules/.bun/@posthog+core@1.48.9/node_modules/@posthog/core/dist/utils/string-utils.mjs
|
|
734
|
+
function safeJsonStringify(value) {
|
|
735
|
+
const ancestors = [];
|
|
736
|
+
return JSON.stringify(value, function(_key, replacementValue) {
|
|
737
|
+
if (typeof replacementValue == "bigint")
|
|
738
|
+
return replacementValue.toString();
|
|
739
|
+
if (typeof replacementValue == "function" || typeof replacementValue == "symbol")
|
|
740
|
+
return;
|
|
741
|
+
if (replacementValue instanceof Error)
|
|
742
|
+
return {
|
|
743
|
+
name: replacementValue.name,
|
|
744
|
+
message: replacementValue.message,
|
|
745
|
+
stack: replacementValue.stack
|
|
746
|
+
};
|
|
747
|
+
if (replacementValue && typeof replacementValue == "object") {
|
|
748
|
+
while (ancestors.length > 0 && ancestors[ancestors.length - 1] !== this)
|
|
749
|
+
ancestors.pop();
|
|
750
|
+
if (ancestors.includes(replacementValue))
|
|
751
|
+
return "[Circular]";
|
|
752
|
+
ancestors.push(replacementValue);
|
|
753
|
+
}
|
|
754
|
+
return replacementValue;
|
|
755
|
+
}) ?? "null";
|
|
756
|
+
}
|
|
757
|
+
// ../../../../../node_modules/.bun/@posthog+core@1.48.9/node_modules/@posthog/core/dist/utils/type-utils.mjs
|
|
641
758
|
var nativeIsArray = Array.isArray;
|
|
642
759
|
var ObjProto = Object.prototype;
|
|
643
760
|
var type_utils_hasOwnProperty = ObjProto.hasOwnProperty;
|
|
@@ -649,14 +766,28 @@ var isObject = (x) => x === Object(x) && !isArray(x);
|
|
|
649
766
|
var isUndefined = (x) => x === undefined;
|
|
650
767
|
var isString = (x) => type_utils_toString.call(x) == "[object String]";
|
|
651
768
|
var isEmptyString = (x) => isString(x) && x.trim().length === 0;
|
|
769
|
+
var isNull = (x) => x === null;
|
|
770
|
+
var isNullish = (x) => isUndefined(x) || isNull(x);
|
|
652
771
|
var isNumber = (x) => type_utils_toString.call(x) == "[object Number]" && x === x;
|
|
653
|
-
var
|
|
772
|
+
var isBoolean = (x) => type_utils_toString.call(x) === "[object Boolean]";
|
|
654
773
|
function isPrimitive(value) {
|
|
655
774
|
return value === null || typeof value != "object";
|
|
656
775
|
}
|
|
657
776
|
function isBuiltin(candidate, className) {
|
|
658
777
|
return Object.prototype.toString.call(candidate) === `[object ${className}]`;
|
|
659
778
|
}
|
|
779
|
+
function isError(candidate) {
|
|
780
|
+
switch (Object.prototype.toString.call(candidate)) {
|
|
781
|
+
case "[object Error]":
|
|
782
|
+
case "[object Exception]":
|
|
783
|
+
case "[object DOMException]":
|
|
784
|
+
case "[object DOMError]":
|
|
785
|
+
case "[object WebAssembly.Exception]":
|
|
786
|
+
return true;
|
|
787
|
+
default:
|
|
788
|
+
return isInstanceOf(candidate, Error);
|
|
789
|
+
}
|
|
790
|
+
}
|
|
660
791
|
function isErrorEvent(event) {
|
|
661
792
|
return isBuiltin(event, "ErrorEvent");
|
|
662
793
|
}
|
|
@@ -674,7 +805,7 @@ function isInstanceOf(candidate, base) {
|
|
|
674
805
|
}
|
|
675
806
|
}
|
|
676
807
|
|
|
677
|
-
// ../../../../../node_modules/.bun/@posthog+core@1.
|
|
808
|
+
// ../../../../../node_modules/.bun/@posthog+core@1.48.9/node_modules/@posthog/core/dist/utils/number-utils.mjs
|
|
678
809
|
function clampToRange(value, min, max, logger, fallbackValue) {
|
|
679
810
|
if (min > max) {
|
|
680
811
|
logger.warn("min cannot be greater than max.");
|
|
@@ -694,8 +825,16 @@ function clampToRange(value, min, max, logger, fallbackValue) {
|
|
|
694
825
|
return clampToRange(fallbackValue || max, min, max, logger);
|
|
695
826
|
}
|
|
696
827
|
|
|
697
|
-
// ../../../../../node_modules/.bun/@posthog+core@1.
|
|
828
|
+
// ../../../../../node_modules/.bun/@posthog+core@1.48.9/node_modules/@posthog/core/dist/utils/bucketed-rate-limiter.mjs
|
|
698
829
|
var ONE_DAY_IN_MS = 86400000;
|
|
830
|
+
var DEFAULT_EXCEPTION_RATE_LIMITER_REFILL_RATE = 1;
|
|
831
|
+
var DEFAULT_EXCEPTION_RATE_LIMITER_BUCKET_SIZE = 10;
|
|
832
|
+
function resolveExceptionRateLimiterConfig(config = {}) {
|
|
833
|
+
return {
|
|
834
|
+
refillRate: config.exceptionRateLimiterRefillRate ?? config.__exceptionRateLimiterRefillRate ?? DEFAULT_EXCEPTION_RATE_LIMITER_REFILL_RATE,
|
|
835
|
+
bucketSize: config.exceptionRateLimiterBucketSize ?? config.__exceptionRateLimiterBucketSize ?? DEFAULT_EXCEPTION_RATE_LIMITER_BUCKET_SIZE
|
|
836
|
+
};
|
|
837
|
+
}
|
|
699
838
|
|
|
700
839
|
class BucketedRateLimiter {
|
|
701
840
|
constructor(options) {
|
|
@@ -738,7 +877,7 @@ class BucketedRateLimiter {
|
|
|
738
877
|
this._buckets = {};
|
|
739
878
|
}
|
|
740
879
|
}
|
|
741
|
-
// ../../../../../node_modules/.bun/@posthog+core@1.
|
|
880
|
+
// ../../../../../node_modules/.bun/@posthog+core@1.48.9/node_modules/@posthog/core/dist/vendor/uuidv7.mjs
|
|
742
881
|
/*! For license information please see uuidv7.mjs.LICENSE.txt */
|
|
743
882
|
var DIGITS = "0123456789abcdef";
|
|
744
883
|
|
|
@@ -916,33 +1055,45 @@ var defaultGenerator;
|
|
|
916
1055
|
var uuidv7 = () => uuidv7obj().toString();
|
|
917
1056
|
var uuidv7obj = () => (defaultGenerator || (defaultGenerator = new V7Generator)).generate();
|
|
918
1057
|
|
|
919
|
-
// ../../../../../node_modules/.bun/@posthog+core@1.
|
|
1058
|
+
// ../../../../../node_modules/.bun/@posthog+core@1.48.9/node_modules/@posthog/core/dist/utils/promise-queue.mjs
|
|
920
1059
|
class PromiseQueue {
|
|
921
1060
|
add(promise) {
|
|
922
1061
|
const promiseUUID = uuidv7();
|
|
923
|
-
|
|
1062
|
+
const id = ++this.nextId;
|
|
1063
|
+
this.promiseByIds[promiseUUID] = {
|
|
1064
|
+
id,
|
|
1065
|
+
promise
|
|
1066
|
+
};
|
|
924
1067
|
promise.catch(() => {}).finally(() => {
|
|
925
1068
|
delete this.promiseByIds[promiseUUID];
|
|
926
1069
|
});
|
|
927
1070
|
return promise;
|
|
928
1071
|
}
|
|
929
1072
|
async join() {
|
|
930
|
-
let promises = Object.values(this.promiseByIds);
|
|
1073
|
+
let promises = Object.values(this.promiseByIds).map((item) => item.promise);
|
|
931
1074
|
let length = promises.length;
|
|
932
1075
|
while (length > 0) {
|
|
933
1076
|
await Promise.all(promises);
|
|
934
|
-
promises = Object.values(this.promiseByIds);
|
|
1077
|
+
promises = Object.values(this.promiseByIds).map((item) => item.promise);
|
|
935
1078
|
length = promises.length;
|
|
936
1079
|
}
|
|
937
1080
|
}
|
|
1081
|
+
getPromises(ignoredPromises = [], maxId = this.nextId) {
|
|
1082
|
+
const ignoredPromiseSet = new Set(ignoredPromises);
|
|
1083
|
+
return Object.values(this.promiseByIds).filter((item) => item.id <= maxId && !ignoredPromiseSet.has(item.promise)).map((item) => item.promise);
|
|
1084
|
+
}
|
|
1085
|
+
get maxId() {
|
|
1086
|
+
return this.nextId;
|
|
1087
|
+
}
|
|
938
1088
|
get length() {
|
|
939
1089
|
return Object.keys(this.promiseByIds).length;
|
|
940
1090
|
}
|
|
941
1091
|
constructor() {
|
|
942
1092
|
this.promiseByIds = {};
|
|
1093
|
+
this.nextId = 0;
|
|
943
1094
|
}
|
|
944
1095
|
}
|
|
945
|
-
// ../../../../../node_modules/.bun/@posthog+core@1.
|
|
1096
|
+
// ../../../../../node_modules/.bun/@posthog+core@1.48.9/node_modules/@posthog/core/dist/utils/logger.mjs
|
|
946
1097
|
function createConsole(consoleLike = console) {
|
|
947
1098
|
const lockedMethods = {
|
|
948
1099
|
log: consoleLike.log.bind(consoleLike),
|
|
@@ -983,7 +1134,7 @@ var passThrough = (fn) => fn();
|
|
|
983
1134
|
function createLogger(prefix, maybeCall = passThrough) {
|
|
984
1135
|
return _createLogger(prefix, maybeCall, createConsole());
|
|
985
1136
|
}
|
|
986
|
-
// ../../../../../node_modules/.bun/@posthog+core@1.
|
|
1137
|
+
// ../../../../../node_modules/.bun/@posthog+core@1.48.9/node_modules/@posthog/core/dist/utils/user-agent-utils.mjs
|
|
987
1138
|
var MOBILE = "Mobile";
|
|
988
1139
|
var IOS = "iOS";
|
|
989
1140
|
var ANDROID = "Android";
|
|
@@ -1026,6 +1177,7 @@ var DUCKDUCKGO = "DuckDuckGo";
|
|
|
1026
1177
|
var PALE_MOON = "Pale Moon";
|
|
1027
1178
|
var WATERFOX = "Waterfox";
|
|
1028
1179
|
var BRAVE = "Brave";
|
|
1180
|
+
var GOOGLE_SEARCH_APP = "Google Search App";
|
|
1029
1181
|
var BROWSER_VERSION_REGEX_SUFFIX = "(\\d+(\\.\\d+)?)";
|
|
1030
1182
|
var DEFAULT_BROWSER_VERSION_REGEX = new RegExp("Version/" + BROWSER_VERSION_REGEX_SUFFIX);
|
|
1031
1183
|
var XBOX_REGEX = new RegExp(XBOX, "i");
|
|
@@ -1113,6 +1265,9 @@ var versionRegexes = {
|
|
|
1113
1265
|
[WATERFOX]: [
|
|
1114
1266
|
new RegExp(WATERFOX + "\\/" + BROWSER_VERSION_REGEX_SUFFIX)
|
|
1115
1267
|
],
|
|
1268
|
+
[GOOGLE_SEARCH_APP]: [
|
|
1269
|
+
new RegExp("GSA\\/" + BROWSER_VERSION_REGEX_SUFFIX)
|
|
1270
|
+
],
|
|
1116
1271
|
[INTERNET_EXPLORER]: [
|
|
1117
1272
|
new RegExp("(rv:|MSIE )" + BROWSER_VERSION_REGEX_SUFFIX)
|
|
1118
1273
|
],
|
|
@@ -1272,8 +1427,15 @@ var osMatchers = [
|
|
|
1272
1427
|
]
|
|
1273
1428
|
];
|
|
1274
1429
|
|
|
1275
|
-
// ../../../../../node_modules/.bun/@posthog+core@1.
|
|
1430
|
+
// ../../../../../node_modules/.bun/@posthog+core@1.48.9/node_modules/@posthog/core/dist/utils/index.mjs
|
|
1276
1431
|
var STRING_FORMAT = "utf8";
|
|
1432
|
+
var UUID_REGEX = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
1433
|
+
function isValidUUID(value) {
|
|
1434
|
+
return typeof value == "string" && UUID_REGEX.test(value);
|
|
1435
|
+
}
|
|
1436
|
+
function getEventUuid(uuid, generateUuid) {
|
|
1437
|
+
return isValidUUID(uuid) ? uuid : generateUuid();
|
|
1438
|
+
}
|
|
1277
1439
|
function removeTrailingSlash(url) {
|
|
1278
1440
|
return url?.replace(/\/+$/, "");
|
|
1279
1441
|
}
|
|
@@ -1301,7 +1463,26 @@ function safeSetTimeout(fn, timeout) {
|
|
|
1301
1463
|
t?.unref && t?.unref();
|
|
1302
1464
|
return t;
|
|
1303
1465
|
}
|
|
1304
|
-
|
|
1466
|
+
async function raceWithTimeout(promise, timeoutMs, onTimeout) {
|
|
1467
|
+
let timeoutHandle;
|
|
1468
|
+
try {
|
|
1469
|
+
return await Promise.race([
|
|
1470
|
+
promise,
|
|
1471
|
+
new Promise((resolve, reject) => {
|
|
1472
|
+
timeoutHandle = safeSetTimeout(() => {
|
|
1473
|
+
try {
|
|
1474
|
+
onTimeout?.();
|
|
1475
|
+
resolve();
|
|
1476
|
+
} catch (error) {
|
|
1477
|
+
reject(error);
|
|
1478
|
+
}
|
|
1479
|
+
}, timeoutMs);
|
|
1480
|
+
})
|
|
1481
|
+
]);
|
|
1482
|
+
} finally {
|
|
1483
|
+
clearTimeout(timeoutHandle);
|
|
1484
|
+
}
|
|
1485
|
+
}
|
|
1305
1486
|
function allSettled(promises) {
|
|
1306
1487
|
return Promise.all(promises.map((p) => (p ?? Promise.resolve()).then((value) => ({
|
|
1307
1488
|
status: "fulfilled",
|
|
@@ -1312,7 +1493,7 @@ function allSettled(promises) {
|
|
|
1312
1493
|
}))));
|
|
1313
1494
|
}
|
|
1314
1495
|
|
|
1315
|
-
// ../../../../../node_modules/.bun/@posthog+core@1.
|
|
1496
|
+
// ../../../../../node_modules/.bun/@posthog+core@1.48.9/node_modules/@posthog/core/dist/logs/logs-utils.mjs
|
|
1316
1497
|
var OTLP_SEVERITY_MAP = {
|
|
1317
1498
|
trace: {
|
|
1318
1499
|
text: "TRACE",
|
|
@@ -1340,7 +1521,570 @@ var OTLP_SEVERITY_MAP = {
|
|
|
1340
1521
|
}
|
|
1341
1522
|
};
|
|
1342
1523
|
var DEFAULT_OTLP_SEVERITY = OTLP_SEVERITY_MAP.info;
|
|
1343
|
-
|
|
1524
|
+
var INT64_RANGE_LIMIT = 9223372036854776000;
|
|
1525
|
+
var propertyIsEnumerable = Object.prototype.propertyIsEnumerable;
|
|
1526
|
+
function newState() {
|
|
1527
|
+
return {
|
|
1528
|
+
ancestors: new WeakSet,
|
|
1529
|
+
remainingNodes: MAX_JSON_SAFE_VALUE_NODES
|
|
1530
|
+
};
|
|
1531
|
+
}
|
|
1532
|
+
function toOtlpKeyValueList(attrs, logger2) {
|
|
1533
|
+
try {
|
|
1534
|
+
return encodeKeyValueList(attrs, logger2, newState(), 0);
|
|
1535
|
+
} catch {
|
|
1536
|
+
return [];
|
|
1537
|
+
}
|
|
1538
|
+
}
|
|
1539
|
+
function encodeAnyValue(value, logger2, state, depth) {
|
|
1540
|
+
if (state.remainingNodes <= 0)
|
|
1541
|
+
return {
|
|
1542
|
+
stringValue: TRUNCATED_VALUE
|
|
1543
|
+
};
|
|
1544
|
+
state.remainingNodes--;
|
|
1545
|
+
if (isBoolean(value))
|
|
1546
|
+
return {
|
|
1547
|
+
boolValue: value
|
|
1548
|
+
};
|
|
1549
|
+
if (typeof value == "number") {
|
|
1550
|
+
if (!Number.isFinite(value))
|
|
1551
|
+
return {
|
|
1552
|
+
stringValue: String(value)
|
|
1553
|
+
};
|
|
1554
|
+
if (Number.isInteger(value)) {
|
|
1555
|
+
if (Number.isSafeInteger(value))
|
|
1556
|
+
return {
|
|
1557
|
+
intValue: String(value)
|
|
1558
|
+
};
|
|
1559
|
+
if (typeof BigInt == "undefined")
|
|
1560
|
+
return {
|
|
1561
|
+
stringValue: String(value)
|
|
1562
|
+
};
|
|
1563
|
+
const decimal = BigInt(value).toString();
|
|
1564
|
+
if (value >= INT64_RANGE_LIMIT || value < -INT64_RANGE_LIMIT) {
|
|
1565
|
+
logger2?.debug(`Attribute ${decimal} is outside the int64 range; encoding it as a string`);
|
|
1566
|
+
return {
|
|
1567
|
+
stringValue: decimal
|
|
1568
|
+
};
|
|
1569
|
+
}
|
|
1570
|
+
return {
|
|
1571
|
+
intValue: decimal
|
|
1572
|
+
};
|
|
1573
|
+
}
|
|
1574
|
+
return {
|
|
1575
|
+
doubleValue: value
|
|
1576
|
+
};
|
|
1577
|
+
}
|
|
1578
|
+
if (typeof value == "string")
|
|
1579
|
+
return {
|
|
1580
|
+
stringValue: sanitizeString(value)
|
|
1581
|
+
};
|
|
1582
|
+
if (typeof value == "function")
|
|
1583
|
+
return {
|
|
1584
|
+
stringValue: FUNCTION_VALUE
|
|
1585
|
+
};
|
|
1586
|
+
if (typeof value == "symbol")
|
|
1587
|
+
return {
|
|
1588
|
+
stringValue: String(value)
|
|
1589
|
+
};
|
|
1590
|
+
if (typeof value == "object" && value !== null) {
|
|
1591
|
+
if (state.ancestors.has(value))
|
|
1592
|
+
return {
|
|
1593
|
+
stringValue: CIRCULAR_VALUE
|
|
1594
|
+
};
|
|
1595
|
+
if (depth >= MAX_JSON_SAFE_VALUE_DEPTH)
|
|
1596
|
+
return {
|
|
1597
|
+
stringValue: TRUNCATED_VALUE
|
|
1598
|
+
};
|
|
1599
|
+
if (value instanceof Date) {
|
|
1600
|
+
const time = value.getTime();
|
|
1601
|
+
const iso = Number.isFinite(time) ? value.toISOString() : String(value);
|
|
1602
|
+
return {
|
|
1603
|
+
stringValue: typeof iso == "string" ? sanitizeString(iso) : String(iso)
|
|
1604
|
+
};
|
|
1605
|
+
}
|
|
1606
|
+
state.ancestors.add(value);
|
|
1607
|
+
try {
|
|
1608
|
+
try {
|
|
1609
|
+
const toJSON = value.toJSON;
|
|
1610
|
+
if (typeof toJSON == "function")
|
|
1611
|
+
return encodeAnyValue(toJSON.call(value), logger2, state, depth + 1);
|
|
1612
|
+
} catch {}
|
|
1613
|
+
if (isArray(value))
|
|
1614
|
+
return {
|
|
1615
|
+
arrayValue: {
|
|
1616
|
+
values: encodeArrayValues(value, logger2, state, depth + 1)
|
|
1617
|
+
}
|
|
1618
|
+
};
|
|
1619
|
+
return {
|
|
1620
|
+
kvlistValue: {
|
|
1621
|
+
values: encodeKeyValueList(value, logger2, state, depth + 1)
|
|
1622
|
+
}
|
|
1623
|
+
};
|
|
1624
|
+
} finally {
|
|
1625
|
+
state.ancestors.delete(value);
|
|
1626
|
+
}
|
|
1627
|
+
}
|
|
1628
|
+
return {
|
|
1629
|
+
stringValue: sanitizeString(String(value))
|
|
1630
|
+
};
|
|
1631
|
+
}
|
|
1632
|
+
function encodeArrayValues(values, logger2, state, depth) {
|
|
1633
|
+
const result = [];
|
|
1634
|
+
const itemCount = Math.min(values.length, MAX_JSON_SAFE_VALUE_ITEMS);
|
|
1635
|
+
let index = 0;
|
|
1636
|
+
for (;index < itemCount && state.remainingNodes > 0; index++)
|
|
1637
|
+
try {
|
|
1638
|
+
const element = index in values ? values[index] : undefined;
|
|
1639
|
+
if (isNullish(element))
|
|
1640
|
+
continue;
|
|
1641
|
+
result.push(encodeAnyValue(element, logger2, state, depth));
|
|
1642
|
+
} catch {
|
|
1643
|
+
result.push({
|
|
1644
|
+
stringValue: UNSERIALIZABLE_VALUE
|
|
1645
|
+
});
|
|
1646
|
+
}
|
|
1647
|
+
if (values.length > index)
|
|
1648
|
+
result.push({
|
|
1649
|
+
stringValue: TRUNCATED_VALUE
|
|
1650
|
+
});
|
|
1651
|
+
return result;
|
|
1652
|
+
}
|
|
1653
|
+
function encodeKeyValueList(attrs, logger2, state, depth) {
|
|
1654
|
+
const result = [];
|
|
1655
|
+
for (const key in attrs)
|
|
1656
|
+
if (propertyIsEnumerable.call(attrs, key)) {
|
|
1657
|
+
if (result.length >= MAX_JSON_SAFE_VALUE_ITEMS || state.remainingNodes <= 0) {
|
|
1658
|
+
logger2?.debug("Attributes truncated: the value exceeds the OTLP encoder budget");
|
|
1659
|
+
break;
|
|
1660
|
+
}
|
|
1661
|
+
try {
|
|
1662
|
+
const value = attrs[key];
|
|
1663
|
+
if (isNull(value) || isUndefined(value))
|
|
1664
|
+
continue;
|
|
1665
|
+
result.push({
|
|
1666
|
+
key: sanitizeString(key),
|
|
1667
|
+
value: encodeAnyValue(value, logger2, state, depth)
|
|
1668
|
+
});
|
|
1669
|
+
} catch {
|
|
1670
|
+
result.push({
|
|
1671
|
+
key: sanitizeString(key),
|
|
1672
|
+
value: {
|
|
1673
|
+
stringValue: UNSERIALIZABLE_VALUE
|
|
1674
|
+
}
|
|
1675
|
+
});
|
|
1676
|
+
}
|
|
1677
|
+
}
|
|
1678
|
+
return result;
|
|
1679
|
+
}
|
|
1680
|
+
|
|
1681
|
+
// ../../../../../node_modules/.bun/@posthog+core@1.48.9/node_modules/@posthog/core/dist/metrics/metrics-utils.mjs
|
|
1682
|
+
var DEFAULT_HISTOGRAM_BOUNDS = [
|
|
1683
|
+
0,
|
|
1684
|
+
5,
|
|
1685
|
+
10,
|
|
1686
|
+
25,
|
|
1687
|
+
50,
|
|
1688
|
+
75,
|
|
1689
|
+
100,
|
|
1690
|
+
250,
|
|
1691
|
+
500,
|
|
1692
|
+
750,
|
|
1693
|
+
1000,
|
|
1694
|
+
2500,
|
|
1695
|
+
5000,
|
|
1696
|
+
7500,
|
|
1697
|
+
1e4
|
|
1698
|
+
];
|
|
1699
|
+
function msToUnixNano(ms) {
|
|
1700
|
+
return String(ms) + "000000";
|
|
1701
|
+
}
|
|
1702
|
+
function seriesKey(type, name, unit, attributes) {
|
|
1703
|
+
let attrsKey = "";
|
|
1704
|
+
if (attributes) {
|
|
1705
|
+
const keys = Object.keys(attributes).sort();
|
|
1706
|
+
attrsKey = keys.map((k) => `${JSON.stringify(k)}:${JSON.stringify(attributes[k])}`).join(",");
|
|
1707
|
+
}
|
|
1708
|
+
return `${type}\x00${name}\x00${unit ?? ""}\x00${attrsKey}`;
|
|
1709
|
+
}
|
|
1710
|
+
function bucketIndexFor(value, bounds) {
|
|
1711
|
+
for (let i = 0;i < bounds.length; i++)
|
|
1712
|
+
if (value <= bounds[i])
|
|
1713
|
+
return i;
|
|
1714
|
+
return bounds.length;
|
|
1715
|
+
}
|
|
1716
|
+
function buildMetricsResourceAttributes(config, scopeName, scopeVersion) {
|
|
1717
|
+
return {
|
|
1718
|
+
...config.resourceAttributes,
|
|
1719
|
+
"service.name": config.serviceName || "unknown_service",
|
|
1720
|
+
...config.environment && {
|
|
1721
|
+
"deployment.environment": config.environment
|
|
1722
|
+
},
|
|
1723
|
+
...config.serviceVersion && {
|
|
1724
|
+
"service.version": config.serviceVersion
|
|
1725
|
+
},
|
|
1726
|
+
"telemetry.sdk.name": scopeName,
|
|
1727
|
+
"telemetry.sdk.version": scopeVersion
|
|
1728
|
+
};
|
|
1729
|
+
}
|
|
1730
|
+
function buildOtlpMetricsPayload(metrics, resourceAttributes, scopeName, scopeVersion) {
|
|
1731
|
+
return {
|
|
1732
|
+
resourceMetrics: [
|
|
1733
|
+
{
|
|
1734
|
+
resource: {
|
|
1735
|
+
attributes: toOtlpKeyValueList(resourceAttributes)
|
|
1736
|
+
},
|
|
1737
|
+
scopeMetrics: [
|
|
1738
|
+
{
|
|
1739
|
+
scope: {
|
|
1740
|
+
name: scopeName,
|
|
1741
|
+
version: scopeVersion
|
|
1742
|
+
},
|
|
1743
|
+
metrics
|
|
1744
|
+
}
|
|
1745
|
+
]
|
|
1746
|
+
}
|
|
1747
|
+
]
|
|
1748
|
+
};
|
|
1749
|
+
}
|
|
1750
|
+
|
|
1751
|
+
// ../../../../../node_modules/.bun/@posthog+core@1.48.9/node_modules/@posthog/core/dist/metrics/config.mjs
|
|
1752
|
+
var DEFAULT_FLUSH_INTERVAL_MS = 1e4;
|
|
1753
|
+
var DEFAULT_MAX_SERIES_PER_FLUSH = 1000;
|
|
1754
|
+
function resolveMetricsConfig(config) {
|
|
1755
|
+
const resourceAttributes = config?.resourceAttributes;
|
|
1756
|
+
return {
|
|
1757
|
+
serviceName: resourceAttributes?.["service.name"] ?? config?.serviceName,
|
|
1758
|
+
serviceVersion: resourceAttributes?.["service.version"] ?? config?.serviceVersion,
|
|
1759
|
+
environment: resourceAttributes?.["deployment.environment"] ?? config?.environment,
|
|
1760
|
+
resourceAttributes,
|
|
1761
|
+
beforeSend: config?.beforeSend,
|
|
1762
|
+
flushIntervalMs: config?.flushIntervalMs ?? DEFAULT_FLUSH_INTERVAL_MS,
|
|
1763
|
+
maxSeriesPerFlush: config?.maxSeriesPerFlush ?? DEFAULT_MAX_SERIES_PER_FLUSH
|
|
1764
|
+
};
|
|
1765
|
+
}
|
|
1766
|
+
|
|
1767
|
+
// ../../../../../node_modules/.bun/@posthog+core@1.48.9/node_modules/@posthog/core/dist/metrics/index.mjs
|
|
1768
|
+
var OTLP_TEMPORALITY_DELTA = 1;
|
|
1769
|
+
|
|
1770
|
+
class PostHogMetrics {
|
|
1771
|
+
constructor(_instance, _config, _logger) {
|
|
1772
|
+
this._instance = _instance;
|
|
1773
|
+
this._config = _config;
|
|
1774
|
+
this._logger = _logger;
|
|
1775
|
+
this._series = new Map;
|
|
1776
|
+
this._flushPromise = null;
|
|
1777
|
+
this._seriesCapWarned = false;
|
|
1778
|
+
this._typeByName = new Map;
|
|
1779
|
+
this._typeCollisionWarned = new Set;
|
|
1780
|
+
this._generation = 0;
|
|
1781
|
+
}
|
|
1782
|
+
count(name, value = 1, options) {
|
|
1783
|
+
this._capture({
|
|
1784
|
+
name,
|
|
1785
|
+
type: "count",
|
|
1786
|
+
value,
|
|
1787
|
+
unit: options?.unit,
|
|
1788
|
+
attributes: options?.attributes
|
|
1789
|
+
});
|
|
1790
|
+
}
|
|
1791
|
+
gauge(name, value, options) {
|
|
1792
|
+
this._capture({
|
|
1793
|
+
name,
|
|
1794
|
+
type: "gauge",
|
|
1795
|
+
value,
|
|
1796
|
+
unit: options?.unit,
|
|
1797
|
+
attributes: options?.attributes
|
|
1798
|
+
});
|
|
1799
|
+
}
|
|
1800
|
+
histogram(name, value, options) {
|
|
1801
|
+
this._capture({
|
|
1802
|
+
name,
|
|
1803
|
+
type: "histogram",
|
|
1804
|
+
value,
|
|
1805
|
+
unit: options?.unit,
|
|
1806
|
+
attributes: options?.attributes
|
|
1807
|
+
});
|
|
1808
|
+
}
|
|
1809
|
+
flush() {
|
|
1810
|
+
const prev = this._flushPromise;
|
|
1811
|
+
const run = async () => {
|
|
1812
|
+
if (prev)
|
|
1813
|
+
await prev.catch(() => {});
|
|
1814
|
+
await this._doFlush();
|
|
1815
|
+
};
|
|
1816
|
+
const p = run().finally(() => {
|
|
1817
|
+
if (this._flushPromise === p)
|
|
1818
|
+
this._flushPromise = null;
|
|
1819
|
+
});
|
|
1820
|
+
this._flushPromise = p;
|
|
1821
|
+
return p;
|
|
1822
|
+
}
|
|
1823
|
+
drainWindow() {
|
|
1824
|
+
if (this._series.size === 0)
|
|
1825
|
+
return null;
|
|
1826
|
+
const window = this._series;
|
|
1827
|
+
this._series = new Map;
|
|
1828
|
+
this._seriesCapWarned = false;
|
|
1829
|
+
this._typeByName = new Map;
|
|
1830
|
+
this._typeCollisionWarned = new Set;
|
|
1831
|
+
return this._buildPayload(window);
|
|
1832
|
+
}
|
|
1833
|
+
reset() {
|
|
1834
|
+
this._generation++;
|
|
1835
|
+
this._clearFlushTimer();
|
|
1836
|
+
this._series = new Map;
|
|
1837
|
+
this._flushPromise = null;
|
|
1838
|
+
this._seriesCapWarned = false;
|
|
1839
|
+
this._typeByName = new Map;
|
|
1840
|
+
this._typeCollisionWarned = new Set;
|
|
1841
|
+
}
|
|
1842
|
+
_capture(sample) {
|
|
1843
|
+
if (this._instance.isDisabled || this._instance.optedOut)
|
|
1844
|
+
return;
|
|
1845
|
+
const filtered = this._runBeforeSend(sample);
|
|
1846
|
+
if (filtered === null)
|
|
1847
|
+
return;
|
|
1848
|
+
if (!filtered.name || typeof filtered.name != "string")
|
|
1849
|
+
return void this._logger.warn("Dropping metric with empty name");
|
|
1850
|
+
if (typeof filtered.value != "number" || !Number.isFinite(filtered.value))
|
|
1851
|
+
return void this._logger.warn(`Dropping metric '${filtered.name}': value must be a finite number`);
|
|
1852
|
+
if (filtered.type === "count" && filtered.value < 0)
|
|
1853
|
+
return void this._logger.warn(`Dropping count '${filtered.name}': counters are monotonic, value must be >= 0`);
|
|
1854
|
+
let attributes;
|
|
1855
|
+
let key;
|
|
1856
|
+
try {
|
|
1857
|
+
attributes = filtered.attributes ? {
|
|
1858
|
+
...filtered.attributes
|
|
1859
|
+
} : undefined;
|
|
1860
|
+
key = seriesKey(filtered.type, filtered.name, filtered.unit, attributes);
|
|
1861
|
+
} catch (e) {
|
|
1862
|
+
this._logger.warn(`Dropping metric '${filtered.name}': attributes could not be serialized`, e);
|
|
1863
|
+
return;
|
|
1864
|
+
}
|
|
1865
|
+
let state = this._series.get(key);
|
|
1866
|
+
if (!state) {
|
|
1867
|
+
if (!this._admitNewSeries())
|
|
1868
|
+
return;
|
|
1869
|
+
state = {
|
|
1870
|
+
name: filtered.name,
|
|
1871
|
+
type: filtered.type,
|
|
1872
|
+
unit: filtered.unit,
|
|
1873
|
+
attributes,
|
|
1874
|
+
windowStartMs: Date.now()
|
|
1875
|
+
};
|
|
1876
|
+
this._series.set(key, state);
|
|
1877
|
+
}
|
|
1878
|
+
const seenType = this._typeByName.get(filtered.name);
|
|
1879
|
+
if (seenType === undefined)
|
|
1880
|
+
this._typeByName.set(filtered.name, filtered.type);
|
|
1881
|
+
else if (seenType !== filtered.type && !this._typeCollisionWarned.has(filtered.name)) {
|
|
1882
|
+
this._typeCollisionWarned.add(filtered.name);
|
|
1883
|
+
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.`);
|
|
1884
|
+
}
|
|
1885
|
+
this._fold(state, filtered.value);
|
|
1886
|
+
this._armFlushTimer();
|
|
1887
|
+
}
|
|
1888
|
+
_admitNewSeries() {
|
|
1889
|
+
if (this._series.size < this._config.maxSeriesPerFlush)
|
|
1890
|
+
return true;
|
|
1891
|
+
if (!this._seriesCapWarned) {
|
|
1892
|
+
this._seriesCapWarned = true;
|
|
1893
|
+
this._logger.warn(`Metric series cap reached (${this._config.maxSeriesPerFlush} per flush window); dropping new series until the next flush. Reduce attribute cardinality.`);
|
|
1894
|
+
}
|
|
1895
|
+
return false;
|
|
1896
|
+
}
|
|
1897
|
+
_fold(state, value) {
|
|
1898
|
+
switch (state.type) {
|
|
1899
|
+
case "count":
|
|
1900
|
+
state.total = (state.total ?? 0) + value;
|
|
1901
|
+
break;
|
|
1902
|
+
case "gauge":
|
|
1903
|
+
state.last = value;
|
|
1904
|
+
break;
|
|
1905
|
+
case "histogram": {
|
|
1906
|
+
if (!state.hist)
|
|
1907
|
+
state.hist = {
|
|
1908
|
+
count: 0,
|
|
1909
|
+
sum: 0,
|
|
1910
|
+
min: value,
|
|
1911
|
+
max: value,
|
|
1912
|
+
bucketCounts: new Array(DEFAULT_HISTOGRAM_BOUNDS.length + 1).fill(0)
|
|
1913
|
+
};
|
|
1914
|
+
const hist = state.hist;
|
|
1915
|
+
hist.count += 1;
|
|
1916
|
+
hist.sum += value;
|
|
1917
|
+
hist.min = Math.min(hist.min, value);
|
|
1918
|
+
hist.max = Math.max(hist.max, value);
|
|
1919
|
+
hist.bucketCounts[bucketIndexFor(value, DEFAULT_HISTOGRAM_BOUNDS)] += 1;
|
|
1920
|
+
break;
|
|
1921
|
+
}
|
|
1922
|
+
}
|
|
1923
|
+
}
|
|
1924
|
+
_runBeforeSend(sample) {
|
|
1925
|
+
const beforeSend = this._config.beforeSend;
|
|
1926
|
+
if (!beforeSend)
|
|
1927
|
+
return sample;
|
|
1928
|
+
const fns = isArray(beforeSend) ? beforeSend : [
|
|
1929
|
+
beforeSend
|
|
1930
|
+
];
|
|
1931
|
+
let result = sample;
|
|
1932
|
+
for (const fn of fns)
|
|
1933
|
+
try {
|
|
1934
|
+
const next = fn(result);
|
|
1935
|
+
if (!next) {
|
|
1936
|
+
this._logger.info("Metric was rejected in beforeSend function");
|
|
1937
|
+
return null;
|
|
1938
|
+
}
|
|
1939
|
+
result = next;
|
|
1940
|
+
} catch (e) {
|
|
1941
|
+
this._logger.error("Error in beforeSend function for metric:", e);
|
|
1942
|
+
return null;
|
|
1943
|
+
}
|
|
1944
|
+
return result;
|
|
1945
|
+
}
|
|
1946
|
+
_armFlushTimer() {
|
|
1947
|
+
if (this._flushTimer)
|
|
1948
|
+
return;
|
|
1949
|
+
this._flushTimer = safeSetTimeout(() => {
|
|
1950
|
+
this._flushTimer = undefined;
|
|
1951
|
+
this.flush().catch((e) => {
|
|
1952
|
+
this._logger.error("Metrics flush failed:", e);
|
|
1953
|
+
});
|
|
1954
|
+
}, this._config.flushIntervalMs);
|
|
1955
|
+
}
|
|
1956
|
+
_clearFlushTimer() {
|
|
1957
|
+
if (this._flushTimer) {
|
|
1958
|
+
clearTimeout(this._flushTimer);
|
|
1959
|
+
this._flushTimer = undefined;
|
|
1960
|
+
}
|
|
1961
|
+
}
|
|
1962
|
+
async _doFlush() {
|
|
1963
|
+
if (this._series.size === 0)
|
|
1964
|
+
return;
|
|
1965
|
+
const window = this._series;
|
|
1966
|
+
this._series = new Map;
|
|
1967
|
+
this._seriesCapWarned = false;
|
|
1968
|
+
this._typeByName = new Map;
|
|
1969
|
+
this._typeCollisionWarned = new Set;
|
|
1970
|
+
const generation = this._generation;
|
|
1971
|
+
const outcome = await this._instance._sendMetricsBatch(this._buildPayload(window));
|
|
1972
|
+
if (generation !== this._generation)
|
|
1973
|
+
return;
|
|
1974
|
+
switch (outcome.kind) {
|
|
1975
|
+
case "ok":
|
|
1976
|
+
return;
|
|
1977
|
+
case "retry-later":
|
|
1978
|
+
this._mergeWindowBack(window);
|
|
1979
|
+
this._armFlushTimer();
|
|
1980
|
+
return;
|
|
1981
|
+
case "too-large":
|
|
1982
|
+
this._logger.warn("Metrics batch exceeded the server size limit and was dropped");
|
|
1983
|
+
return;
|
|
1984
|
+
case "fatal":
|
|
1985
|
+
this._logger.error("Failed to send metrics batch:", outcome.error);
|
|
1986
|
+
return;
|
|
1987
|
+
}
|
|
1988
|
+
}
|
|
1989
|
+
_buildPayload(window) {
|
|
1990
|
+
return buildOtlpMetricsPayload(this._buildMetrics(window), buildMetricsResourceAttributes(this._config, this._instance.getLibraryId(), this._instance.getLibraryVersion()), this._instance.getLibraryId(), this._instance.getLibraryVersion());
|
|
1991
|
+
}
|
|
1992
|
+
_buildMetrics(window) {
|
|
1993
|
+
const nowNano = msToUnixNano(Date.now());
|
|
1994
|
+
const byMetric = new Map;
|
|
1995
|
+
for (const state of window.values()) {
|
|
1996
|
+
const metricKey = seriesKey(state.type, state.name, state.unit, undefined);
|
|
1997
|
+
let metric = byMetric.get(metricKey);
|
|
1998
|
+
if (!metric) {
|
|
1999
|
+
metric = {
|
|
2000
|
+
name: state.name,
|
|
2001
|
+
...state.unit && {
|
|
2002
|
+
unit: state.unit
|
|
2003
|
+
}
|
|
2004
|
+
};
|
|
2005
|
+
if (state.type === "count")
|
|
2006
|
+
metric.sum = {
|
|
2007
|
+
aggregationTemporality: OTLP_TEMPORALITY_DELTA,
|
|
2008
|
+
isMonotonic: true,
|
|
2009
|
+
dataPoints: []
|
|
2010
|
+
};
|
|
2011
|
+
else if (state.type === "gauge")
|
|
2012
|
+
metric.gauge = {
|
|
2013
|
+
dataPoints: []
|
|
2014
|
+
};
|
|
2015
|
+
else
|
|
2016
|
+
metric.histogram = {
|
|
2017
|
+
aggregationTemporality: OTLP_TEMPORALITY_DELTA,
|
|
2018
|
+
dataPoints: []
|
|
2019
|
+
};
|
|
2020
|
+
byMetric.set(metricKey, metric);
|
|
2021
|
+
}
|
|
2022
|
+
const attributes = toOtlpKeyValueList(state.attributes ?? {}, this._logger);
|
|
2023
|
+
const startNano = msToUnixNano(state.windowStartMs);
|
|
2024
|
+
if (state.type === "count") {
|
|
2025
|
+
const dp = {
|
|
2026
|
+
attributes,
|
|
2027
|
+
startTimeUnixNano: startNano,
|
|
2028
|
+
timeUnixNano: nowNano,
|
|
2029
|
+
asDouble: state.total ?? 0
|
|
2030
|
+
};
|
|
2031
|
+
metric.sum.dataPoints.push(dp);
|
|
2032
|
+
} else if (state.type === "gauge") {
|
|
2033
|
+
const dp = {
|
|
2034
|
+
attributes,
|
|
2035
|
+
timeUnixNano: nowNano,
|
|
2036
|
+
asDouble: state.last ?? 0
|
|
2037
|
+
};
|
|
2038
|
+
metric.gauge.dataPoints.push(dp);
|
|
2039
|
+
} else if (state.hist) {
|
|
2040
|
+
const dp = {
|
|
2041
|
+
attributes,
|
|
2042
|
+
startTimeUnixNano: startNano,
|
|
2043
|
+
timeUnixNano: nowNano,
|
|
2044
|
+
count: state.hist.count,
|
|
2045
|
+
sum: state.hist.sum,
|
|
2046
|
+
min: state.hist.min,
|
|
2047
|
+
max: state.hist.max,
|
|
2048
|
+
bucketCounts: state.hist.bucketCounts,
|
|
2049
|
+
explicitBounds: DEFAULT_HISTOGRAM_BOUNDS
|
|
2050
|
+
};
|
|
2051
|
+
metric.histogram.dataPoints.push(dp);
|
|
2052
|
+
}
|
|
2053
|
+
}
|
|
2054
|
+
return Array.from(byMetric.values());
|
|
2055
|
+
}
|
|
2056
|
+
_mergeWindowBack(window) {
|
|
2057
|
+
for (const [key, old] of window) {
|
|
2058
|
+
const current = this._series.get(key);
|
|
2059
|
+
if (!current) {
|
|
2060
|
+
if (this._admitNewSeries())
|
|
2061
|
+
this._series.set(key, old);
|
|
2062
|
+
continue;
|
|
2063
|
+
}
|
|
2064
|
+
current.windowStartMs = Math.min(current.windowStartMs, old.windowStartMs);
|
|
2065
|
+
switch (current.type) {
|
|
2066
|
+
case "count":
|
|
2067
|
+
current.total = (current.total ?? 0) + (old.total ?? 0);
|
|
2068
|
+
break;
|
|
2069
|
+
case "gauge":
|
|
2070
|
+
break;
|
|
2071
|
+
case "histogram":
|
|
2072
|
+
if (old.hist)
|
|
2073
|
+
if (current.hist) {
|
|
2074
|
+
current.hist.count += old.hist.count;
|
|
2075
|
+
current.hist.sum += old.hist.sum;
|
|
2076
|
+
current.hist.min = Math.min(current.hist.min, old.hist.min);
|
|
2077
|
+
current.hist.max = Math.max(current.hist.max, old.hist.max);
|
|
2078
|
+
for (let i = 0;i < current.hist.bucketCounts.length; i++)
|
|
2079
|
+
current.hist.bucketCounts[i] += old.hist.bucketCounts[i];
|
|
2080
|
+
} else
|
|
2081
|
+
current.hist = old.hist;
|
|
2082
|
+
break;
|
|
2083
|
+
}
|
|
2084
|
+
}
|
|
2085
|
+
}
|
|
2086
|
+
}
|
|
2087
|
+
// ../../../../../node_modules/.bun/@posthog+core@1.48.9/node_modules/@posthog/core/dist/eventemitter.mjs
|
|
1344
2088
|
class SimpleEventEmitter {
|
|
1345
2089
|
constructor() {
|
|
1346
2090
|
this.events = {};
|
|
@@ -1362,37 +2106,38 @@ class SimpleEventEmitter {
|
|
|
1362
2106
|
}
|
|
1363
2107
|
}
|
|
1364
2108
|
|
|
1365
|
-
// ../../../../../node_modules/.bun/@posthog+core@1.
|
|
2109
|
+
// ../../../../../node_modules/.bun/@posthog+core@1.48.9/node_modules/@posthog/core/dist/error-tracking/index.mjs
|
|
1366
2110
|
var exports_error_tracking = {};
|
|
1367
2111
|
__export(exports_error_tracking, {
|
|
1368
|
-
|
|
1369
|
-
stripReservedExceptionStepFields: () => stripReservedExceptionStepFields,
|
|
1370
|
-
reverseAndStripFrames: () => reverseAndStripFrames,
|
|
1371
|
-
resolveExceptionStepsConfig: () => resolveExceptionStepsConfig,
|
|
1372
|
-
opera11StackLineParser: () => opera11StackLineParser,
|
|
1373
|
-
opera10StackLineParser: () => opera10StackLineParser,
|
|
1374
|
-
nodeStackLineParser: () => nodeStackLineParser,
|
|
1375
|
-
getUtf8ByteLength: () => getUtf8ByteLength,
|
|
1376
|
-
geckoStackLineParser: () => geckoStackLineParser,
|
|
1377
|
-
createStackParser: () => createStackParser,
|
|
1378
|
-
createDefaultStackParser: () => createDefaultStackParser,
|
|
1379
|
-
chromeStackLineParser: () => chromeStackLineParser,
|
|
1380
|
-
StringCoercer: () => StringCoercer,
|
|
1381
|
-
ReduceableCache: () => ReduceableCache,
|
|
1382
|
-
PromiseRejectionEventCoercer: () => PromiseRejectionEventCoercer,
|
|
1383
|
-
PrimitiveCoercer: () => PrimitiveCoercer,
|
|
1384
|
-
ObjectCoercer: () => ObjectCoercer,
|
|
1385
|
-
ExceptionStepsBuffer: () => ExceptionStepsBuffer,
|
|
1386
|
-
EventCoercer: () => EventCoercer,
|
|
1387
|
-
ErrorPropertiesBuilder: () => ErrorPropertiesBuilder,
|
|
1388
|
-
ErrorEventCoercer: () => ErrorEventCoercer,
|
|
1389
|
-
ErrorCoercer: () => ErrorCoercer,
|
|
1390
|
-
EXCEPTION_STEP_INTERNAL_FIELDS: () => EXCEPTION_STEP_INTERNAL_FIELDS,
|
|
2112
|
+
DEFAULT_EXCEPTION_STEPS_CONFIG: () => DEFAULT_EXCEPTION_STEPS_CONFIG,
|
|
1391
2113
|
DOMExceptionCoercer: () => DOMExceptionCoercer,
|
|
1392
|
-
|
|
2114
|
+
EXCEPTION_STEP_INTERNAL_FIELDS: () => EXCEPTION_STEP_INTERNAL_FIELDS,
|
|
2115
|
+
ErrorCoercer: () => ErrorCoercer,
|
|
2116
|
+
ErrorEventCoercer: () => ErrorEventCoercer,
|
|
2117
|
+
ErrorPropertiesBuilder: () => ErrorPropertiesBuilder,
|
|
2118
|
+
EventCoercer: () => EventCoercer,
|
|
2119
|
+
ExceptionStepsBuffer: () => ExceptionStepsBuffer,
|
|
2120
|
+
ObjectCoercer: () => ObjectCoercer,
|
|
2121
|
+
PrimitiveCoercer: () => PrimitiveCoercer,
|
|
2122
|
+
PromiseRejectionEventCoercer: () => PromiseRejectionEventCoercer,
|
|
2123
|
+
ReduceableCache: () => ReduceableCache,
|
|
2124
|
+
StringCoercer: () => StringCoercer,
|
|
2125
|
+
chromeStackLineParser: () => chromeStackLineParser,
|
|
2126
|
+
createDefaultStackParser: () => createDefaultStackParser,
|
|
2127
|
+
createStackParser: () => createStackParser,
|
|
2128
|
+
geckoStackLineParser: () => geckoStackLineParser,
|
|
2129
|
+
getInjectedReleaseId: () => getInjectedReleaseId,
|
|
2130
|
+
getUtf8ByteLength: () => getUtf8ByteLength,
|
|
2131
|
+
nodeStackLineParser: () => nodeStackLineParser,
|
|
2132
|
+
opera10StackLineParser: () => opera10StackLineParser,
|
|
2133
|
+
opera11StackLineParser: () => opera11StackLineParser,
|
|
2134
|
+
resolveExceptionStepsConfig: () => resolveExceptionStepsConfig,
|
|
2135
|
+
reverseAndStripFrames: () => reverseAndStripFrames,
|
|
2136
|
+
stripReservedExceptionStepFields: () => stripReservedExceptionStepFields,
|
|
2137
|
+
winjsStackLineParser: () => winjsStackLineParser
|
|
1393
2138
|
});
|
|
1394
2139
|
|
|
1395
|
-
// ../../../../../node_modules/.bun/@posthog+core@1.
|
|
2140
|
+
// ../../../../../node_modules/.bun/@posthog+core@1.48.9/node_modules/@posthog/core/dist/error-tracking/chunk-ids.mjs
|
|
1396
2141
|
var parsedStackResults;
|
|
1397
2142
|
var lastKeysCount;
|
|
1398
2143
|
var cachedFilenameChunkIds;
|
|
@@ -1431,7 +2176,7 @@ function getFilenameToChunkIdMap(stackParser) {
|
|
|
1431
2176
|
return cachedFilenameChunkIds;
|
|
1432
2177
|
}
|
|
1433
2178
|
|
|
1434
|
-
// ../../../../../node_modules/.bun/@posthog+core@1.
|
|
2179
|
+
// ../../../../../node_modules/.bun/@posthog+core@1.48.9/node_modules/@posthog/core/dist/error-tracking/error-properties-builder.mjs
|
|
1435
2180
|
var MAX_CAUSE_RECURSION = 4;
|
|
1436
2181
|
|
|
1437
2182
|
class ErrorPropertiesBuilder {
|
|
@@ -1553,14 +2298,16 @@ class ErrorPropertiesBuilder {
|
|
|
1553
2298
|
return context;
|
|
1554
2299
|
}
|
|
1555
2300
|
}
|
|
1556
|
-
// ../../../../../node_modules/.bun/@posthog+core@1.
|
|
2301
|
+
// ../../../../../node_modules/.bun/@posthog+core@1.48.9/node_modules/@posthog/core/dist/error-tracking/parsers/base.mjs
|
|
1557
2302
|
var UNKNOWN_FUNCTION = "?";
|
|
2303
|
+
var MASKED_URL_PREFIX = "webkit-masked-url://";
|
|
2304
|
+
var ANONYMOUS_FILENAME = "<anonymous>";
|
|
1558
2305
|
function createFrame(platform, filename, func, lineno, colno) {
|
|
1559
2306
|
const frame = {
|
|
1560
2307
|
platform,
|
|
1561
2308
|
filename,
|
|
1562
2309
|
function: func === "<anonymous>" ? UNKNOWN_FUNCTION : func,
|
|
1563
|
-
in_app:
|
|
2310
|
+
in_app: !filename?.startsWith(MASKED_URL_PREFIX) && filename !== ANONYMOUS_FILENAME
|
|
1564
2311
|
};
|
|
1565
2312
|
if (!isUndefined(lineno))
|
|
1566
2313
|
frame.lineno = lineno;
|
|
@@ -1569,7 +2316,7 @@ function createFrame(platform, filename, func, lineno, colno) {
|
|
|
1569
2316
|
return frame;
|
|
1570
2317
|
}
|
|
1571
2318
|
|
|
1572
|
-
// ../../../../../node_modules/.bun/@posthog+core@1.
|
|
2319
|
+
// ../../../../../node_modules/.bun/@posthog+core@1.48.9/node_modules/@posthog/core/dist/error-tracking/parsers/safari.mjs
|
|
1573
2320
|
var extractSafariExtensionDetails = (func, filename) => {
|
|
1574
2321
|
const isSafariExtension = func.indexOf("safari-extension") !== -1;
|
|
1575
2322
|
const isSafariWebExtension = func.indexOf("safari-web-extension") !== -1;
|
|
@@ -1582,7 +2329,7 @@ var extractSafariExtensionDetails = (func, filename) => {
|
|
|
1582
2329
|
];
|
|
1583
2330
|
};
|
|
1584
2331
|
|
|
1585
|
-
// ../../../../../node_modules/.bun/@posthog+core@1.
|
|
2332
|
+
// ../../../../../node_modules/.bun/@posthog+core@1.48.9/node_modules/@posthog/core/dist/error-tracking/parsers/chrome.mjs
|
|
1586
2333
|
var chromeRegexNoFnName = /^\s*at (\S+?)(?::(\d+))(?::(\d+))\s*$/i;
|
|
1587
2334
|
var chromeRegex = /^\s*at (?:(.+?\)(?: \[.+\])?|.*?) ?\((?:address at )?)?(?:async )?((?:<anonymous>|[-a-z]+:|.*bundle|\/)?.*?)(?::(\d+))?(?::(\d+))?\)?\s*$/i;
|
|
1588
2335
|
var chromeEvalRegex = /\((\S*)(?::(\d+))(?::(\d+))\)/;
|
|
@@ -1608,7 +2355,7 @@ var chromeStackLineParser = (line, platform) => {
|
|
|
1608
2355
|
}
|
|
1609
2356
|
};
|
|
1610
2357
|
|
|
1611
|
-
// ../../../../../node_modules/.bun/@posthog+core@1.
|
|
2358
|
+
// ../../../../../node_modules/.bun/@posthog+core@1.48.9/node_modules/@posthog/core/dist/error-tracking/parsers/gecko.mjs
|
|
1612
2359
|
var geckoREgex = /^\s*(.*?)(?:\((.*?)\))?(?:^|@)?((?:[-a-z]+)?:\/.*?|\[native code\]|[^@]*(?:bundle|\d+\.js)|\/[\w\-. /=]+)(?::(\d+))?(?::(\d+))?\s*$/i;
|
|
1613
2360
|
var geckoEvalRegex = /(\S+) line (\d+)(?: > eval line \d+)* > eval/i;
|
|
1614
2361
|
var geckoStackLineParser = (line, platform) => {
|
|
@@ -1631,14 +2378,14 @@ var geckoStackLineParser = (line, platform) => {
|
|
|
1631
2378
|
}
|
|
1632
2379
|
};
|
|
1633
2380
|
|
|
1634
|
-
// ../../../../../node_modules/.bun/@posthog+core@1.
|
|
2381
|
+
// ../../../../../node_modules/.bun/@posthog+core@1.48.9/node_modules/@posthog/core/dist/error-tracking/parsers/winjs.mjs
|
|
1635
2382
|
var winjsRegex = /^\s*at (?:((?:\[object object\])?.+) )?\(?((?:[-a-z]+):.*?):(\d+)(?::(\d+))?\)?\s*$/i;
|
|
1636
2383
|
var winjsStackLineParser = (line, platform) => {
|
|
1637
2384
|
const parts = winjsRegex.exec(line);
|
|
1638
2385
|
return parts ? createFrame(platform, parts[2], parts[1] || UNKNOWN_FUNCTION, +parts[3], parts[4] ? +parts[4] : undefined) : undefined;
|
|
1639
2386
|
};
|
|
1640
2387
|
|
|
1641
|
-
// ../../../../../node_modules/.bun/@posthog+core@1.
|
|
2388
|
+
// ../../../../../node_modules/.bun/@posthog+core@1.48.9/node_modules/@posthog/core/dist/error-tracking/parsers/opera.mjs
|
|
1642
2389
|
var opera10Regex = / line (\d+).*script (?:in )?(\S+)(?:: in function (\S+))?$/i;
|
|
1643
2390
|
var opera10StackLineParser = (line, platform) => {
|
|
1644
2391
|
const parts = opera10Regex.exec(line);
|
|
@@ -1650,9 +2397,12 @@ var opera11StackLineParser = (line, platform) => {
|
|
|
1650
2397
|
return parts ? createFrame(platform, parts[5], parts[3] || parts[4] || UNKNOWN_FUNCTION, +parts[1], +parts[2]) : undefined;
|
|
1651
2398
|
};
|
|
1652
2399
|
|
|
1653
|
-
// ../../../../../node_modules/.bun/@posthog+core@1.
|
|
2400
|
+
// ../../../../../node_modules/.bun/@posthog+core@1.48.9/node_modules/@posthog/core/dist/error-tracking/parsers/node.mjs
|
|
1654
2401
|
var FILENAME_MATCH = /^\s*[-]{4,}$/;
|
|
1655
2402
|
var FULL_MATCH = /at (?:async )?(?:(.+?)\s+\()?(?:(.+):(\d+):(\d+)?|([^)]+))\)?/;
|
|
2403
|
+
var PROMISE_COMBINATOR = /^Promise\.(?:all|any)$/;
|
|
2404
|
+
var PROMISE_INDEX = /^index \d+$/;
|
|
2405
|
+
var PROMISE_FRAME_FILENAME = "node:internal/promise";
|
|
1656
2406
|
var nodeStackLineParser = (line, platform) => {
|
|
1657
2407
|
const lineMatch = line.match(FULL_MATCH);
|
|
1658
2408
|
if (lineMatch) {
|
|
@@ -1695,6 +2445,8 @@ var nodeStackLineParser = (line, platform) => {
|
|
|
1695
2445
|
filename = filename.slice(1);
|
|
1696
2446
|
if (!filename && lineMatch[5] && !isNative)
|
|
1697
2447
|
filename = lineMatch[5];
|
|
2448
|
+
if (PROMISE_COMBINATOR.test(functionName) && PROMISE_INDEX.test(filename || ""))
|
|
2449
|
+
filename = PROMISE_FRAME_FILENAME;
|
|
1698
2450
|
return {
|
|
1699
2451
|
filename: filename ? decodeURI(filename) : undefined,
|
|
1700
2452
|
module: undefined,
|
|
@@ -1719,7 +2471,7 @@ function _parseIntOrUndefined(input) {
|
|
|
1719
2471
|
return parseInt(input || "", 10) || undefined;
|
|
1720
2472
|
}
|
|
1721
2473
|
|
|
1722
|
-
// ../../../../../node_modules/.bun/@posthog+core@1.
|
|
2474
|
+
// ../../../../../node_modules/.bun/@posthog+core@1.48.9/node_modules/@posthog/core/dist/error-tracking/parsers/index.mjs
|
|
1723
2475
|
var WEBPACK_ERROR_REGEXP = /\(error: (.*)\)/;
|
|
1724
2476
|
var STACKTRACE_FRAME_LIMIT = 50;
|
|
1725
2477
|
function reverseAndStripFrames(stack) {
|
|
@@ -1764,7 +2516,7 @@ function createStackParser(platform, ...parsers) {
|
|
|
1764
2516
|
return reverseAndStripFrames(frames);
|
|
1765
2517
|
};
|
|
1766
2518
|
}
|
|
1767
|
-
// ../../../../../node_modules/.bun/@posthog+core@1.
|
|
2519
|
+
// ../../../../../node_modules/.bun/@posthog+core@1.48.9/node_modules/@posthog/core/dist/error-tracking/coercers/dom-exception-coercer.mjs
|
|
1768
2520
|
class DOMExceptionCoercer {
|
|
1769
2521
|
match(err) {
|
|
1770
2522
|
return this.isDOMException(err) || this.isDOMError(err);
|
|
@@ -1794,18 +2546,20 @@ class DOMExceptionCoercer {
|
|
|
1794
2546
|
return isBuiltin(err, "DOMError");
|
|
1795
2547
|
}
|
|
1796
2548
|
}
|
|
1797
|
-
// ../../../../../node_modules/.bun/@posthog+core@1.
|
|
2549
|
+
// ../../../../../node_modules/.bun/@posthog+core@1.48.9/node_modules/@posthog/core/dist/error-tracking/coercers/error-coercer.mjs
|
|
1798
2550
|
class ErrorCoercer {
|
|
1799
2551
|
match(err) {
|
|
1800
|
-
return
|
|
2552
|
+
return isError(err);
|
|
1801
2553
|
}
|
|
1802
2554
|
coerce(err, ctx) {
|
|
2555
|
+
const stack = this.getStack(err);
|
|
2556
|
+
const synthetic = stack === undefined;
|
|
1803
2557
|
return {
|
|
1804
2558
|
type: this.getType(err),
|
|
1805
2559
|
value: this.getMessage(err, ctx),
|
|
1806
|
-
stack:
|
|
2560
|
+
stack: stack ?? ctx.syntheticException?.stack,
|
|
1807
2561
|
cause: err.cause ? ctx.next(err.cause) : undefined,
|
|
1808
|
-
synthetic
|
|
2562
|
+
synthetic
|
|
1809
2563
|
};
|
|
1810
2564
|
}
|
|
1811
2565
|
getType(err) {
|
|
@@ -1821,25 +2575,41 @@ class ErrorCoercer {
|
|
|
1821
2575
|
return err.stacktrace || err.stack || undefined;
|
|
1822
2576
|
}
|
|
1823
2577
|
}
|
|
1824
|
-
// ../../../../../node_modules/.bun/@posthog+core@1.
|
|
2578
|
+
// ../../../../../node_modules/.bun/@posthog+core@1.48.9/node_modules/@posthog/core/dist/error-tracking/coercers/error-event-coercer.mjs
|
|
1825
2579
|
class ErrorEventCoercer {
|
|
1826
2580
|
constructor() {}
|
|
1827
2581
|
match(err) {
|
|
1828
|
-
|
|
2582
|
+
if (!isErrorEvent(err))
|
|
2583
|
+
return false;
|
|
2584
|
+
const errorEvent = err;
|
|
2585
|
+
return errorEvent.error != null || this._hasUsableMessage(errorEvent);
|
|
1829
2586
|
}
|
|
1830
2587
|
coerce(err, ctx) {
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
|
|
1835
|
-
|
|
1836
|
-
|
|
1837
|
-
|
|
1838
|
-
|
|
1839
|
-
|
|
2588
|
+
if (err.error != null)
|
|
2589
|
+
return ctx.apply(err.error);
|
|
2590
|
+
const exceptionLike = ctx.apply(err.message);
|
|
2591
|
+
return {
|
|
2592
|
+
...exceptionLike,
|
|
2593
|
+
stack: this._buildLocationStack(err) ?? exceptionLike.stack,
|
|
2594
|
+
synthetic: true
|
|
2595
|
+
};
|
|
2596
|
+
}
|
|
2597
|
+
_hasUsableMessage(err) {
|
|
2598
|
+
return isString(err.message) && err.message.length > 0;
|
|
2599
|
+
}
|
|
2600
|
+
_buildLocationStack(err) {
|
|
2601
|
+
const location = err;
|
|
2602
|
+
const lineno = location.lineno ?? 0;
|
|
2603
|
+
const colno = location.colno ?? 0;
|
|
2604
|
+
if (!isString(location.filename) || location.filename.length === 0)
|
|
2605
|
+
return;
|
|
2606
|
+
if (lineno === 0)
|
|
2607
|
+
return;
|
|
2608
|
+
return `Error
|
|
2609
|
+
at ${location.filename}:${lineno}:${colno}`;
|
|
1840
2610
|
}
|
|
1841
2611
|
}
|
|
1842
|
-
// ../../../../../node_modules/.bun/@posthog+core@1.
|
|
2612
|
+
// ../../../../../node_modules/.bun/@posthog+core@1.48.9/node_modules/@posthog/core/dist/error-tracking/coercers/string-coercer.mjs
|
|
1843
2613
|
var ERROR_TYPES_PATTERN = /^(?:[Uu]ncaught (?:exception: )?)?(?:((?:Eval|Internal|Range|Reference|Syntax|Type|URI|)Error): )?(.*)$/i;
|
|
1844
2614
|
|
|
1845
2615
|
class StringCoercer {
|
|
@@ -1869,7 +2639,7 @@ class StringCoercer {
|
|
|
1869
2639
|
];
|
|
1870
2640
|
}
|
|
1871
2641
|
}
|
|
1872
|
-
// ../../../../../node_modules/.bun/@posthog+core@1.
|
|
2642
|
+
// ../../../../../node_modules/.bun/@posthog+core@1.48.9/node_modules/@posthog/core/dist/error-tracking/types.mjs
|
|
1873
2643
|
var severityLevels = [
|
|
1874
2644
|
"fatal",
|
|
1875
2645
|
"error",
|
|
@@ -1879,7 +2649,7 @@ var severityLevels = [
|
|
|
1879
2649
|
"debug"
|
|
1880
2650
|
];
|
|
1881
2651
|
|
|
1882
|
-
// ../../../../../node_modules/.bun/@posthog+core@1.
|
|
2652
|
+
// ../../../../../node_modules/.bun/@posthog+core@1.48.9/node_modules/@posthog/core/dist/error-tracking/coercers/utils.mjs
|
|
1883
2653
|
function extractExceptionKeysForMessage(err, maxLength = 40) {
|
|
1884
2654
|
const keys = Object.keys(err);
|
|
1885
2655
|
keys.sort();
|
|
@@ -1896,7 +2666,7 @@ function extractExceptionKeysForMessage(err, maxLength = 40) {
|
|
|
1896
2666
|
return "";
|
|
1897
2667
|
}
|
|
1898
2668
|
|
|
1899
|
-
// ../../../../../node_modules/.bun/@posthog+core@1.
|
|
2669
|
+
// ../../../../../node_modules/.bun/@posthog+core@1.48.9/node_modules/@posthog/core/dist/error-tracking/coercers/object-coercer.mjs
|
|
1900
2670
|
class ObjectCoercer {
|
|
1901
2671
|
match(candidate) {
|
|
1902
2672
|
return typeof candidate == "object" && candidate !== null;
|
|
@@ -1908,13 +2678,16 @@ class ObjectCoercer {
|
|
|
1908
2678
|
return {
|
|
1909
2679
|
type: this.getType(candidate),
|
|
1910
2680
|
value: this.getValue(candidate),
|
|
1911
|
-
stack: ctx.syntheticException?.stack,
|
|
2681
|
+
stack: this.getStack(candidate) ?? ctx.syntheticException?.stack,
|
|
1912
2682
|
level: this.isSeverityLevel(candidate.level) ? candidate.level : "error",
|
|
1913
2683
|
synthetic: true
|
|
1914
2684
|
};
|
|
1915
2685
|
}
|
|
1916
2686
|
getType(err) {
|
|
1917
|
-
|
|
2687
|
+
if (isEvent(err))
|
|
2688
|
+
return err.constructor.name;
|
|
2689
|
+
const name = "name" in err ? err.name : undefined;
|
|
2690
|
+
return isString(name) && !isEmptyString(name) ? name : "Error";
|
|
1918
2691
|
}
|
|
1919
2692
|
getValue(err) {
|
|
1920
2693
|
if ("name" in err && typeof err.name == "string") {
|
|
@@ -1932,6 +2705,15 @@ class ObjectCoercer {
|
|
|
1932
2705
|
isSeverityLevel(x) {
|
|
1933
2706
|
return isString(x) && !isEmptyString(x) && severityLevels.indexOf(x) >= 0;
|
|
1934
2707
|
}
|
|
2708
|
+
getStack(candidate) {
|
|
2709
|
+
try {
|
|
2710
|
+
if (isString(candidate.stacktrace) && candidate.stacktrace.length > 0)
|
|
2711
|
+
return candidate.stacktrace;
|
|
2712
|
+
return isString(candidate.stack) && candidate.stack.length > 0 ? candidate.stack : undefined;
|
|
2713
|
+
} catch {
|
|
2714
|
+
return;
|
|
2715
|
+
}
|
|
2716
|
+
}
|
|
1935
2717
|
getErrorPropertyFromObject(obj) {
|
|
1936
2718
|
for (const prop in obj)
|
|
1937
2719
|
if (Object.prototype.hasOwnProperty.call(obj, prop)) {
|
|
@@ -1949,7 +2731,7 @@ class ObjectCoercer {
|
|
|
1949
2731
|
}
|
|
1950
2732
|
}
|
|
1951
2733
|
}
|
|
1952
|
-
// ../../../../../node_modules/.bun/@posthog+core@1.
|
|
2734
|
+
// ../../../../../node_modules/.bun/@posthog+core@1.48.9/node_modules/@posthog/core/dist/error-tracking/coercers/event-coercer.mjs
|
|
1953
2735
|
class EventCoercer {
|
|
1954
2736
|
match(err) {
|
|
1955
2737
|
return isEvent(err);
|
|
@@ -1964,7 +2746,7 @@ class EventCoercer {
|
|
|
1964
2746
|
};
|
|
1965
2747
|
}
|
|
1966
2748
|
}
|
|
1967
|
-
// ../../../../../node_modules/.bun/@posthog+core@1.
|
|
2749
|
+
// ../../../../../node_modules/.bun/@posthog+core@1.48.9/node_modules/@posthog/core/dist/error-tracking/coercers/primitive-coercer.mjs
|
|
1968
2750
|
class PrimitiveCoercer {
|
|
1969
2751
|
match(candidate) {
|
|
1970
2752
|
return isPrimitive(candidate);
|
|
@@ -1978,7 +2760,7 @@ class PrimitiveCoercer {
|
|
|
1978
2760
|
};
|
|
1979
2761
|
}
|
|
1980
2762
|
}
|
|
1981
|
-
// ../../../../../node_modules/.bun/@posthog+core@1.
|
|
2763
|
+
// ../../../../../node_modules/.bun/@posthog+core@1.48.9/node_modules/@posthog/core/dist/error-tracking/coercers/promise-rejection-event.mjs
|
|
1982
2764
|
class PromiseRejectionEventCoercer {
|
|
1983
2765
|
match(err) {
|
|
1984
2766
|
return isBuiltin(err, "PromiseRejectionEvent") || this.isCustomEventWrappingRejection(err);
|
|
@@ -2014,7 +2796,7 @@ class PromiseRejectionEventCoercer {
|
|
|
2014
2796
|
return error;
|
|
2015
2797
|
}
|
|
2016
2798
|
}
|
|
2017
|
-
// ../../../../../node_modules/.bun/@posthog+core@1.
|
|
2799
|
+
// ../../../../../node_modules/.bun/@posthog+core@1.48.9/node_modules/@posthog/core/dist/error-tracking/utils.mjs
|
|
2018
2800
|
class ReduceableCache {
|
|
2019
2801
|
constructor(_maxSize) {
|
|
2020
2802
|
this._maxSize = _maxSize;
|
|
@@ -2039,7 +2821,7 @@ class ReduceableCache {
|
|
|
2039
2821
|
}
|
|
2040
2822
|
}
|
|
2041
2823
|
}
|
|
2042
|
-
// ../../../../../node_modules/.bun/@posthog+core@1.
|
|
2824
|
+
// ../../../../../node_modules/.bun/@posthog+core@1.48.9/node_modules/@posthog/core/dist/error-tracking/exception-steps.mjs
|
|
2043
2825
|
var EXCEPTION_STEP_INTERNAL_FIELDS = {
|
|
2044
2826
|
MESSAGE: "$message",
|
|
2045
2827
|
TIMESTAMP: "$timestamp"
|
|
@@ -2134,9 +2916,12 @@ function normalizePositiveInteger(input, fallback) {
|
|
|
2134
2916
|
return normalized;
|
|
2135
2917
|
}
|
|
2136
2918
|
function normalizeAndSerializeStep(step) {
|
|
2137
|
-
|
|
2138
|
-
|
|
2919
|
+
let json;
|
|
2920
|
+
try {
|
|
2921
|
+
json = safeJsonStringify(step);
|
|
2922
|
+
} catch {
|
|
2139
2923
|
return;
|
|
2924
|
+
}
|
|
2140
2925
|
try {
|
|
2141
2926
|
const parsed = JSON.parse(json);
|
|
2142
2927
|
if (!isObject(parsed))
|
|
@@ -2156,33 +2941,6 @@ function normalizeAndSerializeStep(step) {
|
|
|
2156
2941
|
return;
|
|
2157
2942
|
}
|
|
2158
2943
|
}
|
|
2159
|
-
function safeStringify(value) {
|
|
2160
|
-
const seen = new WeakSet;
|
|
2161
|
-
try {
|
|
2162
|
-
return JSON.stringify(value, (_key, replacementValue) => {
|
|
2163
|
-
if (typeof replacementValue == "bigint")
|
|
2164
|
-
return replacementValue.toString();
|
|
2165
|
-
if (typeof replacementValue == "function" || typeof replacementValue == "symbol")
|
|
2166
|
-
return;
|
|
2167
|
-
if (replacementValue instanceof Date)
|
|
2168
|
-
return replacementValue.toISOString();
|
|
2169
|
-
if (replacementValue instanceof Error)
|
|
2170
|
-
return {
|
|
2171
|
-
name: replacementValue.name,
|
|
2172
|
-
message: replacementValue.message,
|
|
2173
|
-
stack: replacementValue.stack
|
|
2174
|
-
};
|
|
2175
|
-
if (replacementValue && typeof replacementValue == "object") {
|
|
2176
|
-
if (seen.has(replacementValue))
|
|
2177
|
-
return "[Circular]";
|
|
2178
|
-
seen.add(replacementValue);
|
|
2179
|
-
}
|
|
2180
|
-
return replacementValue;
|
|
2181
|
-
});
|
|
2182
|
-
} catch {
|
|
2183
|
-
return;
|
|
2184
|
-
}
|
|
2185
|
-
}
|
|
2186
2944
|
function getUtf8ByteLength(value) {
|
|
2187
2945
|
if (typeof TextEncoder != "undefined")
|
|
2188
2946
|
return new TextEncoder().encode(value).length;
|
|
@@ -2196,19 +2954,65 @@ function getUtf8ByteLength(value) {
|
|
|
2196
2954
|
byteLength += 1;
|
|
2197
2955
|
return byteLength;
|
|
2198
2956
|
}
|
|
2199
|
-
// ../../../../../node_modules/.bun/@posthog+core@1.
|
|
2957
|
+
// ../../../../../node_modules/.bun/@posthog+core@1.48.9/node_modules/@posthog/core/dist/error-tracking/release.mjs
|
|
2958
|
+
function getInjectedReleaseId() {
|
|
2959
|
+
const injected = globalThis._posthogReleaseId;
|
|
2960
|
+
return typeof injected == "string" && injected.length > 0 ? injected : undefined;
|
|
2961
|
+
}
|
|
2962
|
+
// ../../../../../node_modules/.bun/@posthog+core@1.48.9/node_modules/@posthog/core/dist/posthog-core-stateless.mjs
|
|
2200
2963
|
class PostHogFetchHttpError extends Error {
|
|
2201
|
-
constructor(response, reqByteLength) {
|
|
2202
|
-
super("HTTP error while fetching PostHog: status=" + response.status + ", reqByteLength=" + reqByteLength), this.response = response, this.reqByteLength = reqByteLength, this.name = "PostHogFetchHttpError";
|
|
2964
|
+
constructor(response, reqByteLength, responseBodyDeadline, abortController) {
|
|
2965
|
+
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;
|
|
2203
2966
|
}
|
|
2204
2967
|
get status() {
|
|
2205
2968
|
return this.response.status;
|
|
2206
2969
|
}
|
|
2970
|
+
get bodyReadTimedOut() {
|
|
2971
|
+
return this._bodyReadTimedOut;
|
|
2972
|
+
}
|
|
2207
2973
|
get text() {
|
|
2208
|
-
|
|
2974
|
+
if (!this.responseBodyTextPromise)
|
|
2975
|
+
if (Date.now() >= this.responseBodyDeadline) {
|
|
2976
|
+
this._bodyReadTimedOut = true;
|
|
2977
|
+
const timeoutError = new Error("Response body read timed out");
|
|
2978
|
+
timeoutError.name = "AbortError";
|
|
2979
|
+
this.cancelResponseBody(timeoutError);
|
|
2980
|
+
this.responseBodyTextPromise = Promise.reject(timeoutError);
|
|
2981
|
+
} else {
|
|
2982
|
+
const responseBodyTimeout = new Promise((_resolve, reject) => {
|
|
2983
|
+
this.responseBodyTimer = safeSetTimeout(() => {
|
|
2984
|
+
this._bodyReadTimedOut = true;
|
|
2985
|
+
const timeoutError = new Error("Response body read timed out");
|
|
2986
|
+
timeoutError.name = "AbortError";
|
|
2987
|
+
reject(timeoutError);
|
|
2988
|
+
this.cancelResponseBody(timeoutError);
|
|
2989
|
+
}, this.responseBodyDeadline - Date.now());
|
|
2990
|
+
});
|
|
2991
|
+
let responseBodyText;
|
|
2992
|
+
try {
|
|
2993
|
+
responseBodyText = Promise.resolve(this.response.text());
|
|
2994
|
+
} catch (error) {
|
|
2995
|
+
responseBodyText = Promise.reject(error);
|
|
2996
|
+
}
|
|
2997
|
+
this.responseBodyTextPromise = Promise.race([
|
|
2998
|
+
responseBodyText,
|
|
2999
|
+
responseBodyTimeout
|
|
3000
|
+
]).finally(() => clearTimeout(this.responseBodyTimer));
|
|
3001
|
+
}
|
|
3002
|
+
return this.responseBodyTextPromise;
|
|
2209
3003
|
}
|
|
2210
3004
|
get json() {
|
|
2211
|
-
return this.
|
|
3005
|
+
return this.text.then((text) => JSON.parse(text));
|
|
3006
|
+
}
|
|
3007
|
+
cancelResponseBody(reason) {
|
|
3008
|
+
clearTimeout(this.responseBodyTimer);
|
|
3009
|
+
if (!this.abortController.signal.aborted)
|
|
3010
|
+
this.abortController.abort(reason);
|
|
3011
|
+
(async () => {
|
|
3012
|
+
try {
|
|
3013
|
+
await this.response.body?.cancel();
|
|
3014
|
+
} catch {}
|
|
3015
|
+
})();
|
|
2212
3016
|
}
|
|
2213
3017
|
}
|
|
2214
3018
|
|
|
@@ -2219,12 +3023,20 @@ class PostHogFetchNetworkError extends Error {
|
|
|
2219
3023
|
} : {}), this.error = error, this.name = "PostHogFetchNetworkError";
|
|
2220
3024
|
}
|
|
2221
3025
|
}
|
|
3026
|
+
var applyCallerFeatureFlagOverrides = (target, callerProperties) => {
|
|
3027
|
+
for (const key of Object.keys(callerProperties))
|
|
3028
|
+
if (key.startsWith("$feature/") || key === "$active_feature_flags")
|
|
3029
|
+
target[key] = callerProperties[key];
|
|
3030
|
+
};
|
|
2222
3031
|
async function logFlushError(err) {
|
|
2223
3032
|
if (err instanceof PostHogFetchHttpError) {
|
|
2224
3033
|
let text = "";
|
|
2225
3034
|
try {
|
|
2226
3035
|
text = await err.text;
|
|
2227
|
-
} catch {
|
|
3036
|
+
} catch {
|
|
3037
|
+
if (err.bodyReadTimedOut)
|
|
3038
|
+
text = "<response body read timed out>";
|
|
3039
|
+
}
|
|
2228
3040
|
console.error(`Error while flushing PostHog: message=${err.message}, response body=${text}`, err);
|
|
2229
3041
|
} else
|
|
2230
3042
|
console.error("Error while flushing PostHog", err);
|
|
@@ -2236,9 +3048,28 @@ function isPostHogFetchError(err) {
|
|
|
2236
3048
|
function isPostHogFetchNetworkError(err) {
|
|
2237
3049
|
return err instanceof PostHogFetchNetworkError;
|
|
2238
3050
|
}
|
|
3051
|
+
function isRetryableFlagsFetchError(err) {
|
|
3052
|
+
if (err instanceof PostHogFetchHttpError)
|
|
3053
|
+
return err.status === 502 || err.status === 504;
|
|
3054
|
+
if (!(err instanceof PostHogFetchNetworkError))
|
|
3055
|
+
return false;
|
|
3056
|
+
const cause = err.error;
|
|
3057
|
+
const code = cause?.code ?? cause?.cause?.code;
|
|
3058
|
+
return code !== "ECONNREFUSED";
|
|
3059
|
+
}
|
|
2239
3060
|
function isPostHogFetchContentTooLargeError(err) {
|
|
2240
3061
|
return typeof err == "object" && err instanceof PostHogFetchHttpError && err.status === 413;
|
|
2241
3062
|
}
|
|
3063
|
+
function isPostHogFetchRetryableError(err) {
|
|
3064
|
+
if (err instanceof PostHogFetchHttpError)
|
|
3065
|
+
return err.status === 408 || err.status === 429 || err.status >= 500;
|
|
3066
|
+
return isPostHogFetchNetworkError(err);
|
|
3067
|
+
}
|
|
3068
|
+
function isPostHogEventProperties(value) {
|
|
3069
|
+
return value !== null && typeof value == "object" && !Array.isArray(value);
|
|
3070
|
+
}
|
|
3071
|
+
var DEFAULT_QUEUE_ROUTE = "default";
|
|
3072
|
+
|
|
2242
3073
|
class PostHogCoreStateless {
|
|
2243
3074
|
getErrorPropertiesBuilder() {
|
|
2244
3075
|
if (!this._errorPropertiesBuilder)
|
|
@@ -2255,6 +3086,9 @@ class PostHogCoreStateless {
|
|
|
2255
3086
|
}
|
|
2256
3087
|
constructor(apiKey, options = {}) {
|
|
2257
3088
|
this.flushPromise = null;
|
|
3089
|
+
this.pendingFlushPromise = null;
|
|
3090
|
+
this.flushPromises = new Set;
|
|
3091
|
+
this._dequeuedMessagesCount = 0;
|
|
2258
3092
|
this.shutdownPromise = null;
|
|
2259
3093
|
this.promiseQueue = new PromiseQueue;
|
|
2260
3094
|
this._events = new SimpleEventEmitter;
|
|
@@ -2277,10 +3111,11 @@ class PostHogCoreStateless {
|
|
|
2277
3111
|
this._retryOptions = {
|
|
2278
3112
|
retryCount: options.fetchRetryCount ?? 3,
|
|
2279
3113
|
retryDelay: options.fetchRetryDelay ?? 3000,
|
|
2280
|
-
retryCheck:
|
|
3114
|
+
retryCheck: isPostHogFetchRetryableError
|
|
2281
3115
|
};
|
|
2282
3116
|
this.requestTimeout = options.requestTimeout ?? 1e4;
|
|
2283
3117
|
this.featureFlagsRequestTimeoutMs = options.featureFlagsRequestTimeoutMs ?? 3000;
|
|
3118
|
+
this.featureFlagsRequestMaxRetries = options.featureFlagsRequestMaxRetries ?? 1;
|
|
2284
3119
|
this.remoteConfigRequestTimeoutMs = options.remoteConfigRequestTimeoutMs ?? 3000;
|
|
2285
3120
|
this.disableGeoip = options.disableGeoip ?? true;
|
|
2286
3121
|
this.disabled = (options.disabled ?? false) || missingApiKey;
|
|
@@ -2342,15 +3177,23 @@ class PostHogCoreStateless {
|
|
|
2342
3177
|
return this.disabled;
|
|
2343
3178
|
}
|
|
2344
3179
|
buildPayload(payload) {
|
|
3180
|
+
const userProperties = payload.properties || {};
|
|
3181
|
+
let properties = {
|
|
3182
|
+
...userProperties,
|
|
3183
|
+
...this.getCommonEventProperties()
|
|
3184
|
+
};
|
|
3185
|
+
applyCallerFeatureFlagOverrides(properties, userProperties);
|
|
3186
|
+
if (payload.event === "$feature_flag_called" && properties.$feature_flag_has_experiment === false && this.isMinimalFlagCalledEventsEnabled())
|
|
3187
|
+
properties = minimizeFlagCalledEventProperties(properties);
|
|
2345
3188
|
return {
|
|
2346
3189
|
distinct_id: payload.distinct_id,
|
|
2347
3190
|
event: payload.event,
|
|
2348
|
-
properties
|
|
2349
|
-
...payload.properties || {},
|
|
2350
|
-
...this.getCommonEventProperties()
|
|
2351
|
-
}
|
|
3191
|
+
properties
|
|
2352
3192
|
};
|
|
2353
3193
|
}
|
|
3194
|
+
isMinimalFlagCalledEventsEnabled() {
|
|
3195
|
+
return false;
|
|
3196
|
+
}
|
|
2354
3197
|
addPendingPromise(promise) {
|
|
2355
3198
|
return this.promiseQueue.add(promise);
|
|
2356
3199
|
}
|
|
@@ -2435,6 +3278,19 @@ class PostHogCoreStateless {
|
|
|
2435
3278
|
this.enqueue("capture", payload, options);
|
|
2436
3279
|
});
|
|
2437
3280
|
}
|
|
3281
|
+
async groupIdentifyStatelessImmediate(groupType, groupKey, groupProperties, options, distinctId, eventProperties) {
|
|
3282
|
+
const payload = this.buildPayload({
|
|
3283
|
+
distinct_id: distinctId || `$${groupType}_${groupKey}`,
|
|
3284
|
+
event: "$groupidentify",
|
|
3285
|
+
properties: {
|
|
3286
|
+
$group_type: groupType,
|
|
3287
|
+
$group_key: groupKey,
|
|
3288
|
+
$group_set: groupProperties || {},
|
|
3289
|
+
...eventProperties || {}
|
|
3290
|
+
}
|
|
3291
|
+
});
|
|
3292
|
+
await this.sendImmediate("capture", payload, options);
|
|
3293
|
+
}
|
|
2438
3294
|
async getRemoteConfig() {
|
|
2439
3295
|
await this._initPromise;
|
|
2440
3296
|
let host = this.host;
|
|
@@ -2451,8 +3307,11 @@ class PostHogCoreStateless {
|
|
|
2451
3307
|
}
|
|
2452
3308
|
};
|
|
2453
3309
|
return this.fetchWithRetry(url, fetchOptions, {
|
|
3310
|
+
type: "required",
|
|
3311
|
+
consume: (response) => response.json()
|
|
3312
|
+
}, {
|
|
2454
3313
|
retryCount: 0
|
|
2455
|
-
}, this.remoteConfigRequestTimeoutMs).
|
|
3314
|
+
}, this.remoteConfigRequestTimeoutMs).catch((error) => {
|
|
2456
3315
|
this._logger.error("Remote config could not be loaded", error);
|
|
2457
3316
|
this._events.emit("error", error);
|
|
2458
3317
|
});
|
|
@@ -2483,8 +3342,12 @@ class PostHogCoreStateless {
|
|
|
2483
3342
|
};
|
|
2484
3343
|
this._logger.info("Flags URL", url);
|
|
2485
3344
|
return this.fetchWithRetry(url, fetchOptions, {
|
|
2486
|
-
|
|
2487
|
-
|
|
3345
|
+
type: "required",
|
|
3346
|
+
consume: (response) => response.json()
|
|
3347
|
+
}, {
|
|
3348
|
+
retryCount: this.featureFlagsRequestMaxRetries,
|
|
3349
|
+
retryCheck: isRetryableFlagsFetchError
|
|
3350
|
+
}, this.featureFlagsRequestTimeoutMs).then((response) => ({
|
|
2488
3351
|
success: true,
|
|
2489
3352
|
response: normalizeFlagsResponse(response)
|
|
2490
3353
|
})).catch((error) => {
|
|
@@ -2584,9 +3447,9 @@ class PostHogCoreStateless {
|
|
|
2584
3447
|
}
|
|
2585
3448
|
async getFeatureFlagDetailsStateless(distinctId, groups = {}, personProperties = {}, groupProperties = {}, disableGeoip, flagKeysToEvaluate) {
|
|
2586
3449
|
await this._initPromise;
|
|
2587
|
-
const extraPayload = {
|
|
2588
|
-
|
|
2589
|
-
|
|
3450
|
+
const extraPayload = {
|
|
3451
|
+
geoip_disable: disableGeoip ?? this.disableGeoip
|
|
3452
|
+
};
|
|
2590
3453
|
if (flagKeysToEvaluate)
|
|
2591
3454
|
extraPayload["flag_keys_to_evaluate"] = flagKeysToEvaluate;
|
|
2592
3455
|
const result = await this.getFlags(distinctId, groups, personProperties, groupProperties, extraPayload);
|
|
@@ -2623,15 +3486,18 @@ class PostHogCoreStateless {
|
|
|
2623
3486
|
"Content-Type": "application/json"
|
|
2624
3487
|
}
|
|
2625
3488
|
};
|
|
2626
|
-
const response = await this.fetchWithRetry(url, fetchOptions
|
|
2627
|
-
|
|
2628
|
-
|
|
2629
|
-
|
|
2630
|
-
|
|
2631
|
-
|
|
2632
|
-
|
|
3489
|
+
const response = await this.fetchWithRetry(url, fetchOptions, {
|
|
3490
|
+
type: "required",
|
|
3491
|
+
consume: (response2) => {
|
|
3492
|
+
if (response2.status !== 200 || !response2.json) {
|
|
3493
|
+
const msg = `Surveys API could not be loaded: ${response2.status}`;
|
|
3494
|
+
const error = new Error(msg);
|
|
3495
|
+
this._logger.error(error);
|
|
3496
|
+
this._events.emit("error", new Error(msg));
|
|
3497
|
+
return Promise.resolve(undefined);
|
|
3498
|
+
}
|
|
3499
|
+
return response2.json();
|
|
2633
3500
|
}
|
|
2634
|
-
return response2.json();
|
|
2635
3501
|
}).catch((error) => {
|
|
2636
3502
|
this._logger.error("Surveys API could not be loaded", error);
|
|
2637
3503
|
this._events.emit("error", error);
|
|
@@ -2668,23 +3534,39 @@ class PostHogCoreStateless {
|
|
|
2668
3534
|
return message;
|
|
2669
3535
|
}
|
|
2670
3536
|
async flushStorage() {}
|
|
2671
|
-
|
|
3537
|
+
getQueueRouteKey(_message) {
|
|
3538
|
+
return DEFAULT_QUEUE_ROUTE;
|
|
3539
|
+
}
|
|
3540
|
+
persistedQueueKeyForRoute(_route) {
|
|
3541
|
+
return types_PostHogPersistedProperty.Queue;
|
|
3542
|
+
}
|
|
3543
|
+
getActiveQueueRoutes() {
|
|
3544
|
+
return [
|
|
3545
|
+
DEFAULT_QUEUE_ROUTE
|
|
3546
|
+
];
|
|
3547
|
+
}
|
|
3548
|
+
getRouteQueue(route) {
|
|
3549
|
+
return this.getPersistedProperty(this.persistedQueueKeyForRoute(route)) || [];
|
|
3550
|
+
}
|
|
3551
|
+
enqueue(type, _message, options, explicitRoute) {
|
|
2672
3552
|
this.wrap(() => {
|
|
2673
3553
|
if (this.optedOut)
|
|
2674
3554
|
return void this._events.emit(type, "Library is disabled. Not sending event. To re-enable, call posthog.optIn()");
|
|
2675
|
-
let message = this.prepareMessage(
|
|
3555
|
+
let message = this.prepareMessage(_message, options);
|
|
2676
3556
|
message = this.processBeforeEnqueue(message);
|
|
2677
3557
|
if (message === null)
|
|
2678
3558
|
return;
|
|
2679
|
-
|
|
3559
|
+
message = this.normalizeMessage(message);
|
|
3560
|
+
const queueKey = this.persistedQueueKeyForRoute(explicitRoute ?? this.getQueueRouteKey(message));
|
|
3561
|
+
const queue = this.getPersistedProperty(queueKey) || [];
|
|
2680
3562
|
if (queue.length >= this.maxQueueSize) {
|
|
2681
3563
|
queue.shift();
|
|
2682
|
-
this._logger.
|
|
3564
|
+
this._logger.warn("Queue is full, the oldest event is dropped.");
|
|
2683
3565
|
}
|
|
2684
3566
|
queue.push({
|
|
2685
3567
|
message
|
|
2686
3568
|
});
|
|
2687
|
-
this.setPersistedProperty(
|
|
3569
|
+
this.setPersistedProperty(queueKey, queue);
|
|
2688
3570
|
this._events.emit(type, message);
|
|
2689
3571
|
if (queue.length >= this.flushAt)
|
|
2690
3572
|
this.flushBackground();
|
|
@@ -2692,61 +3574,63 @@ class PostHogCoreStateless {
|
|
|
2692
3574
|
this._flushTimer = safeSetTimeout(() => this.flushBackground(), this.flushInterval);
|
|
2693
3575
|
});
|
|
2694
3576
|
}
|
|
2695
|
-
async sendImmediate(type, _message, options) {
|
|
3577
|
+
async sendImmediate(type, _message, options, explicitRoute) {
|
|
2696
3578
|
if (this.disabled)
|
|
2697
3579
|
return void this._logger.warn("The client is disabled");
|
|
2698
3580
|
if (!this._isInitialized)
|
|
2699
3581
|
await this._initPromise;
|
|
2700
3582
|
if (this.optedOut)
|
|
2701
3583
|
return void this._events.emit(type, "Library is disabled. Not sending event. To re-enable, call posthog.optIn()");
|
|
2702
|
-
let message = this.prepareMessage(
|
|
3584
|
+
let message = this.prepareMessage(_message, options);
|
|
2703
3585
|
message = this.processBeforeEnqueue(message);
|
|
2704
3586
|
if (message === null)
|
|
2705
3587
|
return;
|
|
2706
|
-
|
|
2707
|
-
api_key: this.apiKey,
|
|
2708
|
-
batch: [
|
|
2709
|
-
message
|
|
2710
|
-
],
|
|
2711
|
-
sent_at: currentISOTime()
|
|
2712
|
-
};
|
|
2713
|
-
if (this.historicalMigration)
|
|
2714
|
-
data.historical_migration = true;
|
|
2715
|
-
const payload = JSON.stringify(data);
|
|
2716
|
-
const url = `${this.host}/batch/`;
|
|
2717
|
-
const gzippedPayload = this.disableCompression ? null : await gzipCompress(payload, this.isDebug);
|
|
2718
|
-
const fetchOptions = {
|
|
2719
|
-
method: "POST",
|
|
2720
|
-
headers: {
|
|
2721
|
-
...this.getCustomHeaders(),
|
|
2722
|
-
"Content-Type": "application/json",
|
|
2723
|
-
...gzippedPayload !== null && {
|
|
2724
|
-
"Content-Encoding": "gzip"
|
|
2725
|
-
}
|
|
2726
|
-
},
|
|
2727
|
-
body: gzippedPayload || payload
|
|
2728
|
-
};
|
|
3588
|
+
message = this.normalizeMessage(message);
|
|
2729
3589
|
try {
|
|
2730
|
-
|
|
2731
|
-
|
|
3590
|
+
await this.sendBatch([
|
|
3591
|
+
message
|
|
3592
|
+
], undefined, explicitRoute ?? this.getQueueRouteKey(message));
|
|
2732
3593
|
} catch (err) {
|
|
2733
3594
|
this._events.emit("error", err);
|
|
2734
3595
|
}
|
|
2735
3596
|
}
|
|
2736
|
-
|
|
3597
|
+
normalizeMessage(message) {
|
|
3598
|
+
const { type: _type, library, library_version, ...sanitizedMessage } = message;
|
|
3599
|
+
let properties = isPostHogEventProperties(sanitizedMessage.properties) ? sanitizedMessage.properties : undefined;
|
|
3600
|
+
if (library !== undefined && properties?.$lib === undefined)
|
|
3601
|
+
properties = {
|
|
3602
|
+
...properties || {},
|
|
3603
|
+
$lib: library
|
|
3604
|
+
};
|
|
3605
|
+
if (library_version !== undefined && properties?.$lib_version === undefined)
|
|
3606
|
+
properties = {
|
|
3607
|
+
...properties || {},
|
|
3608
|
+
$lib_version: library_version
|
|
3609
|
+
};
|
|
3610
|
+
if (properties)
|
|
3611
|
+
sanitizedMessage.properties = properties;
|
|
3612
|
+
sanitizedMessage.uuid = getEventUuid(sanitizedMessage.uuid, uuidv7);
|
|
3613
|
+
return sanitizedMessage;
|
|
3614
|
+
}
|
|
3615
|
+
normalizeTimestampForWire(timestamp) {
|
|
3616
|
+
const parsedTimestamp = timestamp instanceof Date ? timestamp : typeof timestamp == "string" ? new Date(timestamp) : null;
|
|
3617
|
+
if (!parsedTimestamp || Number.isNaN(parsedTimestamp.getTime()))
|
|
3618
|
+
return timestamp;
|
|
3619
|
+
const normalized = parsedTimestamp.toISOString();
|
|
3620
|
+
const fractionalSeconds = typeof timestamp == "string" ? timestamp.match(/\.(\d+)(?:Z|[+-]\d{2}:?\d{2})?$/i)?.[1] : undefined;
|
|
3621
|
+
return fractionalSeconds && fractionalSeconds.length > 3 ? normalized.replace(/\.\d{3}Z$/, `.${fractionalSeconds}Z`) : normalized;
|
|
3622
|
+
}
|
|
3623
|
+
prepareMessage(_message, options) {
|
|
2737
3624
|
const message = {
|
|
2738
3625
|
..._message,
|
|
2739
|
-
type,
|
|
2740
|
-
library: this.getLibraryId(),
|
|
2741
|
-
library_version: this.getLibraryVersion(),
|
|
2742
3626
|
timestamp: options?.timestamp ? options?.timestamp : currentISOTime(),
|
|
2743
|
-
uuid: options?.uuid
|
|
3627
|
+
uuid: getEventUuid(options?.uuid, uuidv7)
|
|
2744
3628
|
};
|
|
2745
3629
|
const addGeoipDisableProperty = options?.disableGeoip ?? this.disableGeoip;
|
|
2746
3630
|
if (addGeoipDisableProperty) {
|
|
2747
|
-
if (!message.properties)
|
|
3631
|
+
if (!isPostHogEventProperties(message.properties))
|
|
2748
3632
|
message.properties = {};
|
|
2749
|
-
message
|
|
3633
|
+
message.properties["$geoip_disable"] = true;
|
|
2750
3634
|
}
|
|
2751
3635
|
if (message.distinctId) {
|
|
2752
3636
|
message.distinct_id = message.distinctId;
|
|
@@ -2761,21 +3645,64 @@ class PostHogCoreStateless {
|
|
|
2761
3645
|
}
|
|
2762
3646
|
}
|
|
2763
3647
|
flushBackground() {
|
|
3648
|
+
if (this.pendingFlushPromise)
|
|
3649
|
+
return;
|
|
2764
3650
|
this.flush().catch(async (err) => {
|
|
2765
3651
|
await logFlushError(err);
|
|
2766
3652
|
});
|
|
2767
3653
|
}
|
|
2768
|
-
async
|
|
3654
|
+
async waitForPendingPromises(maxPromiseId, ignoredPromises = []) {
|
|
3655
|
+
const ignoredPendingPromises = ignoredPromises.filter((promise) => !!promise);
|
|
3656
|
+
let iteration = 0;
|
|
3657
|
+
while (true) {
|
|
3658
|
+
const promises = this.promiseQueue.getPromises([
|
|
3659
|
+
...ignoredPendingPromises,
|
|
3660
|
+
...this.flushPromises
|
|
3661
|
+
], maxPromiseId);
|
|
3662
|
+
if (promises.length === 0)
|
|
3663
|
+
return;
|
|
3664
|
+
if (iteration > 0)
|
|
3665
|
+
this._logger.debug(`flush() re-checking ${promises.length} pending promise(s) before flushing`);
|
|
3666
|
+
await Promise.all(promises.map((promise) => promise.catch(() => {})));
|
|
3667
|
+
iteration++;
|
|
3668
|
+
}
|
|
3669
|
+
}
|
|
3670
|
+
flushWithPendingPromises() {
|
|
3671
|
+
return this.flushInternal(true);
|
|
3672
|
+
}
|
|
3673
|
+
flush() {
|
|
3674
|
+
return this.flushInternal(false);
|
|
3675
|
+
}
|
|
3676
|
+
flushInternal(waitForPendingPromises) {
|
|
2769
3677
|
if (this.disabled)
|
|
2770
|
-
return;
|
|
2771
|
-
|
|
2772
|
-
this.
|
|
2773
|
-
|
|
3678
|
+
return Promise.resolve();
|
|
3679
|
+
if (!waitForPendingPromises && this.pendingFlushPromise)
|
|
3680
|
+
return this.pendingFlushPromise;
|
|
3681
|
+
const previousFlushPromise = this.flushPromise;
|
|
3682
|
+
const maxPromiseId = this.promiseQueue.maxId;
|
|
3683
|
+
const nextFlushPromise = Promise.resolve().then(() => {
|
|
3684
|
+
if (waitForPendingPromises)
|
|
3685
|
+
return this.waitForPendingPromises(maxPromiseId, [
|
|
3686
|
+
previousFlushPromise,
|
|
3687
|
+
nextFlushPromise
|
|
3688
|
+
]);
|
|
3689
|
+
}).then(() => allSettled([
|
|
3690
|
+
previousFlushPromise
|
|
3691
|
+
])).then(() => {
|
|
3692
|
+
if (this.pendingFlushPromise === nextFlushPromise)
|
|
3693
|
+
this.pendingFlushPromise = null;
|
|
3694
|
+
return this._flush();
|
|
3695
|
+
});
|
|
3696
|
+
this.pendingFlushPromise = nextFlushPromise;
|
|
2774
3697
|
this.flushPromise = nextFlushPromise;
|
|
3698
|
+
this.flushPromises.add(nextFlushPromise);
|
|
2775
3699
|
this.addPendingPromise(nextFlushPromise);
|
|
2776
3700
|
allSettled([
|
|
2777
3701
|
nextFlushPromise
|
|
2778
3702
|
]).then(() => {
|
|
3703
|
+
this.flushPromises.delete(nextFlushPromise);
|
|
3704
|
+
if (this.pendingFlushPromise === nextFlushPromise)
|
|
3705
|
+
this.pendingFlushPromise = null;
|
|
2779
3706
|
if (this.flushPromise === nextFlushPromise)
|
|
2780
3707
|
this.flushPromise = null;
|
|
2781
3708
|
});
|
|
@@ -2788,55 +3715,102 @@ class PostHogCoreStateless {
|
|
|
2788
3715
|
headers["User-Agent"] = customUserAgent;
|
|
2789
3716
|
return headers;
|
|
2790
3717
|
}
|
|
3718
|
+
compressPayload(payload) {
|
|
3719
|
+
return gzipCompress(payload, this.isDebug);
|
|
3720
|
+
}
|
|
3721
|
+
getBatchEndpointPath(_route) {
|
|
3722
|
+
return "/batch/";
|
|
3723
|
+
}
|
|
3724
|
+
async sendBatch(batchMessages, retryOptions, route = DEFAULT_QUEUE_ROUTE) {
|
|
3725
|
+
const data = {
|
|
3726
|
+
api_key: this.apiKey,
|
|
3727
|
+
batch: batchMessages.map((message) => {
|
|
3728
|
+
if (!message)
|
|
3729
|
+
return message;
|
|
3730
|
+
const timestamp = this.normalizeTimestampForWire(message.timestamp);
|
|
3731
|
+
return timestamp === message.timestamp ? message : {
|
|
3732
|
+
...message,
|
|
3733
|
+
timestamp
|
|
3734
|
+
};
|
|
3735
|
+
}),
|
|
3736
|
+
sent_at: currentISOTime()
|
|
3737
|
+
};
|
|
3738
|
+
if (this.historicalMigration)
|
|
3739
|
+
data.historical_migration = true;
|
|
3740
|
+
const payload = safeJsonStringify(data);
|
|
3741
|
+
const url = `${this.host}${this.getBatchEndpointPath(route)}`;
|
|
3742
|
+
const gzippedPayload = this.disableCompression ? null : await this.compressPayload(payload);
|
|
3743
|
+
const fetchOptions = {
|
|
3744
|
+
method: "POST",
|
|
3745
|
+
headers: {
|
|
3746
|
+
...this.getCustomHeaders(),
|
|
3747
|
+
"Content-Type": "application/json",
|
|
3748
|
+
...gzippedPayload !== null && {
|
|
3749
|
+
"Content-Encoding": "gzip"
|
|
3750
|
+
}
|
|
3751
|
+
},
|
|
3752
|
+
body: gzippedPayload || payload
|
|
3753
|
+
};
|
|
3754
|
+
await this.fetchWithRetry(url, fetchOptions, {
|
|
3755
|
+
type: "successful-write"
|
|
3756
|
+
}, retryOptions);
|
|
3757
|
+
}
|
|
2791
3758
|
async _flush() {
|
|
2792
3759
|
this.clearFlushTimer();
|
|
2793
3760
|
await this._initPromise;
|
|
2794
|
-
|
|
2795
|
-
if (!
|
|
3761
|
+
const routes = this.getActiveQueueRoutes();
|
|
3762
|
+
if (!routes.some((route) => this.getRouteQueue(route).length > 0))
|
|
2796
3763
|
return;
|
|
2797
3764
|
const sentMessages = [];
|
|
3765
|
+
let firstError;
|
|
3766
|
+
for (const route of routes)
|
|
3767
|
+
try {
|
|
3768
|
+
await this._flushRoute(route, sentMessages);
|
|
3769
|
+
} catch (err) {
|
|
3770
|
+
if (firstError === undefined)
|
|
3771
|
+
firstError = err;
|
|
3772
|
+
}
|
|
3773
|
+
if (firstError !== undefined)
|
|
3774
|
+
throw firstError;
|
|
3775
|
+
this._events.emit("flush", sentMessages);
|
|
3776
|
+
}
|
|
3777
|
+
async _flushRoute(route, sentMessages) {
|
|
3778
|
+
const queueKey = this.persistedQueueKeyForRoute(route);
|
|
3779
|
+
let queue = this.getPersistedProperty(queueKey) || [];
|
|
3780
|
+
if (!queue.length)
|
|
3781
|
+
return;
|
|
2798
3782
|
const originalQueueLength = queue.length;
|
|
2799
|
-
|
|
3783
|
+
let sentFromRoute = 0;
|
|
3784
|
+
while (queue.length > 0 && sentFromRoute < originalQueueLength) {
|
|
2800
3785
|
const batchItems = queue.slice(0, this.maxBatchSize);
|
|
2801
|
-
const batchMessages = batchItems.map((item) => item.message);
|
|
3786
|
+
const batchMessages = batchItems.map((item) => item.message === undefined ? item.message : this.normalizeMessage(item.message));
|
|
2802
3787
|
const persistQueueChange = async () => {
|
|
2803
|
-
const refreshedQueue = this.getPersistedProperty(
|
|
2804
|
-
const
|
|
2805
|
-
|
|
3788
|
+
const refreshedQueue = this.getPersistedProperty(queueKey) || [];
|
|
3789
|
+
const remainingBatchItems = [
|
|
3790
|
+
...batchItems
|
|
3791
|
+
];
|
|
3792
|
+
const newQueue = refreshedQueue.filter((item) => {
|
|
3793
|
+
const itemUuid = item.message?.uuid;
|
|
3794
|
+
const batchItemIndex = remainingBatchItems.findIndex((batchItem) => batchItem === item || typeof itemUuid == "string" && itemUuid.length > 0 && batchItem.message?.uuid === itemUuid);
|
|
3795
|
+
if (batchItemIndex === -1)
|
|
3796
|
+
return true;
|
|
3797
|
+
remainingBatchItems.splice(batchItemIndex, 1);
|
|
3798
|
+
return false;
|
|
3799
|
+
});
|
|
3800
|
+
this.setPersistedProperty(queueKey, newQueue);
|
|
2806
3801
|
queue = newQueue;
|
|
3802
|
+
this._dequeuedMessagesCount += batchItems.length;
|
|
2807
3803
|
await this.flushStorage();
|
|
2808
3804
|
};
|
|
2809
|
-
const data = {
|
|
2810
|
-
api_key: this.apiKey,
|
|
2811
|
-
batch: batchMessages,
|
|
2812
|
-
sent_at: currentISOTime()
|
|
2813
|
-
};
|
|
2814
|
-
if (this.historicalMigration)
|
|
2815
|
-
data.historical_migration = true;
|
|
2816
|
-
const payload = JSON.stringify(data);
|
|
2817
|
-
const url = `${this.host}/batch/`;
|
|
2818
|
-
const gzippedPayload = this.disableCompression ? null : await gzipCompress(payload, this.isDebug);
|
|
2819
|
-
const fetchOptions = {
|
|
2820
|
-
method: "POST",
|
|
2821
|
-
headers: {
|
|
2822
|
-
...this.getCustomHeaders(),
|
|
2823
|
-
"Content-Type": "application/json",
|
|
2824
|
-
...gzippedPayload !== null && {
|
|
2825
|
-
"Content-Encoding": "gzip"
|
|
2826
|
-
}
|
|
2827
|
-
},
|
|
2828
|
-
body: gzippedPayload || payload
|
|
2829
|
-
};
|
|
2830
3805
|
const retryOptions = {
|
|
2831
3806
|
retryCheck: (err) => {
|
|
2832
3807
|
if (isPostHogFetchContentTooLargeError(err))
|
|
2833
3808
|
return false;
|
|
2834
|
-
return
|
|
3809
|
+
return isPostHogFetchRetryableError(err);
|
|
2835
3810
|
}
|
|
2836
3811
|
};
|
|
2837
3812
|
try {
|
|
2838
|
-
|
|
2839
|
-
await response.body?.cancel()?.catch(() => {});
|
|
3813
|
+
await this.sendBatch(batchMessages, retryOptions, route);
|
|
2840
3814
|
} catch (err) {
|
|
2841
3815
|
if (isPostHogFetchContentTooLargeError(err) && batchMessages.length > 1) {
|
|
2842
3816
|
this.maxBatchSize = Math.max(1, Math.floor(batchMessages.length / 2));
|
|
@@ -2850,8 +3824,8 @@ class PostHogCoreStateless {
|
|
|
2850
3824
|
}
|
|
2851
3825
|
await persistQueueChange();
|
|
2852
3826
|
sentMessages.push(...batchMessages);
|
|
3827
|
+
sentFromRoute += batchMessages.length;
|
|
2853
3828
|
}
|
|
2854
|
-
this._events.emit("flush", sentMessages);
|
|
2855
3829
|
}
|
|
2856
3830
|
async _sendLogsBatch(payload) {
|
|
2857
3831
|
if (this.disabled)
|
|
@@ -2861,7 +3835,7 @@ class PostHogCoreStateless {
|
|
|
2861
3835
|
};
|
|
2862
3836
|
const serialized = JSON.stringify(payload);
|
|
2863
3837
|
const url = `${this.host}/i/v1/logs?token=${encodeURIComponent(this.apiKey)}`;
|
|
2864
|
-
const gzippedPayload = this.disableCompression ? null : await
|
|
3838
|
+
const gzippedPayload = this.disableCompression ? null : await this.compressPayload(serialized);
|
|
2865
3839
|
const fetchOptions = {
|
|
2866
3840
|
method: "POST",
|
|
2867
3841
|
headers: {
|
|
@@ -2875,10 +3849,12 @@ class PostHogCoreStateless {
|
|
|
2875
3849
|
};
|
|
2876
3850
|
try {
|
|
2877
3851
|
await this.fetchWithRetry(url, fetchOptions, {
|
|
3852
|
+
type: "successful-write"
|
|
3853
|
+
}, {
|
|
2878
3854
|
retryCheck: (err) => {
|
|
2879
3855
|
if (isPostHogFetchContentTooLargeError(err))
|
|
2880
3856
|
return false;
|
|
2881
|
-
return
|
|
3857
|
+
return isPostHogFetchRetryableError(err);
|
|
2882
3858
|
}
|
|
2883
3859
|
});
|
|
2884
3860
|
return {
|
|
@@ -2900,41 +3876,155 @@ class PostHogCoreStateless {
|
|
|
2900
3876
|
};
|
|
2901
3877
|
}
|
|
2902
3878
|
}
|
|
2903
|
-
async
|
|
3879
|
+
async _sendMetricsBatch(payload) {
|
|
3880
|
+
if (this.disabled)
|
|
3881
|
+
return {
|
|
3882
|
+
kind: "fatal",
|
|
3883
|
+
error: new Error("The client is disabled")
|
|
3884
|
+
};
|
|
3885
|
+
const serialized = JSON.stringify(payload);
|
|
3886
|
+
const url = `${this.host}/i/v1/metrics?token=${encodeURIComponent(this.apiKey)}`;
|
|
3887
|
+
const gzippedPayload = this.disableCompression ? null : await this.compressPayload(serialized);
|
|
3888
|
+
const fetchOptions = {
|
|
3889
|
+
method: "POST",
|
|
3890
|
+
headers: {
|
|
3891
|
+
...this.getCustomHeaders(),
|
|
3892
|
+
"Content-Type": "application/json",
|
|
3893
|
+
...gzippedPayload !== null && {
|
|
3894
|
+
"Content-Encoding": "gzip"
|
|
3895
|
+
}
|
|
3896
|
+
},
|
|
3897
|
+
body: gzippedPayload || serialized
|
|
3898
|
+
};
|
|
3899
|
+
try {
|
|
3900
|
+
await this.fetchWithRetry(url, fetchOptions, {
|
|
3901
|
+
type: "successful-write"
|
|
3902
|
+
}, {
|
|
3903
|
+
retryCheck: (err) => {
|
|
3904
|
+
if (isPostHogFetchContentTooLargeError(err))
|
|
3905
|
+
return false;
|
|
3906
|
+
return isPostHogFetchRetryableError(err);
|
|
3907
|
+
}
|
|
3908
|
+
});
|
|
3909
|
+
return {
|
|
3910
|
+
kind: "ok"
|
|
3911
|
+
};
|
|
3912
|
+
} catch (err) {
|
|
3913
|
+
if (isPostHogFetchContentTooLargeError(err))
|
|
3914
|
+
return {
|
|
3915
|
+
kind: "too-large"
|
|
3916
|
+
};
|
|
3917
|
+
if (isPostHogFetchRetryableError(err))
|
|
3918
|
+
return {
|
|
3919
|
+
kind: "retry-later",
|
|
3920
|
+
error: err
|
|
3921
|
+
};
|
|
3922
|
+
return {
|
|
3923
|
+
kind: "fatal",
|
|
3924
|
+
error: err
|
|
3925
|
+
};
|
|
3926
|
+
}
|
|
3927
|
+
}
|
|
3928
|
+
async fetchWithRetry(url, options, responseHandling, retryOptions, requestTimeout) {
|
|
2904
3929
|
const body = options.body ? options.body : "";
|
|
2905
3930
|
let reqByteLength = -1;
|
|
2906
3931
|
try {
|
|
2907
|
-
reqByteLength = body instanceof Blob ? body.size : Buffer.byteLength(body, STRING_FORMAT);
|
|
3932
|
+
reqByteLength = body instanceof Blob ? body.size : body instanceof Uint8Array ? body.byteLength : Buffer.byteLength(body, STRING_FORMAT);
|
|
2908
3933
|
} catch {
|
|
2909
3934
|
if (body instanceof Blob)
|
|
2910
3935
|
reqByteLength = body.size;
|
|
3936
|
+
else if (body instanceof Uint8Array)
|
|
3937
|
+
reqByteLength = body.byteLength;
|
|
2911
3938
|
else {
|
|
2912
3939
|
const encoded = new TextEncoder().encode(body);
|
|
2913
3940
|
reqByteLength = encoded.length;
|
|
2914
3941
|
}
|
|
2915
3942
|
}
|
|
3943
|
+
const retriableOptions = {
|
|
3944
|
+
...this._retryOptions,
|
|
3945
|
+
...retryOptions
|
|
3946
|
+
};
|
|
3947
|
+
let attempt = 0;
|
|
2916
3948
|
return await retriable(async () => {
|
|
3949
|
+
attempt++;
|
|
2917
3950
|
const ctrl = new AbortController;
|
|
2918
3951
|
const timeoutMs = requestTimeout ?? this.requestTimeout;
|
|
2919
|
-
const
|
|
2920
|
-
let
|
|
3952
|
+
const requestDeadline = Date.now() + timeoutMs;
|
|
3953
|
+
let timer;
|
|
3954
|
+
const deadline = new Promise((_resolve, reject) => {
|
|
3955
|
+
timer = safeSetTimeout(() => {
|
|
3956
|
+
const timeoutError = new Error(`Request timed out after ${timeoutMs}ms`);
|
|
3957
|
+
timeoutError.name = "AbortError";
|
|
3958
|
+
reject(timeoutError);
|
|
3959
|
+
ctrl.abort(timeoutError);
|
|
3960
|
+
}, timeoutMs);
|
|
3961
|
+
});
|
|
3962
|
+
let res;
|
|
3963
|
+
let responseAccepted = false;
|
|
3964
|
+
let cancellation;
|
|
3965
|
+
const cancelBody = () => cancellation ??= (async () => {
|
|
3966
|
+
try {
|
|
3967
|
+
await res?.body?.cancel();
|
|
3968
|
+
} catch {}
|
|
3969
|
+
})();
|
|
2921
3970
|
try {
|
|
2922
|
-
|
|
2923
|
-
|
|
2924
|
-
|
|
2925
|
-
|
|
2926
|
-
|
|
2927
|
-
|
|
3971
|
+
let fetchPromise;
|
|
3972
|
+
try {
|
|
3973
|
+
fetchPromise = this.fetch(url, {
|
|
3974
|
+
signal: ctrl.signal,
|
|
3975
|
+
...options
|
|
3976
|
+
});
|
|
3977
|
+
} catch (e) {
|
|
3978
|
+
throw new PostHogFetchNetworkError(e);
|
|
3979
|
+
}
|
|
3980
|
+
fetchPromise.then((lateResponse) => {
|
|
3981
|
+
if (ctrl.signal.aborted && !responseAccepted)
|
|
3982
|
+
Promise.resolve(lateResponse.body?.cancel()).catch(() => {});
|
|
3983
|
+
}).catch(() => {});
|
|
3984
|
+
try {
|
|
3985
|
+
res = await Promise.race([
|
|
3986
|
+
fetchPromise,
|
|
3987
|
+
deadline
|
|
3988
|
+
]);
|
|
3989
|
+
responseAccepted = true;
|
|
3990
|
+
} catch (e) {
|
|
3991
|
+
throw new PostHogFetchNetworkError(e);
|
|
3992
|
+
}
|
|
3993
|
+
const isNoCors = options.mode === "no-cors";
|
|
3994
|
+
if (!isNoCors && (res.status < 200 || res.status >= 400))
|
|
3995
|
+
throw new PostHogFetchHttpError(res, reqByteLength, requestDeadline, ctrl);
|
|
3996
|
+
if (responseHandling.type === "successful-write") {
|
|
3997
|
+
try {
|
|
3998
|
+
await Promise.race([
|
|
3999
|
+
cancelBody(),
|
|
4000
|
+
deadline
|
|
4001
|
+
]);
|
|
4002
|
+
} catch {}
|
|
4003
|
+
return;
|
|
4004
|
+
}
|
|
4005
|
+
try {
|
|
4006
|
+
return await Promise.race([
|
|
4007
|
+
responseHandling.consume(res),
|
|
4008
|
+
deadline
|
|
4009
|
+
]);
|
|
4010
|
+
} catch (e) {
|
|
4011
|
+
if (ctrl.signal.aborted)
|
|
4012
|
+
throw new PostHogFetchNetworkError(e);
|
|
4013
|
+
throw e;
|
|
4014
|
+
}
|
|
2928
4015
|
} finally {
|
|
2929
4016
|
clearTimeout(timer);
|
|
4017
|
+
if (ctrl.signal.aborted && res)
|
|
4018
|
+
cancelBody();
|
|
2930
4019
|
}
|
|
2931
|
-
const isNoCors = options.mode === "no-cors";
|
|
2932
|
-
if (!isNoCors && (res.status < 200 || res.status >= 400))
|
|
2933
|
-
throw new PostHogFetchHttpError(res, reqByteLength);
|
|
2934
|
-
return res;
|
|
2935
4020
|
}, {
|
|
2936
|
-
...
|
|
2937
|
-
|
|
4021
|
+
...retriableOptions,
|
|
4022
|
+
retryCheck: (error) => {
|
|
4023
|
+
const shouldRetry = retriableOptions.retryCheck(error);
|
|
4024
|
+
if (shouldRetry && attempt <= retriableOptions.retryCount && error instanceof PostHogFetchHttpError)
|
|
4025
|
+
error.cancelResponseBody();
|
|
4026
|
+
return shouldRetry;
|
|
4027
|
+
}
|
|
2938
4028
|
});
|
|
2939
4029
|
}
|
|
2940
4030
|
async _shutdown(shutdownTimeoutMs = 30000) {
|
|
@@ -2947,12 +4037,17 @@ class PostHogCoreStateless {
|
|
|
2947
4037
|
try {
|
|
2948
4038
|
await this.promiseQueue.join();
|
|
2949
4039
|
while (true) {
|
|
2950
|
-
const
|
|
2951
|
-
if (
|
|
4040
|
+
const hasQueuedEvents = this.getActiveQueueRoutes().some((route) => this.getRouteQueue(route).length > 0);
|
|
4041
|
+
if (!hasQueuedEvents)
|
|
2952
4042
|
break;
|
|
4043
|
+
const dequeuedBeforeFlush = this._dequeuedMessagesCount;
|
|
2953
4044
|
await this.flush();
|
|
2954
4045
|
if (hasTimedOut)
|
|
2955
4046
|
break;
|
|
4047
|
+
if (this._dequeuedMessagesCount === dequeuedBeforeFlush) {
|
|
4048
|
+
this._logger.warn("Shutdown flush completed but did not send any queued events. Stopping drain to avoid a loop.");
|
|
4049
|
+
break;
|
|
4050
|
+
}
|
|
2956
4051
|
}
|
|
2957
4052
|
} catch (e) {
|
|
2958
4053
|
if (!isPostHogFetchError(e))
|
|
@@ -2960,21 +4055,12 @@ class PostHogCoreStateless {
|
|
|
2960
4055
|
await logFlushError(e);
|
|
2961
4056
|
}
|
|
2962
4057
|
};
|
|
2963
|
-
|
|
2964
|
-
|
|
2965
|
-
|
|
2966
|
-
|
|
2967
|
-
|
|
2968
|
-
|
|
2969
|
-
hasTimedOut = true;
|
|
2970
|
-
reject("Timeout while shutting down PostHog. Some events may not have been sent.");
|
|
2971
|
-
}, shutdownTimeoutMs);
|
|
2972
|
-
}),
|
|
2973
|
-
doShutdown()
|
|
2974
|
-
]);
|
|
2975
|
-
} finally {
|
|
2976
|
-
clearTimeout(timeoutHandle);
|
|
2977
|
-
}
|
|
4058
|
+
return raceWithTimeout(doShutdown(), shutdownTimeoutMs, () => {
|
|
4059
|
+
this._logger.critical("Timeout while shutting down PostHog. Some events may not have been sent.", {
|
|
4060
|
+
shutdownTimeoutMs
|
|
4061
|
+
});
|
|
4062
|
+
hasTimedOut = true;
|
|
4063
|
+
});
|
|
2978
4064
|
}
|
|
2979
4065
|
async shutdown(shutdownTimeoutMs = 30000) {
|
|
2980
4066
|
if (this.shutdownPromise)
|
|
@@ -2986,21 +4072,30 @@ class PostHogCoreStateless {
|
|
|
2986
4072
|
return this.shutdownPromise;
|
|
2987
4073
|
}
|
|
2988
4074
|
}
|
|
2989
|
-
// ../../../../../node_modules/.bun/posthog-node@5.
|
|
2990
|
-
import {
|
|
4075
|
+
// ../../../../../node_modules/.bun/posthog-node@5.51.1/node_modules/posthog-node/dist/extensions/error-tracking/modifiers/context-lines.node.mjs
|
|
4076
|
+
import { constants as constants2 } from "node:fs";
|
|
4077
|
+
import { open as promises_open } from "node:fs/promises";
|
|
4078
|
+
import { isAbsolute } from "node:path";
|
|
2991
4079
|
import { createInterface } from "node:readline";
|
|
2992
4080
|
var LRU_FILE_CONTENTS_CACHE = new exports_error_tracking.ReduceableCache(25);
|
|
2993
4081
|
var LRU_FILE_CONTENTS_FS_READ_FAILED = new exports_error_tracking.ReduceableCache(20);
|
|
2994
4082
|
var DEFAULT_LINES_OF_CONTEXT = 7;
|
|
2995
4083
|
var MAX_CONTEXTLINES_COLNO = 1000;
|
|
2996
4084
|
var MAX_CONTEXTLINES_LINENO = 1e4;
|
|
2997
|
-
|
|
4085
|
+
var MAX_CONTEXTLINES_FILE_SIZE = 10485760;
|
|
4086
|
+
async function addSourceContext(frames, openSourceFile = promises_open, logger2) {
|
|
2998
4087
|
const filesToLines = {};
|
|
4088
|
+
let basePath;
|
|
4089
|
+
try {
|
|
4090
|
+
basePath = process.cwd();
|
|
4091
|
+
} catch {}
|
|
2999
4092
|
for (let i = frames.length - 1;i >= 0; i--) {
|
|
3000
4093
|
const frame = frames[i];
|
|
3001
4094
|
const filename = frame?.filename;
|
|
3002
4095
|
if (!frame || typeof filename != "string" || typeof frame.lineno != "number" || shouldSkipContextLinesForFile(filename) || shouldSkipContextLinesForFrame(frame))
|
|
3003
4096
|
continue;
|
|
4097
|
+
if (!isAbsolute(filename) && basePath === undefined)
|
|
4098
|
+
continue;
|
|
3004
4099
|
const filesToLinesOutput = filesToLines[filename];
|
|
3005
4100
|
if (!filesToLinesOutput)
|
|
3006
4101
|
filesToLines[filename] = [];
|
|
@@ -3011,50 +4106,98 @@ async function addSourceContext(frames) {
|
|
|
3011
4106
|
return frames;
|
|
3012
4107
|
const readlinePromises = [];
|
|
3013
4108
|
for (const file of files) {
|
|
3014
|
-
|
|
4109
|
+
const cacheKey = makeSourceCacheKey(file, basePath);
|
|
4110
|
+
if (cacheKey === undefined)
|
|
4111
|
+
continue;
|
|
4112
|
+
if (LRU_FILE_CONTENTS_FS_READ_FAILED.get(cacheKey))
|
|
3015
4113
|
continue;
|
|
3016
4114
|
const filesToLineRanges = filesToLines[file];
|
|
3017
4115
|
if (!filesToLineRanges)
|
|
3018
4116
|
continue;
|
|
3019
4117
|
filesToLineRanges.sort((a, b) => a - b);
|
|
3020
4118
|
const ranges = makeLineReaderRanges(filesToLineRanges);
|
|
3021
|
-
if (ranges.every((r) => rangeExistsInContentCache(
|
|
4119
|
+
if (ranges.every((r) => rangeExistsInContentCache(cacheKey, r)))
|
|
3022
4120
|
continue;
|
|
3023
|
-
const cache = emplace(LRU_FILE_CONTENTS_CACHE,
|
|
3024
|
-
readlinePromises.push(getContextLinesFromFile(file, ranges, cache));
|
|
4121
|
+
const cache = emplace(LRU_FILE_CONTENTS_CACHE, cacheKey, {});
|
|
4122
|
+
readlinePromises.push(getContextLinesFromFile(file, ranges, cache, cacheKey, openSourceFile, logger2));
|
|
3025
4123
|
}
|
|
3026
4124
|
await Promise.all(readlinePromises).catch(() => {});
|
|
3027
4125
|
if (frames && frames.length > 0)
|
|
3028
|
-
addSourceContextToFrames(frames, LRU_FILE_CONTENTS_CACHE);
|
|
4126
|
+
addSourceContextToFrames(frames, LRU_FILE_CONTENTS_CACHE, basePath);
|
|
3029
4127
|
LRU_FILE_CONTENTS_CACHE.reduce();
|
|
3030
4128
|
return frames;
|
|
3031
4129
|
}
|
|
3032
|
-
function
|
|
4130
|
+
async function openRegularSourceFile(path2, openSourceFile, logger2) {
|
|
4131
|
+
let fileHandle;
|
|
4132
|
+
let isValid = false;
|
|
4133
|
+
try {
|
|
4134
|
+
fileHandle = await openSourceFile(path2, constants2.O_RDONLY | constants2.O_NONBLOCK);
|
|
4135
|
+
const fileStat = await fileHandle.stat();
|
|
4136
|
+
if (!fileStat.isFile())
|
|
4137
|
+
return;
|
|
4138
|
+
if (fileStat.size > MAX_CONTEXTLINES_FILE_SIZE)
|
|
4139
|
+
return void logger2?.debug(`Skipping source context for oversized file ${path2}: ${fileStat.size} bytes exceeds ${MAX_CONTEXTLINES_FILE_SIZE}`);
|
|
4140
|
+
isValid = true;
|
|
4141
|
+
return fileHandle;
|
|
4142
|
+
} catch {
|
|
4143
|
+
return;
|
|
4144
|
+
} finally {
|
|
4145
|
+
if (fileHandle && !isValid)
|
|
4146
|
+
await fileHandle.close().catch(() => {});
|
|
4147
|
+
}
|
|
4148
|
+
}
|
|
4149
|
+
async function getContextLinesFromFile(path2, ranges, output, cacheKey, openSourceFile, logger2) {
|
|
4150
|
+
const fileHandle = await openRegularSourceFile(path2, openSourceFile, logger2);
|
|
4151
|
+
if (fileHandle === undefined)
|
|
4152
|
+
return void LRU_FILE_CONTENTS_FS_READ_FAILED.set(cacheKey, 1);
|
|
4153
|
+
const openedFileHandle = fileHandle;
|
|
3033
4154
|
return new Promise((resolve) => {
|
|
3034
|
-
|
|
3035
|
-
|
|
3036
|
-
|
|
3037
|
-
|
|
3038
|
-
|
|
3039
|
-
|
|
3040
|
-
|
|
4155
|
+
let finished = false;
|
|
4156
|
+
function destroyStreamAndResolve(stream2) {
|
|
4157
|
+
if (finished)
|
|
4158
|
+
return;
|
|
4159
|
+
finished = true;
|
|
4160
|
+
stream2?.destroy();
|
|
4161
|
+
openedFileHandle.close().then(resolve, resolve);
|
|
4162
|
+
}
|
|
4163
|
+
let stream;
|
|
4164
|
+
try {
|
|
4165
|
+
stream = openedFileHandle.createReadStream({
|
|
4166
|
+
autoClose: false,
|
|
4167
|
+
start: 0,
|
|
4168
|
+
end: MAX_CONTEXTLINES_FILE_SIZE - 1
|
|
4169
|
+
});
|
|
4170
|
+
} catch {
|
|
4171
|
+
LRU_FILE_CONTENTS_FS_READ_FAILED.set(cacheKey, 1);
|
|
4172
|
+
destroyStreamAndResolve();
|
|
4173
|
+
return;
|
|
4174
|
+
}
|
|
4175
|
+
let lineReaded;
|
|
4176
|
+
try {
|
|
4177
|
+
lineReaded = createInterface({
|
|
4178
|
+
input: stream
|
|
4179
|
+
});
|
|
4180
|
+
} catch {
|
|
4181
|
+
LRU_FILE_CONTENTS_FS_READ_FAILED.set(cacheKey, 1);
|
|
4182
|
+
destroyStreamAndResolve(stream);
|
|
4183
|
+
return;
|
|
3041
4184
|
}
|
|
3042
4185
|
let lineNumber = 0;
|
|
3043
4186
|
let currentRangeIndex = 0;
|
|
3044
4187
|
const range = ranges[currentRangeIndex];
|
|
3045
4188
|
if (range === undefined)
|
|
3046
|
-
return void destroyStreamAndResolve();
|
|
4189
|
+
return void destroyStreamAndResolve(stream);
|
|
3047
4190
|
let rangeStart = range[0];
|
|
3048
4191
|
let rangeEnd = range[1];
|
|
3049
4192
|
function onStreamError() {
|
|
3050
|
-
LRU_FILE_CONTENTS_FS_READ_FAILED.set(
|
|
4193
|
+
LRU_FILE_CONTENTS_FS_READ_FAILED.set(cacheKey, 1);
|
|
3051
4194
|
lineReaded.close();
|
|
3052
4195
|
lineReaded.removeAllListeners();
|
|
3053
|
-
destroyStreamAndResolve();
|
|
4196
|
+
destroyStreamAndResolve(stream);
|
|
3054
4197
|
}
|
|
3055
4198
|
stream.on("error", onStreamError);
|
|
3056
4199
|
lineReaded.on("error", onStreamError);
|
|
3057
|
-
lineReaded.on("close", destroyStreamAndResolve);
|
|
4200
|
+
lineReaded.on("close", () => destroyStreamAndResolve(stream));
|
|
3058
4201
|
lineReaded.on("line", (line) => {
|
|
3059
4202
|
lineNumber++;
|
|
3060
4203
|
if (lineNumber < rangeStart)
|
|
@@ -3079,10 +4222,11 @@ function getContextLinesFromFile(path2, ranges, output) {
|
|
|
3079
4222
|
});
|
|
3080
4223
|
});
|
|
3081
4224
|
}
|
|
3082
|
-
function addSourceContextToFrames(frames, cache) {
|
|
4225
|
+
function addSourceContextToFrames(frames, cache, basePath) {
|
|
3083
4226
|
for (const frame of frames)
|
|
3084
4227
|
if (frame.filename && frame.context_line === undefined && typeof frame.lineno == "number") {
|
|
3085
|
-
const
|
|
4228
|
+
const cacheKey = makeSourceCacheKey(frame.filename, basePath);
|
|
4229
|
+
const contents = cacheKey === undefined ? undefined : cache.get(cacheKey);
|
|
3086
4230
|
if (contents === undefined)
|
|
3087
4231
|
continue;
|
|
3088
4232
|
addContextToFrame(frame.lineno, frame, contents);
|
|
@@ -3125,8 +4269,19 @@ function shouldSkipContextLinesForFrame(frame) {
|
|
|
3125
4269
|
return true;
|
|
3126
4270
|
return false;
|
|
3127
4271
|
}
|
|
3128
|
-
function
|
|
3129
|
-
|
|
4272
|
+
function makeSourceCacheKey(path2, basePath) {
|
|
4273
|
+
if (isAbsolute(path2))
|
|
4274
|
+
return JSON.stringify([
|
|
4275
|
+
null,
|
|
4276
|
+
path2
|
|
4277
|
+
]);
|
|
4278
|
+
return basePath === undefined ? undefined : JSON.stringify([
|
|
4279
|
+
basePath,
|
|
4280
|
+
path2
|
|
4281
|
+
]);
|
|
4282
|
+
}
|
|
4283
|
+
function rangeExistsInContentCache(cacheKey, range) {
|
|
4284
|
+
const contents = LRU_FILE_CONTENTS_CACHE.get(cacheKey);
|
|
3130
4285
|
if (contents === undefined)
|
|
3131
4286
|
return false;
|
|
3132
4287
|
for (let i = range[0];i <= range[1]; i++)
|
|
@@ -3204,8 +4359,8 @@ function snipLine(line, colno) {
|
|
|
3204
4359
|
return newLine;
|
|
3205
4360
|
}
|
|
3206
4361
|
|
|
3207
|
-
// ../../../../../node_modules/.bun/posthog-node@5.
|
|
3208
|
-
import { isAbsolute, relative, sep as sep2 } from "path";
|
|
4362
|
+
// ../../../../../node_modules/.bun/posthog-node@5.51.1/node_modules/posthog-node/dist/extensions/error-tracking/modifiers/relative-path.node.mjs
|
|
4363
|
+
import { isAbsolute as isAbsolute2, relative, sep as sep2 } from "path";
|
|
3209
4364
|
function createRelativePathModifier(basePath = process.cwd()) {
|
|
3210
4365
|
const isWindows = sep2 === "\\";
|
|
3211
4366
|
const toUnix = (p) => isWindows ? p.replace(/\\/g, "/") : p;
|
|
@@ -3213,17 +4368,17 @@ function createRelativePathModifier(basePath = process.cwd()) {
|
|
|
3213
4368
|
return async (frames) => {
|
|
3214
4369
|
for (const frame of frames)
|
|
3215
4370
|
if (!(!frame.filename || frame.filename.startsWith("node:") || frame.filename.startsWith("data:"))) {
|
|
3216
|
-
if (
|
|
4371
|
+
if (isAbsolute2(frame.filename))
|
|
3217
4372
|
frame.filename = toUnix(relative(normalizedBase, toUnix(frame.filename)));
|
|
3218
4373
|
}
|
|
3219
4374
|
return frames;
|
|
3220
4375
|
};
|
|
3221
4376
|
}
|
|
3222
4377
|
|
|
3223
|
-
// ../../../../../node_modules/.bun/posthog-node@5.
|
|
3224
|
-
var version = "5.
|
|
4378
|
+
// ../../../../../node_modules/.bun/posthog-node@5.51.1/node_modules/posthog-node/dist/version.mjs
|
|
4379
|
+
var version = "5.51.1";
|
|
3225
4380
|
|
|
3226
|
-
// ../../../../../node_modules/.bun/posthog-node@5.
|
|
4381
|
+
// ../../../../../node_modules/.bun/posthog-node@5.51.1/node_modules/posthog-node/dist/types.mjs
|
|
3227
4382
|
var FeatureFlagError2 = {
|
|
3228
4383
|
ERRORS_WHILE_COMPUTING: "errors_while_computing_flags",
|
|
3229
4384
|
FLAG_MISSING: "flag_missing",
|
|
@@ -3231,7 +4386,7 @@ var FeatureFlagError2 = {
|
|
|
3231
4386
|
UNKNOWN_ERROR: "unknown_error"
|
|
3232
4387
|
};
|
|
3233
4388
|
|
|
3234
|
-
// ../../../../../node_modules/.bun/posthog-node@5.
|
|
4389
|
+
// ../../../../../node_modules/.bun/posthog-node@5.51.1/node_modules/posthog-node/dist/feature-flag-evaluations.mjs
|
|
3235
4390
|
class FeatureFlagEvaluations {
|
|
3236
4391
|
constructor(init) {
|
|
3237
4392
|
this._host = init.host;
|
|
@@ -3247,10 +4402,10 @@ class FeatureFlagEvaluations {
|
|
|
3247
4402
|
this._accessed = init.accessed ?? new Set;
|
|
3248
4403
|
this._isSlice = init.isSlice ?? false;
|
|
3249
4404
|
}
|
|
3250
|
-
isEnabled(key) {
|
|
4405
|
+
isEnabled(key, options = {}) {
|
|
3251
4406
|
const flag = this._flags[key];
|
|
3252
4407
|
this._recordAccess(key);
|
|
3253
|
-
return flag?.enabled ?? false;
|
|
4408
|
+
return flag?.enabled ?? options.defaultValue ?? false;
|
|
3254
4409
|
}
|
|
3255
4410
|
getFlag(key) {
|
|
3256
4411
|
const flag = this._flags[key];
|
|
@@ -3340,6 +4495,8 @@ class FeatureFlagEvaluations {
|
|
|
3340
4495
|
$feature_flag_request_id: this._requestId,
|
|
3341
4496
|
$feature_flag_evaluated_at: flag?.locallyEvaluated ? Date.now() : this._evaluatedAt
|
|
3342
4497
|
};
|
|
4498
|
+
if (flag?.hasExperiment !== undefined)
|
|
4499
|
+
properties.$feature_flag_has_experiment = flag.hasExperiment;
|
|
3343
4500
|
if (flag?.locallyEvaluated && this._flagDefinitionsLoadedAt !== undefined)
|
|
3344
4501
|
properties.$feature_flag_definitions_loaded_at = this._flagDefinitionsLoadedAt;
|
|
3345
4502
|
const errors = [];
|
|
@@ -3362,7 +4519,7 @@ class FeatureFlagEvaluations {
|
|
|
3362
4519
|
}
|
|
3363
4520
|
}
|
|
3364
4521
|
|
|
3365
|
-
// ../../../../../node_modules/.bun/posthog-node@5.
|
|
4522
|
+
// ../../../../../node_modules/.bun/posthog-node@5.51.1/node_modules/posthog-node/dist/extensions/feature-flags/crypto.mjs
|
|
3366
4523
|
async function hashSHA1(text) {
|
|
3367
4524
|
const subtle = globalThis.crypto?.subtle;
|
|
3368
4525
|
if (!subtle)
|
|
@@ -3372,7 +4529,7 @@ async function hashSHA1(text) {
|
|
|
3372
4529
|
return hashArray.map((byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
3373
4530
|
}
|
|
3374
4531
|
|
|
3375
|
-
// ../../../../../node_modules/.bun/posthog-node@5.
|
|
4532
|
+
// ../../../../../node_modules/.bun/posthog-node@5.51.1/node_modules/posthog-node/dist/extensions/feature-flags/feature-flags.mjs
|
|
3376
4533
|
var SIXTY_SECONDS = 60000;
|
|
3377
4534
|
var LONG_SCALE = 1152921504606847000;
|
|
3378
4535
|
var NULL_VALUES_ALLOWED_OPERATORS = [
|
|
@@ -3389,22 +4546,23 @@ class ClientError extends Error {
|
|
|
3389
4546
|
Object.setPrototypeOf(this, ClientError.prototype);
|
|
3390
4547
|
}
|
|
3391
4548
|
}
|
|
4549
|
+
function setCustomErrorPrototype(error, constructor) {
|
|
4550
|
+
error.name = constructor.name;
|
|
4551
|
+
Error.captureStackTrace(error, constructor);
|
|
4552
|
+
Object.setPrototypeOf(error, constructor.prototype);
|
|
4553
|
+
}
|
|
3392
4554
|
|
|
3393
4555
|
class InconclusiveMatchError extends Error {
|
|
3394
4556
|
constructor(message) {
|
|
3395
4557
|
super(message);
|
|
3396
|
-
this
|
|
3397
|
-
Error.captureStackTrace(this, this.constructor);
|
|
3398
|
-
Object.setPrototypeOf(this, InconclusiveMatchError.prototype);
|
|
4558
|
+
setCustomErrorPrototype(this, InconclusiveMatchError);
|
|
3399
4559
|
}
|
|
3400
4560
|
}
|
|
3401
4561
|
|
|
3402
4562
|
class RequiresServerEvaluation extends Error {
|
|
3403
4563
|
constructor(message) {
|
|
3404
4564
|
super(message);
|
|
3405
|
-
this
|
|
3406
|
-
Error.captureStackTrace(this, this.constructor);
|
|
3407
|
-
Object.setPrototypeOf(this, RequiresServerEvaluation.prototype);
|
|
4565
|
+
setCustomErrorPrototype(this, RequiresServerEvaluation);
|
|
3408
4566
|
}
|
|
3409
4567
|
}
|
|
3410
4568
|
|
|
@@ -3413,6 +4571,7 @@ class FeatureFlagsPoller {
|
|
|
3413
4571
|
this.debugMode = false;
|
|
3414
4572
|
this.shouldBeginExponentialBackoff = false;
|
|
3415
4573
|
this.backOffCount = 0;
|
|
4574
|
+
this.pollerStopped = false;
|
|
3416
4575
|
this.pollingInterval = pollingInterval;
|
|
3417
4576
|
this.personalApiKey = personalApiKey;
|
|
3418
4577
|
this.featureFlags = [];
|
|
@@ -3428,6 +4587,7 @@ class FeatureFlagsPoller {
|
|
|
3428
4587
|
this.onError = options.onError;
|
|
3429
4588
|
this.customHeaders = customHeaders;
|
|
3430
4589
|
this.onLoad = options.onLoad;
|
|
4590
|
+
this.onMinimalFlagCalledEvents = options.onMinimalFlagCalledEvents;
|
|
3431
4591
|
this.cacheProvider = options.cacheProvider;
|
|
3432
4592
|
this.strictLocalEvaluation = options.strictLocalEvaluation ?? false;
|
|
3433
4593
|
this.loadFeatureFlags();
|
|
@@ -3625,6 +4785,7 @@ class FeatureFlagsPoller {
|
|
|
3625
4785
|
const flagFilters = flag.filters || {};
|
|
3626
4786
|
const flagConditions = flagFilters.groups || [];
|
|
3627
4787
|
const flagAggregation = flagFilters.aggregation_group_type_index;
|
|
4788
|
+
const earlyExitEnabled = flagFilters.early_exit ?? false;
|
|
3628
4789
|
const { groups, groupProperties } = evaluationContext;
|
|
3629
4790
|
let isInconclusive = false;
|
|
3630
4791
|
let result;
|
|
@@ -3648,12 +4809,15 @@ class FeatureFlagsPoller {
|
|
|
3648
4809
|
effectiveBucketingValue = groups[groupName];
|
|
3649
4810
|
}
|
|
3650
4811
|
}
|
|
3651
|
-
|
|
4812
|
+
const matchResult = await this.isConditionMatch(flag, effectiveBucketingValue, condition, effectiveProperties, evaluationContext);
|
|
4813
|
+
if (matchResult === "match") {
|
|
3652
4814
|
const variantOverride = condition.variant;
|
|
3653
4815
|
const flagVariants = flagFilters.multivariate?.variants || [];
|
|
3654
4816
|
result = variantOverride && flagVariants.some((variant) => variant.key === variantOverride) ? variantOverride : await this.getMatchingVariant(flag, effectiveBucketingValue) || true;
|
|
3655
4817
|
break;
|
|
3656
4818
|
}
|
|
4819
|
+
if (earlyExitEnabled && matchResult === "out_of_rollout_bound")
|
|
4820
|
+
return false;
|
|
3657
4821
|
} catch (e) {
|
|
3658
4822
|
if (e instanceof RequiresServerEvaluation)
|
|
3659
4823
|
throw e;
|
|
@@ -3677,16 +4841,20 @@ class FeatureFlagsPoller {
|
|
|
3677
4841
|
for (const prop of condition.properties) {
|
|
3678
4842
|
const propertyType = prop.type;
|
|
3679
4843
|
let matches = false;
|
|
3680
|
-
|
|
4844
|
+
if (propertyType === "cohort") {
|
|
4845
|
+
const inCohort = await matchCohort(prop, properties, this.cohorts, this.debugMode, (depProp) => this.evaluateFlagDependency(depProp, properties, evaluationContext));
|
|
4846
|
+
matches = prop.operator === "not_in" ? !inCohort : inCohort;
|
|
4847
|
+
} else
|
|
4848
|
+
matches = propertyType === "flag" ? await this.evaluateFlagDependency(prop, properties, evaluationContext) : matchProperty(prop, properties, warnFunction);
|
|
3681
4849
|
if (!matches)
|
|
3682
|
-
return
|
|
4850
|
+
return "no_match";
|
|
3683
4851
|
}
|
|
3684
4852
|
if (rolloutPercentage == undefined)
|
|
3685
|
-
return
|
|
4853
|
+
return "match";
|
|
3686
4854
|
}
|
|
3687
4855
|
if (rolloutPercentage != null && await _hash(flag.key, bucketingValue) > rolloutPercentage / 100)
|
|
3688
|
-
return
|
|
3689
|
-
return
|
|
4856
|
+
return "out_of_rollout_bound";
|
|
4857
|
+
return "match";
|
|
3690
4858
|
}
|
|
3691
4859
|
async getMatchingVariant(flag, bucketingValue) {
|
|
3692
4860
|
const hashValue = await _hash(flag.key, bucketingValue, "variant");
|
|
@@ -3717,6 +4885,7 @@ class FeatureFlagsPoller {
|
|
|
3717
4885
|
this.groupTypeMapping = flagData.groupTypeMapping;
|
|
3718
4886
|
this.cohorts = flagData.cohorts;
|
|
3719
4887
|
this.loadedSuccessfullyOnce = true;
|
|
4888
|
+
this.onMinimalFlagCalledEvents?.(flagData.minimalFlagCalledEvents === true);
|
|
3720
4889
|
}
|
|
3721
4890
|
warnAboutExperienceContinuityFlags(flags) {
|
|
3722
4891
|
if (this.strictLocalEvaluation)
|
|
@@ -3780,7 +4949,6 @@ class FeatureFlagsPoller {
|
|
|
3780
4949
|
clearTimeout(this.poller);
|
|
3781
4950
|
this.poller = undefined;
|
|
3782
4951
|
}
|
|
3783
|
-
this.poller = setTimeout(() => this.loadFeatureFlags(true), this.getPollingInterval());
|
|
3784
4952
|
try {
|
|
3785
4953
|
let shouldFetch = true;
|
|
3786
4954
|
if (this.cacheProvider)
|
|
@@ -3808,17 +4976,18 @@ class FeatureFlagsPoller {
|
|
|
3808
4976
|
return;
|
|
3809
4977
|
case 401:
|
|
3810
4978
|
this.beginBackoff();
|
|
3811
|
-
throw new ClientError(`Your project key or
|
|
4979
|
+
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`);
|
|
3812
4980
|
case 402:
|
|
3813
4981
|
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");
|
|
3814
4982
|
this.featureFlags = [];
|
|
3815
4983
|
this.featureFlagsByKey = {};
|
|
3816
4984
|
this.groupTypeMapping = {};
|
|
3817
4985
|
this.cohorts = {};
|
|
4986
|
+
this.onMinimalFlagCalledEvents?.(false);
|
|
3818
4987
|
return;
|
|
3819
4988
|
case 403:
|
|
3820
4989
|
this.beginBackoff();
|
|
3821
|
-
throw new ClientError(`Your
|
|
4990
|
+
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`);
|
|
3822
4991
|
case 429:
|
|
3823
4992
|
this.beginBackoff();
|
|
3824
4993
|
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`);
|
|
@@ -3830,7 +4999,8 @@ class FeatureFlagsPoller {
|
|
|
3830
4999
|
const flagData = {
|
|
3831
5000
|
flags: responseJson.flags ?? [],
|
|
3832
5001
|
groupTypeMapping: responseJson.group_type_mapping || {},
|
|
3833
|
-
cohorts: responseJson.cohorts || {}
|
|
5002
|
+
cohorts: responseJson.cohorts || {},
|
|
5003
|
+
minimalFlagCalledEvents: responseJson.minimal_flag_called_events === true
|
|
3834
5004
|
};
|
|
3835
5005
|
this.updateFlagState(flagData);
|
|
3836
5006
|
this.flagDefinitionsLoadedAt = Date.now();
|
|
@@ -3851,6 +5021,9 @@ class FeatureFlagsPoller {
|
|
|
3851
5021
|
} catch (err) {
|
|
3852
5022
|
if (err instanceof ClientError)
|
|
3853
5023
|
this.onError?.(err);
|
|
5024
|
+
} finally {
|
|
5025
|
+
if (!this.pollerStopped)
|
|
5026
|
+
this.poller = setTimeout(() => this.loadFeatureFlags(true), this.getPollingInterval());
|
|
3854
5027
|
}
|
|
3855
5028
|
}
|
|
3856
5029
|
getPersonalApiKeyRequestOptions(method = "GET", etag) {
|
|
@@ -3866,7 +5039,7 @@ class FeatureFlagsPoller {
|
|
|
3866
5039
|
headers
|
|
3867
5040
|
};
|
|
3868
5041
|
}
|
|
3869
|
-
_requestFeatureFlagDefinitions() {
|
|
5042
|
+
async _requestFeatureFlagDefinitions() {
|
|
3870
5043
|
const url = `${this.host}/flags/definitions?token=${this.projectApiKey}&send_cohorts`;
|
|
3871
5044
|
const options = this.getPersonalApiKeyRequestOptions("GET", this.flagsEtag);
|
|
3872
5045
|
let abortTimeout = null;
|
|
@@ -3877,23 +5050,49 @@ class FeatureFlagsPoller {
|
|
|
3877
5050
|
}, this.timeout);
|
|
3878
5051
|
options.signal = controller.signal;
|
|
3879
5052
|
}
|
|
5053
|
+
const clearAbortTimeout = () => clearTimeout(abortTimeout);
|
|
3880
5054
|
try {
|
|
3881
5055
|
const fetch1 = this.fetch;
|
|
3882
|
-
|
|
3883
|
-
|
|
3884
|
-
|
|
5056
|
+
const res = await fetch1(url, options);
|
|
5057
|
+
if (res.status !== 200) {
|
|
5058
|
+
clearAbortTimeout();
|
|
5059
|
+
return res;
|
|
5060
|
+
}
|
|
5061
|
+
return {
|
|
5062
|
+
status: res.status,
|
|
5063
|
+
headers: res.headers,
|
|
5064
|
+
body: res.body,
|
|
5065
|
+
text: async () => {
|
|
5066
|
+
try {
|
|
5067
|
+
return await res.text();
|
|
5068
|
+
} finally {
|
|
5069
|
+
clearAbortTimeout();
|
|
5070
|
+
}
|
|
5071
|
+
},
|
|
5072
|
+
json: async () => {
|
|
5073
|
+
try {
|
|
5074
|
+
return await res.json();
|
|
5075
|
+
} finally {
|
|
5076
|
+
clearAbortTimeout();
|
|
5077
|
+
}
|
|
5078
|
+
}
|
|
5079
|
+
};
|
|
5080
|
+
} catch (err) {
|
|
5081
|
+
clearAbortTimeout();
|
|
5082
|
+
throw err;
|
|
3885
5083
|
}
|
|
3886
5084
|
}
|
|
3887
5085
|
async stopPoller(timeoutMs = 30000) {
|
|
5086
|
+
this.pollerStopped = true;
|
|
3888
5087
|
clearTimeout(this.poller);
|
|
5088
|
+
this.poller = undefined;
|
|
3889
5089
|
if (this.cacheProvider)
|
|
3890
5090
|
try {
|
|
3891
5091
|
const shutdownResult = this.cacheProvider.shutdown();
|
|
3892
5092
|
if (shutdownResult instanceof Promise)
|
|
3893
|
-
await
|
|
3894
|
-
|
|
3895
|
-
|
|
3896
|
-
]);
|
|
5093
|
+
await raceWithTimeout(shutdownResult, timeoutMs, () => {
|
|
5094
|
+
throw new Error(`Cache shutdown timeout after ${timeoutMs}ms`);
|
|
5095
|
+
});
|
|
3897
5096
|
} catch (err) {
|
|
3898
5097
|
this.onError?.(new Error(`Error during cache shutdown: ${err}`));
|
|
3899
5098
|
}
|
|
@@ -3948,6 +5147,14 @@ function matchProperty(property, propertyValues, warnFunction) {
|
|
|
3948
5147
|
return String(overrideValue).toLowerCase().includes(String(value).toLowerCase());
|
|
3949
5148
|
case "not_icontains":
|
|
3950
5149
|
return !String(overrideValue).toLowerCase().includes(String(value).toLowerCase());
|
|
5150
|
+
case "starts_with":
|
|
5151
|
+
return String(overrideValue).toLowerCase().startsWith(String(value).toLowerCase());
|
|
5152
|
+
case "not_starts_with":
|
|
5153
|
+
return !String(overrideValue).toLowerCase().startsWith(String(value).toLowerCase());
|
|
5154
|
+
case "ends_with":
|
|
5155
|
+
return String(overrideValue).toLowerCase().endsWith(String(value).toLowerCase());
|
|
5156
|
+
case "not_ends_with":
|
|
5157
|
+
return !String(overrideValue).toLowerCase().endsWith(String(value).toLowerCase());
|
|
3951
5158
|
case "regex":
|
|
3952
5159
|
return isValidRegex(String(value)) && String(overrideValue).match(String(value)) !== null;
|
|
3953
5160
|
case "not_regex":
|
|
@@ -4274,19 +5481,75 @@ function relativeDateParseForFeatureFlagMatching(value) {
|
|
|
4274
5481
|
}
|
|
4275
5482
|
}
|
|
4276
5483
|
|
|
4277
|
-
// ../../../../../node_modules/.bun/posthog-node@5.
|
|
5484
|
+
// ../../../../../node_modules/.bun/posthog-node@5.51.1/node_modules/posthog-node/dist/extensions/error-tracking/autocapture.mjs
|
|
5485
|
+
var UNHANDLED_REJECTION_OPTION_NAMES = [
|
|
5486
|
+
"--unhandled-rejections",
|
|
5487
|
+
"--unhandled_rejections"
|
|
5488
|
+
];
|
|
5489
|
+
var UNHANDLED_REJECTION_MODES = new Set([
|
|
5490
|
+
"throw",
|
|
5491
|
+
"strict",
|
|
5492
|
+
"warn",
|
|
5493
|
+
"warn-with-error-code",
|
|
5494
|
+
"none"
|
|
5495
|
+
]);
|
|
5496
|
+
var STARTUP_EXEC_ARGV = [
|
|
5497
|
+
...globalThis.process?.execArgv ?? []
|
|
5498
|
+
];
|
|
5499
|
+
var STARTUP_NODE_OPTIONS = globalThis.process?.env?.NODE_OPTIONS;
|
|
5500
|
+
function splitNodeOptions(nodeOptions) {
|
|
5501
|
+
const args = [];
|
|
5502
|
+
let current = "";
|
|
5503
|
+
let isInString = false;
|
|
5504
|
+
for (let index = 0;index < nodeOptions.length; index++) {
|
|
5505
|
+
const character = nodeOptions[index];
|
|
5506
|
+
if (character === "\\" && isInString && index + 1 < nodeOptions.length)
|
|
5507
|
+
current += nodeOptions[++index];
|
|
5508
|
+
else if (character !== " " || isInString)
|
|
5509
|
+
if (character === '"')
|
|
5510
|
+
isInString = !isInString;
|
|
5511
|
+
else
|
|
5512
|
+
current += character;
|
|
5513
|
+
else if (current) {
|
|
5514
|
+
args.push(current);
|
|
5515
|
+
current = "";
|
|
5516
|
+
}
|
|
5517
|
+
}
|
|
5518
|
+
if (current)
|
|
5519
|
+
args.push(current);
|
|
5520
|
+
return args;
|
|
5521
|
+
}
|
|
5522
|
+
function findUnhandledRejectionMode(args) {
|
|
5523
|
+
let mode;
|
|
5524
|
+
for (let index = 0;index < args.length; index++) {
|
|
5525
|
+
const argument = args[index];
|
|
5526
|
+
const optionName = UNHANDLED_REJECTION_OPTION_NAMES.find((name) => argument === name || argument.startsWith(`${name}=`));
|
|
5527
|
+
if (!optionName)
|
|
5528
|
+
continue;
|
|
5529
|
+
const value = argument === optionName ? args[++index] : argument.slice(optionName.length + 1);
|
|
5530
|
+
if (UNHANDLED_REJECTION_MODES.has(value))
|
|
5531
|
+
mode = value;
|
|
5532
|
+
}
|
|
5533
|
+
return mode;
|
|
5534
|
+
}
|
|
5535
|
+
function getUnhandledRejectionMode(execArgv = STARTUP_EXEC_ARGV, nodeOptions = STARTUP_NODE_OPTIONS) {
|
|
5536
|
+
return findUnhandledRejectionMode(execArgv) ?? findUnhandledRejectionMode(splitNodeOptions(nodeOptions ?? "")) ?? "throw";
|
|
5537
|
+
}
|
|
5538
|
+
var STARTUP_UNHANDLED_REJECTION_MODE = getUnhandledRejectionMode();
|
|
5539
|
+
function captureUncaughtException(captureFn, error, origin) {
|
|
5540
|
+
captureFn(error, {
|
|
5541
|
+
mechanism: {
|
|
5542
|
+
type: origin === "unhandledRejection" ? "onunhandledrejection" : "onuncaughtexception",
|
|
5543
|
+
handled: false
|
|
5544
|
+
}
|
|
5545
|
+
});
|
|
5546
|
+
}
|
|
4278
5547
|
function makeUncaughtExceptionHandler(captureFn, onFatalFn) {
|
|
4279
5548
|
let calledFatalError = false;
|
|
4280
|
-
return Object.assign((error) => {
|
|
5549
|
+
return Object.assign((error, origin) => {
|
|
4281
5550
|
const userProvidedListenersCount = global.process.listeners("uncaughtException").filter((listener) => listener.name !== "domainUncaughtExceptionClear" && listener._posthogErrorHandler !== true).length;
|
|
4282
|
-
|
|
4283
|
-
|
|
4284
|
-
mechanism: {
|
|
4285
|
-
type: "onuncaughtexception",
|
|
4286
|
-
handled: false
|
|
4287
|
-
}
|
|
4288
|
-
});
|
|
4289
|
-
if (!calledFatalError && processWouldExit) {
|
|
5551
|
+
captureUncaughtException(captureFn, error, origin);
|
|
5552
|
+
if (!calledFatalError && userProvidedListenersCount === 0) {
|
|
4290
5553
|
calledFatalError = true;
|
|
4291
5554
|
onFatalFn(error);
|
|
4292
5555
|
}
|
|
@@ -4294,29 +5557,38 @@ function makeUncaughtExceptionHandler(captureFn, onFatalFn) {
|
|
|
4294
5557
|
_posthogErrorHandler: true
|
|
4295
5558
|
});
|
|
4296
5559
|
}
|
|
4297
|
-
function addUncaughtExceptionListener(captureFn, onFatalFn) {
|
|
4298
|
-
globalThis.process
|
|
5560
|
+
function addUncaughtExceptionListener(captureFn, onFatalFn, mode = STARTUP_UNHANDLED_REJECTION_MODE) {
|
|
5561
|
+
const process2 = globalThis.process;
|
|
5562
|
+
if (!process2)
|
|
5563
|
+
return;
|
|
5564
|
+
if (mode === "strict")
|
|
5565
|
+
return void process2.on("uncaughtExceptionMonitor", (error, origin) => captureUncaughtException(captureFn, error, origin));
|
|
5566
|
+
process2.on("uncaughtException", makeUncaughtExceptionHandler(captureFn, onFatalFn));
|
|
4299
5567
|
}
|
|
4300
|
-
function addUnhandledRejectionListener(captureFn) {
|
|
4301
|
-
globalThis.process
|
|
4302
|
-
|
|
4303
|
-
|
|
4304
|
-
|
|
4305
|
-
|
|
4306
|
-
|
|
5568
|
+
function addUnhandledRejectionListener(captureFn, mode = STARTUP_UNHANDLED_REJECTION_MODE) {
|
|
5569
|
+
const process2 = globalThis.process;
|
|
5570
|
+
if (!process2 || mode === "throw" || mode === "strict" || mode === "warn-with-error-code")
|
|
5571
|
+
return;
|
|
5572
|
+
process2.on("unhandledRejection", (reason) => {
|
|
5573
|
+
captureFn(reason, {
|
|
5574
|
+
mechanism: {
|
|
5575
|
+
type: "onunhandledrejection",
|
|
5576
|
+
handled: false
|
|
5577
|
+
}
|
|
5578
|
+
});
|
|
5579
|
+
});
|
|
4307
5580
|
}
|
|
4308
5581
|
|
|
4309
|
-
// ../../../../../node_modules/.bun/posthog-node@5.
|
|
5582
|
+
// ../../../../../node_modules/.bun/posthog-node@5.51.1/node_modules/posthog-node/dist/extensions/error-tracking/index.mjs
|
|
4310
5583
|
var SHUTDOWN_TIMEOUT = 2000;
|
|
4311
5584
|
|
|
4312
|
-
class
|
|
5585
|
+
class error_tracking_ErrorTracking {
|
|
4313
5586
|
constructor(client, options, _logger) {
|
|
4314
5587
|
this.client = client;
|
|
4315
5588
|
this._exceptionAutocaptureEnabled = options.enableExceptionAutocapture || false;
|
|
4316
5589
|
this._logger = _logger;
|
|
4317
5590
|
this._rateLimiter = new BucketedRateLimiter({
|
|
4318
|
-
|
|
4319
|
-
bucketSize: 10,
|
|
5591
|
+
...resolveExceptionRateLimiterConfig(options),
|
|
4320
5592
|
refillInterval: 1e4,
|
|
4321
5593
|
_logger: this._logger
|
|
4322
5594
|
});
|
|
@@ -4331,6 +5603,9 @@ class ErrorTracking {
|
|
|
4331
5603
|
};
|
|
4332
5604
|
const exceptionProperties = builder.buildFromUnknown(error, hint);
|
|
4333
5605
|
exceptionProperties.$exception_list = await builder.modifyFrames(exceptionProperties.$exception_list);
|
|
5606
|
+
const injectedReleaseId = exports_error_tracking.getInjectedReleaseId();
|
|
5607
|
+
if (injectedReleaseId)
|
|
5608
|
+
properties.$release_id = injectedReleaseId;
|
|
4334
5609
|
return {
|
|
4335
5610
|
event: "$exception",
|
|
4336
5611
|
distinctId,
|
|
@@ -4349,8 +5624,8 @@ class ErrorTracking {
|
|
|
4349
5624
|
}
|
|
4350
5625
|
onException(exception, hint) {
|
|
4351
5626
|
this.client.addPendingPromise((async () => {
|
|
4352
|
-
if (!
|
|
4353
|
-
const eventMessage = await
|
|
5627
|
+
if (!error_tracking_ErrorTracking.isPreviouslyCapturedError(exception)) {
|
|
5628
|
+
const eventMessage = await error_tracking_ErrorTracking.buildEventMessage(this.client.getErrorPropertiesBuilder(), exception, hint);
|
|
4354
5629
|
const exceptionProperties = eventMessage.properties;
|
|
4355
5630
|
const exceptionType = exceptionProperties?.$exception_list[0]?.type ?? "Exception";
|
|
4356
5631
|
const isRateLimited = this._rateLimiter.consumeRateLimit(exceptionType);
|
|
@@ -4358,14 +5633,14 @@ class ErrorTracking {
|
|
|
4358
5633
|
return void this._logger.info("Skipping exception capture because of client rate limiting.", {
|
|
4359
5634
|
exception: exceptionType
|
|
4360
5635
|
});
|
|
4361
|
-
return this.client.
|
|
5636
|
+
return this.client._capturePreparedEvent(eventMessage, false);
|
|
4362
5637
|
}
|
|
4363
5638
|
})());
|
|
4364
5639
|
}
|
|
4365
5640
|
async onFatalError(exception) {
|
|
4366
5641
|
console.error(exception);
|
|
4367
5642
|
await this.client.shutdown(SHUTDOWN_TIMEOUT);
|
|
4368
|
-
process.exit(1);
|
|
5643
|
+
globalThis.process.exit(1);
|
|
4369
5644
|
}
|
|
4370
5645
|
isEnabled() {
|
|
4371
5646
|
return !this.client.isDisabled && this._exceptionAutocaptureEnabled;
|
|
@@ -4375,7 +5650,7 @@ class ErrorTracking {
|
|
|
4375
5650
|
}
|
|
4376
5651
|
}
|
|
4377
5652
|
|
|
4378
|
-
// ../../../../../node_modules/.bun/posthog-node@5.
|
|
5653
|
+
// ../../../../../node_modules/.bun/posthog-node@5.51.1/node_modules/posthog-node/dist/storage-memory.mjs
|
|
4379
5654
|
class PostHogMemoryStorage {
|
|
4380
5655
|
getProperty(key) {
|
|
4381
5656
|
return this._memoryStorage[key];
|
|
@@ -4388,7 +5663,452 @@ class PostHogMemoryStorage {
|
|
|
4388
5663
|
}
|
|
4389
5664
|
}
|
|
4390
5665
|
|
|
4391
|
-
// ../../../../../node_modules/.bun/posthog-node@5.
|
|
5666
|
+
// ../../../../../node_modules/.bun/posthog-node@5.51.1/node_modules/posthog-node/dist/capture-v1/config.mjs
|
|
5667
|
+
function isCaptureMode(value) {
|
|
5668
|
+
return value === "v0" || value === "v1";
|
|
5669
|
+
}
|
|
5670
|
+
function resolveCaptureMode() {
|
|
5671
|
+
const envMode = typeof process != "undefined" ? process.env?.POSTHOG_CAPTURE_MODE : undefined;
|
|
5672
|
+
return isCaptureMode(envMode) ? envMode : "v0";
|
|
5673
|
+
}
|
|
5674
|
+
|
|
5675
|
+
// ../../../../../node_modules/.bun/posthog-node@5.51.1/node_modules/posthog-node/dist/capture-v1/routing.mjs
|
|
5676
|
+
var AI_EVENT_PREFIX = "$ai_";
|
|
5677
|
+
var ANALYTICS_ROUTE = "analytics";
|
|
5678
|
+
var AI_ROUTE = "ai";
|
|
5679
|
+
function isLegacyOnlyEvent(message) {
|
|
5680
|
+
return typeof message.event == "string" && message.event.startsWith(AI_EVENT_PREFIX);
|
|
5681
|
+
}
|
|
5682
|
+
|
|
5683
|
+
// ../../../../../node_modules/.bun/posthog-node@5.51.1/node_modules/posthog-node/dist/capture-v1/errors.mjs
|
|
5684
|
+
class CaptureV1Error extends Error {
|
|
5685
|
+
constructor({ requestId, drops, retryExhausted, cause }) {
|
|
5686
|
+
super(CaptureV1Error.buildMessage(requestId, drops, retryExhausted, cause)), this.name = "CaptureV1Error";
|
|
5687
|
+
this.requestId = requestId;
|
|
5688
|
+
this.drops = drops;
|
|
5689
|
+
this.retryExhausted = retryExhausted;
|
|
5690
|
+
this.cause = cause;
|
|
5691
|
+
}
|
|
5692
|
+
static buildMessage(requestId, drops, retryExhausted, cause) {
|
|
5693
|
+
let message = `Capture V1 batch ${requestId} did not fully deliver: ${drops.length} dropped, ${retryExhausted.length} undelivered`;
|
|
5694
|
+
if (cause instanceof Error)
|
|
5695
|
+
message += ` (${cause.message})`;
|
|
5696
|
+
return message;
|
|
5697
|
+
}
|
|
5698
|
+
}
|
|
5699
|
+
|
|
5700
|
+
// ../../../../../node_modules/.bun/posthog-node@5.51.1/node_modules/posthog-node/dist/capture-v1/transform.mjs
|
|
5701
|
+
function coerceBool(value) {
|
|
5702
|
+
if (typeof value == "boolean")
|
|
5703
|
+
return value;
|
|
5704
|
+
if (typeof value == "number")
|
|
5705
|
+
return value !== 0;
|
|
5706
|
+
if (typeof value == "string") {
|
|
5707
|
+
const normalized = value.trim().toLowerCase();
|
|
5708
|
+
if (normalized === "true" || normalized === "1")
|
|
5709
|
+
return true;
|
|
5710
|
+
if (normalized === "false" || normalized === "0")
|
|
5711
|
+
return false;
|
|
5712
|
+
}
|
|
5713
|
+
}
|
|
5714
|
+
function coerceString(value) {
|
|
5715
|
+
return typeof value == "string" ? value : undefined;
|
|
5716
|
+
}
|
|
5717
|
+
var OPTION_SENTINELS = [
|
|
5718
|
+
{
|
|
5719
|
+
property: "$cookieless_mode",
|
|
5720
|
+
optionKey: "cookieless_mode",
|
|
5721
|
+
coerce: coerceBool
|
|
5722
|
+
},
|
|
5723
|
+
{
|
|
5724
|
+
property: "$ignore_sent_at",
|
|
5725
|
+
optionKey: "disable_skew_correction",
|
|
5726
|
+
coerce: coerceBool
|
|
5727
|
+
},
|
|
5728
|
+
{
|
|
5729
|
+
property: "$process_person_profile",
|
|
5730
|
+
optionKey: "process_person_profile",
|
|
5731
|
+
coerce: coerceBool
|
|
5732
|
+
},
|
|
5733
|
+
{
|
|
5734
|
+
property: "$product_tour_id",
|
|
5735
|
+
optionKey: "product_tour_id",
|
|
5736
|
+
coerce: coerceString
|
|
5737
|
+
}
|
|
5738
|
+
];
|
|
5739
|
+
var TOPLEVEL_SENTINELS = [
|
|
5740
|
+
{
|
|
5741
|
+
property: "$session_id",
|
|
5742
|
+
field: "session_id"
|
|
5743
|
+
},
|
|
5744
|
+
{
|
|
5745
|
+
property: "$window_id",
|
|
5746
|
+
field: "window_id"
|
|
5747
|
+
}
|
|
5748
|
+
];
|
|
5749
|
+
function isRecord2(value) {
|
|
5750
|
+
return typeof value == "object" && value !== null && !Array.isArray(value);
|
|
5751
|
+
}
|
|
5752
|
+
function toRfc3339(timestamp) {
|
|
5753
|
+
if (typeof timestamp == "string") {
|
|
5754
|
+
const asDate2 = new Date(timestamp);
|
|
5755
|
+
if (Number.isNaN(asDate2.getTime()))
|
|
5756
|
+
return new Date().toISOString();
|
|
5757
|
+
const normalized = asDate2.toISOString();
|
|
5758
|
+
const fractionalSeconds = timestamp.match(/\.(\d+)(?:Z|[+-]\d{2}:?\d{2})?$/i)?.[1];
|
|
5759
|
+
return fractionalSeconds && fractionalSeconds.length > 3 ? normalized.replace(/\.\d{3}Z$/, `.${fractionalSeconds}Z`) : normalized;
|
|
5760
|
+
}
|
|
5761
|
+
if (timestamp instanceof Date)
|
|
5762
|
+
return Number.isNaN(timestamp.getTime()) ? new Date().toISOString() : timestamp.toISOString();
|
|
5763
|
+
const asDate = timestamp == null ? new Date : new Date(timestamp);
|
|
5764
|
+
return Number.isNaN(asDate.getTime()) ? new Date().toISOString() : asDate.toISOString();
|
|
5765
|
+
}
|
|
5766
|
+
function relocateInto(properties, key, value) {
|
|
5767
|
+
if (value !== undefined && !(key in properties))
|
|
5768
|
+
properties[key] = value;
|
|
5769
|
+
}
|
|
5770
|
+
function buildV1Event(message) {
|
|
5771
|
+
const sourceProperties = isRecord2(message.properties) ? message.properties : {};
|
|
5772
|
+
const properties = {
|
|
5773
|
+
...sourceProperties
|
|
5774
|
+
};
|
|
5775
|
+
const options = {};
|
|
5776
|
+
for (const { property, optionKey, coerce } of OPTION_SENTINELS)
|
|
5777
|
+
if (property in properties) {
|
|
5778
|
+
const coerced = coerce(properties[property]);
|
|
5779
|
+
if (coerced !== undefined)
|
|
5780
|
+
options[optionKey] = coerced;
|
|
5781
|
+
delete properties[property];
|
|
5782
|
+
}
|
|
5783
|
+
const topLevel = {};
|
|
5784
|
+
for (const { property, field } of TOPLEVEL_SENTINELS)
|
|
5785
|
+
if (property in properties) {
|
|
5786
|
+
const value = properties[property];
|
|
5787
|
+
if (typeof value == "string")
|
|
5788
|
+
topLevel[field] = value;
|
|
5789
|
+
delete properties[property];
|
|
5790
|
+
}
|
|
5791
|
+
delete properties.$lib;
|
|
5792
|
+
delete properties.$lib_version;
|
|
5793
|
+
relocateInto(properties, "$set", message.$set);
|
|
5794
|
+
relocateInto(properties, "$set_once", message.$set_once);
|
|
5795
|
+
return {
|
|
5796
|
+
event: String(message.event ?? ""),
|
|
5797
|
+
uuid: String(message.uuid ?? ""),
|
|
5798
|
+
distinct_id: String(message.distinct_id ?? ""),
|
|
5799
|
+
timestamp: toRfc3339(message.timestamp),
|
|
5800
|
+
...topLevel,
|
|
5801
|
+
options,
|
|
5802
|
+
properties
|
|
5803
|
+
};
|
|
5804
|
+
}
|
|
5805
|
+
function buildV1Batch(messages, { createdAt, historicalMigration }) {
|
|
5806
|
+
const batch = {
|
|
5807
|
+
created_at: createdAt,
|
|
5808
|
+
batch: messages.map(buildV1Event)
|
|
5809
|
+
};
|
|
5810
|
+
if (historicalMigration)
|
|
5811
|
+
batch.historical_migration = true;
|
|
5812
|
+
return batch;
|
|
5813
|
+
}
|
|
5814
|
+
|
|
5815
|
+
// ../../../../../node_modules/.bun/posthog-node@5.51.1/node_modules/posthog-node/dist/capture-v1/sender.mjs
|
|
5816
|
+
var V1_ANALYTICS_PATH = "/i/v1/analytics/events";
|
|
5817
|
+
var DEFAULT_MAX_BACKOFF_MS = 30000;
|
|
5818
|
+
var RETRYABLE_STATUSES = new Set([
|
|
5819
|
+
408,
|
|
5820
|
+
500,
|
|
5821
|
+
502,
|
|
5822
|
+
503,
|
|
5823
|
+
504
|
|
5824
|
+
]);
|
|
5825
|
+
|
|
5826
|
+
class V1CaptureSender {
|
|
5827
|
+
constructor(config, hooks) {
|
|
5828
|
+
this.config = config;
|
|
5829
|
+
this.maxBackoffMs = config.maxBackoffMs ?? DEFAULT_MAX_BACKOFF_MS;
|
|
5830
|
+
this.fetchFn = hooks.fetch;
|
|
5831
|
+
this.onError = hooks.onError;
|
|
5832
|
+
this.now = hooks.now ?? Date.now;
|
|
5833
|
+
this.sleep = hooks.sleep ?? ((ms) => new Promise((resolve) => safeSetTimeout(resolve, ms)));
|
|
5834
|
+
this.generateRequestId = hooks.generateRequestId ?? uuidv7;
|
|
5835
|
+
this.compress = hooks.compress ?? gzipCompress;
|
|
5836
|
+
}
|
|
5837
|
+
async sendV1Batch(messages) {
|
|
5838
|
+
if (messages.length === 0)
|
|
5839
|
+
return;
|
|
5840
|
+
const requestId = this.generateRequestId();
|
|
5841
|
+
const createdAt = new Date(this.now()).toISOString();
|
|
5842
|
+
const { batch } = buildV1Batch(messages, {
|
|
5843
|
+
createdAt,
|
|
5844
|
+
historicalMigration: this.config.historicalMigration
|
|
5845
|
+
});
|
|
5846
|
+
const url = `${this.config.host}${V1_ANALYTICS_PATH}`;
|
|
5847
|
+
const drops = [];
|
|
5848
|
+
let pending = batch;
|
|
5849
|
+
const maxAttempts = Math.max(1, this.config.maxAttempts);
|
|
5850
|
+
for (let attempt = 1;attempt <= maxAttempts; attempt++) {
|
|
5851
|
+
const isLastAttempt = attempt === maxAttempts;
|
|
5852
|
+
const payload = safeJsonStringify({
|
|
5853
|
+
created_at: createdAt,
|
|
5854
|
+
...this.config.historicalMigration ? {
|
|
5855
|
+
historical_migration: true
|
|
5856
|
+
} : {},
|
|
5857
|
+
batch: pending
|
|
5858
|
+
});
|
|
5859
|
+
let captureAttempt;
|
|
5860
|
+
let retryDelayMs;
|
|
5861
|
+
try {
|
|
5862
|
+
captureAttempt = await this.sendOnce(url, payload, attempt, requestId);
|
|
5863
|
+
const { response, signal } = captureAttempt;
|
|
5864
|
+
const { status } = response;
|
|
5865
|
+
if (status < 200 || status >= 300)
|
|
5866
|
+
if (!isLastAttempt && RETRYABLE_STATUSES.has(status)) {
|
|
5867
|
+
const retryAfterMs = this.parseRetryAfter(response);
|
|
5868
|
+
await captureAttempt.waitFor(captureAttempt.cancelBody()).catch(() => {});
|
|
5869
|
+
retryDelayMs = this.backoffDelay(attempt, retryAfterMs);
|
|
5870
|
+
} else {
|
|
5871
|
+
const httpError = await this.buildHttpError(response, status, captureAttempt.waitFor);
|
|
5872
|
+
return this.surfaceBatchFailure(requestId, drops, pending, httpError);
|
|
5873
|
+
}
|
|
5874
|
+
else {
|
|
5875
|
+
let parsed;
|
|
5876
|
+
try {
|
|
5877
|
+
parsed = await captureAttempt.waitFor(this.parseResponse(response));
|
|
5878
|
+
} catch (error) {
|
|
5879
|
+
if (signal.aborted)
|
|
5880
|
+
throw error;
|
|
5881
|
+
return this.surfaceBatchFailure(requestId, drops, pending, new Error(`Capture V1 returned an unparseable ${status} response body`));
|
|
5882
|
+
}
|
|
5883
|
+
const retryable = this.classify(pending, parsed, drops);
|
|
5884
|
+
if (retryable.length === 0)
|
|
5885
|
+
return this.surfacePartialDrops(requestId, drops);
|
|
5886
|
+
if (isLastAttempt)
|
|
5887
|
+
return void this.onError(new CaptureV1Error({
|
|
5888
|
+
requestId,
|
|
5889
|
+
drops,
|
|
5890
|
+
retryExhausted: retryable.map((event) => event.uuid)
|
|
5891
|
+
}));
|
|
5892
|
+
pending = retryable;
|
|
5893
|
+
const retryAfterMs = this.parseRetryAfter(response);
|
|
5894
|
+
retryDelayMs = this.backoffDelay(attempt, retryAfterMs);
|
|
5895
|
+
}
|
|
5896
|
+
} catch (transportError) {
|
|
5897
|
+
if (captureAttempt && !captureAttempt.signal.aborted)
|
|
5898
|
+
throw transportError;
|
|
5899
|
+
if (isLastAttempt)
|
|
5900
|
+
return this.surfaceBatchFailure(requestId, drops, pending, transportError);
|
|
5901
|
+
retryDelayMs = this.backoffDelay(attempt);
|
|
5902
|
+
} finally {
|
|
5903
|
+
captureAttempt?.cleanup();
|
|
5904
|
+
}
|
|
5905
|
+
if (retryDelayMs !== undefined)
|
|
5906
|
+
await this.sleep(retryDelayMs);
|
|
5907
|
+
}
|
|
5908
|
+
}
|
|
5909
|
+
async sendOnce(url, payload, attempt, requestId) {
|
|
5910
|
+
const headers = this.buildHeaders(attempt, requestId);
|
|
5911
|
+
let body = payload;
|
|
5912
|
+
if (this.config.compressionEnabled) {
|
|
5913
|
+
const compressed = await this.compress(payload, this.config.isDebug);
|
|
5914
|
+
if (compressed !== null) {
|
|
5915
|
+
body = compressed;
|
|
5916
|
+
headers["Content-Encoding"] = "gzip";
|
|
5917
|
+
}
|
|
5918
|
+
}
|
|
5919
|
+
const controller = new AbortController;
|
|
5920
|
+
let timeoutPhase = "waiting for response headers";
|
|
5921
|
+
let timer;
|
|
5922
|
+
const deadline = new Promise((_resolve, reject) => {
|
|
5923
|
+
timer = safeSetTimeout(() => {
|
|
5924
|
+
const timeoutError = new Error(`Capture V1 request timed out ${timeoutPhase} after ${this.config.requestTimeoutMs}ms`);
|
|
5925
|
+
timeoutError.name = "AbortError";
|
|
5926
|
+
reject(timeoutError);
|
|
5927
|
+
controller.abort(timeoutError);
|
|
5928
|
+
}, this.config.requestTimeoutMs);
|
|
5929
|
+
});
|
|
5930
|
+
try {
|
|
5931
|
+
const fetchPromise = this.fetchFn(url, {
|
|
5932
|
+
method: "POST",
|
|
5933
|
+
headers,
|
|
5934
|
+
body,
|
|
5935
|
+
signal: controller.signal
|
|
5936
|
+
});
|
|
5937
|
+
let responseAccepted = false;
|
|
5938
|
+
fetchPromise.then((lateResponse) => {
|
|
5939
|
+
if (controller.signal.aborted && !responseAccepted)
|
|
5940
|
+
this.cancelBody(lateResponse);
|
|
5941
|
+
}).catch(() => {});
|
|
5942
|
+
const response = await Promise.race([
|
|
5943
|
+
fetchPromise,
|
|
5944
|
+
deadline
|
|
5945
|
+
]);
|
|
5946
|
+
responseAccepted = true;
|
|
5947
|
+
timeoutPhase = "while reading the response body";
|
|
5948
|
+
let cleanedUp = false;
|
|
5949
|
+
let cancellation;
|
|
5950
|
+
const cancelBody = () => cancellation ??= this.cancelBody(response);
|
|
5951
|
+
return {
|
|
5952
|
+
response,
|
|
5953
|
+
signal: controller.signal,
|
|
5954
|
+
waitFor: (operation) => Promise.race([
|
|
5955
|
+
operation,
|
|
5956
|
+
deadline
|
|
5957
|
+
]),
|
|
5958
|
+
cancelBody,
|
|
5959
|
+
cleanup: () => {
|
|
5960
|
+
if (cleanedUp)
|
|
5961
|
+
return;
|
|
5962
|
+
cleanedUp = true;
|
|
5963
|
+
clearTimeout(timer);
|
|
5964
|
+
if (controller.signal.aborted)
|
|
5965
|
+
cancelBody();
|
|
5966
|
+
}
|
|
5967
|
+
};
|
|
5968
|
+
} catch (error) {
|
|
5969
|
+
clearTimeout(timer);
|
|
5970
|
+
throw error;
|
|
5971
|
+
}
|
|
5972
|
+
}
|
|
5973
|
+
buildHeaders(attempt, requestId) {
|
|
5974
|
+
const sdkInfo = `${this.config.libraryId}/${this.config.libraryVersion}`;
|
|
5975
|
+
const headers = {
|
|
5976
|
+
"Content-Type": "application/json",
|
|
5977
|
+
Authorization: `Bearer ${this.config.apiKey}`,
|
|
5978
|
+
"PostHog-Sdk-Info": sdkInfo,
|
|
5979
|
+
"PostHog-Attempt": String(attempt),
|
|
5980
|
+
"PostHog-Request-Id": requestId,
|
|
5981
|
+
"PostHog-Request-Timestamp": new Date(this.now()).toISOString()
|
|
5982
|
+
};
|
|
5983
|
+
if (this.config.userAgent)
|
|
5984
|
+
headers["User-Agent"] = this.config.userAgent;
|
|
5985
|
+
return headers;
|
|
5986
|
+
}
|
|
5987
|
+
classify(pending, parsed, drops) {
|
|
5988
|
+
const results = parsed.results ?? {};
|
|
5989
|
+
const retryable = [];
|
|
5990
|
+
for (const event of pending) {
|
|
5991
|
+
const result = results[event.uuid];
|
|
5992
|
+
if (result) {
|
|
5993
|
+
if (result.result === "drop")
|
|
5994
|
+
drops.push({
|
|
5995
|
+
uuid: event.uuid,
|
|
5996
|
+
details: result.details ?? undefined
|
|
5997
|
+
});
|
|
5998
|
+
else if (result.result === "retry")
|
|
5999
|
+
retryable.push(event);
|
|
6000
|
+
}
|
|
6001
|
+
}
|
|
6002
|
+
return retryable;
|
|
6003
|
+
}
|
|
6004
|
+
backoffDelay(attempt, retryAfterMs) {
|
|
6005
|
+
const exponential = Math.min(this.config.initialRetryDelayMs * 2 ** (attempt - 1), this.maxBackoffMs);
|
|
6006
|
+
if (retryAfterMs === undefined)
|
|
6007
|
+
return exponential;
|
|
6008
|
+
return Math.max(exponential, Math.min(retryAfterMs, this.maxBackoffMs));
|
|
6009
|
+
}
|
|
6010
|
+
parseRetryAfter(response) {
|
|
6011
|
+
const raw = response.headers?.get("Retry-After");
|
|
6012
|
+
if (!raw)
|
|
6013
|
+
return;
|
|
6014
|
+
const trimmed = raw.trim();
|
|
6015
|
+
if (/^\d+$/.test(trimmed)) {
|
|
6016
|
+
const seconds = parseInt(trimmed, 10);
|
|
6017
|
+
return Number.isFinite(seconds) && seconds > 0 ? 1000 * seconds : undefined;
|
|
6018
|
+
}
|
|
6019
|
+
const dateMs = Date.parse(trimmed);
|
|
6020
|
+
if (Number.isNaN(dateMs))
|
|
6021
|
+
return;
|
|
6022
|
+
const delta = dateMs - this.now();
|
|
6023
|
+
return delta > 0 ? delta : undefined;
|
|
6024
|
+
}
|
|
6025
|
+
async parseResponse(response) {
|
|
6026
|
+
const text = await response.text();
|
|
6027
|
+
const parsed = JSON.parse(text);
|
|
6028
|
+
if (typeof parsed != "object" || parsed === null || Array.isArray(parsed))
|
|
6029
|
+
throw new Error("unexpected response shape");
|
|
6030
|
+
const results = parsed.results;
|
|
6031
|
+
if (results !== undefined && (typeof results != "object" || results === null || Array.isArray(results)))
|
|
6032
|
+
throw new Error("unexpected results shape");
|
|
6033
|
+
return {
|
|
6034
|
+
results: results ?? {}
|
|
6035
|
+
};
|
|
6036
|
+
}
|
|
6037
|
+
async buildHttpError(response, status, waitFor) {
|
|
6038
|
+
let bodyText = "";
|
|
6039
|
+
try {
|
|
6040
|
+
bodyText = (await waitFor(response.text())).slice(0, 512);
|
|
6041
|
+
} catch {}
|
|
6042
|
+
const suffix = bodyText ? `: ${bodyText}` : "";
|
|
6043
|
+
return new Error(`Capture V1 request failed with HTTP ${status}${suffix}`);
|
|
6044
|
+
}
|
|
6045
|
+
surfaceBatchFailure(requestId, drops, pending, cause) {
|
|
6046
|
+
this.onError(new CaptureV1Error({
|
|
6047
|
+
requestId,
|
|
6048
|
+
drops,
|
|
6049
|
+
retryExhausted: pending.map((event) => event.uuid),
|
|
6050
|
+
cause
|
|
6051
|
+
}));
|
|
6052
|
+
}
|
|
6053
|
+
surfacePartialDrops(requestId, drops) {
|
|
6054
|
+
if (drops.length > 0)
|
|
6055
|
+
this.onError(new CaptureV1Error({
|
|
6056
|
+
requestId,
|
|
6057
|
+
drops,
|
|
6058
|
+
retryExhausted: []
|
|
6059
|
+
}));
|
|
6060
|
+
}
|
|
6061
|
+
async cancelBody(response) {
|
|
6062
|
+
try {
|
|
6063
|
+
await response.body?.cancel();
|
|
6064
|
+
} catch {}
|
|
6065
|
+
}
|
|
6066
|
+
}
|
|
6067
|
+
|
|
6068
|
+
// ../../../../../node_modules/.bun/posthog-node@5.51.1/node_modules/posthog-node/dist/ai-capture/routing.mjs
|
|
6069
|
+
var AI_CAPTURE_ROUTE = "ai-capture";
|
|
6070
|
+
var AI_CAPTURE_ENDPOINT_PATH = "/i/v0/ai/batch/";
|
|
6071
|
+
var AI_MAX_EVENT_BYTES = 8388608;
|
|
6072
|
+
var AI_BATCH_TARGET_BYTES = 5242880;
|
|
6073
|
+
|
|
6074
|
+
// ../../../../../node_modules/.bun/posthog-node@5.51.1/node_modules/posthog-node/dist/ai-capture/batching.mjs
|
|
6075
|
+
var encoder = new TextEncoder;
|
|
6076
|
+
function eventByteSize(message) {
|
|
6077
|
+
return encoder.encode(safeJsonStringify(message)).length;
|
|
6078
|
+
}
|
|
6079
|
+
function partitionAiBatch(messages, maxEventBytes = AI_MAX_EVENT_BYTES, targetBatchBytes = AI_BATCH_TARGET_BYTES) {
|
|
6080
|
+
const batches = [];
|
|
6081
|
+
const dropped = [];
|
|
6082
|
+
let current = [];
|
|
6083
|
+
let currentBytes = 0;
|
|
6084
|
+
for (const message of messages) {
|
|
6085
|
+
if (message === undefined)
|
|
6086
|
+
continue;
|
|
6087
|
+
const bytes = eventByteSize(message);
|
|
6088
|
+
if (bytes > maxEventBytes) {
|
|
6089
|
+
dropped.push({
|
|
6090
|
+
event: typeof message.event == "string" ? message.event : "unknown",
|
|
6091
|
+
bytes
|
|
6092
|
+
});
|
|
6093
|
+
continue;
|
|
6094
|
+
}
|
|
6095
|
+
if (current.length > 0 && currentBytes + bytes > targetBatchBytes) {
|
|
6096
|
+
batches.push(current);
|
|
6097
|
+
current = [];
|
|
6098
|
+
currentBytes = 0;
|
|
6099
|
+
}
|
|
6100
|
+
current.push(message);
|
|
6101
|
+
currentBytes += bytes;
|
|
6102
|
+
}
|
|
6103
|
+
if (current.length > 0)
|
|
6104
|
+
batches.push(current);
|
|
6105
|
+
return {
|
|
6106
|
+
batches,
|
|
6107
|
+
dropped
|
|
6108
|
+
};
|
|
6109
|
+
}
|
|
6110
|
+
|
|
6111
|
+
// ../../../../../node_modules/.bun/posthog-node@5.51.1/node_modules/posthog-node/dist/client.mjs
|
|
4392
6112
|
var MINIMUM_POLLING_INTERVAL = 100;
|
|
4393
6113
|
var THIRTY_SECONDS = 30000;
|
|
4394
6114
|
var MAX_CACHE_SIZE = 50000;
|
|
@@ -4413,6 +6133,12 @@ function normalizeHost(value) {
|
|
|
4413
6133
|
const normalizedValue = typeof value == "string" ? value.trim() : "";
|
|
4414
6134
|
return normalizedValue || DEFAULT_NODE_HOST;
|
|
4415
6135
|
}
|
|
6136
|
+
function normalizeUnsetPersonProperties(value) {
|
|
6137
|
+
const propertyNames = Array.isArray(value) ? value : [
|
|
6138
|
+
value
|
|
6139
|
+
];
|
|
6140
|
+
return propertyNames.filter((propertyName) => typeof propertyName == "string" && propertyName.trim().length > 0);
|
|
6141
|
+
}
|
|
4416
6142
|
function buildFlagEventProperties(flagValues) {
|
|
4417
6143
|
if (!flagValues)
|
|
4418
6144
|
return {};
|
|
@@ -4430,11 +6156,15 @@ class PostHogBackendClient extends PostHogCoreStateless {
|
|
|
4430
6156
|
const normalizedApiKey = normalizeApiKey(apiKey);
|
|
4431
6157
|
const normalizedOptions = {
|
|
4432
6158
|
...options,
|
|
6159
|
+
maxQueueSize: options.maxQueueSize ?? 1e4,
|
|
6160
|
+
flushInterval: options.flushInterval ?? 5000,
|
|
4433
6161
|
host: normalizeHost(options.host),
|
|
4434
|
-
personalApiKey: normalizePersonalApiKey(options.personalApiKey)
|
|
6162
|
+
personalApiKey: normalizePersonalApiKey(options.secretKey ?? options.personalApiKey)
|
|
4435
6163
|
};
|
|
4436
|
-
super(normalizedApiKey, normalizedOptions), this._memoryStorage = new PostHogMemoryStorage;
|
|
6164
|
+
super(normalizedApiKey, normalizedOptions), this._memoryStorage = new PostHogMemoryStorage, this._aiCaptureRouteActive = false, this._minimalFlagCalledEvents = false;
|
|
4437
6165
|
this.options = normalizedOptions;
|
|
6166
|
+
this.captureMode = resolveCaptureMode();
|
|
6167
|
+
this.enableFullAiCapture = normalizedOptions.enableFullAiCapture === true;
|
|
4438
6168
|
this.context = this.initializeContext();
|
|
4439
6169
|
this.options.featureFlagsPollingInterval = typeof normalizedOptions.featureFlagsPollingInterval == "number" ? Math.max(normalizedOptions.featureFlagsPollingInterval, MINIMUM_POLLING_INTERVAL) : THIRTY_SECONDS;
|
|
4440
6170
|
if (typeof normalizedOptions.waitUntilDebounceMs == "number")
|
|
@@ -4459,21 +6189,24 @@ class PostHogBackendClient extends PostHogCoreStateless {
|
|
|
4459
6189
|
onLoad: (count) => {
|
|
4460
6190
|
this._events.emit("localEvaluationFlagsLoaded", count);
|
|
4461
6191
|
},
|
|
6192
|
+
onMinimalFlagCalledEvents: (enabled) => {
|
|
6193
|
+
this._minimalFlagCalledEvents = enabled;
|
|
6194
|
+
},
|
|
4462
6195
|
customHeaders: this.getCustomHeaders(),
|
|
4463
6196
|
cacheProvider: normalizedOptions.flagDefinitionCacheProvider,
|
|
4464
6197
|
strictLocalEvaluation: normalizedOptions.strictLocalEvaluation
|
|
4465
6198
|
});
|
|
4466
6199
|
}
|
|
4467
|
-
this.errorTracking = new
|
|
6200
|
+
this.errorTracking = new error_tracking_ErrorTracking(this, normalizedOptions, this._logger);
|
|
4468
6201
|
this.distinctIdHasSentFlagCalls = {};
|
|
4469
6202
|
this.maxCacheSize = normalizedOptions.maxCacheSize || MAX_CACHE_SIZE;
|
|
4470
6203
|
}
|
|
4471
|
-
enqueue(type, message, options) {
|
|
4472
|
-
super.enqueue(type, message, options);
|
|
6204
|
+
enqueue(type, message, options, explicitRoute) {
|
|
6205
|
+
super.enqueue(type, message, options, explicitRoute);
|
|
4473
6206
|
this.scheduleDebouncedFlush();
|
|
4474
6207
|
}
|
|
4475
6208
|
async flush() {
|
|
4476
|
-
const flushPromise =
|
|
6209
|
+
const flushPromise = this.flushWithPendingPromises();
|
|
4477
6210
|
const waitUntil = this.options.waitUntil;
|
|
4478
6211
|
if (waitUntil && !this._waitUntilCycle)
|
|
4479
6212
|
try {
|
|
@@ -4526,7 +6259,7 @@ class PostHogBackendClient extends PostHogCoreStateless {
|
|
|
4526
6259
|
async resolveWaitUntilFlush() {
|
|
4527
6260
|
const resolve = this._consumeWaitUntilCycle();
|
|
4528
6261
|
try {
|
|
4529
|
-
await
|
|
6262
|
+
await this.flushWithPendingPromises();
|
|
4530
6263
|
} catch {} finally {
|
|
4531
6264
|
resolve?.();
|
|
4532
6265
|
}
|
|
@@ -4540,12 +6273,103 @@ class PostHogBackendClient extends PostHogCoreStateless {
|
|
|
4540
6273
|
fetch(url, options) {
|
|
4541
6274
|
return this.options.fetch ? this.options.fetch(url, options) : fetch(url, options);
|
|
4542
6275
|
}
|
|
6276
|
+
getQueueRouteKey(message) {
|
|
6277
|
+
return this.captureMode === "v1" && isLegacyOnlyEvent(message) ? AI_ROUTE : ANALYTICS_ROUTE;
|
|
6278
|
+
}
|
|
6279
|
+
persistedQueueKeyForRoute(route) {
|
|
6280
|
+
if (route === AI_CAPTURE_ROUTE)
|
|
6281
|
+
return types_PostHogPersistedProperty.AiCaptureQueue;
|
|
6282
|
+
return route === AI_ROUTE ? types_PostHogPersistedProperty.AiQueue : types_PostHogPersistedProperty.Queue;
|
|
6283
|
+
}
|
|
6284
|
+
getActiveQueueRoutes() {
|
|
6285
|
+
const routes = this.captureMode === "v1" ? [
|
|
6286
|
+
ANALYTICS_ROUTE,
|
|
6287
|
+
AI_ROUTE
|
|
6288
|
+
] : [
|
|
6289
|
+
ANALYTICS_ROUTE
|
|
6290
|
+
];
|
|
6291
|
+
if (this._aiCaptureRouteActive)
|
|
6292
|
+
routes.push(AI_CAPTURE_ROUTE);
|
|
6293
|
+
return routes;
|
|
6294
|
+
}
|
|
6295
|
+
getBatchEndpointPath(route) {
|
|
6296
|
+
return route === AI_CAPTURE_ROUTE ? AI_CAPTURE_ENDPOINT_PATH : super.getBatchEndpointPath(route);
|
|
6297
|
+
}
|
|
6298
|
+
async sendBatch(batchMessages, retryOptions, route = ANALYTICS_ROUTE) {
|
|
6299
|
+
if (route === AI_CAPTURE_ROUTE)
|
|
6300
|
+
return this.sendAiCaptureBatch(batchMessages, retryOptions);
|
|
6301
|
+
if (this.captureMode !== "v1" || route === AI_ROUTE)
|
|
6302
|
+
return super.sendBatch(batchMessages, retryOptions, route);
|
|
6303
|
+
const v1Events = batchMessages.filter((message) => message !== undefined);
|
|
6304
|
+
await this.getV1Sender().sendV1Batch(v1Events);
|
|
6305
|
+
}
|
|
6306
|
+
async sendAiCaptureBatch(batchMessages, retryOptions) {
|
|
6307
|
+
const { batches, dropped } = partitionAiBatch(batchMessages);
|
|
6308
|
+
for (const { event, bytes } of dropped) {
|
|
6309
|
+
const message = `Event ${event} (${bytes} bytes) exceeds the ${AI_MAX_EVENT_BYTES / 1048576}MiB limit for ${AI_CAPTURE_ENDPOINT_PATH}, dropping.`;
|
|
6310
|
+
this._logger.error(message);
|
|
6311
|
+
this._events.emit("error", new Error(message));
|
|
6312
|
+
}
|
|
6313
|
+
for (const batch of batches)
|
|
6314
|
+
await this.sendAiSubBatch(batch, retryOptions);
|
|
6315
|
+
}
|
|
6316
|
+
async sendAiSubBatch(batch, retryOptions) {
|
|
6317
|
+
try {
|
|
6318
|
+
await super.sendBatch(batch, retryOptions, AI_CAPTURE_ROUTE);
|
|
6319
|
+
} catch (err) {
|
|
6320
|
+
if (!isPostHogFetchContentTooLargeError(err))
|
|
6321
|
+
throw err;
|
|
6322
|
+
if (batch.length === 1) {
|
|
6323
|
+
const [event] = batch;
|
|
6324
|
+
const eventName = typeof event.event == "string" ? event.event : "unknown";
|
|
6325
|
+
const message = `Event ${eventName} (${eventByteSize(event)} bytes) was rejected with 413 by ${AI_CAPTURE_ENDPOINT_PATH} on its own, dropping.`;
|
|
6326
|
+
this._logger.error(message);
|
|
6327
|
+
this._events.emit("error", new Error(message));
|
|
6328
|
+
return;
|
|
6329
|
+
}
|
|
6330
|
+
const mid = Math.ceil(batch.length / 2);
|
|
6331
|
+
await this.sendAiSubBatch(batch.slice(0, mid), retryOptions);
|
|
6332
|
+
await this.sendAiSubBatch(batch.slice(mid), retryOptions);
|
|
6333
|
+
}
|
|
6334
|
+
}
|
|
6335
|
+
getV1Sender() {
|
|
6336
|
+
if (!this._v1Sender)
|
|
6337
|
+
this._v1Sender = new V1CaptureSender({
|
|
6338
|
+
host: this.host,
|
|
6339
|
+
apiKey: this.apiKey,
|
|
6340
|
+
libraryId: this.getLibraryId(),
|
|
6341
|
+
libraryVersion: this.getLibraryVersion(),
|
|
6342
|
+
userAgent: this.getCustomUserAgent() || undefined,
|
|
6343
|
+
historicalMigration: this.historicalMigration,
|
|
6344
|
+
compressionEnabled: !this.disableCompression,
|
|
6345
|
+
requestTimeoutMs: this.requestTimeout,
|
|
6346
|
+
maxAttempts: (this.options.fetchRetryCount ?? 3) + 1,
|
|
6347
|
+
initialRetryDelayMs: this.options.fetchRetryDelay ?? 3000,
|
|
6348
|
+
isDebug: this.isDebug
|
|
6349
|
+
}, {
|
|
6350
|
+
fetch: (url, fetchOptions) => this.fetch(url, fetchOptions),
|
|
6351
|
+
onError: (error) => this._events.emit("error", error),
|
|
6352
|
+
compress: (payload) => this.compressPayload(payload)
|
|
6353
|
+
});
|
|
6354
|
+
return this._v1Sender;
|
|
6355
|
+
}
|
|
4543
6356
|
getLibraryVersion() {
|
|
4544
6357
|
return version;
|
|
4545
6358
|
}
|
|
6359
|
+
get metrics() {
|
|
6360
|
+
if (!this._metrics)
|
|
6361
|
+
this._metrics = new PostHogMetrics(this, resolveMetricsConfig(this.options.metrics), this._logger);
|
|
6362
|
+
return this._metrics;
|
|
6363
|
+
}
|
|
4546
6364
|
getCustomUserAgent() {
|
|
4547
6365
|
return `${this.getLibraryId()}/${this.getLibraryVersion()}`;
|
|
4548
6366
|
}
|
|
6367
|
+
getCommonEventProperties() {
|
|
6368
|
+
const commonProperties = super.getCommonEventProperties();
|
|
6369
|
+
if (this.options.isServer ?? true)
|
|
6370
|
+
commonProperties.$is_server = true;
|
|
6371
|
+
return commonProperties;
|
|
6372
|
+
}
|
|
4549
6373
|
enable() {
|
|
4550
6374
|
return super.optIn();
|
|
4551
6375
|
}
|
|
@@ -4556,33 +6380,69 @@ class PostHogBackendClient extends PostHogCoreStateless {
|
|
|
4556
6380
|
super.debug(enabled);
|
|
4557
6381
|
this.featureFlagsPoller?.debug(enabled);
|
|
4558
6382
|
}
|
|
4559
|
-
|
|
6383
|
+
_warnIfInvalidCapture(props, stringArgumentWarning, exceptionCaptureWarning) {
|
|
4560
6384
|
if (typeof props == "string")
|
|
4561
|
-
this._logger.warn(
|
|
6385
|
+
this._logger.warn(stringArgumentWarning);
|
|
4562
6386
|
if (props.event === "$exception" && !props._originatedFromCaptureException)
|
|
4563
|
-
this._logger.warn(
|
|
4564
|
-
|
|
4565
|
-
|
|
4566
|
-
|
|
4567
|
-
|
|
4568
|
-
|
|
6387
|
+
this._logger.warn(exceptionCaptureWarning);
|
|
6388
|
+
}
|
|
6389
|
+
_sendPreparedEvent(type, props, immediate, prepareOptions, explicitRoute) {
|
|
6390
|
+
return this.addPendingPromise(this._prepareEventMessage(props, prepareOptions).then(({ distinctId, event, properties, options }) => {
|
|
6391
|
+
const captureOptions = {
|
|
6392
|
+
timestamp: options.timestamp,
|
|
6393
|
+
disableGeoip: options.disableGeoip,
|
|
6394
|
+
uuid: options.uuid
|
|
6395
|
+
};
|
|
6396
|
+
const message = {
|
|
6397
|
+
distinctId,
|
|
6398
|
+
event,
|
|
6399
|
+
properties: {
|
|
6400
|
+
...properties,
|
|
6401
|
+
...this.getCommonEventProperties()
|
|
6402
|
+
}
|
|
6403
|
+
};
|
|
6404
|
+
return immediate ? this.sendImmediate(type, message, captureOptions, explicitRoute) : this.enqueue(type, message, captureOptions, explicitRoute);
|
|
6405
|
+
}).catch((err) => {
|
|
4569
6406
|
if (err)
|
|
4570
6407
|
console.error(err);
|
|
4571
6408
|
}));
|
|
4572
6409
|
}
|
|
6410
|
+
_capturePreparedEvent(props, immediate) {
|
|
6411
|
+
return this._sendPreparedEvent("capture", props, immediate);
|
|
6412
|
+
}
|
|
6413
|
+
capture(props) {
|
|
6414
|
+
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.");
|
|
6415
|
+
this._capturePreparedEvent(props, false);
|
|
6416
|
+
}
|
|
4573
6417
|
async captureImmediate(props) {
|
|
4574
|
-
|
|
4575
|
-
|
|
4576
|
-
|
|
4577
|
-
|
|
4578
|
-
|
|
4579
|
-
|
|
4580
|
-
|
|
4581
|
-
|
|
4582
|
-
|
|
4583
|
-
|
|
4584
|
-
|
|
4585
|
-
|
|
6418
|
+
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.");
|
|
6419
|
+
return this._capturePreparedEvent(props, true);
|
|
6420
|
+
}
|
|
6421
|
+
captureAi(props) {
|
|
6422
|
+
if (this.disabled)
|
|
6423
|
+
return;
|
|
6424
|
+
const uuid = getEventUuid(props.uuid, uuidv7);
|
|
6425
|
+
this._sendPreparedAiEvent({
|
|
6426
|
+
...props,
|
|
6427
|
+
uuid
|
|
6428
|
+
}, false);
|
|
6429
|
+
return uuid;
|
|
6430
|
+
}
|
|
6431
|
+
async captureAiImmediate(props) {
|
|
6432
|
+
if (this.disabled)
|
|
6433
|
+
return;
|
|
6434
|
+
const uuid = getEventUuid(props.uuid, uuidv7);
|
|
6435
|
+
await this._sendPreparedAiEvent({
|
|
6436
|
+
...props,
|
|
6437
|
+
uuid
|
|
6438
|
+
}, true);
|
|
6439
|
+
return uuid;
|
|
6440
|
+
}
|
|
6441
|
+
_sendPreparedAiEvent(props, immediate) {
|
|
6442
|
+
if (typeof props?.event == "string" && !props.event.startsWith("$ai_"))
|
|
6443
|
+
this._logger.debug(`captureAi called with non-AI event ${props.event}; routing it to the AI endpoint anyway.`);
|
|
6444
|
+
this._aiCaptureRouteActive = true;
|
|
6445
|
+
return this._sendPreparedEvent("capture", props, immediate, undefined, AI_CAPTURE_ROUTE);
|
|
4586
6446
|
}
|
|
4587
6447
|
identify({ distinctId, properties = {}, disableGeoip }) {
|
|
4588
6448
|
const { $set, $set_once, $anon_distinct_id, ...rest } = properties;
|
|
@@ -4593,8 +6453,13 @@ class PostHogBackendClient extends PostHogCoreStateless {
|
|
|
4593
6453
|
$set_once: setOnceProps,
|
|
4594
6454
|
$anon_distinct_id: $anon_distinct_id ?? undefined
|
|
4595
6455
|
};
|
|
4596
|
-
|
|
6456
|
+
this._sendPreparedEvent("identify", {
|
|
6457
|
+
distinctId,
|
|
6458
|
+
event: "$identify",
|
|
6459
|
+
properties: eventProperties,
|
|
4597
6460
|
disableGeoip
|
|
6461
|
+
}, false, {
|
|
6462
|
+
includeContextProperties: false
|
|
4598
6463
|
});
|
|
4599
6464
|
}
|
|
4600
6465
|
async identifyImmediate({ distinctId, properties = {}, disableGeoip }) {
|
|
@@ -4606,18 +6471,65 @@ class PostHogBackendClient extends PostHogCoreStateless {
|
|
|
4606
6471
|
$set_once: setOnceProps,
|
|
4607
6472
|
$anon_distinct_id: $anon_distinct_id ?? undefined
|
|
4608
6473
|
};
|
|
4609
|
-
await
|
|
6474
|
+
await this._sendPreparedEvent("identify", {
|
|
6475
|
+
distinctId,
|
|
6476
|
+
event: "$identify",
|
|
6477
|
+
properties: eventProperties,
|
|
4610
6478
|
disableGeoip
|
|
6479
|
+
}, true, {
|
|
6480
|
+
includeContextProperties: false
|
|
6481
|
+
});
|
|
6482
|
+
}
|
|
6483
|
+
setPersonProperties({ distinctId, properties = {}, propertiesOnce = {} }) {
|
|
6484
|
+
if (Object.keys(properties).length === 0 && Object.keys(propertiesOnce).length === 0)
|
|
6485
|
+
return;
|
|
6486
|
+
const eventProperties = {};
|
|
6487
|
+
if (Object.keys(properties).length > 0)
|
|
6488
|
+
eventProperties.$set = properties;
|
|
6489
|
+
if (Object.keys(propertiesOnce).length > 0)
|
|
6490
|
+
eventProperties.$set_once = propertiesOnce;
|
|
6491
|
+
this.capture({
|
|
6492
|
+
distinctId,
|
|
6493
|
+
event: "$set",
|
|
6494
|
+
properties: eventProperties
|
|
6495
|
+
});
|
|
6496
|
+
}
|
|
6497
|
+
unsetPersonProperties({ distinctId, properties }) {
|
|
6498
|
+
const propertyNames = normalizeUnsetPersonProperties(properties);
|
|
6499
|
+
if (propertyNames.length === 0)
|
|
6500
|
+
return;
|
|
6501
|
+
this.capture({
|
|
6502
|
+
distinctId,
|
|
6503
|
+
event: "$set",
|
|
6504
|
+
properties: {
|
|
6505
|
+
$unset: propertyNames
|
|
6506
|
+
}
|
|
4611
6507
|
});
|
|
4612
6508
|
}
|
|
4613
6509
|
alias(data) {
|
|
4614
|
-
|
|
6510
|
+
this._sendPreparedEvent("alias", {
|
|
6511
|
+
distinctId: data.distinctId,
|
|
6512
|
+
event: "$create_alias",
|
|
6513
|
+
properties: {
|
|
6514
|
+
distinct_id: data.distinctId,
|
|
6515
|
+
alias: data.alias
|
|
6516
|
+
},
|
|
4615
6517
|
disableGeoip: data.disableGeoip
|
|
6518
|
+
}, false, {
|
|
6519
|
+
includeContextProperties: false
|
|
4616
6520
|
});
|
|
4617
6521
|
}
|
|
4618
6522
|
async aliasImmediate(data) {
|
|
4619
|
-
await
|
|
6523
|
+
await this._sendPreparedEvent("alias", {
|
|
6524
|
+
distinctId: data.distinctId,
|
|
6525
|
+
event: "$create_alias",
|
|
6526
|
+
properties: {
|
|
6527
|
+
distinct_id: data.distinctId,
|
|
6528
|
+
alias: data.alias
|
|
6529
|
+
},
|
|
4620
6530
|
disableGeoip: data.disableGeoip
|
|
6531
|
+
}, true, {
|
|
6532
|
+
includeContextProperties: false
|
|
4621
6533
|
});
|
|
4622
6534
|
}
|
|
4623
6535
|
isLocalEvaluationReady() {
|
|
@@ -4672,7 +6584,7 @@ class PostHogBackendClient extends PostHogCoreStateless {
|
|
|
4672
6584
|
const adjustedProperties = this.addLocalPersonAndGroupProperties(distinctId, groups, personProperties, groupProperties);
|
|
4673
6585
|
personProperties = adjustedProperties.allPersonProperties;
|
|
4674
6586
|
groupProperties = adjustedProperties.allGroupProperties;
|
|
4675
|
-
const evaluationContext = this.createFeatureFlagEvaluationContext(distinctId, groups, personProperties, groupProperties);
|
|
6587
|
+
const evaluationContext = this.createFeatureFlagEvaluationContext(distinctId, groups, this.personPropertiesForLocalEvaluation(distinctId, personProperties), groupProperties);
|
|
4676
6588
|
if (onlyEvaluateLocally == undefined)
|
|
4677
6589
|
onlyEvaluateLocally = this.options.strictLocalEvaluation ?? false;
|
|
4678
6590
|
let result;
|
|
@@ -4683,6 +6595,7 @@ class PostHogBackendClient extends PostHogCoreStateless {
|
|
|
4683
6595
|
let flagId;
|
|
4684
6596
|
let flagVersion;
|
|
4685
6597
|
let flagReason;
|
|
6598
|
+
let flagHasExperiment;
|
|
4686
6599
|
const localEvaluationEnabled = this.featureFlagsPoller !== undefined;
|
|
4687
6600
|
if (localEvaluationEnabled) {
|
|
4688
6601
|
await this.featureFlagsPoller?.loadFeatureFlags();
|
|
@@ -4697,6 +6610,7 @@ class PostHogBackendClient extends PostHogCoreStateless {
|
|
|
4697
6610
|
const value = localResult.value;
|
|
4698
6611
|
flagId = flag.id;
|
|
4699
6612
|
flagReason = "Evaluated locally";
|
|
6613
|
+
flagHasExperiment = flag.has_experiment;
|
|
4700
6614
|
result = {
|
|
4701
6615
|
key,
|
|
4702
6616
|
enabled: value !== false,
|
|
@@ -4712,12 +6626,13 @@ class PostHogBackendClient extends PostHogCoreStateless {
|
|
|
4712
6626
|
}
|
|
4713
6627
|
}
|
|
4714
6628
|
if (!flagWasLocallyEvaluated && !onlyEvaluateLocally) {
|
|
4715
|
-
const flagsResponse = await super.getFeatureFlagDetailsStateless(evaluationContext.distinctId, evaluationContext.groups,
|
|
6629
|
+
const flagsResponse = await super.getFeatureFlagDetailsStateless(evaluationContext.distinctId, evaluationContext.groups, personProperties, groupProperties, disableGeoip, [
|
|
4716
6630
|
key
|
|
4717
6631
|
]);
|
|
4718
6632
|
if (flagsResponse === undefined)
|
|
4719
6633
|
featureFlagError = FeatureFlagError2.UNKNOWN_ERROR;
|
|
4720
6634
|
else {
|
|
6635
|
+
this._minimalFlagCalledEvents = flagsResponse.minimalFlagCalledEvents === true;
|
|
4721
6636
|
requestId = flagsResponse.requestId;
|
|
4722
6637
|
evaluatedAt = flagsResponse.evaluatedAt;
|
|
4723
6638
|
const errors = [];
|
|
@@ -4732,6 +6647,7 @@ class PostHogBackendClient extends PostHogCoreStateless {
|
|
|
4732
6647
|
flagId = flagDetail.metadata?.id;
|
|
4733
6648
|
flagVersion = flagDetail.metadata?.version;
|
|
4734
6649
|
flagReason = flagDetail.reason?.description ?? flagDetail.reason?.code;
|
|
6650
|
+
flagHasExperiment = flagDetail.metadata?.has_experiment;
|
|
4735
6651
|
let parsedPayload;
|
|
4736
6652
|
if (flagDetail.metadata?.payload !== undefined)
|
|
4737
6653
|
try {
|
|
@@ -4742,7 +6658,7 @@ class PostHogBackendClient extends PostHogCoreStateless {
|
|
|
4742
6658
|
result = {
|
|
4743
6659
|
key,
|
|
4744
6660
|
enabled: flagDetail.enabled,
|
|
4745
|
-
variant: flagDetail.variant,
|
|
6661
|
+
variant: flagDetail.variant ?? undefined,
|
|
4746
6662
|
payload: parsedPayload
|
|
4747
6663
|
};
|
|
4748
6664
|
}
|
|
@@ -4763,6 +6679,8 @@ class PostHogBackendClient extends PostHogCoreStateless {
|
|
|
4763
6679
|
$feature_flag_request_id: requestId,
|
|
4764
6680
|
$feature_flag_evaluated_at: flagWasLocallyEvaluated ? Date.now() : evaluatedAt
|
|
4765
6681
|
};
|
|
6682
|
+
if (flagHasExperiment !== undefined)
|
|
6683
|
+
properties.$feature_flag_has_experiment = flagHasExperiment;
|
|
4766
6684
|
if (flagWasLocallyEvaluated && this.featureFlagsPoller) {
|
|
4767
6685
|
const flagDefinitionsLoadedAt = this.featureFlagsPoller.getFlagDefinitionsLoadedAt();
|
|
4768
6686
|
if (flagDefinitionsLoadedAt !== undefined)
|
|
@@ -4877,7 +6795,7 @@ class PostHogBackendClient extends PostHogCoreStateless {
|
|
|
4877
6795
|
const adjustedProperties = this.addLocalPersonAndGroupProperties(resolvedDistinctId, groups, personProperties, groupProperties);
|
|
4878
6796
|
personProperties = adjustedProperties.allPersonProperties;
|
|
4879
6797
|
groupProperties = adjustedProperties.allGroupProperties;
|
|
4880
|
-
const evaluationContext = this.createFeatureFlagEvaluationContext(resolvedDistinctId, groups, personProperties, groupProperties);
|
|
6798
|
+
const evaluationContext = this.createFeatureFlagEvaluationContext(resolvedDistinctId, groups, this.personPropertiesForLocalEvaluation(resolvedDistinctId, personProperties), groupProperties);
|
|
4881
6799
|
if (onlyEvaluateLocally == undefined)
|
|
4882
6800
|
onlyEvaluateLocally = this.options.strictLocalEvaluation ?? false;
|
|
4883
6801
|
const localEvaluationResult = await this.featureFlagsPoller?.getAllFlagsAndPayloads(evaluationContext, flagKeys);
|
|
@@ -4890,7 +6808,7 @@ class PostHogBackendClient extends PostHogCoreStateless {
|
|
|
4890
6808
|
fallbackToFlags = localEvaluationResult.fallbackToFlags;
|
|
4891
6809
|
}
|
|
4892
6810
|
if (fallbackToFlags && !onlyEvaluateLocally) {
|
|
4893
|
-
const remoteEvaluationResult = await super.getFeatureFlagsAndPayloadsStateless(evaluationContext.distinctId, evaluationContext.groups,
|
|
6811
|
+
const remoteEvaluationResult = await super.getFeatureFlagsAndPayloadsStateless(evaluationContext.distinctId, evaluationContext.groups, personProperties, groupProperties, disableGeoip, flagKeys);
|
|
4894
6812
|
featureFlags = {
|
|
4895
6813
|
...featureFlags,
|
|
4896
6814
|
...remoteEvaluationResult.flags || {}
|
|
@@ -4938,9 +6856,10 @@ class PostHogBackendClient extends PostHogCoreStateless {
|
|
|
4938
6856
|
const adjustedProperties = this.addLocalPersonAndGroupProperties(resolvedDistinctId, groups, personProperties, groupProperties);
|
|
4939
6857
|
personProperties = adjustedProperties.allPersonProperties;
|
|
4940
6858
|
groupProperties = adjustedProperties.allGroupProperties;
|
|
4941
|
-
const evaluationContext = this.createFeatureFlagEvaluationContext(resolvedDistinctId, groups, personProperties, groupProperties);
|
|
6859
|
+
const evaluationContext = this.createFeatureFlagEvaluationContext(resolvedDistinctId, groups, this.personPropertiesForLocalEvaluation(resolvedDistinctId, personProperties), groupProperties);
|
|
4942
6860
|
if (onlyEvaluateLocally == undefined)
|
|
4943
6861
|
onlyEvaluateLocally = this.options.strictLocalEvaluation ?? false;
|
|
6862
|
+
const requestedFlagKeys = flagKeys ? new Set(flagKeys) : undefined;
|
|
4944
6863
|
const records = {};
|
|
4945
6864
|
let requestId;
|
|
4946
6865
|
let evaluatedAt;
|
|
@@ -4959,14 +6878,17 @@ class PostHogBackendClient extends PostHogCoreStateless {
|
|
|
4959
6878
|
id: flagDef?.id,
|
|
4960
6879
|
version: undefined,
|
|
4961
6880
|
reason: "Evaluated locally",
|
|
4962
|
-
locallyEvaluated: true
|
|
6881
|
+
locallyEvaluated: true,
|
|
6882
|
+
hasExperiment: flagDef?.has_experiment
|
|
4963
6883
|
};
|
|
4964
6884
|
locallyEvaluatedKeys.add(key);
|
|
4965
6885
|
}
|
|
4966
|
-
const
|
|
6886
|
+
const requestedFlagMissingLocally = requestedFlagKeys !== undefined && Array.from(requestedFlagKeys).some((key) => this.featureFlagsPoller?.featureFlagsByKey[key] === undefined);
|
|
6887
|
+
const fallbackToFlags = localResult ? localResult.fallbackToFlags || requestedFlagMissingLocally : true;
|
|
4967
6888
|
if (fallbackToFlags && !onlyEvaluateLocally) {
|
|
4968
|
-
const details = await super.getFeatureFlagDetailsStateless(evaluationContext.distinctId, evaluationContext.groups,
|
|
6889
|
+
const details = await super.getFeatureFlagDetailsStateless(evaluationContext.distinctId, evaluationContext.groups, personProperties, groupProperties, disableGeoip, flagKeys);
|
|
4969
6890
|
if (details) {
|
|
6891
|
+
this._minimalFlagCalledEvents = details.minimalFlagCalledEvents === true;
|
|
4970
6892
|
requestId = details.requestId;
|
|
4971
6893
|
evaluatedAt = details.evaluatedAt;
|
|
4972
6894
|
errorsWhileComputing = Boolean(details.errorsWhileComputingFlags);
|
|
@@ -4989,7 +6911,8 @@ class PostHogBackendClient extends PostHogCoreStateless {
|
|
|
4989
6911
|
id: detail.metadata?.id,
|
|
4990
6912
|
version: detail.metadata?.version,
|
|
4991
6913
|
reason: detail.reason?.description ?? detail.reason?.code,
|
|
4992
|
-
locallyEvaluated: false
|
|
6914
|
+
locallyEvaluated: false,
|
|
6915
|
+
hasExperiment: detail.metadata?.has_experiment
|
|
4993
6916
|
};
|
|
4994
6917
|
}
|
|
4995
6918
|
}
|
|
@@ -5009,7 +6932,8 @@ class PostHogBackendClient extends PostHogCoreStateless {
|
|
|
5009
6932
|
id: existing?.id,
|
|
5010
6933
|
version: existing?.version,
|
|
5011
6934
|
reason: existing?.reason,
|
|
5012
|
-
locallyEvaluated: existing?.locallyEvaluated ?? false
|
|
6935
|
+
locallyEvaluated: existing?.locallyEvaluated ?? false,
|
|
6936
|
+
hasExperiment: existing?.hasExperiment
|
|
5013
6937
|
};
|
|
5014
6938
|
}
|
|
5015
6939
|
if (this._payloadOverrides !== undefined)
|
|
@@ -5021,6 +6945,11 @@ class PostHogBackendClient extends PostHogCoreStateless {
|
|
|
5021
6945
|
payload
|
|
5022
6946
|
};
|
|
5023
6947
|
}
|
|
6948
|
+
if (requestedFlagKeys !== undefined) {
|
|
6949
|
+
for (const key of Object.keys(records))
|
|
6950
|
+
if (!requestedFlagKeys.has(key))
|
|
6951
|
+
delete records[key];
|
|
6952
|
+
}
|
|
5024
6953
|
return new FeatureFlagEvaluations({
|
|
5025
6954
|
host: this._getFeatureFlagEvaluationsHost(),
|
|
5026
6955
|
distinctId: resolvedDistinctId,
|
|
@@ -5034,6 +6963,9 @@ class PostHogBackendClient extends PostHogCoreStateless {
|
|
|
5034
6963
|
quotaLimited
|
|
5035
6964
|
});
|
|
5036
6965
|
}
|
|
6966
|
+
_shouldSendMinimalFlagCalledEvent(event, properties) {
|
|
6967
|
+
return event === "$feature_flag_called" && this._minimalFlagCalledEvents && properties.$feature_flag_has_experiment === false;
|
|
6968
|
+
}
|
|
5037
6969
|
_captureFlagCalledEventIfNeeded(params) {
|
|
5038
6970
|
const { distinctId, key, response, groups, disableGeoip, properties } = params;
|
|
5039
6971
|
const groupSuffix = groups && Object.keys(groups).length > 0 ? `_${JSON.stringify(Object.entries(groups).sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0))}` : "";
|
|
@@ -5068,9 +7000,32 @@ class PostHogBackendClient extends PostHogCoreStateless {
|
|
|
5068
7000
|
return this._featureFlagEvaluationsHost;
|
|
5069
7001
|
}
|
|
5070
7002
|
groupIdentify({ groupType, groupKey, properties, distinctId, disableGeoip }) {
|
|
5071
|
-
|
|
7003
|
+
this._sendPreparedEvent("capture", {
|
|
7004
|
+
distinctId: distinctId || `$${groupType}_${groupKey}`,
|
|
7005
|
+
event: "$groupidentify",
|
|
7006
|
+
properties: {
|
|
7007
|
+
$group_type: groupType,
|
|
7008
|
+
$group_key: groupKey,
|
|
7009
|
+
$group_set: properties || {}
|
|
7010
|
+
},
|
|
7011
|
+
disableGeoip
|
|
7012
|
+
}, false, {
|
|
7013
|
+
includeContextProperties: false
|
|
7014
|
+
});
|
|
7015
|
+
}
|
|
7016
|
+
async groupIdentifyImmediate({ groupType, groupKey, properties, distinctId, disableGeoip }) {
|
|
7017
|
+
await this._sendPreparedEvent("capture", {
|
|
7018
|
+
distinctId: distinctId || `$${groupType}_${groupKey}`,
|
|
7019
|
+
event: "$groupidentify",
|
|
7020
|
+
properties: {
|
|
7021
|
+
$group_type: groupType,
|
|
7022
|
+
$group_key: groupKey,
|
|
7023
|
+
$group_set: properties || {}
|
|
7024
|
+
},
|
|
5072
7025
|
disableGeoip
|
|
5073
|
-
},
|
|
7026
|
+
}, true, {
|
|
7027
|
+
includeContextProperties: false
|
|
7028
|
+
});
|
|
5074
7029
|
}
|
|
5075
7030
|
async reloadFeatureFlags() {
|
|
5076
7031
|
await this.featureFlagsPoller?.loadFeatureFlags(true);
|
|
@@ -5142,12 +7097,18 @@ class PostHogBackendClient extends PostHogCoreStateless {
|
|
|
5142
7097
|
this.context?.enter(data, options);
|
|
5143
7098
|
}
|
|
5144
7099
|
async _shutdown(shutdownTimeoutMs) {
|
|
7100
|
+
const shutdownDeadlineMs = Date.now() + (shutdownTimeoutMs ?? 30000);
|
|
5145
7101
|
const resolve = this._consumeWaitUntilCycle();
|
|
5146
7102
|
await this.featureFlagsPoller?.stopPoller(shutdownTimeoutMs);
|
|
5147
7103
|
this.errorTracking.shutdown();
|
|
7104
|
+
if (this._metrics) {
|
|
7105
|
+
await raceWithTimeout(this._metrics.flush().catch(() => {}), Math.max(0, shutdownDeadlineMs - Date.now()));
|
|
7106
|
+
this._metrics.reset();
|
|
7107
|
+
}
|
|
5148
7108
|
try {
|
|
5149
|
-
return await super._shutdown(
|
|
7109
|
+
return await super._shutdown(Math.max(0, shutdownDeadlineMs - Date.now()));
|
|
5150
7110
|
} finally {
|
|
7111
|
+
this.distinctIdHasSentFlagCalls = {};
|
|
5151
7112
|
resolve?.();
|
|
5152
7113
|
}
|
|
5153
7114
|
}
|
|
@@ -5242,7 +7203,6 @@ class PostHogBackendClient extends PostHogCoreStateless {
|
|
|
5242
7203
|
}
|
|
5243
7204
|
addLocalPersonAndGroupProperties(distinctId, groups, personProperties, groupProperties) {
|
|
5244
7205
|
const allPersonProperties = {
|
|
5245
|
-
distinct_id: distinctId,
|
|
5246
7206
|
...personProperties || {}
|
|
5247
7207
|
};
|
|
5248
7208
|
const allGroupProperties = {};
|
|
@@ -5257,6 +7217,12 @@ class PostHogBackendClient extends PostHogCoreStateless {
|
|
|
5257
7217
|
allGroupProperties
|
|
5258
7218
|
};
|
|
5259
7219
|
}
|
|
7220
|
+
personPropertiesForLocalEvaluation(distinctId, personProperties) {
|
|
7221
|
+
return {
|
|
7222
|
+
distinct_id: distinctId,
|
|
7223
|
+
...personProperties || {}
|
|
7224
|
+
};
|
|
7225
|
+
}
|
|
5260
7226
|
createFeatureFlagEvaluationContext(distinctId, groups, personProperties, groupProperties) {
|
|
5261
7227
|
return {
|
|
5262
7228
|
distinctId,
|
|
@@ -5267,21 +7233,21 @@ class PostHogBackendClient extends PostHogCoreStateless {
|
|
|
5267
7233
|
};
|
|
5268
7234
|
}
|
|
5269
7235
|
captureException(error, distinctId, additionalProperties, uuid, flags) {
|
|
5270
|
-
if (!
|
|
7236
|
+
if (!error_tracking_ErrorTracking.isPreviouslyCapturedError(error)) {
|
|
5271
7237
|
const syntheticException = new Error("PostHog syntheticException");
|
|
5272
|
-
this.addPendingPromise(
|
|
7238
|
+
this.addPendingPromise(error_tracking_ErrorTracking.buildEventMessage(this.getErrorPropertiesBuilder(), error, {
|
|
5273
7239
|
syntheticException
|
|
5274
|
-
}, distinctId, additionalProperties).then((msg) => this.
|
|
7240
|
+
}, distinctId, additionalProperties).then((msg) => this._capturePreparedEvent({
|
|
5275
7241
|
...msg,
|
|
5276
7242
|
uuid,
|
|
5277
7243
|
flags
|
|
5278
|
-
})));
|
|
7244
|
+
}, false)));
|
|
5279
7245
|
}
|
|
5280
7246
|
}
|
|
5281
7247
|
async captureExceptionImmediate(error, distinctId, additionalProperties, flags) {
|
|
5282
|
-
if (!
|
|
7248
|
+
if (!error_tracking_ErrorTracking.isPreviouslyCapturedError(error)) {
|
|
5283
7249
|
const syntheticException = new Error("PostHog syntheticException");
|
|
5284
|
-
return this.addPendingPromise(
|
|
7250
|
+
return this.addPendingPromise(error_tracking_ErrorTracking.buildEventMessage(this.getErrorPropertiesBuilder(), error, {
|
|
5285
7251
|
syntheticException
|
|
5286
7252
|
}, distinctId, additionalProperties).then((msg) => this.captureImmediate({
|
|
5287
7253
|
...msg,
|
|
@@ -5290,24 +7256,31 @@ class PostHogBackendClient extends PostHogCoreStateless {
|
|
|
5290
7256
|
}
|
|
5291
7257
|
}
|
|
5292
7258
|
async prepareEventMessage(props) {
|
|
7259
|
+
return this._prepareEventMessage(props);
|
|
7260
|
+
}
|
|
7261
|
+
async _prepareEventMessage(props, options = {}) {
|
|
5293
7262
|
const { distinctId, event, properties, groups, flags, sendFeatureFlags, timestamp, disableGeoip, uuid } = props;
|
|
5294
7263
|
const contextData = this.context?.get();
|
|
7264
|
+
const includeContextProperties = options.includeContextProperties ?? true;
|
|
5295
7265
|
let mergedDistinctId = distinctId || contextData?.distinctId;
|
|
5296
|
-
const mergedProperties = {
|
|
7266
|
+
const mergedProperties = includeContextProperties ? {
|
|
5297
7267
|
...this.props,
|
|
5298
7268
|
...contextData?.properties || {},
|
|
5299
7269
|
...properties || {}
|
|
7270
|
+
} : {
|
|
7271
|
+
...properties || {}
|
|
5300
7272
|
};
|
|
5301
7273
|
if (!mergedDistinctId) {
|
|
5302
7274
|
mergedDistinctId = uuidv7();
|
|
5303
7275
|
mergedProperties.$process_person_profile = false;
|
|
5304
7276
|
}
|
|
5305
|
-
if (contextData?.sessionId && !mergedProperties.$session_id)
|
|
7277
|
+
if (includeContextProperties && contextData?.sessionId && !mergedProperties.$session_id)
|
|
5306
7278
|
mergedProperties.$session_id = contextData.sessionId;
|
|
7279
|
+
const finalProperties = this._shouldSendMinimalFlagCalledEvent(event, mergedProperties) ? minimizeFlagCalledEventProperties(mergedProperties) : mergedProperties;
|
|
5307
7280
|
const eventMessage = this._runBeforeSend({
|
|
5308
7281
|
distinctId: mergedDistinctId,
|
|
5309
7282
|
event,
|
|
5310
|
-
properties:
|
|
7283
|
+
properties: finalProperties,
|
|
5311
7284
|
groups,
|
|
5312
7285
|
flags,
|
|
5313
7286
|
sendFeatureFlags,
|
|
@@ -5331,12 +7304,14 @@ class PostHogBackendClient extends PostHogCoreStateless {
|
|
|
5331
7304
|
}
|
|
5332
7305
|
return {};
|
|
5333
7306
|
}).catch(() => ({})).then((additionalProperties) => {
|
|
5334
|
-
const
|
|
7307
|
+
const resolvedGroups = eventMessage.groups || groups;
|
|
7308
|
+
return {
|
|
5335
7309
|
...additionalProperties,
|
|
5336
7310
|
...eventMessage.properties || {},
|
|
5337
|
-
|
|
7311
|
+
...resolvedGroups !== undefined && Object.keys(resolvedGroups).length > 0 ? {
|
|
7312
|
+
$groups: resolvedGroups
|
|
7313
|
+
} : {}
|
|
5338
7314
|
};
|
|
5339
|
-
return props2;
|
|
5340
7315
|
});
|
|
5341
7316
|
if (eventMessage.event === "$pageview" && this.options.__preview_capture_bot_pageviews && typeof eventProperties.$raw_user_agent == "string") {
|
|
5342
7317
|
if (isBlockedUA(eventProperties.$raw_user_agent, this.options.custom_blocked_useragents || [])) {
|
|
@@ -5363,22 +7338,26 @@ class PostHogBackendClient extends PostHogCoreStateless {
|
|
|
5363
7338
|
beforeSend
|
|
5364
7339
|
];
|
|
5365
7340
|
let result = eventMessage;
|
|
5366
|
-
for (const fn of fns)
|
|
5367
|
-
|
|
5368
|
-
|
|
5369
|
-
|
|
7341
|
+
for (const fn of fns)
|
|
7342
|
+
try {
|
|
7343
|
+
result = fn(result);
|
|
7344
|
+
if (!result) {
|
|
7345
|
+
this._logger.info(`Event '${eventMessage.event}' was rejected in beforeSend function`);
|
|
7346
|
+
return null;
|
|
7347
|
+
}
|
|
7348
|
+
if (!result.properties || Object.keys(result.properties).length === 0) {
|
|
7349
|
+
const message = `Event '${result.event}' has no properties after beforeSend function, this is likely an error.`;
|
|
7350
|
+
this._logger.warn(message);
|
|
7351
|
+
}
|
|
7352
|
+
} catch (error) {
|
|
7353
|
+
this._logger.error(`Error in before_send function for event '${eventMessage.event}':`, error);
|
|
5370
7354
|
return null;
|
|
5371
7355
|
}
|
|
5372
|
-
if (!result.properties || Object.keys(result.properties).length === 0) {
|
|
5373
|
-
const message = `Event '${result.event}' has no properties after beforeSend function, this is likely an error.`;
|
|
5374
|
-
this._logger.warn(message);
|
|
5375
|
-
}
|
|
5376
|
-
}
|
|
5377
7356
|
return result;
|
|
5378
7357
|
}
|
|
5379
7358
|
}
|
|
5380
7359
|
|
|
5381
|
-
// ../../../../../node_modules/.bun/posthog-node@5.
|
|
7360
|
+
// ../../../../../node_modules/.bun/posthog-node@5.51.1/node_modules/posthog-node/dist/extensions/context/context.mjs
|
|
5382
7361
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
5383
7362
|
|
|
5384
7363
|
class PostHogContext {
|
|
@@ -5409,7 +7388,22 @@ class PostHogContext {
|
|
|
5409
7388
|
}
|
|
5410
7389
|
}
|
|
5411
7390
|
|
|
5412
|
-
// ../../../../../node_modules/.bun/posthog-node@5.
|
|
7391
|
+
// ../../../../../node_modules/.bun/posthog-node@5.51.1/node_modules/posthog-node/dist/gzip.node.mjs
|
|
7392
|
+
import { gzip } from "node:zlib";
|
|
7393
|
+
import { promisify } from "node:util";
|
|
7394
|
+
var gzipAsync = promisify(gzip);
|
|
7395
|
+
async function gzipCompress2(input, isDebug = true) {
|
|
7396
|
+
try {
|
|
7397
|
+
const compressed = await gzipAsync(input);
|
|
7398
|
+
return new Uint8Array(compressed);
|
|
7399
|
+
} catch (error) {
|
|
7400
|
+
if (isDebug)
|
|
7401
|
+
console.error("Failed to gzip compress data", error);
|
|
7402
|
+
return null;
|
|
7403
|
+
}
|
|
7404
|
+
}
|
|
7405
|
+
|
|
7406
|
+
// ../../../../../node_modules/.bun/posthog-node@5.51.1/node_modules/posthog-node/dist/extensions/sentry-integration.mjs
|
|
5413
7407
|
var NAME = "posthog-node";
|
|
5414
7408
|
function createEventProcessor(_posthog, { organization, projectId, prefix, severityAllowList = [
|
|
5415
7409
|
"error"
|
|
@@ -5449,6 +7443,9 @@ function createEventProcessor(_posthog, { organization, projectId, prefix, sever
|
|
|
5449
7443
|
$sentry_exception_type: exceptions[0]?.type,
|
|
5450
7444
|
$sentry_tags: event.tags
|
|
5451
7445
|
};
|
|
7446
|
+
const injectedReleaseId = exports_error_tracking.getInjectedReleaseId();
|
|
7447
|
+
if (injectedReleaseId)
|
|
7448
|
+
properties.$release_id = injectedReleaseId;
|
|
5452
7449
|
if (organization && projectId)
|
|
5453
7450
|
properties["$sentry_url"] = (prefix || "https://sentry.io/organizations/") + organization + "/issues/?project=" + projectId + "&query=" + event.event_id;
|
|
5454
7451
|
if (sendExceptionsToPostHog)
|
|
@@ -5477,11 +7474,14 @@ class PostHogSentryIntegration {
|
|
|
5477
7474
|
};
|
|
5478
7475
|
}
|
|
5479
7476
|
}
|
|
5480
|
-
// ../../../../../node_modules/.bun/posthog-node@5.
|
|
7477
|
+
// ../../../../../node_modules/.bun/posthog-node@5.51.1/node_modules/posthog-node/dist/entrypoints/index.node.mjs
|
|
5481
7478
|
class PostHog extends PostHogBackendClient {
|
|
5482
7479
|
getLibraryId() {
|
|
5483
7480
|
return "posthog-node";
|
|
5484
7481
|
}
|
|
7482
|
+
compressPayload(payload) {
|
|
7483
|
+
return gzipCompress2(payload, this.isDebug);
|
|
7484
|
+
}
|
|
5485
7485
|
initializeContext() {
|
|
5486
7486
|
return new PostHogContext;
|
|
5487
7487
|
}
|
|
@@ -5494,12 +7494,22 @@ class PostHog extends PostHogBackendClient {
|
|
|
5494
7494
|
new exports_error_tracking.PrimitiveCoercer
|
|
5495
7495
|
], exports_error_tracking.createStackParser("node:javascript", exports_error_tracking.nodeStackLineParser), [
|
|
5496
7496
|
createModulerModifier(),
|
|
5497
|
-
addSourceContext,
|
|
7497
|
+
(frames) => addSourceContext(frames, undefined, this._logger),
|
|
5498
7498
|
createRelativePathModifier()
|
|
5499
7499
|
]);
|
|
5500
7500
|
}
|
|
5501
7501
|
}
|
|
5502
7502
|
|
|
7503
|
+
// ../../../../telemetry-core/src/machine-id.ts
|
|
7504
|
+
import { createHash } from "node:crypto";
|
|
7505
|
+
import os2 from "node:os";
|
|
7506
|
+
function getDefaultTelemetryOsProvider() {
|
|
7507
|
+
return os2;
|
|
7508
|
+
}
|
|
7509
|
+
function getTelemetryDistinctId(machineIdPrefix, osProvider = getDefaultTelemetryOsProvider()) {
|
|
7510
|
+
return createHash("sha256").update(`${machineIdPrefix}${osProvider.hostname()}`).digest("hex");
|
|
7511
|
+
}
|
|
7512
|
+
|
|
5503
7513
|
// ../../../../telemetry-core/src/posthog-client.ts
|
|
5504
7514
|
var NO_OP_CLIENT = {
|
|
5505
7515
|
enabled: false,
|
|
@@ -5534,7 +7544,7 @@ function createDefaultPostHogTransport(apiKey, options) {
|
|
|
5534
7544
|
}
|
|
5535
7545
|
function isTelemetryClientEnabled(input) {
|
|
5536
7546
|
const env = input.env ?? process.env;
|
|
5537
|
-
return !shouldDisableTelemetry({ env, productEnvPrefix: input.product.productEnvPrefix }) &&
|
|
7547
|
+
return !shouldDisableTelemetry({ env, productEnvPrefix: input.product.productEnvPrefix }) && hasTelemetryApiKey(env, input.product.defaultApiKey);
|
|
5538
7548
|
}
|
|
5539
7549
|
function createTelemetryClient(input) {
|
|
5540
7550
|
if (!isTelemetryClientEnabled(input)) {
|
|
@@ -5600,7 +7610,8 @@ function createTransport(input) {
|
|
|
5600
7610
|
flushAt: 1,
|
|
5601
7611
|
flushInterval: 0,
|
|
5602
7612
|
host: getTelemetryHost(env, input.product.defaultHost),
|
|
5603
|
-
disableGeoip: false
|
|
7613
|
+
disableGeoip: input.product.disableGeoip ?? false,
|
|
7614
|
+
...input.product.transportOptions
|
|
5604
7615
|
});
|
|
5605
7616
|
} catch (error) {
|
|
5606
7617
|
input.diagnostics?.({
|
|
@@ -5804,11 +7815,11 @@ function getPostHogDistinctIdForTesting(osProvider) {
|
|
|
5804
7815
|
return getTelemetryDistinctId(MACHINE_ID_PREFIX, osProvider);
|
|
5805
7816
|
}
|
|
5806
7817
|
export {
|
|
5807
|
-
|
|
5808
|
-
getPostHogDistinctId,
|
|
5809
|
-
getComponentVersion,
|
|
5810
|
-
createPluginPostHog,
|
|
5811
|
-
__createPluginPostHogForTesting,
|
|
7818
|
+
DEFAULT_POSTHOG_API_KEY,
|
|
5812
7819
|
DEFAULT_POSTHOG_HOST,
|
|
5813
|
-
|
|
7820
|
+
__createPluginPostHogForTesting,
|
|
7821
|
+
createPluginPostHog,
|
|
7822
|
+
getComponentVersion,
|
|
7823
|
+
getPostHogDistinctId,
|
|
7824
|
+
getPostHogDistinctIdForTesting
|
|
5814
7825
|
};
|