@egbe-ai/opencode 0.0.0-stage → 0.1.8
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/LICENSE +4 -0
- package/README.md +124 -2
- package/index.js +5 -0
- package/package.json +55 -4
- package/plugin.js +230 -0
- package/session-log.js +315 -0
- package/skills/.egbe-catalog/manifest.json +1 -0
- package/skills/egbe-os-analytics/SKILL.md +499 -0
- package/skills/egbe-os-analytics/canonical-events.v1.json +256 -0
- package/skills/egbe-os-analytics/references/session-funnel.md +130 -0
- package/skills/egbe-os-analytics/references/workflows/activation-tracking.md +147 -0
- package/skills/egbe-os-analytics/references/workflows/landing-click-tracking.md +209 -0
- package/skills/egbe-os-analytics/references/workflows/payment-lifecycle-tracking.md +122 -0
- package/skills/egbe-os-analytics/references/workflows/product-funnel-tracking.md +77 -0
- package/skills/egbe-os-analytics/references/workflows/signup-lifecycle-tracking.md +208 -0
- package/skills/egbe-os-analytics/scripts/umami_funnel.py +927 -0
- package/skills/egbe-os-apollo-lead-finder/SKILL.md +135 -0
- package/skills/egbe-os-apollo-lead-finder/references/operations.md +240 -0
- package/skills/egbe-os-apollo-lead-finder/scripts/enrich.js +6 -0
- package/skills/egbe-os-apollo-lead-finder/scripts/enrich.sh +4 -0
- package/skills/egbe-os-apollo-lead-finder/scripts/find-leads.js +6 -0
- package/skills/egbe-os-apollo-lead-finder/scripts/find-leads.sh +4 -0
- package/skills/egbe-os-apollo-lead-finder/scripts/lib/apollo-client.js +343 -0
- package/skills/egbe-os-apollo-lead-finder/scripts/lib/connection-identity.js +17 -0
- package/skills/egbe-os-apollo-lead-finder/scripts/lib/helpers.js +127 -0
- package/skills/egbe-os-apollo-lead-finder/scripts/lib/places-filters.js +217 -0
- package/skills/egbe-os-apollo-lead-finder/scripts/lib/sourcing.js +153 -0
- package/skills/egbe-os-apollo-lead-finder/scripts/places-leads.js +653 -0
- package/skills/egbe-os-apollo-lead-finder/scripts/places-leads.sh +4 -0
- package/skills/egbe-os-apollo-lead-finder/scripts/search.js +6 -0
- package/skills/egbe-os-apollo-lead-finder/scripts/search.sh +4 -0
- package/skills/egbe-os-campaign-landing-page/SKILL.md +95 -0
- package/skills/egbe-os-campaign-landing-page/agents/openai.yaml +4 -0
- package/skills/egbe-os-campaign-landing-page/references/leads-calendar-and-tracking.md +66 -0
- package/skills/egbe-os-campaign-landing-page/references/os-wiring.md +58 -0
- package/skills/egbe-os-campaign-landing-page/references/qa.md +40 -0
- package/skills/egbe-os-campaign-landing-page/references/routing.md +32 -0
- package/skills/egbe-os-db/SKILL.md +174 -0
- package/skills/egbe-os-deploy/SKILL.md +412 -0
- package/skills/egbe-os-design/SKILL.md +182 -0
- package/skills/egbe-os-design-landing-page/SKILL.md +117 -0
- package/skills/egbe-os-design-landing-page/agents/openai.yaml +4 -0
- package/skills/egbe-os-design-landing-page/assets/scaffold/.dockerignore +11 -0
- package/skills/egbe-os-design-landing-page/assets/scaffold/AGENTS.md +31 -0
- package/skills/egbe-os-design-landing-page/assets/scaffold/Dockerfile +21 -0
- package/skills/egbe-os-design-landing-page/assets/scaffold/eslint.config.mjs +18 -0
- package/skills/egbe-os-design-landing-page/assets/scaffold/next.config.ts +11 -0
- package/skills/egbe-os-design-landing-page/assets/scaffold/package.json +36 -0
- package/skills/egbe-os-design-landing-page/assets/scaffold/postcss.config.mjs +7 -0
- package/skills/egbe-os-design-landing-page/assets/scaffold/public/.gitkeep +1 -0
- package/skills/egbe-os-design-landing-page/assets/scaffold/sentry.edge.config.ts +13 -0
- package/skills/egbe-os-design-landing-page/assets/scaffold/sentry.server.config.ts +13 -0
- package/skills/egbe-os-design-landing-page/assets/scaffold/src/app/global-error.tsx +19 -0
- package/skills/egbe-os-design-landing-page/assets/scaffold/src/app/globals.css +22 -0
- package/skills/egbe-os-design-landing-page/assets/scaffold/src/app/layout.tsx +21 -0
- package/skills/egbe-os-design-landing-page/assets/scaffold/src/app/page.tsx +3 -0
- package/skills/egbe-os-design-landing-page/assets/scaffold/src/app/privacy/page.tsx +28 -0
- package/skills/egbe-os-design-landing-page/assets/scaffold/src/components/egbe-analytics.tsx +39 -0
- package/skills/egbe-os-design-landing-page/assets/scaffold/src/instrumentation-client.ts +15 -0
- package/skills/egbe-os-design-landing-page/assets/scaffold/src/instrumentation.ts +13 -0
- package/skills/egbe-os-design-landing-page/assets/scaffold/src/lib/egbe-observability.generated.ts +20 -0
- package/skills/egbe-os-design-landing-page/assets/scaffold/src/lib/utils.ts +6 -0
- package/skills/egbe-os-design-landing-page/assets/scaffold/tsconfig.json +34 -0
- package/skills/egbe-os-design-landing-page/references/application-preparation.md +44 -0
- package/skills/egbe-os-design-landing-page/references/page-inputs.md +22 -0
- package/skills/egbe-os-destination-readiness/SKILL.md +132 -0
- package/skills/egbe-os-destination-readiness/references/checks.md +130 -0
- package/skills/egbe-os-destination-readiness/references/network-requirements.md +34 -0
- package/skills/egbe-os-destination-readiness/references/report.md +116 -0
- package/skills/egbe-os-domains/SKILL.md +189 -0
- package/skills/egbe-os-errors/SKILL.md +259 -0
- package/skills/egbe-os-git/SKILL.md +275 -0
- package/skills/egbe-os-git/references/issues.md +33 -0
- package/skills/egbe-os-google-ads/SKILL.md +163 -0
- package/skills/egbe-os-google-ads/references/artifacts.md +133 -0
- package/skills/egbe-os-google-ads/references/campaigns.md +157 -0
- package/skills/egbe-os-google-ads/references/conversions.md +153 -0
- package/skills/egbe-os-google-ads/references/delivery.md +128 -0
- package/skills/egbe-os-google-ads/references/keyword-ideas.md +40 -0
- package/skills/egbe-os-google-ads/references/reporting.md +105 -0
- package/skills/egbe-os-google-ads/references/search-assets.md +219 -0
- package/skills/egbe-os-google-ads/references/server-conversions.md +119 -0
- package/skills/egbe-os-google-auth/SKILL.md +285 -0
- package/skills/egbe-os-google-auth/agents/openai.yaml +4 -0
- package/skills/egbe-os-gtm-knowledge/SKILL.md +151 -0
- package/skills/egbe-os-images/SKILL.md +163 -0
- package/skills/egbe-os-images/references/stock-images.md +21 -0
- package/skills/egbe-os-instantly-campaign-launcher/SKILL.md +127 -0
- package/skills/egbe-os-instantly-campaign-launcher/references/instantly-ops.md +260 -0
- package/skills/egbe-os-instantly-campaign-launcher/references/observation-and-scheduling.md +188 -0
- package/skills/egbe-os-instantly-campaign-launcher/references/reply-handling.md +116 -0
- package/skills/egbe-os-instantly-campaign-launcher/references/run-spec-template.json +65 -0
- package/skills/egbe-os-instantly-campaign-launcher/references/run-state.md +145 -0
- package/skills/egbe-os-instantly-campaign-launcher/scripts/conclude-campaign.js +158 -0
- package/skills/egbe-os-instantly-campaign-launcher/scripts/install-crons.js +956 -0
- package/skills/egbe-os-instantly-campaign-launcher/scripts/launch-campaign.js +2008 -0
- package/skills/egbe-os-instantly-campaign-launcher/scripts/lib/campaign-metrics.js +124 -0
- package/skills/egbe-os-instantly-campaign-launcher/scripts/lib/confirmed-opt-outs.js +208 -0
- package/skills/egbe-os-instantly-campaign-launcher/scripts/lib/connection-identity.js +17 -0
- package/skills/egbe-os-instantly-campaign-launcher/scripts/lib/create-once.js +23 -0
- package/skills/egbe-os-instantly-campaign-launcher/scripts/lib/gtm-identity.js +125 -0
- package/skills/egbe-os-instantly-campaign-launcher/scripts/lib/helpers.js +545 -0
- package/skills/egbe-os-instantly-campaign-launcher/scripts/lib/html-body.js +266 -0
- package/skills/egbe-os-instantly-campaign-launcher/scripts/lib/instantly-client.js +328 -0
- package/skills/egbe-os-instantly-campaign-launcher/scripts/lib/outreach-db.js +370 -0
- package/skills/egbe-os-instantly-campaign-launcher/scripts/lib/recipient-exclusion/index.js +86 -0
- package/skills/egbe-os-instantly-campaign-launcher/scripts/lib/replenish-test-harness.js +53 -0
- package/skills/egbe-os-instantly-campaign-launcher/scripts/lib/reply-queue.js +67 -0
- package/skills/egbe-os-instantly-campaign-launcher/scripts/lib/run-config.js +103 -0
- package/skills/egbe-os-instantly-campaign-launcher/scripts/lib/sender-selection.js +105 -0
- package/skills/egbe-os-instantly-campaign-launcher/scripts/monitor-campaign.js +607 -0
- package/skills/egbe-os-instantly-campaign-launcher/scripts/outreach-report.js +147 -0
- package/skills/egbe-os-instantly-campaign-launcher/scripts/replenish-leads.js +619 -0
- package/skills/egbe-os-instantly-campaign-launcher/scripts/reply-worker.js +258 -0
- package/skills/egbe-os-instantly-campaign-launcher/scripts/run-cron-job.js +32 -0
- package/skills/egbe-os-instantly-campaign-launcher/scripts/send-reply.js +260 -0
- package/skills/egbe-os-linkedin-ads/SKILL.md +114 -0
- package/skills/egbe-os-linkedin-ads/references/destination-requirements.md +30 -0
- package/skills/egbe-os-linkedin-ads/references/runtime/api-reference.md +154 -0
- package/skills/egbe-os-linkedin-ads/references/runtime/artifacts.md +63 -0
- package/skills/egbe-os-linkedin-ads/references/workflows/build-paused.md +44 -0
- package/skills/egbe-os-linkedin-ads/references/workflows/conversions.md +88 -0
- package/skills/egbe-os-linkedin-ads/references/workflows/launch-and-pause.md +49 -0
- package/skills/egbe-os-linkedin-ads/references/workflows/monitoring.md +35 -0
- package/skills/egbe-os-linkedin-ads/references/workflows/readiness.md +63 -0
- package/skills/egbe-os-linkedin-ads/references/workflows/targeting-and-creative.md +52 -0
- package/skills/egbe-os-llm/SKILL.md +160 -0
- package/skills/egbe-os-mail/SKILL.md +180 -0
- package/skills/egbe-os-me/SKILL.md +119 -0
- package/skills/egbe-os-meta-ads/SKILL.md +114 -0
- package/skills/egbe-os-meta-ads/references/creative/creative-specs.md +15 -0
- package/skills/egbe-os-meta-ads/references/creative/talking-head.md +35 -0
- package/skills/egbe-os-meta-ads/references/destination-requirements.md +30 -0
- package/skills/egbe-os-meta-ads/references/runtime/api-reference.md +436 -0
- package/skills/egbe-os-meta-ads/references/runtime/artifacts.md +51 -0
- package/skills/egbe-os-meta-ads/references/runtime/insights-reference.md +187 -0
- package/skills/egbe-os-meta-ads/references/runtime/pixel-install.md +196 -0
- package/skills/egbe-os-meta-ads/references/runtime/shared-analytics-attribution.md +16 -0
- package/skills/egbe-os-meta-ads/references/workflows/build-paused.md +36 -0
- package/skills/egbe-os-meta-ads/references/workflows/launch-ready.md +16 -0
- package/skills/egbe-os-meta-ads/references/workflows/launch.md +23 -0
- package/skills/egbe-os-meta-ads/references/workflows/monitoring.md +72 -0
- package/skills/egbe-os-meta-ads/references/workflows/pause.md +17 -0
- package/skills/egbe-os-meta-ads/references/workflows/recovery.md +23 -0
- package/skills/egbe-os-meta-ads/scripts/check-pixel.py +229 -0
- package/skills/egbe-os-meta-ads/scripts/validate-meta-artifacts.py +187 -0
- package/skills/egbe-os-notifications/SKILL.md +78 -0
- package/skills/egbe-os-openai-ads/SKILL.md +149 -0
- package/skills/egbe-os-openai-ads/references/creative/chat-card.md +51 -0
- package/skills/egbe-os-openai-ads/references/destination-requirements.md +29 -0
- package/skills/egbe-os-openai-ads/references/runtime/api-reference.md +219 -0
- package/skills/egbe-os-openai-ads/references/runtime/artifacts.md +169 -0
- package/skills/egbe-os-openai-ads/references/workflows/build-paused.md +40 -0
- package/skills/egbe-os-openai-ads/references/workflows/conversions.md +40 -0
- package/skills/egbe-os-openai-ads/references/workflows/creative-assembly.md +24 -0
- package/skills/egbe-os-openai-ads/references/workflows/launch.md +27 -0
- package/skills/egbe-os-openai-ads/references/workflows/monitoring.md +54 -0
- package/skills/egbe-os-openai-ads/references/workflows/pause.md +22 -0
- package/skills/egbe-os-openai-ads/references/workflows/readiness.md +37 -0
- package/skills/egbe-os-openai-ads/references/workflows/tracking.md +32 -0
- package/skills/egbe-os-openai-ads/scripts/validate-openai-artifacts.py +271 -0
- package/skills/egbe-os-organic-trend-watch/SKILL.md +139 -0
- package/skills/egbe-os-organic-trend-watch/agents/openai.yaml +4 -0
- package/skills/egbe-os-organic-trend-watch/references/analysis-and-adaptation.md +54 -0
- package/skills/egbe-os-organic-trend-watch/references/collection-and-analysis.md +117 -0
- package/skills/egbe-os-organic-trend-watch/references/output-contract.md +133 -0
- package/skills/egbe-os-organic-trend-watch/references/provider-contract.md +169 -0
- package/skills/egbe-os-organic-trend-watch/references/runtime-contract.md +204 -0
- package/skills/egbe-os-organic-trend-watch/references/visual-analysis-prompt.md +17 -0
- package/skills/egbe-os-organic-trend-watch/scripts/_analysis.py +612 -0
- package/skills/egbe-os-organic-trend-watch/scripts/_contract.py +1133 -0
- package/skills/egbe-os-organic-trend-watch/scripts/_provider_inputs.py +165 -0
- package/skills/egbe-os-organic-trend-watch/scripts/analyze-visual-evidence.py +315 -0
- package/skills/egbe-os-organic-trend-watch/scripts/build-provider-inputs.py +88 -0
- package/skills/egbe-os-organic-trend-watch/scripts/connection_identity.py +22 -0
- package/skills/egbe-os-organic-trend-watch/scripts/egbe_artifacts.py +24 -0
- package/skills/egbe-os-organic-trend-watch/scripts/finalize-receipt.py +106 -0
- package/skills/egbe-os-organic-trend-watch/scripts/normalize-videos.py +647 -0
- package/skills/egbe-os-organic-trend-watch/scripts/prepare-visual-evidence.py +324 -0
- package/skills/egbe-os-organic-trend-watch/scripts/render-result.py +30 -0
- package/skills/egbe-os-organic-trend-watch/scripts/run-apify.py +723 -0
- package/skills/egbe-os-organic-trend-watch/scripts/run-state.py +192 -0
- package/skills/egbe-os-organic-trend-watch/scripts/validate-context.py +27 -0
- package/skills/egbe-os-organic-trend-watch/scripts/validate-runtime.py +137 -0
- package/skills/egbe-os-payments/SKILL.md +215 -0
- package/skills/egbe-os-payments/agents/openai.yaml +4 -0
- package/skills/egbe-os-payments/assets/scaffolds/billing-nextjs-subscription/.egbe/scaffolds/billing-nextjs-subscription.v1.json +5 -0
- package/skills/egbe-os-payments/assets/scaffolds/billing-nextjs-subscription/AGENTS.append.md +13 -0
- package/skills/egbe-os-payments/assets/scaffolds/billing-nextjs-subscription/db/migrations/1000_egbe_billing.sql +66 -0
- package/skills/egbe-os-payments/assets/scaffolds/billing-nextjs-subscription/package.fragment.json +12 -0
- package/skills/egbe-os-payments/assets/scaffolds/billing-nextjs-subscription/scripts/billing-sync.mjs +162 -0
- package/skills/egbe-os-payments/assets/scaffolds/billing-nextjs-subscription/src/app/account/billing/error.tsx +11 -0
- package/skills/egbe-os-payments/assets/scaffolds/billing-nextjs-subscription/src/app/account/billing/loading.tsx +8 -0
- package/skills/egbe-os-payments/assets/scaffolds/billing-nextjs-subscription/src/app/account/billing/page.tsx +121 -0
- package/skills/egbe-os-payments/assets/scaffolds/billing-nextjs-subscription/src/app/api/billing/checkout/route.ts +102 -0
- package/skills/egbe-os-payments/assets/scaffolds/billing-nextjs-subscription/src/app/api/billing/portal/route.ts +54 -0
- package/skills/egbe-os-payments/assets/scaffolds/billing-nextjs-subscription/src/app/api/billing/status/route.ts +22 -0
- package/skills/egbe-os-payments/assets/scaffolds/billing-nextjs-subscription/src/app/api/payments/webhook/route.ts +65 -0
- package/skills/egbe-os-payments/assets/scaffolds/billing-nextjs-subscription/src/components/egbe-billing/plan-badge.tsx +16 -0
- package/skills/egbe-os-payments/assets/scaffolds/billing-nextjs-subscription/src/lib/egbe-billing/billing-sync.test.mjs +58 -0
- package/skills/egbe-os-payments/assets/scaffolds/billing-nextjs-subscription/src/lib/egbe-billing/catalog.ts +82 -0
- package/skills/egbe-os-payments/assets/scaffolds/billing-nextjs-subscription/src/lib/egbe-billing/checkout-payload.ts +47 -0
- package/skills/egbe-os-payments/assets/scaffolds/billing-nextjs-subscription/src/lib/egbe-billing/foundation-contract.test.mjs +59 -0
- package/skills/egbe-os-payments/assets/scaffolds/billing-nextjs-subscription/src/lib/egbe-billing/lifecycle.d.ts +16 -0
- package/skills/egbe-os-payments/assets/scaffolds/billing-nextjs-subscription/src/lib/egbe-billing/lifecycle.mjs +82 -0
- package/skills/egbe-os-payments/assets/scaffolds/billing-nextjs-subscription/src/lib/egbe-billing/lifecycle.test.mjs +94 -0
- package/skills/egbe-os-payments/assets/scaffolds/billing-nextjs-subscription/src/lib/egbe-billing/os-client.ts +96 -0
- package/skills/egbe-os-payments/assets/scaffolds/billing-nextjs-subscription/src/lib/egbe-billing/plans.json +17 -0
- package/skills/egbe-os-payments/assets/scaffolds/billing-nextjs-subscription/src/lib/egbe-billing/repository.ts +325 -0
- package/skills/egbe-os-payments/assets/scaffolds/billing-nextjs-subscription/src/lib/egbe-billing/signature.d.ts +6 -0
- package/skills/egbe-os-payments/assets/scaffolds/billing-nextjs-subscription/src/lib/egbe-billing/signature.mjs +22 -0
- package/skills/egbe-os-payments/references/contracts/plan-catalog.md +46 -0
- package/skills/egbe-os-payments/references/security/durable-verification.md +64 -0
- package/skills/egbe-os-payments/references/security/server-integration.md +26 -0
- package/skills/egbe-os-payments/references/security/webhook-and-entitlements.md +152 -0
- package/skills/egbe-os-payments/references/ux/billing-experience.md +47 -0
- package/skills/egbe-os-payments/references/workflows/account-billing.md +64 -0
- package/skills/egbe-os-payments/references/workflows/discounts-and-promotion-codes.md +265 -0
- package/skills/egbe-os-payments/references/workflows/one-time-purchase.md +75 -0
- package/skills/egbe-os-payments/references/workflows/product-checkout.md +355 -0
- package/skills/egbe-os-payments/references/workflows/subscription-lifecycle.md +55 -0
- package/skills/egbe-os-playbook/SKILL.md +79 -0
- package/skills/egbe-os-playbook/playbooks/market-and-acquisition/channels/email-outreach.md +91 -0
- package/skills/egbe-os-playbook/playbooks/market-and-acquisition/channels/google-search.md +40 -0
- package/skills/egbe-os-playbook/playbooks/market-and-acquisition/channels/linkedin.md +24 -0
- package/skills/egbe-os-playbook/playbooks/market-and-acquisition/channels/meta.md +23 -0
- package/skills/egbe-os-playbook/playbooks/market-and-acquisition/channels/openai.md +15 -0
- package/skills/egbe-os-playbook/playbooks/market-and-acquisition/channels/reddit.md +56 -0
- package/skills/egbe-os-playbook/playbooks/market-and-acquisition/choose-test.md +73 -0
- package/skills/egbe-os-playbook/playbooks/market-and-acquisition/evaluate.md +91 -0
- package/skills/egbe-os-playbook/playbooks/market-and-acquisition/market.md +96 -0
- package/skills/egbe-os-playbook/playbooks/market-and-acquisition/run-test.md +111 -0
- package/skills/egbe-os-playbook/playbooks/market-and-acquisition.md +56 -0
- package/skills/egbe-os-playbook/playbooks/product/business-loop.md +141 -0
- package/skills/egbe-os-playbook/playbooks/product/collaboration.md +26 -0
- package/skills/egbe-os-playbook/playbooks/product/deliver.md +75 -0
- package/skills/egbe-os-playbook/playbooks/product/diagnose.md +80 -0
- package/skills/egbe-os-playbook/playbooks/product/evaluate.md +67 -0
- package/skills/egbe-os-playbook/playbooks/product/experience.md +132 -0
- package/skills/egbe-os-playbook/playbooks/product/loop-examples.md +67 -0
- package/skills/egbe-os-playbook/playbooks/product/offer.md +65 -0
- package/skills/egbe-os-playbook/playbooks/product/value.md +91 -0
- package/skills/egbe-os-playbook/playbooks/product.md +67 -0
- package/skills/egbe-os-playbook/references/catalog.md +127 -0
- package/skills/egbe-os-playbook/references/changes.md +167 -0
- package/skills/egbe-os-playbook/scripts/playbook-changes.py +6 -0
- package/skills/egbe-os-playbook/scripts/playbook_changes/__init__.py +1 -0
- package/skills/egbe-os-playbook/scripts/playbook_changes/cli.py +57 -0
- package/skills/egbe-os-playbook/scripts/playbook_changes/operations.py +137 -0
- package/skills/egbe-os-playbook/scripts/playbook_changes/protocol.py +132 -0
- package/skills/egbe-os-playbook/scripts/playbook_changes/storage.py +180 -0
- package/skills/egbe-os-playbook/scripts/playbook_changes/transport.py +113 -0
- package/skills/egbe-os-product-auth/SKILL.md +151 -0
- package/skills/egbe-os-product-auth/agents/openai.yaml +4 -0
- package/skills/egbe-os-product-auth/assets/db/README.md +102 -0
- package/skills/egbe-os-product-auth/assets/db/create-validation-session.mjs +223 -0
- package/skills/egbe-os-product-auth/assets/db/migrate.mjs +64 -0
- package/skills/egbe-os-product-auth/assets/db/migrations/0001_auth.sql +33 -0
- package/skills/egbe-os-product-auth/assets/db/migrations/0002_auth_identities.sql +16 -0
- package/skills/egbe-os-product-auth/assets/scaffolds/product-auth-database/AGENTS.append.md +17 -0
- package/skills/egbe-os-product-auth/assets/scaffolds/product-auth-database/package.fragment.json +10 -0
- package/skills/egbe-os-product-auth/assets/scaffolds/product-nextjs-postgres/AGENTS.append.md +9 -0
- package/skills/egbe-os-product-auth/assets/scaffolds/product-nextjs-postgres/package.fragment.json +13 -0
- package/skills/egbe-os-product-auth/assets/scaffolds/product-nextjs-postgres/src/lib/egbe-product/db.ts +31 -0
- package/skills/egbe-os-product-auth/assets/scaffolds/product-nextjs-postgres/src/lib/egbe-product/identity.ts +94 -0
- package/skills/egbe-os-product-auth/assets/scaffolds/product-nextjs-postgres/src/lib/egbe-product/index.ts +3 -0
- package/skills/egbe-os-product-auth/assets/scaffolds/product-nextjs-postgres/src/lib/egbe-product/session.ts +91 -0
- package/skills/egbe-os-product-auth/references/contracts/live-auth-interface.md +108 -0
- package/skills/egbe-os-product-auth/references/frameworks/nextjs.md +34 -0
- package/skills/egbe-os-product-auth/references/security/session-and-credentials.md +73 -0
- package/skills/egbe-os-product-auth/references/ux/auth-experience.md +58 -0
- package/skills/egbe-os-product-auth/references/workflows/account-recovery.md +22 -0
- package/skills/egbe-os-product-auth/references/workflows/build-auth.md +212 -0
- package/skills/egbe-os-product-auth/references/workflows/google.md +34 -0
- package/skills/egbe-os-product-auth/references/workflows/passwordless-email.md +65 -0
- package/skills/egbe-os-product-build/SKILL.md +111 -0
- package/skills/egbe-os-product-build/agents/openai.yaml +4 -0
- package/skills/egbe-os-product-build/references/capabilities.md +25 -0
- package/skills/egbe-os-product-build/references/engineering.md +72 -0
- package/skills/egbe-os-product-build/references/execution.md +55 -0
- package/skills/egbe-os-product-build/references/foundations.md +93 -0
- package/skills/egbe-os-product-build/references/interface-quality.md +32 -0
- package/skills/egbe-os-product-build/references/workflows/private-review-handoff.md +86 -0
- package/skills/egbe-os-product-build/scripts/scaffold.py +296 -0
- package/skills/egbe-os-product-demo-video/SKILL.md +118 -0
- package/skills/egbe-os-product-demo-video/references/recording.md +32 -0
- package/skills/egbe-os-product-market-research/SKILL.md +159 -0
- package/skills/egbe-os-product-market-research/agents/openai.yaml +4 -0
- package/skills/egbe-os-product-market-research/references/catalog.v1.json +177 -0
- package/skills/egbe-os-product-market-research/references/config/channel-footprint-sources.v1.json +99 -0
- package/skills/egbe-os-product-market-research/references/config/creative-taxonomy.v1.json +367 -0
- package/skills/egbe-os-product-market-research/references/contracts/creative-video.md +75 -0
- package/skills/egbe-os-product-market-research/references/contracts/funnel-teardown.md +235 -0
- package/skills/egbe-os-product-market-research/references/contracts/geography-comparison.md +71 -0
- package/skills/egbe-os-product-market-research/references/contracts/lifecycle-capture.md +119 -0
- package/skills/egbe-os-product-market-research/references/contracts/research-artifacts.md +520 -0
- package/skills/egbe-os-product-market-research/references/contracts/walk-mechanics.v2.json +18 -0
- package/skills/egbe-os-product-market-research/references/prompts/acquisition-channels.md +137 -0
- package/skills/egbe-os-product-market-research/references/prompts/acquisition-channels.user.md +4 -0
- package/skills/egbe-os-product-market-research/references/prompts/competitive-landscape.md +118 -0
- package/skills/egbe-os-product-market-research/references/prompts/competitive-landscape.user.md +4 -0
- package/skills/egbe-os-product-market-research/references/prompts/demand-validation.md +154 -0
- package/skills/egbe-os-product-market-research/references/prompts/demand-validation.user.md +4 -0
- package/skills/egbe-os-product-market-research/references/prompts/market-size-and-dynamics.md +100 -0
- package/skills/egbe-os-product-market-research/references/prompts/market-size-and-dynamics.user.md +4 -0
- package/skills/egbe-os-product-market-research/references/prompts/pricing-and-monetization.md +126 -0
- package/skills/egbe-os-product-market-research/references/prompts/pricing-and-monetization.user.md +4 -0
- package/skills/egbe-os-product-market-research/references/prompts/target-audience.md +98 -0
- package/skills/egbe-os-product-market-research/references/prompts/target-audience.user.md +4 -0
- package/skills/egbe-os-product-market-research/references/prompts/unit-economics.md +217 -0
- package/skills/egbe-os-product-market-research/references/prompts/unit-economics.user.md +4 -0
- package/skills/egbe-os-product-market-research/references/prompts/value-proposition.md +113 -0
- package/skills/egbe-os-product-market-research/references/prompts/value-proposition.user.md +4 -0
- package/skills/egbe-os-product-market-research/references/workflows/acquisition-channels.md +27 -0
- package/skills/egbe-os-product-market-research/references/workflows/channel-footprint.md +163 -0
- package/skills/egbe-os-product-market-research/references/workflows/community-demand.md +100 -0
- package/skills/egbe-os-product-market-research/references/workflows/competitive-landscape.md +27 -0
- package/skills/egbe-os-product-market-research/references/workflows/competitor-ads.md +82 -0
- package/skills/egbe-os-product-market-research/references/workflows/competitor-set.md +300 -0
- package/skills/egbe-os-product-market-research/references/workflows/creative-patterns.md +228 -0
- package/skills/egbe-os-product-market-research/references/workflows/demand-validation.md +27 -0
- package/skills/egbe-os-product-market-research/references/workflows/fleet-prior.md +80 -0
- package/skills/egbe-os-product-market-research/references/workflows/funnel-teardown.md +184 -0
- package/skills/egbe-os-product-market-research/references/workflows/geography-comparison.md +84 -0
- package/skills/egbe-os-product-market-research/references/workflows/keyword-economics.md +122 -0
- package/skills/egbe-os-product-market-research/references/workflows/lifecycle-capture.md +218 -0
- package/skills/egbe-os-product-market-research/references/workflows/local-research.md +55 -0
- package/skills/egbe-os-product-market-research/references/workflows/market-size-and-dynamics.md +27 -0
- package/skills/egbe-os-product-market-research/references/workflows/preview.md +175 -0
- package/skills/egbe-os-product-market-research/references/workflows/pricing-and-monetization.md +27 -0
- package/skills/egbe-os-product-market-research/references/workflows/recommendations.md +35 -0
- package/skills/egbe-os-product-market-research/references/workflows/review-mining.md +76 -0
- package/skills/egbe-os-product-market-research/references/workflows/target-audience.md +27 -0
- package/skills/egbe-os-product-market-research/references/workflows/tiktok-reels-market-trends.md +46 -0
- package/skills/egbe-os-product-market-research/references/workflows/unit-economics.md +27 -0
- package/skills/egbe-os-product-market-research/references/workflows/value-proposition.md +27 -0
- package/skills/egbe-os-product-market-research/scripts/build-organic-trend-context.py +167 -0
- package/skills/egbe-os-product-market-research/scripts/build-preview-context.py +91 -0
- package/skills/egbe-os-product-market-research/scripts/build-research-query.py +225 -0
- package/skills/egbe-os-product-market-research/scripts/channel-footprint-model.py +294 -0
- package/skills/egbe-os-product-market-research/scripts/connection_identity.py +22 -0
- package/skills/egbe-os-product-market-research/scripts/creative-model.py +364 -0
- package/skills/egbe-os-product-market-research/scripts/creative-selection.py +113 -0
- package/skills/egbe-os-product-market-research/scripts/creative-semantics.py +365 -0
- package/skills/egbe-os-product-market-research/scripts/creative-video.py +542 -0
- package/skills/egbe-os-product-market-research/scripts/egbe_artifacts.py +24 -0
- package/skills/egbe-os-product-market-research/scripts/finalize-organic-trend-watch.py +304 -0
- package/skills/egbe-os-product-market-research/scripts/funnel-email-review.py +97 -0
- package/skills/egbe-os-product-market-research/scripts/funnel-model.py +966 -0
- package/skills/egbe-os-product-market-research/scripts/funnel_features.py +50 -0
- package/skills/egbe-os-product-market-research/scripts/geography-comparison-contract.py +172 -0
- package/skills/egbe-os-product-market-research/scripts/geography-comparison.py +169 -0
- package/skills/egbe-os-product-market-research/scripts/keyword-forecast.py +61 -0
- package/skills/egbe-os-product-market-research/scripts/keyword-locale-publication.py +136 -0
- package/skills/egbe-os-product-market-research/scripts/lifecycle-start.py +190 -0
- package/skills/egbe-os-product-market-research/scripts/persist-research-report.py +63 -0
- package/skills/egbe-os-product-market-research/scripts/research-artifact-io.py +281 -0
- package/skills/egbe-os-product-market-research/scripts/research-evidence.py +496 -0
- package/skills/egbe-os-product-market-research/scripts/research-policy.py +33 -0
- package/skills/egbe-os-product-market-research/scripts/research-section-runtime.py +343 -0
- package/skills/egbe-os-product-market-research/scripts/research-section-workflow.py +288 -0
- package/skills/egbe-os-product-market-research/scripts/research_integrity.py +122 -0
- package/skills/egbe-os-product-market-research/scripts/review-research-completion.py +306 -0
- package/skills/egbe-os-product-market-research/scripts/run-acquisition-channels.py +72 -0
- package/skills/egbe-os-product-market-research/scripts/run-channel-footprint.py +2258 -0
- package/skills/egbe-os-product-market-research/scripts/run-community-demand.py +1603 -0
- package/skills/egbe-os-product-market-research/scripts/run-competitive-landscape.py +66 -0
- package/skills/egbe-os-product-market-research/scripts/run-competitor-ads.py +1156 -0
- package/skills/egbe-os-product-market-research/scripts/run-competitor-set.py +2514 -0
- package/skills/egbe-os-product-market-research/scripts/run-creative-patterns.py +2042 -0
- package/skills/egbe-os-product-market-research/scripts/run-demand-validation.py +72 -0
- package/skills/egbe-os-product-market-research/scripts/run-fleet-prior.py +652 -0
- package/skills/egbe-os-product-market-research/scripts/run-funnel-teardown.py +493 -0
- package/skills/egbe-os-product-market-research/scripts/run-keyword-economics.py +1443 -0
- package/skills/egbe-os-product-market-research/scripts/run-lifecycle-capture.py +1543 -0
- package/skills/egbe-os-product-market-research/scripts/run-market-size-and-dynamics.py +66 -0
- package/skills/egbe-os-product-market-research/scripts/run-os-research.py +311 -0
- package/skills/egbe-os-product-market-research/scripts/run-pricing-and-monetization.py +71 -0
- package/skills/egbe-os-product-market-research/scripts/run-review-mining.py +1051 -0
- package/skills/egbe-os-product-market-research/scripts/run-target-audience.py +66 -0
- package/skills/egbe-os-product-market-research/scripts/run-unit-economics.py +71 -0
- package/skills/egbe-os-product-market-research/scripts/run-value-proposition.py +67 -0
- package/skills/egbe-os-product-market-research/scripts/upsert-markdown-section.py +156 -0
- package/skills/egbe-os-product-market-research/scripts/walk-funnels.py +249 -0
- package/skills/egbe-os-product-market-research/scripts/write-preview.py +710 -0
- package/skills/egbe-os-product-market-research/scripts/write-recommendations.py +272 -0
- package/skills/egbe-os-product-report/SKILL.md +150 -0
- package/skills/egbe-os-product-report/references/artifacts.md +84 -0
- package/skills/egbe-os-product-report/references/brief.md +34 -0
- package/skills/egbe-os-product-report/references/daily.md +76 -0
- package/skills/egbe-os-product-report/references/sources.md +68 -0
- package/skills/egbe-os-product-routines/SKILL.md +166 -0
- package/skills/egbe-os-product-routines/references/catalog.md +22 -0
- package/skills/egbe-os-product-routines/references/continuation-check.md +41 -0
- package/skills/egbe-os-product-routines/references/product-reporting.md +163 -0
- package/skills/egbe-os-product-routines/references/run-preset.md +32 -0
- package/skills/egbe-os-quickstart/scripts/egbe-curl.py +357 -0
- package/skills/egbe-os-quiz-funnel/SKILL.md +152 -0
- package/skills/egbe-os-quiz-funnel/agents/openai.yaml +4 -0
- package/skills/egbe-os-quiz-funnel/assets/engine/quiz-engine.d.mts +224 -0
- package/skills/egbe-os-quiz-funnel/assets/engine/quiz-engine.mjs +652 -0
- package/skills/egbe-os-quiz-funnel/assets/engine/quiz-engine.test.mjs +764 -0
- package/skills/egbe-os-quiz-funnel/assets/engine/quiz-history.d.mts +31 -0
- package/skills/egbe-os-quiz-funnel/assets/engine/quiz-history.mjs +87 -0
- package/skills/egbe-os-quiz-funnel/assets/engine/quiz-history.test.mjs +265 -0
- package/skills/egbe-os-quiz-funnel/assets/engine/quiz-reference.test.mjs +254 -0
- package/skills/egbe-os-quiz-funnel/assets/examples/egbe-docs/product/quizzes/books-checkup/QUIZ.md +195 -0
- package/skills/egbe-os-quiz-funnel/assets/examples/egbe-docs/product/quizzes/books-checkup/quiz.json +421 -0
- package/skills/egbe-os-quiz-funnel/assets/examples/egbe-docs/product/quizzes/books-checkup/quiz.public.json +369 -0
- package/skills/egbe-os-quiz-funnel/assets/examples/egbe-docs/product/quizzes/books-checkup/validation.json +21 -0
- package/skills/egbe-os-quiz-funnel/assets/reference/index.html +26 -0
- package/skills/egbe-os-quiz-funnel/assets/reference/quiz-bootstrap.js +31 -0
- package/skills/egbe-os-quiz-funnel/assets/reference/quiz-early-actions.mjs +11 -0
- package/skills/egbe-os-quiz-funnel/assets/reference/quiz-first-screen.mjs +32 -0
- package/skills/egbe-os-quiz-funnel/assets/reference/quiz-page.mjs +480 -0
- package/skills/egbe-os-quiz-funnel/assets/reference/quiz.css +264 -0
- package/skills/egbe-os-quiz-funnel/references/competitor-teardown.md +159 -0
- package/skills/egbe-os-quiz-funnel/references/conversion-handoff.md +156 -0
- package/skills/egbe-os-quiz-funnel/references/implementation.md +207 -0
- package/skills/egbe-os-quiz-funnel/references/inputs.md +37 -0
- package/skills/egbe-os-quiz-funnel/references/measurement.md +122 -0
- package/skills/egbe-os-quiz-funnel/references/spec-contract.md +335 -0
- package/skills/egbe-os-quiz-funnel/references/verification.md +101 -0
- package/skills/egbe-os-quiz-funnel/references/walk-mechanics.v2.json +18 -0
- package/skills/egbe-os-quiz-funnel/scripts/compile-quiz-spec.py +1869 -0
- package/skills/egbe-os-quiz-funnel/scripts/prepare-research-identity.py +66 -0
- package/skills/egbe-os-reddit-ads/SKILL.md +121 -0
- package/skills/egbe-os-reddit-ads/assets/static-banners/bold-statement/schema.json +41 -0
- package/skills/egbe-os-reddit-ads/assets/static-banners/bold-statement/template.html +106 -0
- package/skills/egbe-os-reddit-ads/assets/static-banners/data-proof/schema.json +61 -0
- package/skills/egbe-os-reddit-ads/assets/static-banners/data-proof/template.html +151 -0
- package/skills/egbe-os-reddit-ads/assets/static-banners/honest-breakdown/schema.json +91 -0
- package/skills/egbe-os-reddit-ads/assets/static-banners/honest-breakdown/template.html +185 -0
- package/skills/egbe-os-reddit-ads/assets/static-banners/question-hook/schema.json +51 -0
- package/skills/egbe-os-reddit-ads/assets/static-banners/question-hook/template.html +121 -0
- package/skills/egbe-os-reddit-ads/assets/static-banners/reddit-post-style/schema.json +87 -0
- package/skills/egbe-os-reddit-ads/assets/static-banners/reddit-post-style/template.html +212 -0
- package/skills/egbe-os-reddit-ads/references/creative/html-to-png-pipeline.md +123 -0
- package/skills/egbe-os-reddit-ads/references/creative/static-banner-qa.md +12 -0
- package/skills/egbe-os-reddit-ads/references/creative/static-banner-system.md +16 -0
- package/skills/egbe-os-reddit-ads/references/destination-requirements.md +36 -0
- package/skills/egbe-os-reddit-ads/references/runtime/api-reference.md +435 -0
- package/skills/egbe-os-reddit-ads/references/runtime/artifacts.md +57 -0
- package/skills/egbe-os-reddit-ads/references/runtime/monitoring.md +64 -0
- package/skills/egbe-os-reddit-ads/references/runtime/pixel-and-tracking.md +49 -0
- package/skills/egbe-os-reddit-ads/references/runtime/policies.md +19 -0
- package/skills/egbe-os-reddit-ads/references/runtime/shared-analytics-attribution.md +14 -0
- package/skills/egbe-os-reddit-ads/references/workflows/build-paused.md +35 -0
- package/skills/egbe-os-reddit-ads/references/workflows/launch-ready.md +19 -0
- package/skills/egbe-os-reddit-ads/references/workflows/launch.md +32 -0
- package/skills/egbe-os-reddit-ads/references/workflows/readiness.md +9 -0
- package/skills/egbe-os-reddit-ads/scripts/capture-ad.sh +178 -0
- package/skills/egbe-os-reddit-ads/scripts/validate-reddit-artifacts.py +187 -0
- package/skills/egbe-os-report-ui/SKILL.md +133 -0
- package/skills/egbe-os-report-ui/assets/egbe-wordmark.svg +9 -0
- package/skills/egbe-os-report-ui/assets/examples/components.html +417 -0
- package/skills/egbe-os-report-ui/assets/examples/editorial.html +209 -0
- package/skills/egbe-os-report-ui/assets/scaffold.html +179 -0
- package/skills/egbe-os-report-ui/references/components.md +209 -0
- package/skills/egbe-os-research/SKILL.md +125 -0
- package/skills/egbe-os-saas-unit-economics/SKILL.md +188 -0
- package/skills/egbe-os-scrape/SKILL.md +160 -0
- package/skills/egbe-os-search/SKILL.md +182 -0
- package/skills/egbe-os-search/references/google-places.md +81 -0
- package/skills/egbe-os-support/SKILL.md +149 -0
- package/skills/egbe-os-telemetry/SKILL.md +344 -0
- package/skills/egbe-os-telemetry/references/harnesses/claude-code.md +97 -0
- package/skills/egbe-os-telemetry/references/harnesses/codex.md +22 -0
- package/skills/egbe-os-telemetry/references/harnesses/hermes.md +39 -0
- package/skills/egbe-os-telemetry/references/harnesses/openclaw.md +139 -0
- package/skills/egbe-os-telemetry/references/harnesses/opencode.md +28 -0
- package/skills/egbe-os-tools/SKILL.md +180 -0
- package/skills/egbe-os-tools/references/theona.md +26 -0
- package/skills/egbe-os-wallet/SKILL.md +181 -0
- package/skills/egbe-setup/EGBE.md +484 -0
- package/skills/egbe-setup/SKILL.md +116 -0
- package/skills/egbe-setup/references/project.md +80 -0
- package/state.js +37 -0
- package/update.js +361 -0
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const { metricNumber } = require("./run-config");
|
|
4
|
+
|
|
5
|
+
const COUNTERS = ["contacted_count", "new_leads_contacted_count", "leads_count",
|
|
6
|
+
"emails_sent_count", "reply_count_unique", "bounced_count", "unsubscribed_count",
|
|
7
|
+
"open_count_unique", "spam_complaint_count", "spam_count", "positive_reply_count"];
|
|
8
|
+
|
|
9
|
+
function matchesCampaign(value, campaignId) {
|
|
10
|
+
return value && typeof value === "object" && ["campaign", "campaign_id"].every(key =>
|
|
11
|
+
value[key] == null || value[key] === campaignId);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
async function read(operation) {
|
|
15
|
+
try { return await operation(); }
|
|
16
|
+
catch { return { status: 0, body: null }; }
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// These rows are a diagnostic sample, never complete campaign counts or rate
|
|
20
|
+
// denominators. Keep the legacy partial fallback only when analytics is absent
|
|
21
|
+
// or its all-zero activity is contradicted by actual messages (#3790).
|
|
22
|
+
async function emailSample(client, campaignId) {
|
|
23
|
+
const limit = 100;
|
|
24
|
+
const sent = await read(() => client.listEmails({ campaign_id: campaignId, email_type: "sent", limit }));
|
|
25
|
+
if (sent.status < 200 || sent.status >= 300 || !Array.isArray(sent.body?.items)
|
|
26
|
+
|| sent.body.items.some(item => !matchesCampaign(item, campaignId))) return null;
|
|
27
|
+
const received = await read(() => client.listEmails({ campaign_id: campaignId, email_type: "received", limit }));
|
|
28
|
+
const receivedUsable = received.status >= 200 && received.status < 300
|
|
29
|
+
&& Array.isArray(received.body?.items)
|
|
30
|
+
&& received.body.items.every(item => matchesCampaign(item, campaignId));
|
|
31
|
+
const address = (item, keys) => {
|
|
32
|
+
const value = keys.map(key => item[key]).find(value => typeof value === "string" && value.trim());
|
|
33
|
+
return value ? value.split(",")[0].trim().toLowerCase() : null;
|
|
34
|
+
};
|
|
35
|
+
const recipients = new Set(sent.body.items.map(item =>
|
|
36
|
+
address(item, ["to_address_email_list", "to_address_email", "lead"])).filter(Boolean));
|
|
37
|
+
const repliers = receivedUsable ? new Set(received.body.items.map(item =>
|
|
38
|
+
address(item, ["from_address_email", "from_address", "lead"])).filter(Boolean)) : null;
|
|
39
|
+
return { emails_sent_count: sent.body.items.length, contacted_count: recipients.size,
|
|
40
|
+
reply_count_unique: repliers?.size ?? null, _source: "emails-fallback", _partial: true, _capped_at: limit };
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function completeMembership(counts) {
|
|
44
|
+
return counts?.ok && !counts.partial && counts.contact_activity_unknown === 0;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
async function collectCampaignMetrics(client, campaignId, campaign) {
|
|
48
|
+
campaign = campaign || {};
|
|
49
|
+
const responses = await Promise.all([
|
|
50
|
+
read(() => client.campaignAnalytics(campaignId)),
|
|
51
|
+
read(() => client.analyticsOverview([campaignId])),
|
|
52
|
+
]);
|
|
53
|
+
const sources = ["campaign-analytics", "campaign-filtered-overview"];
|
|
54
|
+
let metrics = {};
|
|
55
|
+
const fieldSources = {};
|
|
56
|
+
const rejected = [];
|
|
57
|
+
for (const [index, response] of responses.entries()) {
|
|
58
|
+
if (!(response.status >= 200 && response.status < 300) || !response.body
|
|
59
|
+
|| typeof response.body !== "object" || Array.isArray(response.body)) continue;
|
|
60
|
+
if (!matchesCampaign(response.body, campaignId)) { rejected.push(sources[index]); continue; }
|
|
61
|
+
if (!COUNTERS.some(key => metricNumber(response.body[key]) != null)) continue;
|
|
62
|
+
if (!metrics._source) {
|
|
63
|
+
metrics = Object.fromEntries(Object.entries(response.body).filter(([key]) => !key.startsWith("_")));
|
|
64
|
+
metrics._source = sources[index];
|
|
65
|
+
}
|
|
66
|
+
for (const key of COUNTERS) {
|
|
67
|
+
if (metricNumber(response.body[key]) != null && !fieldSources[key]) {
|
|
68
|
+
metrics[key] = response.body[key];
|
|
69
|
+
fieldSources[key] = sources[index];
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
if (!metrics._source) {
|
|
74
|
+
const fallback = await emailSample(client, campaignId);
|
|
75
|
+
const unavailable = fallback || { _source: "unavailable", _partial: true };
|
|
76
|
+
if (rejected.length) unavailable._rejected_sources = rejected;
|
|
77
|
+
return { metrics: unavailable, leadCounts: null };
|
|
78
|
+
}
|
|
79
|
+
metrics._field_sources = fieldSources;
|
|
80
|
+
if (rejected.length) metrics._rejected_sources = rejected;
|
|
81
|
+
|
|
82
|
+
// Missing complaints cannot make an otherwise complete bounce observation
|
|
83
|
+
// partial. A bounded email sample cannot fill that missing complaint signal.
|
|
84
|
+
const activity = [metrics.emails_sent_count, metrics.new_leads_contacted_count,
|
|
85
|
+
metrics.reply_count_unique, metrics.bounced_count].some(value => metricNumber(value) > 0);
|
|
86
|
+
if (metrics.contacted_count === 0 && !activity && campaign.lead_stats == null) {
|
|
87
|
+
const sample = await emailSample(client, campaignId);
|
|
88
|
+
if (sample && sample.emails_sent_count > 0 && !(metrics.emails_sent_count > 0))
|
|
89
|
+
return { metrics: { ...sample, _analytics_rejected_reason: "zero_activity_contradicted_by_emails" }, leadCounts: null };
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
let leadCounts = null;
|
|
93
|
+
const membership = async () => {
|
|
94
|
+
if (leadCounts == null) leadCounts = await client.countLeads(campaignId).catch(() => ({ ok: false }));
|
|
95
|
+
return leadCounts;
|
|
96
|
+
};
|
|
97
|
+
const raw = metricNumber(metrics.contacted_count);
|
|
98
|
+
const newContacts = metricNumber(metrics.new_leads_contacted_count);
|
|
99
|
+
// Already needed for utilization with null lead_stats. A disagreement between
|
|
100
|
+
// counters can also expose repeat sends counted as unique within a large list.
|
|
101
|
+
if (metricNumber(campaign.lead_stats?.total) == null
|
|
102
|
+
|| (raw != null && newContacts != null && raw !== newContacts)) await membership();
|
|
103
|
+
const corroborated = completeMembership(leadCounts) && newContacts === leadCounts.contacted;
|
|
104
|
+
const totals = [campaign.lead_stats?.total, metrics.leads_count,
|
|
105
|
+
leadCounts?.ok && !leadCounts.partial ? leadCounts.total : null].map(metricNumber).filter(value => value != null);
|
|
106
|
+
const invalid = raw == null || !Number.isInteger(raw) || totals.some(total => raw > total)
|
|
107
|
+
|| (corroborated && raw !== leadCounts.contacted)
|
|
108
|
+
|| (raw === 0 && (activity || (completeMembership(leadCounts) && leadCounts.contacted > 0)));
|
|
109
|
+
if (invalid) {
|
|
110
|
+
const counts = await membership();
|
|
111
|
+
const populationMatches = completeMembership(counts)
|
|
112
|
+
&& newContacts === counts.contacted
|
|
113
|
+
&& !(counts.contacted === 0 && activity);
|
|
114
|
+
metrics._raw_contacted_count = metrics.contacted_count ?? null;
|
|
115
|
+
metrics._contacted_count_recovery = { source: "campaign-leads", complete: !!completeMembership(counts),
|
|
116
|
+
total: counts.total ?? null, contacted: counts.contacted ?? null, population_matches: !!populationMatches };
|
|
117
|
+
metrics.contacted_count = populationMatches ? counts.contacted : null;
|
|
118
|
+
delete fieldSources.contacted_count;
|
|
119
|
+
if (populationMatches) fieldSources.contacted_count = "campaign-leads";
|
|
120
|
+
}
|
|
121
|
+
return { metrics, leadCounts };
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
module.exports = { collectCampaignMetrics };
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
// Known local project opt-outs only; owned exact-ID exclusion with scoped
|
|
2
|
+
// campaign containment when native exclusion cannot be confirmed.
|
|
3
|
+
const { assessRecipient } = require("./recipient-exclusion");
|
|
4
|
+
const fs = require("fs");
|
|
5
|
+
const path = require("path");
|
|
6
|
+
const { DatabaseSync } = require("node:sqlite");
|
|
7
|
+
const { normalizeEmail, readJson, assertCampaignNotForeign } = require("./helpers");
|
|
8
|
+
const { dbPathForRun } = require("./outreach-db");
|
|
9
|
+
|
|
10
|
+
function successful(response) {
|
|
11
|
+
return response?.status >= 200 && response.status < 300;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function hasSendingEvidence(value) {
|
|
15
|
+
if (!value || typeof value !== "object") return false;
|
|
16
|
+
if (Array.isArray(value)) return value.some(hasSendingEvidence);
|
|
17
|
+
if (value.first_launched_at || value.last_activated_at) return true;
|
|
18
|
+
if (["launched", "active", "sending"].includes(value.launch_status || value.status)) return true;
|
|
19
|
+
if (successful(value.activation) || value.campaign_status === 1) return true;
|
|
20
|
+
for (const key of ["emails_sent_count", "contacted_count", "reply_count", "reply_count_unique", "unique_replies", "sent_count", "contacted", "emails_sent", "replies"])
|
|
21
|
+
if (Number(value[key]) > 0) return true;
|
|
22
|
+
return ["campaign", "metrics", "metrics_summary", "observation", "sending_status"].some((key) => hasSendingEvidence(value[key]));
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function recoveryRuns(runDir) {
|
|
26
|
+
const directory = path.dirname(path.resolve(runDir));
|
|
27
|
+
if (!fs.existsSync(directory)) return [];
|
|
28
|
+
const runs = [];
|
|
29
|
+
for (const entry of fs.readdirSync(directory, { withFileTypes: true })) {
|
|
30
|
+
if (!entry.isDirectory()) continue;
|
|
31
|
+
const dir = path.join(directory, entry.name);
|
|
32
|
+
const manifest = readJson(path.join(dir, "manifest.json"), null);
|
|
33
|
+
const summary = readJson(path.join(dir, "launch-summary.json"), null);
|
|
34
|
+
const monitor = readJson(path.join(dir, "monitor-summary.json"), null);
|
|
35
|
+
const history = readJson(path.join(dir, "state", "analytics-history.json"), []);
|
|
36
|
+
const conclusion = readJson(path.join(dir, "conclusion.json"), null);
|
|
37
|
+
const queue = readJson(path.join(dir, "reply-queue.json"), []);
|
|
38
|
+
const processed = readJson(path.join(dir, "state", "processed-replies.json"), []);
|
|
39
|
+
if (!Array.isArray(queue) || !Array.isArray(processed) || !Array.isArray(history))
|
|
40
|
+
throw new Error(`Opt-out history unknown: malformed recovery state in ${dir}`);
|
|
41
|
+
const sent = [manifest, summary, monitor, history, conclusion].some(hasSendingEvidence)
|
|
42
|
+
|| (Array.isArray(queue) && queue.length > 0) || (Array.isArray(processed) && processed.length > 0);
|
|
43
|
+
const run_key = manifest?.run_key || summary?.run_key || monitor?.run_key || conclusion?.run_key;
|
|
44
|
+
const campaign_id = manifest?.campaign?.id || summary?.campaign_id || monitor?.campaign_id
|
|
45
|
+
|| conclusion?.campaign_id;
|
|
46
|
+
if (sent && (!run_key || !campaign_id))
|
|
47
|
+
throw new Error(`Opt-out history unknown: sending recovery artifacts in ${dir} lack run/campaign identity`);
|
|
48
|
+
if (run_key || campaign_id) runs.push({ run_key, campaign_id, sent, runDir: dir,
|
|
49
|
+
confirmed: queue.filter((item) => item.opt_out_confirmed),
|
|
50
|
+
ownership: readJson(path.join(dir, "state", "ownership.json"), manifest?.ownership || {}) });
|
|
51
|
+
}
|
|
52
|
+
return runs;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function readOptOutHistory(runDir) {
|
|
56
|
+
const dbPath = dbPathForRun(runDir);
|
|
57
|
+
let db;
|
|
58
|
+
try {
|
|
59
|
+
const recovered = recoveryRuns(runDir);
|
|
60
|
+
if (!fs.existsSync(dbPath)) {
|
|
61
|
+
if (recovered.some((run) => run.sent))
|
|
62
|
+
throw new Error("outreach.db is missing but recovery artifacts show prior sending");
|
|
63
|
+
return { dbPath, emails: new Set(), runs: [], recoveryRuns: recovered };
|
|
64
|
+
}
|
|
65
|
+
// Never call initDb here: an empty replacement must not look like history.
|
|
66
|
+
db = new DatabaseSync(dbPath, { readOnly: true });
|
|
67
|
+
db.exec("PRAGMA busy_timeout=5000;");
|
|
68
|
+
const runs = db.prepare("SELECT run_key, campaign_id, status FROM outreach_runs").all();
|
|
69
|
+
db.prepare("SELECT run_key, email, imported_at, last_contacted_at FROM run_leads LIMIT 0").all();
|
|
70
|
+
const events = db.prepare("SELECT run_key, email, payload_json FROM lead_events WHERE event_type = 'opt_out_confirmed'").all();
|
|
71
|
+
if (db.prepare("PRAGMA foreign_key_check").all().length)
|
|
72
|
+
throw new Error("outreach.db has incomplete related history");
|
|
73
|
+
for (const run of recovered.filter((item) => item.sent)) {
|
|
74
|
+
if (!runs.some((row) => row.run_key === run.run_key && row.campaign_id === run.campaign_id))
|
|
75
|
+
throw new Error(`sending run ${run.run_key} (${run.campaign_id}) is missing from outreach.db`);
|
|
76
|
+
}
|
|
77
|
+
const emails = new Set();
|
|
78
|
+
for (const event of events) {
|
|
79
|
+
const payload = JSON.parse(event.payload_json);
|
|
80
|
+
const email = normalizeEmail(event.email);
|
|
81
|
+
if (!email || !payload?.message_id || !payload?.campaign_id)
|
|
82
|
+
throw new Error("confirmed opt-out event is incomplete");
|
|
83
|
+
emails.add(email);
|
|
84
|
+
}
|
|
85
|
+
for (const run of recovered) {
|
|
86
|
+
for (const item of run.confirmed) {
|
|
87
|
+
if (!events.some((event) => event.run_key === run.run_key
|
|
88
|
+
&& normalizeEmail(event.email) === normalizeEmail(item.recipient_email)
|
|
89
|
+
&& JSON.parse(event.payload_json)?.message_id === item.email_id))
|
|
90
|
+
throw new Error(`confirmed reply ${item.email_id} is missing from outreach.db`);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
return { dbPath, emails, runs, recoveryRuns: recovered };
|
|
94
|
+
} catch (error) {
|
|
95
|
+
throw new Error(`Opt-out history unavailable; restore/check project outreach.db before sending: ${error.message}`);
|
|
96
|
+
} finally {
|
|
97
|
+
db?.close();
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function filterConfirmedOptOuts(runDir, leads) {
|
|
102
|
+
const history = readOptOutHistory(runDir);
|
|
103
|
+
const excluded = [];
|
|
104
|
+
const allowed = leads.filter((lead) => {
|
|
105
|
+
if (!history.emails.has(normalizeEmail(lead?.email))) return true;
|
|
106
|
+
excluded.push(lead);
|
|
107
|
+
return false;
|
|
108
|
+
});
|
|
109
|
+
return { leads: allowed, excluded, history };
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function assertRecipientNotOptedOut(runDir, email) {
|
|
113
|
+
email = normalizeEmail(email);
|
|
114
|
+
if (!email) throw new Error("Campaign recipient unknown; verify the original thread before sending");
|
|
115
|
+
if (readOptOutHistory(runDir).emails.has(email))
|
|
116
|
+
throw new Error(`Recipient ${email} has a confirmed opt-out; no reply may be sent`);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// A forwarded reply's author is not automatically the campaign recipient.
|
|
120
|
+
// An explicit operator selection is still checked against campaign membership.
|
|
121
|
+
function resolveCampaignRecipient(item, knownEmails, explicit) {
|
|
122
|
+
const known = new Set([...knownEmails].map(normalizeEmail));
|
|
123
|
+
const supplied = explicit || item.recipient_email || item.lead_email;
|
|
124
|
+
if (supplied) {
|
|
125
|
+
const candidate = normalizeEmail(supplied);
|
|
126
|
+
if (!known.has(candidate)) throw new Error("Selected recipient is not a known lead in this campaign");
|
|
127
|
+
return candidate;
|
|
128
|
+
}
|
|
129
|
+
const author = normalizeEmail(item.from_email);
|
|
130
|
+
if (known.has(author)) return author;
|
|
131
|
+
throw new Error("Campaign recipient unknown (possibly a forwarded reply); check the original thread and pass --recipient-email");
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
function campaignSafetyReadback(campaign) {
|
|
135
|
+
return Object.fromEntries(["stop_on_reply", "stop_on_auto_reply", "insert_unsubscribe_header"]
|
|
136
|
+
.map((key) => [key, typeof campaign?.[key] === "boolean" ? campaign[key] : null]));
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
function checkKnownOwnership(campaign, ownership, campaignId) {
|
|
140
|
+
// Missing local tags cannot overrule a successful tenant-authorized gateway
|
|
141
|
+
// read. When expectations exist, preserve the local conflict check as well.
|
|
142
|
+
if (ownership && ["run_tag_id", "agent_tag_id", "run_tag_label", "agent_tag_label"].some((key) => ownership[key]))
|
|
143
|
+
assertCampaignNotForeign(campaign, ownership, `campaign ${campaignId}`);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
async function stopConfirmedRecipient(client, runDir, email) {
|
|
147
|
+
email = normalizeEmail(email);
|
|
148
|
+
const history = readOptOutHistory(runDir);
|
|
149
|
+
if (!history.emails.has(email)) throw new Error("Recipient has no confirmed opt-out event");
|
|
150
|
+
const campaigns = new Map();
|
|
151
|
+
for (const run of [...history.runs, ...history.recoveryRuns]) {
|
|
152
|
+
if (!run.campaign_id) continue;
|
|
153
|
+
campaigns.set(run.campaign_id, { ...(campaigns.get(run.campaign_id) || {}), ...run });
|
|
154
|
+
}
|
|
155
|
+
const results = [];
|
|
156
|
+
for (const [campaignId, run] of campaigns) {
|
|
157
|
+
const result = { campaign_id: campaignId, run_key: run.run_key, stopped: false };
|
|
158
|
+
results.push(result);
|
|
159
|
+
try {
|
|
160
|
+
// This gateway read is tenant-authorized; local tags only reject a known
|
|
161
|
+
// conflict and never grant permission to touch another campaign.
|
|
162
|
+
const response = await client.getCampaign(campaignId);
|
|
163
|
+
if (!successful(response)) throw new Error(`Campaign readback failed (${response.status}); ownership/stop unknown`);
|
|
164
|
+
checkKnownOwnership(response.body, run.ownership, campaignId);
|
|
165
|
+
result.settings = campaignSafetyReadback(response.body);
|
|
166
|
+
result.campaign_status = response.body?.status ?? null;
|
|
167
|
+
const exclusion = await assessRecipient(client, campaignId, email, { confirmed: true, mutate: true });
|
|
168
|
+
result.recipient_exclusion = exclusion;
|
|
169
|
+
result.membership = exclusion.state === "absent" ? "absent" : exclusion.evidence?.length ? "present" : "unknown";
|
|
170
|
+
if (["absent", "excluded"].includes(exclusion.state)) {
|
|
171
|
+
result.stopped = true;
|
|
172
|
+
result.action = exclusion.state === "absent" ? "recipient_absent" : "recipient_excluded";
|
|
173
|
+
continue;
|
|
174
|
+
}
|
|
175
|
+
if (response.body?.status === 2) {
|
|
176
|
+
result.stopped = true;
|
|
177
|
+
result.action = "campaign_already_paused";
|
|
178
|
+
continue;
|
|
179
|
+
}
|
|
180
|
+
// Settings alone do not prove this lead stopped. Unsupported or uncertain
|
|
181
|
+
// native exclusion still requires containment of this owned campaign.
|
|
182
|
+
// Unknown membership is conservatively contained by pausing this owned
|
|
183
|
+
// campaign too; no global campaign/account pause is performed.
|
|
184
|
+
try {
|
|
185
|
+
const pause = await client.pauseCampaign(campaignId);
|
|
186
|
+
result.pause_status = pause.status;
|
|
187
|
+
} catch (error) {
|
|
188
|
+
// A timeout may follow a successful pause; read before retrying it.
|
|
189
|
+
result.pause_error = error.message;
|
|
190
|
+
}
|
|
191
|
+
const readback = await client.getCampaign(campaignId);
|
|
192
|
+
if (successful(readback))
|
|
193
|
+
checkKnownOwnership(readback.body, run.ownership, campaignId);
|
|
194
|
+
result.readback_status = successful(readback) ? readback.body?.status ?? null : null;
|
|
195
|
+
result.stopped = successful(readback) && readback.body?.status === 2;
|
|
196
|
+
result.action = result.stopped ? "campaign_paused" : "provider_action_unresolved";
|
|
197
|
+
if (!result.stopped) result.error = "Recipient stop unconfirmed after scoped pause; inspect provider before resuming";
|
|
198
|
+
} catch (error) {
|
|
199
|
+
result.action = "provider_action_unresolved";
|
|
200
|
+
result.error = error.message;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
return { email, ok: results.length > 0 && results.every((result) => result.stopped), campaigns: results,
|
|
204
|
+
limitation: "Known local project campaigns only; main-sequence exclusion does not cancel in-flight mail; campaign pause is containment, not provider-wide suppression" };
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
module.exports = { readOptOutHistory, filterConfirmedOptOuts, assertRecipientNotOptedOut,
|
|
208
|
+
resolveCampaignRecipient, campaignSafetyReadback, stopConfirmedRecipient };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
const { spawnSync } = require('child_process');
|
|
4
|
+
|
|
5
|
+
module.exports = function connectionHeaders(url, envFile = null) {
|
|
6
|
+
const root = path.resolve(__dirname, '../..');
|
|
7
|
+
const quickstart = path.basename(root).startsWith('egbe-os-') ? 'egbe-os-quickstart' : 'quickstart';
|
|
8
|
+
const helper = path.resolve(root, '..', quickstart, 'scripts/egbe-curl.py');
|
|
9
|
+
if (!fs.existsSync(helper) || (!envFile && !process.env.OS_AGENT_NAME)) return {};
|
|
10
|
+
const args = [helper, '--identity-headers', url];
|
|
11
|
+
if (envFile) args.push('--env-file', envFile);
|
|
12
|
+
const result = spawnSync('python3', args, {
|
|
13
|
+
encoding: 'utf8', maxBuffer: 65536, windowsHide: true,
|
|
14
|
+
});
|
|
15
|
+
if (result.status !== 0) return {};
|
|
16
|
+
try { return JSON.parse(result.stdout); } catch { return {}; }
|
|
17
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// Adding leads is not repeated on a 5xx, because the batch may have landed
|
|
2
|
+
// anyway; before the next add, leave out leads already in the campaign.
|
|
3
|
+
|
|
4
|
+
// Unknown or incomplete reads cannot establish that a previous import did
|
|
5
|
+
// not land. Stop before writing instead of relying on provider deduplication.
|
|
6
|
+
function leadsNotInCampaign(leads, present) {
|
|
7
|
+
if (!present?.ok || !(present.emails instanceof Set)) {
|
|
8
|
+
throw new Error(
|
|
9
|
+
"Campaign lead list unavailable or incomplete; import stopped to avoid duplicate leads. " +
|
|
10
|
+
"Restore the lead read surface and re-run; do not resend an uncertain batch manually.",
|
|
11
|
+
);
|
|
12
|
+
}
|
|
13
|
+
return leads.filter(
|
|
14
|
+
(lead) =>
|
|
15
|
+
!present.emails.has(
|
|
16
|
+
String(lead.email || "")
|
|
17
|
+
.trim()
|
|
18
|
+
.toLowerCase(),
|
|
19
|
+
),
|
|
20
|
+
);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
module.exports = { leadsNotInCampaign };
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const GTM_IDENTITY_FIELDS = Object.freeze([
|
|
4
|
+
"business_id",
|
|
5
|
+
"product_id",
|
|
6
|
+
"launch_id",
|
|
7
|
+
"experiment_id",
|
|
8
|
+
"variant_id",
|
|
9
|
+
]);
|
|
10
|
+
|
|
11
|
+
const STABLE_ID_PATTERN = /^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$/;
|
|
12
|
+
const INSTANTLY_PROVIDER = "instantly";
|
|
13
|
+
const INSTANTLY_UTM_MEDIUM = "email";
|
|
14
|
+
|
|
15
|
+
function assertStableGtmIdentifiers(record, label) {
|
|
16
|
+
if (!record || typeof record !== "object" || Array.isArray(record)) {
|
|
17
|
+
throw new Error(`${label} must be a JSON object`);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
for (const field of GTM_IDENTITY_FIELDS) {
|
|
21
|
+
const value = record[field];
|
|
22
|
+
if (value == null) continue;
|
|
23
|
+
if (typeof value !== "string" || !STABLE_ID_PATTERN.test(value)) {
|
|
24
|
+
throw new Error(
|
|
25
|
+
`${label}.${field} must be a stable GTM identifier when provided`,
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function reconcileRunIdentity(manifest, spec) {
|
|
32
|
+
assertStableGtmIdentifiers(manifest, "manifest");
|
|
33
|
+
assertStableGtmIdentifiers(spec, "run spec");
|
|
34
|
+
|
|
35
|
+
const incomingRunKey = spec.run_key;
|
|
36
|
+
const storedRunKey = manifest.run_key;
|
|
37
|
+
if (storedRunKey != null && storedRunKey !== incomingRunKey) {
|
|
38
|
+
throw new Error(
|
|
39
|
+
`Immutable Instantly run identity conflict for run_key: manifest has "${storedRunKey}" but run spec has "${incomingRunKey}"`,
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
for (const field of GTM_IDENTITY_FIELDS) {
|
|
43
|
+
const stored = manifest[field];
|
|
44
|
+
const incoming = spec[field];
|
|
45
|
+
if (stored != null && incoming != null && stored !== incoming) {
|
|
46
|
+
throw new Error(
|
|
47
|
+
`Immutable Instantly run identity conflict for ${field}: manifest has "${stored}" but run spec has "${incoming}"`,
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if (storedRunKey == null) manifest.run_key = incomingRunKey;
|
|
53
|
+
for (const field of GTM_IDENTITY_FIELDS) {
|
|
54
|
+
const stored = manifest[field];
|
|
55
|
+
const incoming = spec[field];
|
|
56
|
+
if (stored != null && incoming == null) spec[field] = stored;
|
|
57
|
+
if (stored == null && incoming != null) manifest[field] = incoming;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return { manifest, spec };
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function reconcileInstantlyAttribution(
|
|
64
|
+
record,
|
|
65
|
+
{ runKey, campaignId = null, label = "artifact" },
|
|
66
|
+
) {
|
|
67
|
+
if (!record || typeof record !== "object" || Array.isArray(record)) {
|
|
68
|
+
throw new Error(`${label} must be a JSON object`);
|
|
69
|
+
}
|
|
70
|
+
if (typeof runKey !== "string" || !runKey) {
|
|
71
|
+
throw new Error("run_key is required for Instantly attribution");
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const campaignCandidates = [
|
|
75
|
+
["campaign.id", record.campaign?.id ?? null],
|
|
76
|
+
["campaign_id", record.campaign_id ?? null],
|
|
77
|
+
["provider_campaign_id", record.provider_campaign_id ?? null],
|
|
78
|
+
["expected provider_campaign_id", campaignId],
|
|
79
|
+
].filter(([, value]) => value != null && value !== "");
|
|
80
|
+
if (campaignCandidates.length > 1) {
|
|
81
|
+
const expected = String(campaignCandidates[0][1]);
|
|
82
|
+
const conflict = campaignCandidates.find(
|
|
83
|
+
([, value]) => String(value) !== expected,
|
|
84
|
+
);
|
|
85
|
+
if (conflict) {
|
|
86
|
+
throw new Error(
|
|
87
|
+
`Immutable Instantly attribution conflict for provider_campaign_id: ${campaignCandidates[0][0]} has "${expected}" but ${conflict[0]} has "${conflict[1]}"`,
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const canonical = {
|
|
93
|
+
provider: INSTANTLY_PROVIDER,
|
|
94
|
+
utm_source: INSTANTLY_PROVIDER,
|
|
95
|
+
utm_medium: INSTANTLY_UTM_MEDIUM,
|
|
96
|
+
utm_campaign: runKey,
|
|
97
|
+
};
|
|
98
|
+
for (const [field, expected] of Object.entries(canonical)) {
|
|
99
|
+
if (record[field] != null && record[field] !== expected) {
|
|
100
|
+
throw new Error(
|
|
101
|
+
`Immutable Instantly attribution conflict for ${field}: ${label} has "${record[field]}" but expected "${expected}"`,
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
for (const [field, expected] of Object.entries(canonical)) {
|
|
106
|
+
record[field] = expected;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
const providerCampaignId = campaignCandidates.length
|
|
110
|
+
? String(campaignCandidates[0][1])
|
|
111
|
+
: null;
|
|
112
|
+
if (providerCampaignId) record.provider_campaign_id = providerCampaignId;
|
|
113
|
+
|
|
114
|
+
return { ...canonical, provider_campaign_id: providerCampaignId };
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
module.exports = {
|
|
118
|
+
GTM_IDENTITY_FIELDS,
|
|
119
|
+
STABLE_ID_PATTERN,
|
|
120
|
+
INSTANTLY_PROVIDER,
|
|
121
|
+
INSTANTLY_UTM_MEDIUM,
|
|
122
|
+
assertStableGtmIdentifiers,
|
|
123
|
+
reconcileRunIdentity,
|
|
124
|
+
reconcileInstantlyAttribution,
|
|
125
|
+
};
|