@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
package/skills/egbe-os-payments/assets/scaffolds/billing-nextjs-subscription/package.fragment.json
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
{
|
|
2
|
+
"agentsMarker": "EGBE:BILLING-FOUNDATION",
|
|
3
|
+
"expectedScripts": {
|
|
4
|
+
"start": "npm run db:migrate && next start"
|
|
5
|
+
},
|
|
6
|
+
"dependencies": {},
|
|
7
|
+
"devDependencies": {},
|
|
8
|
+
"scripts": {
|
|
9
|
+
"billing:sync": "npm run db:migrate && node scripts/billing-sync.mjs",
|
|
10
|
+
"billing:test": "node --test src/lib/egbe-billing/*.test.mjs"
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { createHash } from "node:crypto";
|
|
3
|
+
import { readFile } from "node:fs/promises";
|
|
4
|
+
import { dirname, resolve } from "node:path";
|
|
5
|
+
import { fileURLToPath } from "node:url";
|
|
6
|
+
|
|
7
|
+
import pg from "pg";
|
|
8
|
+
|
|
9
|
+
const root = resolve(dirname(fileURLToPath(import.meta.url)), "..");
|
|
10
|
+
const catalogPath = resolve(root, "src/lib/egbe-billing/plans.json");
|
|
11
|
+
|
|
12
|
+
function requiredEnv(name) {
|
|
13
|
+
const value = String(process.env[name] || "").trim();
|
|
14
|
+
if (!value) throw new Error(`${name} is required`);
|
|
15
|
+
return value;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function validateCatalog(value) {
|
|
19
|
+
if (!value || value.catalog_version !== 1 || !Array.isArray(value.plans)) {
|
|
20
|
+
throw new Error("Billing plan catalog is invalid");
|
|
21
|
+
}
|
|
22
|
+
const appSlug = String(value.app_slug || "").trim();
|
|
23
|
+
if (!/^[a-z0-9][a-z0-9-]{0,62}$/.test(appSlug)) {
|
|
24
|
+
throw new Error("Billing catalog app_slug must match the deployed product slug");
|
|
25
|
+
}
|
|
26
|
+
const keys = new Set();
|
|
27
|
+
const paid = [];
|
|
28
|
+
for (const plan of value.plans) {
|
|
29
|
+
const planKey = String(plan.plan_key || "").trim();
|
|
30
|
+
if (!/^[a-z][a-z0-9_-]{1,63}$/.test(planKey) || keys.has(planKey)) {
|
|
31
|
+
throw new Error(`Invalid or duplicate plan_key: ${planKey}`);
|
|
32
|
+
}
|
|
33
|
+
keys.add(planKey);
|
|
34
|
+
if ("provider_product_id" in plan || "provider_price_id" in plan) {
|
|
35
|
+
throw new Error(`Plan ${planKey} must not contain provider ids`);
|
|
36
|
+
}
|
|
37
|
+
if (!String(plan.display_name || "").trim() || !String(plan.summary || "").trim()) {
|
|
38
|
+
throw new Error(`Plan ${planKey} requires display_name and summary`);
|
|
39
|
+
}
|
|
40
|
+
if (!/^[a-z]{3}$/.test(String(plan.currency || "")) || typeof plan.selectable !== "boolean") {
|
|
41
|
+
throw new Error(`Plan ${planKey} has an invalid commercial contract`);
|
|
42
|
+
}
|
|
43
|
+
if (!Array.isArray(plan.entitlements) || plan.entitlements.some((item) => typeof item !== "string" || !item.trim())) {
|
|
44
|
+
throw new Error(`Plan ${planKey} has invalid entitlements`);
|
|
45
|
+
}
|
|
46
|
+
if (new Set(plan.entitlements).size !== plan.entitlements.length) {
|
|
47
|
+
throw new Error(`Plan ${planKey} has duplicate entitlements`);
|
|
48
|
+
}
|
|
49
|
+
if (plan.kind === "subscription") {
|
|
50
|
+
if (!Number.isInteger(plan.amount_cents) || plan.amount_cents < 1) {
|
|
51
|
+
throw new Error(`Plan ${planKey} has invalid amount_cents`);
|
|
52
|
+
}
|
|
53
|
+
if (!new Set(["month", "year"]).has(plan.interval)) {
|
|
54
|
+
throw new Error(`Plan ${planKey} has invalid subscription interval`);
|
|
55
|
+
}
|
|
56
|
+
paid.push(plan);
|
|
57
|
+
} else if (plan.kind !== "free") {
|
|
58
|
+
throw new Error(`Plan ${planKey} must be free or subscription`);
|
|
59
|
+
} else if (plan.amount_cents !== 0 || plan.interval !== null) {
|
|
60
|
+
throw new Error(`Free plan ${planKey} must have zero amount and no interval`);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
if (!keys.has("free")) throw new Error("Billing catalog must define the free plan");
|
|
64
|
+
if (!paid.length) throw new Error("Billing catalog must define at least one subscription plan");
|
|
65
|
+
return { appSlug, paid };
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
async function osRequest(baseUrl, apiKey, path, { body, idempotencyKey } = {}) {
|
|
69
|
+
const response = await fetch(`${baseUrl}/payments${path}`, {
|
|
70
|
+
method: body ? "POST" : "GET",
|
|
71
|
+
headers: {
|
|
72
|
+
Authorization: `Bearer ${apiKey}`,
|
|
73
|
+
...(body ? { "Content-Type": "application/json" } : {}),
|
|
74
|
+
...(idempotencyKey ? { "Idempotency-Key": idempotencyKey } : {}),
|
|
75
|
+
},
|
|
76
|
+
body: body ? JSON.stringify(body) : undefined,
|
|
77
|
+
});
|
|
78
|
+
const envelope = await response.json().catch(() => null);
|
|
79
|
+
if (!response.ok || !envelope || envelope.code >= 400) {
|
|
80
|
+
throw new Error(envelope?.message || `Egbe Payments returned HTTP ${response.status}`);
|
|
81
|
+
}
|
|
82
|
+
return envelope.data;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export function metadataFor(appSlug, planKey) {
|
|
86
|
+
return {
|
|
87
|
+
plan_key: planKey,
|
|
88
|
+
payment_gateway_app_slug: appSlug,
|
|
89
|
+
payment_gateway_webhook_path: "/api/payments/webhook",
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
async function main() {
|
|
94
|
+
const source = await readFile(catalogPath, "utf8");
|
|
95
|
+
const catalog = JSON.parse(source);
|
|
96
|
+
const { appSlug, paid } = validateCatalog(catalog);
|
|
97
|
+
const baseUrl = requiredEnv("OS_URL").replace(/\/$/, "");
|
|
98
|
+
const apiKey = requiredEnv("OS_API_KEY");
|
|
99
|
+
const databaseUrl = requiredEnv("DATABASE_URL");
|
|
100
|
+
const digest = createHash("sha256").update(source).digest("hex");
|
|
101
|
+
const bindings = [];
|
|
102
|
+
for (const plan of paid) {
|
|
103
|
+
const metadata = metadataFor(appSlug, plan.plan_key);
|
|
104
|
+
const product = await osRequest(baseUrl, apiKey, "/products", {
|
|
105
|
+
idempotencyKey: `catalog:${appSlug}:${plan.plan_key}:product:v1`,
|
|
106
|
+
body: { name: plan.display_name, description: plan.summary, metadata },
|
|
107
|
+
});
|
|
108
|
+
if (!product?.id) throw new Error(`No provider product returned for ${plan.plan_key}`);
|
|
109
|
+
const price = await osRequest(baseUrl, apiKey, "/prices", {
|
|
110
|
+
idempotencyKey: `catalog:${appSlug}:${plan.plan_key}:price:${plan.amount_cents}:${plan.currency}:${plan.interval}`,
|
|
111
|
+
body: {
|
|
112
|
+
product: product.id,
|
|
113
|
+
unit_amount: plan.amount_cents,
|
|
114
|
+
currency: plan.currency,
|
|
115
|
+
recurring_interval: plan.interval,
|
|
116
|
+
metadata,
|
|
117
|
+
},
|
|
118
|
+
});
|
|
119
|
+
if (!price?.id) throw new Error(`No provider price returned for ${plan.plan_key}`);
|
|
120
|
+
bindings.push({ planKey: plan.plan_key, productId: product.id, priceId: price.id });
|
|
121
|
+
}
|
|
122
|
+
const evidence = await osRequest(baseUrl, apiKey, "/evidence");
|
|
123
|
+
const productIds = new Set((evidence?.products || []).map((item) => item.id));
|
|
124
|
+
const priceIds = new Set((evidence?.prices || []).map((item) => item.id));
|
|
125
|
+
for (const binding of bindings) {
|
|
126
|
+
if (!productIds.has(binding.productId) || !priceIds.has(binding.priceId)) {
|
|
127
|
+
throw new Error(`Provider readback is incomplete for ${binding.planKey}`);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
const client = new pg.Client({ connectionString: databaseUrl });
|
|
131
|
+
await client.connect();
|
|
132
|
+
try {
|
|
133
|
+
await client.query("begin");
|
|
134
|
+
for (const binding of bindings) {
|
|
135
|
+
await client.query(
|
|
136
|
+
`insert into billing_provider_bindings (
|
|
137
|
+
plan_key, provider_product_id, provider_price_id, catalog_digest
|
|
138
|
+
) values ($1, $2, $3, $4)
|
|
139
|
+
on conflict (plan_key) do update set
|
|
140
|
+
provider_product_id = excluded.provider_product_id,
|
|
141
|
+
provider_price_id = excluded.provider_price_id,
|
|
142
|
+
catalog_digest = excluded.catalog_digest,
|
|
143
|
+
synced_at = now()`,
|
|
144
|
+
[binding.planKey, binding.productId, binding.priceId, digest],
|
|
145
|
+
);
|
|
146
|
+
}
|
|
147
|
+
await client.query("commit");
|
|
148
|
+
} catch (error) {
|
|
149
|
+
await client.query("rollback").catch(() => undefined);
|
|
150
|
+
throw error;
|
|
151
|
+
} finally {
|
|
152
|
+
await client.end();
|
|
153
|
+
}
|
|
154
|
+
process.stdout.write(`${JSON.stringify({ ok: true, plans_synced: bindings.length })}\n`);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
if (process.argv[1] && resolve(process.argv[1]) === fileURLToPath(import.meta.url)) {
|
|
158
|
+
main().catch((error) => {
|
|
159
|
+
process.stderr.write(`billing:sync failed: ${String(error?.message || error)}\n`);
|
|
160
|
+
process.exitCode = 1;
|
|
161
|
+
});
|
|
162
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
export default function BillingError({ reset }: { reset: () => void }) {
|
|
4
|
+
return (
|
|
5
|
+
<main data-billing-page>
|
|
6
|
+
<h1>Billing</h1>
|
|
7
|
+
<p data-billing-error>Billing information is temporarily unavailable.</p>
|
|
8
|
+
<button type="button" onClick={reset}>Try again</button>
|
|
9
|
+
</main>
|
|
10
|
+
);
|
|
11
|
+
}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import Link from "next/link";
|
|
2
|
+
|
|
3
|
+
import { ProductAuthenticationRequired, requireProductAccount } from "@/lib/egbe-product";
|
|
4
|
+
import {
|
|
5
|
+
billingCatalog,
|
|
6
|
+
billingPlan,
|
|
7
|
+
formatPlanAmount,
|
|
8
|
+
type BillingPlan,
|
|
9
|
+
} from "@/lib/egbe-billing/catalog";
|
|
10
|
+
import { readBillingState, type BillingState } from "@/lib/egbe-billing/repository";
|
|
11
|
+
|
|
12
|
+
const WARNING_STATES = new Set(["past_due", "canceling", "paused"]);
|
|
13
|
+
|
|
14
|
+
type BillingPageModel =
|
|
15
|
+
| { kind: "signed-out" }
|
|
16
|
+
| { kind: "unavailable" }
|
|
17
|
+
| {
|
|
18
|
+
kind: "ready";
|
|
19
|
+
state: BillingState;
|
|
20
|
+
current: BillingPlan;
|
|
21
|
+
upgrade?: BillingPlan;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
async function loadBillingPage(): Promise<BillingPageModel> {
|
|
25
|
+
try {
|
|
26
|
+
const account = await requireProductAccount();
|
|
27
|
+
const state = await readBillingState(account.id);
|
|
28
|
+
const current =
|
|
29
|
+
billingCatalog.plans.find((plan) => plan.planKey === state.planKey) ??
|
|
30
|
+
billingPlan("free");
|
|
31
|
+
const upgrade = billingCatalog.plans.find(
|
|
32
|
+
(plan) => plan.kind === "subscription" && plan.selectable,
|
|
33
|
+
);
|
|
34
|
+
return { kind: "ready", state, current, upgrade };
|
|
35
|
+
} catch (error) {
|
|
36
|
+
if (error instanceof ProductAuthenticationRequired) return { kind: "signed-out" };
|
|
37
|
+
console.error("billing page failed", error);
|
|
38
|
+
return { kind: "unavailable" };
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export default async function AccountBillingPage() {
|
|
43
|
+
const model = await loadBillingPage();
|
|
44
|
+
if (model.kind === "signed-out") {
|
|
45
|
+
return (
|
|
46
|
+
<main data-billing-page>
|
|
47
|
+
<h1>Billing</h1>
|
|
48
|
+
<p>Sign in through the product account journey to view billing.</p>
|
|
49
|
+
<Link href="/login?next=/account/billing">Sign in</Link>
|
|
50
|
+
</main>
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
if (model.kind === "unavailable") {
|
|
54
|
+
return (
|
|
55
|
+
<main data-billing-page>
|
|
56
|
+
<h1>Billing</h1>
|
|
57
|
+
<p data-billing-error>Billing information is temporarily unavailable. Please try again.</p>
|
|
58
|
+
<Link href="/account/billing">Retry</Link>
|
|
59
|
+
</main>
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const { current, state, upgrade } = model;
|
|
64
|
+
const paid = current.kind === "subscription";
|
|
65
|
+
const warning = WARNING_STATES.has(state.status);
|
|
66
|
+
return (
|
|
67
|
+
<main data-billing-page aria-labelledby="billing-title">
|
|
68
|
+
<header>
|
|
69
|
+
<p>Account</p>
|
|
70
|
+
<h1 id="billing-title">Billing</h1>
|
|
71
|
+
<p>Understand your current plan and manage it safely.</p>
|
|
72
|
+
</header>
|
|
73
|
+
<section aria-label="Current billing state">
|
|
74
|
+
<div data-billing-plan={current.planKey}>
|
|
75
|
+
<span>Current plan</span>
|
|
76
|
+
<strong>{current.displayName}</strong>
|
|
77
|
+
</div>
|
|
78
|
+
<div data-billing-status={state.status}>
|
|
79
|
+
<span>Status</span>
|
|
80
|
+
<strong>{state.status.replace("_", " ")}</strong>
|
|
81
|
+
</div>
|
|
82
|
+
<div>
|
|
83
|
+
<span>Price</span>
|
|
84
|
+
<strong>
|
|
85
|
+
{current.kind === "free"
|
|
86
|
+
? "Free"
|
|
87
|
+
: `${formatPlanAmount(current)} / ${current.interval}`}
|
|
88
|
+
</strong>
|
|
89
|
+
</div>
|
|
90
|
+
{state.currentPeriodEnd ? (
|
|
91
|
+
<div>
|
|
92
|
+
<span>{state.cancelAtPeriodEnd ? "Access until" : "Renews"}</span>
|
|
93
|
+
<strong>{state.currentPeriodEnd.toLocaleDateString()}</strong>
|
|
94
|
+
</div>
|
|
95
|
+
) : null}
|
|
96
|
+
</section>
|
|
97
|
+
{warning ? (
|
|
98
|
+
<p role="status">
|
|
99
|
+
Your subscription needs attention. Your current state remains authoritative until a signed payment update arrives.
|
|
100
|
+
</p>
|
|
101
|
+
) : null}
|
|
102
|
+
{paid && state.customerId ? (
|
|
103
|
+
<form action="/api/billing/portal" method="post">
|
|
104
|
+
<button type="submit" data-billing-action={state.status === "canceled" ? "reactivate" : "manage"}>
|
|
105
|
+
Manage subscription
|
|
106
|
+
</button>
|
|
107
|
+
</form>
|
|
108
|
+
) : upgrade ? (
|
|
109
|
+
<form action="/api/billing/checkout" method="post">
|
|
110
|
+
<input type="hidden" name="plan_key" value={upgrade.planKey} />
|
|
111
|
+
<button type="submit" data-billing-action="upgrade">
|
|
112
|
+
Upgrade to {upgrade.displayName}
|
|
113
|
+
</button>
|
|
114
|
+
</form>
|
|
115
|
+
) : (
|
|
116
|
+
<p>No paid plan has been configured yet.</p>
|
|
117
|
+
)}
|
|
118
|
+
<Link href="/">Return to the product</Link>
|
|
119
|
+
</main>
|
|
120
|
+
);
|
|
121
|
+
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { randomBytes } from "node:crypto";
|
|
2
|
+
|
|
3
|
+
import { NextRequest, NextResponse } from "next/server";
|
|
4
|
+
|
|
5
|
+
import { ProductAuthenticationRequired, requireProductAccount } from "@/lib/egbe-product";
|
|
6
|
+
import { billingCatalog, billingPlan } from "@/lib/egbe-billing/catalog";
|
|
7
|
+
import { buildCheckoutPayload } from "@/lib/egbe-billing/checkout-payload";
|
|
8
|
+
import { createCheckout, validateCheckout } from "@/lib/egbe-billing/os-client";
|
|
9
|
+
import {
|
|
10
|
+
getOrCreateCheckoutAttempt,
|
|
11
|
+
providerPriceForPlan,
|
|
12
|
+
readBillingState,
|
|
13
|
+
recordCheckoutSession,
|
|
14
|
+
} from "@/lib/egbe-billing/repository";
|
|
15
|
+
|
|
16
|
+
const MANAGED_STATUSES = new Set(["trialing", "active", "past_due", "canceling", "paused"]);
|
|
17
|
+
|
|
18
|
+
async function requestPlanKey(request: NextRequest): Promise<string> {
|
|
19
|
+
if (request.headers.get("content-type")?.includes("application/json")) {
|
|
20
|
+
const body = (await request.json()) as { plan_key?: unknown };
|
|
21
|
+
return String(body.plan_key || "");
|
|
22
|
+
}
|
|
23
|
+
const form = await request.formData();
|
|
24
|
+
return String(form.get("plan_key") || "");
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function probeHeaders(request: NextRequest): Record<string, string> | null {
|
|
28
|
+
const mode = request.headers.get("x-egbe-payment-probe");
|
|
29
|
+
const probeId = request.headers.get("x-egbe-payment-probe-id");
|
|
30
|
+
if (!mode && !probeId) return null;
|
|
31
|
+
if (mode !== "validate-only" || !probeId || !/^[A-Za-z0-9_-]{16,128}$/.test(probeId)) {
|
|
32
|
+
throw new Error("Invalid payment validation probe");
|
|
33
|
+
}
|
|
34
|
+
return {
|
|
35
|
+
"X-Egbe-Payment-Probe": mode,
|
|
36
|
+
"X-Egbe-Payment-Probe-ID": probeId,
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export async function POST(request: NextRequest): Promise<NextResponse> {
|
|
41
|
+
try {
|
|
42
|
+
const account = await requireProductAccount();
|
|
43
|
+
const plan = billingPlan(await requestPlanKey(request));
|
|
44
|
+
if (plan.kind !== "subscription" || !plan.selectable) {
|
|
45
|
+
return NextResponse.json({ error: "paid_plan_required" }, { status: 400 });
|
|
46
|
+
}
|
|
47
|
+
if (!billingCatalog.appSlug) {
|
|
48
|
+
throw new Error("Billing catalog app_slug has not been configured");
|
|
49
|
+
}
|
|
50
|
+
const state = await readBillingState(account.id);
|
|
51
|
+
if (MANAGED_STATUSES.has(state.status)) {
|
|
52
|
+
return NextResponse.json({ error: "subscription_already_managed" }, { status: 409 });
|
|
53
|
+
}
|
|
54
|
+
const price = await providerPriceForPlan(plan.planKey);
|
|
55
|
+
const attempt = await getOrCreateCheckoutAttempt(
|
|
56
|
+
account.id,
|
|
57
|
+
plan.planKey,
|
|
58
|
+
"/account/billing?checkout=success",
|
|
59
|
+
{},
|
|
60
|
+
);
|
|
61
|
+
const origin = process.env.NEXT_PUBLIC_BASE_URL;
|
|
62
|
+
if (!origin) throw new Error("NEXT_PUBLIC_BASE_URL is required for Checkout");
|
|
63
|
+
const payload = buildCheckoutPayload({
|
|
64
|
+
account,
|
|
65
|
+
state,
|
|
66
|
+
attempt,
|
|
67
|
+
appSlug: billingCatalog.appSlug,
|
|
68
|
+
priceId: price,
|
|
69
|
+
origin,
|
|
70
|
+
});
|
|
71
|
+
const validationHeaders = probeHeaders(request);
|
|
72
|
+
if (validationHeaders) {
|
|
73
|
+
const validation = await validateCheckout(
|
|
74
|
+
{ ...payload, idempotency_key: attempt.idempotencyKey },
|
|
75
|
+
validationHeaders,
|
|
76
|
+
);
|
|
77
|
+
if (!validation.valid || !validation.validation_receipt) {
|
|
78
|
+
throw new Error("Egbe Payments returned no validation receipt");
|
|
79
|
+
}
|
|
80
|
+
return NextResponse.json({
|
|
81
|
+
validation_only: true,
|
|
82
|
+
operation: "checkout",
|
|
83
|
+
valid: true,
|
|
84
|
+
validation_receipt: validation.validation_receipt,
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
const checkout = await createCheckout(payload, attempt.idempotencyKey);
|
|
88
|
+
if (!checkout.id || !checkout.url) throw new Error("Egbe Payments returned no Checkout URL");
|
|
89
|
+
await recordCheckoutSession(attempt.id, checkout.id);
|
|
90
|
+
if (request.headers.get("accept")?.includes("application/json")) {
|
|
91
|
+
return NextResponse.json({ url: checkout.url });
|
|
92
|
+
}
|
|
93
|
+
return NextResponse.redirect(checkout.url, 303);
|
|
94
|
+
} catch (error) {
|
|
95
|
+
if (error instanceof ProductAuthenticationRequired) {
|
|
96
|
+
return NextResponse.json({ error: "authentication_required" }, { status: 401 });
|
|
97
|
+
}
|
|
98
|
+
const requestId = randomBytes(8).toString("hex");
|
|
99
|
+
console.error("billing checkout failed", { requestId, error });
|
|
100
|
+
return NextResponse.json({ error: "checkout_unavailable", request_id: requestId }, { status: 503 });
|
|
101
|
+
}
|
|
102
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { NextRequest, NextResponse } from "next/server";
|
|
2
|
+
|
|
3
|
+
import { ProductAuthenticationRequired, requireProductAccount } from "@/lib/egbe-product";
|
|
4
|
+
import { billingCatalog } from "@/lib/egbe-billing/catalog";
|
|
5
|
+
import { createPortal, validatePortal } from "@/lib/egbe-billing/os-client";
|
|
6
|
+
import { readBillingState } from "@/lib/egbe-billing/repository";
|
|
7
|
+
|
|
8
|
+
export async function POST(request: NextRequest): Promise<NextResponse> {
|
|
9
|
+
try {
|
|
10
|
+
const account = await requireProductAccount();
|
|
11
|
+
const state = await readBillingState(account.id);
|
|
12
|
+
if (!state.customerId) {
|
|
13
|
+
return NextResponse.json({ error: "billing_customer_unavailable" }, { status: 409 });
|
|
14
|
+
}
|
|
15
|
+
if (!billingCatalog.appSlug) throw new Error("Billing catalog app_slug has not been configured");
|
|
16
|
+
const payload = {
|
|
17
|
+
customer: state.customerId,
|
|
18
|
+
app_slug: billingCatalog.appSlug,
|
|
19
|
+
return_path: "/account/billing",
|
|
20
|
+
};
|
|
21
|
+
const mode = request.headers.get("x-egbe-payment-probe");
|
|
22
|
+
const probeId = request.headers.get("x-egbe-payment-probe-id");
|
|
23
|
+
if (mode || probeId) {
|
|
24
|
+
if (mode !== "validate-only" || !probeId || !/^[A-Za-z0-9_-]{16,128}$/.test(probeId)) {
|
|
25
|
+
return NextResponse.json({ error: "invalid_payment_probe" }, { status: 400 });
|
|
26
|
+
}
|
|
27
|
+
const validation = await validatePortal(payload, {
|
|
28
|
+
"X-Egbe-Payment-Probe": mode,
|
|
29
|
+
"X-Egbe-Payment-Probe-ID": probeId,
|
|
30
|
+
});
|
|
31
|
+
if (!validation.valid || !validation.validation_receipt) {
|
|
32
|
+
throw new Error("Egbe Payments returned no portal validation receipt");
|
|
33
|
+
}
|
|
34
|
+
return NextResponse.json({
|
|
35
|
+
validation_only: true,
|
|
36
|
+
operation: "portal",
|
|
37
|
+
valid: true,
|
|
38
|
+
validation_receipt: validation.validation_receipt,
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
const portal = await createPortal(payload);
|
|
42
|
+
if (!portal.url) throw new Error("Egbe Payments returned no Customer Portal URL");
|
|
43
|
+
if (request.headers.get("accept")?.includes("application/json")) {
|
|
44
|
+
return NextResponse.json({ url: portal.url });
|
|
45
|
+
}
|
|
46
|
+
return NextResponse.redirect(portal.url, 303);
|
|
47
|
+
} catch (error) {
|
|
48
|
+
if (error instanceof ProductAuthenticationRequired) {
|
|
49
|
+
return NextResponse.json({ error: "authentication_required" }, { status: 401 });
|
|
50
|
+
}
|
|
51
|
+
console.error("billing portal failed", error);
|
|
52
|
+
return NextResponse.json({ error: "billing_portal_unavailable" }, { status: 503 });
|
|
53
|
+
}
|
|
54
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { NextResponse } from "next/server";
|
|
2
|
+
|
|
3
|
+
import { ProductAuthenticationRequired, requireProductAccount } from "@/lib/egbe-product";
|
|
4
|
+
import { readBillingState } from "@/lib/egbe-billing/repository";
|
|
5
|
+
|
|
6
|
+
export async function GET(): Promise<NextResponse> {
|
|
7
|
+
try {
|
|
8
|
+
const account = await requireProductAccount();
|
|
9
|
+
const state = await readBillingState(account.id);
|
|
10
|
+
return NextResponse.json({
|
|
11
|
+
plan_key: state.planKey,
|
|
12
|
+
subscription_status: state.status,
|
|
13
|
+
current_period_end: state.currentPeriodEnd?.toISOString() ?? null,
|
|
14
|
+
cancel_at_period_end: state.cancelAtPeriodEnd,
|
|
15
|
+
});
|
|
16
|
+
} catch (error) {
|
|
17
|
+
if (error instanceof ProductAuthenticationRequired) {
|
|
18
|
+
return NextResponse.json({ error: "authentication_required" }, { status: 401 });
|
|
19
|
+
}
|
|
20
|
+
return NextResponse.json({ error: "billing_status_unavailable" }, { status: 503 });
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { NextRequest, NextResponse } from "next/server";
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
applyLiveBillingEvent,
|
|
5
|
+
readBillingStateForEvent,
|
|
6
|
+
type BillingEvent,
|
|
7
|
+
type BillingTransition,
|
|
8
|
+
} from "@/lib/egbe-billing/repository";
|
|
9
|
+
import { reduceBillingEvent, testLifecycleState } from "@/lib/egbe-billing/lifecycle.mjs";
|
|
10
|
+
import { verifyPaymentSignature } from "@/lib/egbe-billing/signature.mjs";
|
|
11
|
+
|
|
12
|
+
const simulatedEvents = new Set<string>();
|
|
13
|
+
|
|
14
|
+
export async function POST(request: NextRequest): Promise<NextResponse> {
|
|
15
|
+
const rawBody = await request.text();
|
|
16
|
+
const secret = process.env.EGBE_PAYMENT_WEBHOOK_SECRET;
|
|
17
|
+
if (!secret) return NextResponse.json({ error: "webhook_not_configured" }, { status: 503 });
|
|
18
|
+
try {
|
|
19
|
+
verifyPaymentSignature(rawBody, request.headers.get("x-egbe-payment-signature"), secret);
|
|
20
|
+
} catch (error) {
|
|
21
|
+
return NextResponse.json({ error: error instanceof Error ? error.message : "invalid_signature" }, { status: 400 });
|
|
22
|
+
}
|
|
23
|
+
let event: Record<string, unknown>;
|
|
24
|
+
try {
|
|
25
|
+
event = JSON.parse(rawBody) as Record<string, unknown>;
|
|
26
|
+
} catch {
|
|
27
|
+
return NextResponse.json({ error: "invalid_event_json" }, { status: 400 });
|
|
28
|
+
}
|
|
29
|
+
const eventId = String(event.id || "");
|
|
30
|
+
const eventType = String(event.type || "");
|
|
31
|
+
const eventCreated = Number(event.created || 0);
|
|
32
|
+
if (!eventId || !eventType || !Number.isSafeInteger(eventCreated) || eventCreated < 1) {
|
|
33
|
+
return NextResponse.json({ error: "invalid_event" }, { status: 400 });
|
|
34
|
+
}
|
|
35
|
+
const billingEvent = event as BillingEvent;
|
|
36
|
+
const object = (event.data as { object?: Record<string, unknown> } | undefined)?.object ?? {};
|
|
37
|
+
const metadata = (object.metadata as Record<string, unknown> | undefined) ?? {};
|
|
38
|
+
const testEvent = event.livemode === false || metadata.egbe_test || request.headers.get("x-egbe-payment-test") === "1";
|
|
39
|
+
if (testEvent) {
|
|
40
|
+
const duplicate = simulatedEvents.has(eventId);
|
|
41
|
+
simulatedEvents.add(eventId);
|
|
42
|
+
if (simulatedEvents.size > 500) simulatedEvents.delete(simulatedEvents.values().next().value as string);
|
|
43
|
+
const scenario = String(metadata.egbe_lifecycle_test_scenario || "");
|
|
44
|
+
const transition = reduceBillingEvent(testLifecycleState(event, scenario), event) as BillingTransition;
|
|
45
|
+
return NextResponse.json({
|
|
46
|
+
contract_version: 1,
|
|
47
|
+
test_event: true,
|
|
48
|
+
accepted: true,
|
|
49
|
+
duplicate,
|
|
50
|
+
event_id: eventId,
|
|
51
|
+
event_type: eventType,
|
|
52
|
+
transition: { subscription_status: transition.subscription_status },
|
|
53
|
+
side_effects_applied: false,
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
try {
|
|
57
|
+
const current = await readBillingStateForEvent(billingEvent);
|
|
58
|
+
const transition = reduceBillingEvent(current, event) as BillingTransition;
|
|
59
|
+
const result = await applyLiveBillingEvent(billingEvent, transition);
|
|
60
|
+
return NextResponse.json({ accepted: true, duplicate: result.duplicate, stale: result.stale });
|
|
61
|
+
} catch (error) {
|
|
62
|
+
console.error("payment webhook commit failed", error);
|
|
63
|
+
return NextResponse.json({ error: "payment_event_not_committed" }, { status: 503 });
|
|
64
|
+
}
|
|
65
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
type PlanBadgeProps = {
|
|
2
|
+
plan: string;
|
|
3
|
+
warning?: boolean;
|
|
4
|
+
};
|
|
5
|
+
|
|
6
|
+
export function PlanBadge({ plan, warning = false }: PlanBadgeProps) {
|
|
7
|
+
return (
|
|
8
|
+
<span
|
|
9
|
+
data-billing-plan-badge
|
|
10
|
+
data-warning={warning || undefined}
|
|
11
|
+
aria-label={`Current plan: ${plan}`}
|
|
12
|
+
>
|
|
13
|
+
{plan}
|
|
14
|
+
</span>
|
|
15
|
+
);
|
|
16
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import test from "node:test";
|
|
3
|
+
|
|
4
|
+
import { metadataFor, validateCatalog } from "../../../scripts/billing-sync.mjs";
|
|
5
|
+
|
|
6
|
+
const validCatalog = () => ({
|
|
7
|
+
catalog_version: 1,
|
|
8
|
+
app_slug: "example-product",
|
|
9
|
+
plans: [
|
|
10
|
+
{
|
|
11
|
+
plan_key: "free",
|
|
12
|
+
display_name: "Free",
|
|
13
|
+
summary: "Free access",
|
|
14
|
+
kind: "free",
|
|
15
|
+
amount_cents: 0,
|
|
16
|
+
currency: "usd",
|
|
17
|
+
interval: null,
|
|
18
|
+
entitlements: [],
|
|
19
|
+
selectable: true,
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
plan_key: "pro",
|
|
23
|
+
display_name: "Pro",
|
|
24
|
+
summary: "Paid access",
|
|
25
|
+
kind: "subscription",
|
|
26
|
+
amount_cents: 1900,
|
|
27
|
+
currency: "usd",
|
|
28
|
+
interval: "month",
|
|
29
|
+
entitlements: ["book.create"],
|
|
30
|
+
selectable: true,
|
|
31
|
+
},
|
|
32
|
+
],
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
test("catalog validation requires one provider-free subscription contract", () => {
|
|
36
|
+
const result = validateCatalog(validCatalog());
|
|
37
|
+
assert.equal(result.appSlug, "example-product");
|
|
38
|
+
assert.deepEqual(result.paid.map((plan) => plan.plan_key), ["pro"]);
|
|
39
|
+
assert.equal("provider_price_id" in result.paid[0], false);
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
test("catalog validation rejects duplicate identities and incomplete pricing", () => {
|
|
43
|
+
const duplicate = validCatalog();
|
|
44
|
+
duplicate.plans[1].plan_key = "free";
|
|
45
|
+
assert.throws(() => validateCatalog(duplicate), /duplicate/);
|
|
46
|
+
|
|
47
|
+
const incomplete = validCatalog();
|
|
48
|
+
incomplete.plans[1].amount_cents = 0;
|
|
49
|
+
assert.throws(() => validateCatalog(incomplete), /amount_cents/);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
test("provider metadata binds one plan to the deployed product webhook", () => {
|
|
53
|
+
assert.deepEqual(metadataFor("example-product", "pro"), {
|
|
54
|
+
plan_key: "pro",
|
|
55
|
+
payment_gateway_app_slug: "example-product",
|
|
56
|
+
payment_gateway_webhook_path: "/api/payments/webhook",
|
|
57
|
+
});
|
|
58
|
+
});
|