availsync 0.1.0
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/.adal/skills/stripe-best-practices/SKILL.md +42 -0
- package/.adal/skills/stripe-best-practices/references/billing.md +36 -0
- package/.adal/skills/stripe-best-practices/references/connect.md +48 -0
- package/.adal/skills/stripe-best-practices/references/payments.md +79 -0
- package/.adal/skills/stripe-best-practices/references/security.md +109 -0
- package/.adal/skills/stripe-best-practices/references/treasury.md +16 -0
- package/.adal/skills/stripe-projects/SKILL.md +139 -0
- package/.adal/skills/upgrade-stripe/SKILL.md +185 -0
- package/.agents/skills/stripe-best-practices/SKILL.md +42 -0
- package/.agents/skills/stripe-best-practices/references/billing.md +36 -0
- package/.agents/skills/stripe-best-practices/references/connect.md +48 -0
- package/.agents/skills/stripe-best-practices/references/payments.md +79 -0
- package/.agents/skills/stripe-best-practices/references/security.md +109 -0
- package/.agents/skills/stripe-best-practices/references/treasury.md +16 -0
- package/.agents/skills/stripe-projects/SKILL.md +139 -0
- package/.agents/skills/upgrade-stripe/SKILL.md +185 -0
- package/.augment/skills/stripe-best-practices/SKILL.md +42 -0
- package/.augment/skills/stripe-best-practices/references/billing.md +36 -0
- package/.augment/skills/stripe-best-practices/references/connect.md +48 -0
- package/.augment/skills/stripe-best-practices/references/payments.md +79 -0
- package/.augment/skills/stripe-best-practices/references/security.md +109 -0
- package/.augment/skills/stripe-best-practices/references/treasury.md +16 -0
- package/.augment/skills/stripe-projects/SKILL.md +139 -0
- package/.augment/skills/upgrade-stripe/SKILL.md +185 -0
- package/.bob/skills/stripe-best-practices/SKILL.md +42 -0
- package/.bob/skills/stripe-best-practices/references/billing.md +36 -0
- package/.bob/skills/stripe-best-practices/references/connect.md +48 -0
- package/.bob/skills/stripe-best-practices/references/payments.md +79 -0
- package/.bob/skills/stripe-best-practices/references/security.md +109 -0
- package/.bob/skills/stripe-best-practices/references/treasury.md +16 -0
- package/.bob/skills/stripe-projects/SKILL.md +139 -0
- package/.bob/skills/upgrade-stripe/SKILL.md +185 -0
- package/.claude/settings.local.json +7 -0
- package/.claude/skills/stripe-best-practices/SKILL.md +42 -0
- package/.claude/skills/stripe-best-practices/references/billing.md +36 -0
- package/.claude/skills/stripe-best-practices/references/connect.md +48 -0
- package/.claude/skills/stripe-best-practices/references/payments.md +79 -0
- package/.claude/skills/stripe-best-practices/references/security.md +109 -0
- package/.claude/skills/stripe-best-practices/references/treasury.md +16 -0
- package/.claude/skills/stripe-projects/SKILL.md +139 -0
- package/.claude/skills/upgrade-stripe/SKILL.md +185 -0
- package/.codebuddy/skills/stripe-best-practices/SKILL.md +42 -0
- package/.codebuddy/skills/stripe-best-practices/references/billing.md +36 -0
- package/.codebuddy/skills/stripe-best-practices/references/connect.md +48 -0
- package/.codebuddy/skills/stripe-best-practices/references/payments.md +79 -0
- package/.codebuddy/skills/stripe-best-practices/references/security.md +109 -0
- package/.codebuddy/skills/stripe-best-practices/references/treasury.md +16 -0
- package/.codebuddy/skills/stripe-projects/SKILL.md +139 -0
- package/.codebuddy/skills/upgrade-stripe/SKILL.md +185 -0
- package/.commandcode/skills/stripe-best-practices/SKILL.md +42 -0
- package/.commandcode/skills/stripe-best-practices/references/billing.md +36 -0
- package/.commandcode/skills/stripe-best-practices/references/connect.md +48 -0
- package/.commandcode/skills/stripe-best-practices/references/payments.md +79 -0
- package/.commandcode/skills/stripe-best-practices/references/security.md +109 -0
- package/.commandcode/skills/stripe-best-practices/references/treasury.md +16 -0
- package/.commandcode/skills/stripe-projects/SKILL.md +139 -0
- package/.commandcode/skills/upgrade-stripe/SKILL.md +185 -0
- package/.continue/skills/stripe-best-practices/SKILL.md +42 -0
- package/.continue/skills/stripe-best-practices/references/billing.md +36 -0
- package/.continue/skills/stripe-best-practices/references/connect.md +48 -0
- package/.continue/skills/stripe-best-practices/references/payments.md +79 -0
- package/.continue/skills/stripe-best-practices/references/security.md +109 -0
- package/.continue/skills/stripe-best-practices/references/treasury.md +16 -0
- package/.continue/skills/stripe-projects/SKILL.md +139 -0
- package/.continue/skills/upgrade-stripe/SKILL.md +185 -0
- package/.cortex/skills/stripe-best-practices/SKILL.md +42 -0
- package/.cortex/skills/stripe-best-practices/references/billing.md +36 -0
- package/.cortex/skills/stripe-best-practices/references/connect.md +48 -0
- package/.cortex/skills/stripe-best-practices/references/payments.md +79 -0
- package/.cortex/skills/stripe-best-practices/references/security.md +109 -0
- package/.cortex/skills/stripe-best-practices/references/treasury.md +16 -0
- package/.cortex/skills/stripe-projects/SKILL.md +139 -0
- package/.cortex/skills/upgrade-stripe/SKILL.md +185 -0
- package/.crush/skills/stripe-best-practices/SKILL.md +42 -0
- package/.crush/skills/stripe-best-practices/references/billing.md +36 -0
- package/.crush/skills/stripe-best-practices/references/connect.md +48 -0
- package/.crush/skills/stripe-best-practices/references/payments.md +79 -0
- package/.crush/skills/stripe-best-practices/references/security.md +109 -0
- package/.crush/skills/stripe-best-practices/references/treasury.md +16 -0
- package/.crush/skills/stripe-projects/SKILL.md +139 -0
- package/.crush/skills/upgrade-stripe/SKILL.md +185 -0
- package/.env.example +20 -0
- package/.factory/skills/stripe-best-practices/SKILL.md +42 -0
- package/.factory/skills/stripe-best-practices/references/billing.md +36 -0
- package/.factory/skills/stripe-best-practices/references/connect.md +48 -0
- package/.factory/skills/stripe-best-practices/references/payments.md +79 -0
- package/.factory/skills/stripe-best-practices/references/security.md +109 -0
- package/.factory/skills/stripe-best-practices/references/treasury.md +16 -0
- package/.factory/skills/stripe-projects/SKILL.md +139 -0
- package/.factory/skills/upgrade-stripe/SKILL.md +185 -0
- package/.goose/skills/stripe-best-practices/SKILL.md +42 -0
- package/.goose/skills/stripe-best-practices/references/billing.md +36 -0
- package/.goose/skills/stripe-best-practices/references/connect.md +48 -0
- package/.goose/skills/stripe-best-practices/references/payments.md +79 -0
- package/.goose/skills/stripe-best-practices/references/security.md +109 -0
- package/.goose/skills/stripe-best-practices/references/treasury.md +16 -0
- package/.goose/skills/stripe-projects/SKILL.md +139 -0
- package/.goose/skills/upgrade-stripe/SKILL.md +185 -0
- package/.iflow/skills/stripe-best-practices/SKILL.md +42 -0
- package/.iflow/skills/stripe-best-practices/references/billing.md +36 -0
- package/.iflow/skills/stripe-best-practices/references/connect.md +48 -0
- package/.iflow/skills/stripe-best-practices/references/payments.md +79 -0
- package/.iflow/skills/stripe-best-practices/references/security.md +109 -0
- package/.iflow/skills/stripe-best-practices/references/treasury.md +16 -0
- package/.iflow/skills/stripe-projects/SKILL.md +139 -0
- package/.iflow/skills/upgrade-stripe/SKILL.md +185 -0
- package/.junie/skills/stripe-best-practices/SKILL.md +42 -0
- package/.junie/skills/stripe-best-practices/references/billing.md +36 -0
- package/.junie/skills/stripe-best-practices/references/connect.md +48 -0
- package/.junie/skills/stripe-best-practices/references/payments.md +79 -0
- package/.junie/skills/stripe-best-practices/references/security.md +109 -0
- package/.junie/skills/stripe-best-practices/references/treasury.md +16 -0
- package/.junie/skills/stripe-projects/SKILL.md +139 -0
- package/.junie/skills/upgrade-stripe/SKILL.md +185 -0
- package/.kilocode/skills/stripe-best-practices/SKILL.md +42 -0
- package/.kilocode/skills/stripe-best-practices/references/billing.md +36 -0
- package/.kilocode/skills/stripe-best-practices/references/connect.md +48 -0
- package/.kilocode/skills/stripe-best-practices/references/payments.md +79 -0
- package/.kilocode/skills/stripe-best-practices/references/security.md +109 -0
- package/.kilocode/skills/stripe-best-practices/references/treasury.md +16 -0
- package/.kilocode/skills/stripe-projects/SKILL.md +139 -0
- package/.kilocode/skills/upgrade-stripe/SKILL.md +185 -0
- package/.kiro/skills/stripe-best-practices/SKILL.md +42 -0
- package/.kiro/skills/stripe-best-practices/references/billing.md +36 -0
- package/.kiro/skills/stripe-best-practices/references/connect.md +48 -0
- package/.kiro/skills/stripe-best-practices/references/payments.md +79 -0
- package/.kiro/skills/stripe-best-practices/references/security.md +109 -0
- package/.kiro/skills/stripe-best-practices/references/treasury.md +16 -0
- package/.kiro/skills/stripe-projects/SKILL.md +139 -0
- package/.kiro/skills/upgrade-stripe/SKILL.md +185 -0
- package/.kode/skills/stripe-best-practices/SKILL.md +42 -0
- package/.kode/skills/stripe-best-practices/references/billing.md +36 -0
- package/.kode/skills/stripe-best-practices/references/connect.md +48 -0
- package/.kode/skills/stripe-best-practices/references/payments.md +79 -0
- package/.kode/skills/stripe-best-practices/references/security.md +109 -0
- package/.kode/skills/stripe-best-practices/references/treasury.md +16 -0
- package/.kode/skills/stripe-projects/SKILL.md +139 -0
- package/.kode/skills/upgrade-stripe/SKILL.md +185 -0
- package/.mcpjam/skills/stripe-best-practices/SKILL.md +42 -0
- package/.mcpjam/skills/stripe-best-practices/references/billing.md +36 -0
- package/.mcpjam/skills/stripe-best-practices/references/connect.md +48 -0
- package/.mcpjam/skills/stripe-best-practices/references/payments.md +79 -0
- package/.mcpjam/skills/stripe-best-practices/references/security.md +109 -0
- package/.mcpjam/skills/stripe-best-practices/references/treasury.md +16 -0
- package/.mcpjam/skills/stripe-projects/SKILL.md +139 -0
- package/.mcpjam/skills/upgrade-stripe/SKILL.md +185 -0
- package/.mux/skills/stripe-best-practices/SKILL.md +42 -0
- package/.mux/skills/stripe-best-practices/references/billing.md +36 -0
- package/.mux/skills/stripe-best-practices/references/connect.md +48 -0
- package/.mux/skills/stripe-best-practices/references/payments.md +79 -0
- package/.mux/skills/stripe-best-practices/references/security.md +109 -0
- package/.mux/skills/stripe-best-practices/references/treasury.md +16 -0
- package/.mux/skills/stripe-projects/SKILL.md +139 -0
- package/.mux/skills/upgrade-stripe/SKILL.md +185 -0
- package/.neovate/skills/stripe-best-practices/SKILL.md +42 -0
- package/.neovate/skills/stripe-best-practices/references/billing.md +36 -0
- package/.neovate/skills/stripe-best-practices/references/connect.md +48 -0
- package/.neovate/skills/stripe-best-practices/references/payments.md +79 -0
- package/.neovate/skills/stripe-best-practices/references/security.md +109 -0
- package/.neovate/skills/stripe-best-practices/references/treasury.md +16 -0
- package/.neovate/skills/stripe-projects/SKILL.md +139 -0
- package/.neovate/skills/upgrade-stripe/SKILL.md +185 -0
- package/.nixpacksignore +14 -0
- package/.openhands/skills/stripe-best-practices/SKILL.md +42 -0
- package/.openhands/skills/stripe-best-practices/references/billing.md +36 -0
- package/.openhands/skills/stripe-best-practices/references/connect.md +48 -0
- package/.openhands/skills/stripe-best-practices/references/payments.md +79 -0
- package/.openhands/skills/stripe-best-practices/references/security.md +109 -0
- package/.openhands/skills/stripe-best-practices/references/treasury.md +16 -0
- package/.openhands/skills/stripe-projects/SKILL.md +139 -0
- package/.openhands/skills/upgrade-stripe/SKILL.md +185 -0
- package/.pi/skills/stripe-best-practices/SKILL.md +42 -0
- package/.pi/skills/stripe-best-practices/references/billing.md +36 -0
- package/.pi/skills/stripe-best-practices/references/connect.md +48 -0
- package/.pi/skills/stripe-best-practices/references/payments.md +79 -0
- package/.pi/skills/stripe-best-practices/references/security.md +109 -0
- package/.pi/skills/stripe-best-practices/references/treasury.md +16 -0
- package/.pi/skills/stripe-projects/SKILL.md +139 -0
- package/.pi/skills/upgrade-stripe/SKILL.md +185 -0
- package/.pochi/skills/stripe-best-practices/SKILL.md +42 -0
- package/.pochi/skills/stripe-best-practices/references/billing.md +36 -0
- package/.pochi/skills/stripe-best-practices/references/connect.md +48 -0
- package/.pochi/skills/stripe-best-practices/references/payments.md +79 -0
- package/.pochi/skills/stripe-best-practices/references/security.md +109 -0
- package/.pochi/skills/stripe-best-practices/references/treasury.md +16 -0
- package/.pochi/skills/stripe-projects/SKILL.md +139 -0
- package/.pochi/skills/upgrade-stripe/SKILL.md +185 -0
- package/.qoder/skills/stripe-best-practices/SKILL.md +42 -0
- package/.qoder/skills/stripe-best-practices/references/billing.md +36 -0
- package/.qoder/skills/stripe-best-practices/references/connect.md +48 -0
- package/.qoder/skills/stripe-best-practices/references/payments.md +79 -0
- package/.qoder/skills/stripe-best-practices/references/security.md +109 -0
- package/.qoder/skills/stripe-best-practices/references/treasury.md +16 -0
- package/.qoder/skills/stripe-projects/SKILL.md +139 -0
- package/.qoder/skills/upgrade-stripe/SKILL.md +185 -0
- package/.qwen/skills/stripe-best-practices/SKILL.md +42 -0
- package/.qwen/skills/stripe-best-practices/references/billing.md +36 -0
- package/.qwen/skills/stripe-best-practices/references/connect.md +48 -0
- package/.qwen/skills/stripe-best-practices/references/payments.md +79 -0
- package/.qwen/skills/stripe-best-practices/references/security.md +109 -0
- package/.qwen/skills/stripe-best-practices/references/treasury.md +16 -0
- package/.qwen/skills/stripe-projects/SKILL.md +139 -0
- package/.qwen/skills/upgrade-stripe/SKILL.md +185 -0
- package/.roo/skills/stripe-best-practices/SKILL.md +42 -0
- package/.roo/skills/stripe-best-practices/references/billing.md +36 -0
- package/.roo/skills/stripe-best-practices/references/connect.md +48 -0
- package/.roo/skills/stripe-best-practices/references/payments.md +79 -0
- package/.roo/skills/stripe-best-practices/references/security.md +109 -0
- package/.roo/skills/stripe-best-practices/references/treasury.md +16 -0
- package/.roo/skills/stripe-projects/SKILL.md +139 -0
- package/.roo/skills/upgrade-stripe/SKILL.md +185 -0
- package/.trae/skills/stripe-best-practices/SKILL.md +42 -0
- package/.trae/skills/stripe-best-practices/references/billing.md +36 -0
- package/.trae/skills/stripe-best-practices/references/connect.md +48 -0
- package/.trae/skills/stripe-best-practices/references/payments.md +79 -0
- package/.trae/skills/stripe-best-practices/references/security.md +109 -0
- package/.trae/skills/stripe-best-practices/references/treasury.md +16 -0
- package/.trae/skills/stripe-projects/SKILL.md +139 -0
- package/.trae/skills/upgrade-stripe/SKILL.md +185 -0
- package/.vibe/skills/stripe-best-practices/SKILL.md +42 -0
- package/.vibe/skills/stripe-best-practices/references/billing.md +36 -0
- package/.vibe/skills/stripe-best-practices/references/connect.md +48 -0
- package/.vibe/skills/stripe-best-practices/references/payments.md +79 -0
- package/.vibe/skills/stripe-best-practices/references/security.md +109 -0
- package/.vibe/skills/stripe-best-practices/references/treasury.md +16 -0
- package/.vibe/skills/stripe-projects/SKILL.md +139 -0
- package/.vibe/skills/upgrade-stripe/SKILL.md +185 -0
- package/.windsurf/skills/stripe-best-practices/SKILL.md +42 -0
- package/.windsurf/skills/stripe-best-practices/references/billing.md +36 -0
- package/.windsurf/skills/stripe-best-practices/references/connect.md +48 -0
- package/.windsurf/skills/stripe-best-practices/references/payments.md +79 -0
- package/.windsurf/skills/stripe-best-practices/references/security.md +109 -0
- package/.windsurf/skills/stripe-best-practices/references/treasury.md +16 -0
- package/.windsurf/skills/stripe-projects/SKILL.md +139 -0
- package/.windsurf/skills/upgrade-stripe/SKILL.md +185 -0
- package/.zencoder/skills/stripe-best-practices/SKILL.md +42 -0
- package/.zencoder/skills/stripe-best-practices/references/billing.md +36 -0
- package/.zencoder/skills/stripe-best-practices/references/connect.md +48 -0
- package/.zencoder/skills/stripe-best-practices/references/payments.md +79 -0
- package/.zencoder/skills/stripe-best-practices/references/security.md +109 -0
- package/.zencoder/skills/stripe-best-practices/references/treasury.md +16 -0
- package/.zencoder/skills/stripe-projects/SKILL.md +139 -0
- package/.zencoder/skills/upgrade-stripe/SKILL.md +185 -0
- package/AUDIT.md +95 -0
- package/BLOCKERS.md +0 -0
- package/COOLIFY.md +51 -0
- package/MCP_SETUP.md +23 -0
- package/PRODUCTION_CHECKLIST.md +246 -0
- package/README.md +47 -0
- package/ROADMAP.md +91 -0
- package/docs/superpowers/plans/2026-05-11-availsync-frontend-sales-flow.md +2445 -0
- package/frontend/.env.example +2 -0
- package/frontend/app/admin/layout.tsx +13 -0
- package/frontend/app/admin/page.tsx +747 -0
- package/frontend/app/app/activity/page.tsx +257 -0
- package/frontend/app/app/agents/[agentId]/page.tsx +21 -0
- package/frontend/app/app/agents/page.tsx +1155 -0
- package/frontend/app/app/audit/page.tsx +225 -0
- package/frontend/app/app/availability/page.tsx +840 -0
- package/frontend/app/app/holds/page.tsx +262 -0
- package/frontend/app/app/layout.tsx +19 -0
- package/frontend/app/app/onboarding/page.tsx +10 -0
- package/frontend/app/app/onboarding/verify/page.tsx +309 -0
- package/frontend/app/app/page.tsx +508 -0
- package/frontend/app/app/settings/page.tsx +399 -0
- package/frontend/app/app/work/page.tsx +426 -0
- package/frontend/app/changelog/page.tsx +93 -0
- package/frontend/app/checkout/page.tsx +25 -0
- package/frontend/app/docs/api/page.tsx +157 -0
- package/frontend/app/docs/page.tsx +296 -0
- package/frontend/app/docs/pilot/page.tsx +127 -0
- package/frontend/app/docs/quickstart/page.tsx +318 -0
- package/frontend/app/docs/reliability/page.tsx +78 -0
- package/frontend/app/docs/sdk/node/page.tsx +166 -0
- package/frontend/app/globals.css +57 -0
- package/frontend/app/icon.png +0 -0
- package/frontend/app/layout.tsx +87 -0
- package/frontend/app/login/page.tsx +14 -0
- package/frontend/app/page.tsx +47 -0
- package/frontend/app/pricing/page.tsx +66 -0
- package/frontend/app/privacy/page.tsx +52 -0
- package/frontend/app/robots.ts +26 -0
- package/frontend/app/security/page.tsx +74 -0
- package/frontend/app/signup/page.tsx +14 -0
- package/frontend/app/sitemap.ts +14 -0
- package/frontend/app/terms/page.tsx +51 -0
- package/frontend/components/brand/AvailsyncLogo.tsx +56 -0
- package/frontend/components/checkout/CheckoutClient.tsx +100 -0
- package/frontend/components/dashboard/AgentForm.tsx +59 -0
- package/frontend/components/dashboard/AppShell.tsx +291 -0
- package/frontend/components/dashboard/AvailabilityChecker.tsx +117 -0
- package/frontend/components/dashboard/AvailabilityWindowForm.tsx +40 -0
- package/frontend/components/dashboard/HoldForm.tsx +133 -0
- package/frontend/components/dashboard/MetricCard.tsx +10 -0
- package/frontend/components/login/LoginForm.tsx +95 -0
- package/frontend/components/marketing/AgentCoordinationStory.tsx +1530 -0
- package/frontend/components/marketing/Faq.tsx +41 -0
- package/frontend/components/marketing/Hero.tsx +73 -0
- package/frontend/components/marketing/HowItWorks.tsx +28 -0
- package/frontend/components/marketing/ObserveModeTeaser.tsx +41 -0
- package/frontend/components/marketing/PricingTeaser.tsx +23 -0
- package/frontend/components/marketing/ProblemSolution.tsx +36 -0
- package/frontend/components/marketing/SiteFooter.tsx +59 -0
- package/frontend/components/marketing/SiteHeader.tsx +45 -0
- package/frontend/components/marketing/UseCases.tsx +27 -0
- package/frontend/components/onboarding/OnboardingClient.tsx +278 -0
- package/frontend/components/pricing/PricingCards.tsx +65 -0
- package/frontend/components/privacy/CookieConsent.tsx +230 -0
- package/frontend/components/privacy/CookieSettingsButton.tsx +15 -0
- package/frontend/components/seo/JsonLd.tsx +10 -0
- package/frontend/components/signup/SignupForm.tsx +55 -0
- package/frontend/components/ui/Badge.tsx +23 -0
- package/frontend/components/ui/Button.tsx +37 -0
- package/frontend/components/ui/Card.tsx +11 -0
- package/frontend/components/ui/ConfirmDialog.tsx +77 -0
- package/frontend/components/ui/EmptyState.tsx +24 -0
- package/frontend/components/ui/Input.tsx +14 -0
- package/frontend/components/ui/KeyDisplay.tsx +49 -0
- package/frontend/components/ui/Select.tsx +14 -0
- package/frontend/components/ui/Skeleton.tsx +24 -0
- package/frontend/components/ui/Tabs.tsx +19 -0
- package/frontend/components/ui/Textarea.tsx +14 -0
- package/frontend/components/ui/Toast.tsx +78 -0
- package/frontend/components/waitlist/WaitlistDialog.tsx +128 -0
- package/frontend/lib/api.ts +1282 -0
- package/frontend/lib/billing.ts +6 -0
- package/frontend/lib/cookieConsent.ts +113 -0
- package/frontend/lib/format.ts +16 -0
- package/frontend/lib/plans.ts +62 -0
- package/frontend/lib/schemas.ts +108 -0
- package/frontend/lib/seo.ts +376 -0
- package/frontend/lib/setupGuides.ts +630 -0
- package/frontend/lib/storage.ts +30 -0
- package/frontend/next-env.d.ts +6 -0
- package/frontend/next.config.mjs +13 -0
- package/frontend/package-lock.json +14409 -0
- package/frontend/package.json +41 -0
- package/frontend/playwright.config.ts +20 -0
- package/frontend/postcss.config.mjs +8 -0
- package/frontend/public/.gitkeep +0 -0
- package/frontend/public/brand/availsync-logo-board.png +0 -0
- package/frontend/public/brand/availsync-logo-dark.png +0 -0
- package/frontend/public/brand/availsync-mark-dark.png +0 -0
- package/frontend/public/brand/availsync-wordmark-dark.png +0 -0
- package/frontend/public/marketing/hero-agent-coordination.png +0 -0
- package/frontend/tailwind.config.ts +53 -0
- package/frontend/tests/smoke.spec.ts +89 -0
- package/frontend/tsconfig.json +23 -0
- package/jest.config.js +7 -0
- package/nixpacks.toml +11 -0
- package/package.json +53 -0
- package/packages/mcp/LICENSE +21 -0
- package/packages/mcp/README.md +60 -0
- package/packages/mcp/jest.config.cjs +8 -0
- package/packages/mcp/package.json +54 -0
- package/packages/mcp/src/helpers.ts +38 -0
- package/packages/mcp/src/index.test.ts +60 -0
- package/packages/mcp/src/index.ts +387 -0
- package/packages/mcp/tsconfig.json +20 -0
- package/packages/mcp/tsconfig.test.json +12 -0
- package/packages/node/LICENSE +21 -0
- package/packages/node/README.md +120 -0
- package/packages/node/jest.config.cjs +8 -0
- package/packages/node/package.json +46 -0
- package/packages/node/src/index.test.ts +360 -0
- package/packages/node/src/index.ts +402 -0
- package/packages/node/tsconfig.json +20 -0
- package/packages/node/tsconfig.test.json +12 -0
- package/plan.md +923 -0
- package/skills/stripe-best-practices/SKILL.md +42 -0
- package/skills/stripe-best-practices/references/billing.md +36 -0
- package/skills/stripe-best-practices/references/connect.md +48 -0
- package/skills/stripe-best-practices/references/payments.md +79 -0
- package/skills/stripe-best-practices/references/security.md +109 -0
- package/skills/stripe-best-practices/references/treasury.md +16 -0
- package/skills/stripe-projects/SKILL.md +139 -0
- package/skills/upgrade-stripe/SKILL.md +185 -0
- package/skills-lock.json +20 -0
- package/src/core/availability.ts +178 -0
- package/src/core/conflict.ts +209 -0
- package/src/core/work.ts +490 -0
- package/src/db/client.ts +17 -0
- package/src/db/migrations/001_init.sql +88 -0
- package/src/db/migrations/002_stripe.sql +2 -0
- package/src/db/migrations/003_workspace_auth.sql +19 -0
- package/src/db/migrations/004_agent_mcp_status.sql +2 -0
- package/src/db/migrations/005_hold_event_actor.sql +4 -0
- package/src/db/migrations/006_agent_activity.sql +35 -0
- package/src/db/migrations/007_work_coordination.sql +60 -0
- package/src/db/migrations/008_work_claim_leases.sql +20 -0
- package/src/db/migrations/009_billing_subscription_state.sql +23 -0
- package/src/db/migrations/010_agent_api_key_prefix.sql +10 -0
- package/src/db/migrations/011_org_verified_and_work_event_retention.sql +11 -0
- package/src/db/migrations/012_agent_enforcement_mode.sql +12 -0
- package/src/db/migrations/013_support_tickets.sql +21 -0
- package/src/db/migrations/014_paid_plan_waitlist.sql +23 -0
- package/src/db/migrations/015_agent_last_seen.sql +2 -0
- package/src/db/migrations.ts +164 -0
- package/src/db/run-migrations.ts +13 -0
- package/src/index.ts +183 -0
- package/src/lib/activity.ts +137 -0
- package/src/lib/apiKeys.ts +32 -0
- package/src/lib/appInfo.ts +26 -0
- package/src/lib/billingConfig.ts +3 -0
- package/src/lib/env.ts +75 -0
- package/src/lib/logger.ts +8 -0
- package/src/lib/plans.ts +204 -0
- package/src/mcp/server.js +5 -0
- package/src/mcp/server.ts +350 -0
- package/src/middleware/auth.ts +342 -0
- package/src/middleware/requestId.ts +16 -0
- package/src/routes/account.ts +168 -0
- package/src/routes/activity.ts +126 -0
- package/src/routes/admin.ts +514 -0
- package/src/routes/audit.ts +68 -0
- package/src/routes/auth.ts +203 -0
- package/src/routes/availability.ts +325 -0
- package/src/routes/billing.ts +406 -0
- package/src/routes/conflicts.ts +131 -0
- package/src/routes/holds.ts +437 -0
- package/src/routes/mcp.ts +57 -0
- package/src/routes/metrics.ts +39 -0
- package/src/routes/onboarding.ts +273 -0
- package/src/routes/orgs.ts +981 -0
- package/src/routes/preferences.ts +132 -0
- package/src/routes/session.ts +16 -0
- package/src/routes/support.ts +77 -0
- package/src/routes/value.ts +186 -0
- package/src/routes/waitlist.ts +63 -0
- package/src/routes/work.ts +1578 -0
- package/src/server.ts +36 -0
- package/src/types/index.ts +109 -0
- package/tests/integration/activity.route.test.ts +103 -0
- package/tests/integration/admin.route.test.ts +143 -0
- package/tests/integration/agent-keys.route.test.ts +237 -0
- package/tests/integration/availability.route.test.ts +125 -0
- package/tests/integration/billing.route.test.ts +393 -0
- package/tests/integration/conflicts.route.test.ts +131 -0
- package/tests/integration/flows.test.ts +154 -0
- package/tests/integration/helpers.ts +134 -0
- package/tests/integration/holds.route.test.ts +185 -0
- package/tests/integration/metrics.route.test.ts +100 -0
- package/tests/integration/onboarding.verify.route.test.ts +163 -0
- package/tests/integration/preferences.route.test.ts +53 -0
- package/tests/integration/session.route.test.ts +97 -0
- package/tests/integration/system.route.test.ts +92 -0
- package/tests/integration/value.route.test.ts +235 -0
- package/tests/integration/work.route.test.ts +745 -0
- package/tests/setup.ts +4 -0
- package/tests/smoke.sh +62 -0
- package/tests/unit/auth.test.ts +114 -0
- package/tests/unit/availability.test.ts +149 -0
- package/tests/unit/conflict.test.ts +118 -0
- package/tests/unit/env.test.ts +69 -0
- package/tests/unit/migrations.test.ts +135 -0
- package/tests/unit/request-id.test.ts +37 -0
- package/tmp-mobile-agents.png +0 -0
- package/tmp-next-mobile.err.log +10 -0
- package/tmp-next-mobile.log +5 -0
- package/tsconfig.json +16 -0
|
@@ -0,0 +1,406 @@
|
|
|
1
|
+
import express from 'express';
|
|
2
|
+
import Stripe from 'stripe';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
import pool from '../db/client';
|
|
5
|
+
import { requireWorkspaceSession, type WorkspaceAuthenticatedRequest } from '../middleware/auth';
|
|
6
|
+
import { log } from '../lib/logger';
|
|
7
|
+
import { billingUpgradesEnabled } from '../lib/billingConfig';
|
|
8
|
+
import { requestIdFrom } from '../middleware/requestId';
|
|
9
|
+
import {
|
|
10
|
+
PLAN_CONFIG,
|
|
11
|
+
applyPlanToOrg,
|
|
12
|
+
getPlanConfig,
|
|
13
|
+
getPlanUsage,
|
|
14
|
+
paidPlanIds,
|
|
15
|
+
parsePlan,
|
|
16
|
+
serializableLimits,
|
|
17
|
+
upgradeReasons,
|
|
18
|
+
type PlanId,
|
|
19
|
+
} from '../lib/plans';
|
|
20
|
+
|
|
21
|
+
const router = express.Router();
|
|
22
|
+
|
|
23
|
+
const PaidPlanSchema = z.enum(paidPlanIds() as ['individual', 'team']);
|
|
24
|
+
const AnyPlanSchema = z.enum(['free', 'individual', 'team']);
|
|
25
|
+
|
|
26
|
+
type StripeMetadata = Record<string, string> | null | undefined;
|
|
27
|
+
type StripeEvent = {
|
|
28
|
+
id?: string;
|
|
29
|
+
type: string;
|
|
30
|
+
data: {
|
|
31
|
+
object: {
|
|
32
|
+
id?: string;
|
|
33
|
+
customer?: string;
|
|
34
|
+
subscription?: string;
|
|
35
|
+
customer_email?: string;
|
|
36
|
+
customer_details?: { email?: string | null } | null;
|
|
37
|
+
metadata?: StripeMetadata;
|
|
38
|
+
status?: string;
|
|
39
|
+
current_period_start?: number;
|
|
40
|
+
current_period_end?: number;
|
|
41
|
+
cancel_at_period_end?: boolean;
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
const CheckoutSchema = z.object({
|
|
47
|
+
plan: PaidPlanSchema,
|
|
48
|
+
org_id: z.string().uuid().optional(),
|
|
49
|
+
email: z.string().email().optional(),
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
function getStripe(secret: string) {
|
|
53
|
+
return new Stripe(secret);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function parsePlanMetadata(metadata: StripeMetadata) {
|
|
57
|
+
const orgId = metadata?.org_id;
|
|
58
|
+
const planResult = AnyPlanSchema.safeParse(metadata?.plan);
|
|
59
|
+
if (!orgId || !planResult.success) {
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
62
|
+
return { orgId, plan: planResult.data };
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function stripeTimestamp(value: number | undefined) {
|
|
66
|
+
return typeof value === 'number' ? new Date(value * 1000) : null;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
async function updateSubscriptionState(input: {
|
|
70
|
+
org_id: string;
|
|
71
|
+
plan: PlanId;
|
|
72
|
+
subscription_status: string;
|
|
73
|
+
stripe_customer_id?: string | null;
|
|
74
|
+
stripe_subscription_id?: string | null;
|
|
75
|
+
current_period_start?: Date | null;
|
|
76
|
+
current_period_end?: Date | null;
|
|
77
|
+
cancel_at_period_end?: boolean;
|
|
78
|
+
billing_email?: string | null;
|
|
79
|
+
}) {
|
|
80
|
+
await applyPlanToOrg(pool, input.org_id, input.plan);
|
|
81
|
+
await pool.query(
|
|
82
|
+
`UPDATE orgs
|
|
83
|
+
SET subscription_status = $1,
|
|
84
|
+
stripe_customer_id = COALESCE($2, stripe_customer_id),
|
|
85
|
+
stripe_subscription_id = COALESCE($3, stripe_subscription_id),
|
|
86
|
+
current_period_start = COALESCE($4, current_period_start),
|
|
87
|
+
current_period_end = COALESCE($5, current_period_end),
|
|
88
|
+
cancel_at_period_end = $6,
|
|
89
|
+
billing_email = COALESCE($7, billing_email)
|
|
90
|
+
WHERE id = $8`,
|
|
91
|
+
[
|
|
92
|
+
input.subscription_status,
|
|
93
|
+
input.stripe_customer_id ?? null,
|
|
94
|
+
input.stripe_subscription_id ?? null,
|
|
95
|
+
input.current_period_start ?? null,
|
|
96
|
+
input.current_period_end ?? null,
|
|
97
|
+
input.cancel_at_period_end ?? false,
|
|
98
|
+
input.billing_email ?? null,
|
|
99
|
+
input.org_id,
|
|
100
|
+
],
|
|
101
|
+
);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// POST /v1/billing/checkout (auth required)
|
|
105
|
+
router.post('/billing/checkout', requireWorkspaceSession, async (req, res) => {
|
|
106
|
+
const parsed = CheckoutSchema.safeParse(req.body);
|
|
107
|
+
if (!parsed.success) {
|
|
108
|
+
return res.status(422).json({ error: 'validation_error', details: parsed.error.flatten() });
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
const authReq = req as WorkspaceAuthenticatedRequest;
|
|
112
|
+
const orgId = parsed.data.org_id || authReq.org.id;
|
|
113
|
+
if (orgId !== authReq.org.id) {
|
|
114
|
+
return res.status(403).json({ error: 'forbidden', message: 'Organization is outside your workspace' });
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
if (!billingUpgradesEnabled()) {
|
|
118
|
+
return res.status(403).json({
|
|
119
|
+
error: 'billing_upgrades_disabled',
|
|
120
|
+
message: 'Paid upgrades are currently waitlist-only.',
|
|
121
|
+
waitlist_url: '/pricing#waitlist',
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
const secret = process.env.STRIPE_SECRET_KEY;
|
|
126
|
+
const appUrl = process.env.APP_URL || process.env.FRONTEND_URL || 'http://localhost:3001';
|
|
127
|
+
const priceEnv = PLAN_CONFIG[parsed.data.plan].stripe_price_env;
|
|
128
|
+
const price = priceEnv ? process.env[priceEnv] : undefined;
|
|
129
|
+
|
|
130
|
+
if (!secret || !price) {
|
|
131
|
+
return res.status(501).json({
|
|
132
|
+
error: 'billing_not_configured',
|
|
133
|
+
message: 'Stripe is not configured for this environment',
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
try {
|
|
138
|
+
const stripe = getStripe(secret);
|
|
139
|
+
|
|
140
|
+
// Look up or create Stripe customer
|
|
141
|
+
const orgResult = await pool.query('SELECT id, stripe_customer_id FROM orgs WHERE id = $1', [orgId]);
|
|
142
|
+
if (orgResult.rows.length === 0) {
|
|
143
|
+
return res.status(404).json({ error: 'org_not_found', message: 'Organization not found' });
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
let stripeCustomerId = orgResult.rows[0].stripe_customer_id;
|
|
147
|
+
if (!stripeCustomerId) {
|
|
148
|
+
const customer = await stripe.customers.create({
|
|
149
|
+
email: parsed.data.email,
|
|
150
|
+
metadata: { org_id: orgId },
|
|
151
|
+
});
|
|
152
|
+
stripeCustomerId = customer.id;
|
|
153
|
+
await pool.query('UPDATE orgs SET stripe_customer_id = $1 WHERE id = $2', [stripeCustomerId, orgId]);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
const metadata = { org_id: orgId, plan: parsed.data.plan };
|
|
157
|
+
const session = await stripe.checkout.sessions.create({
|
|
158
|
+
mode: 'subscription',
|
|
159
|
+
customer: stripeCustomerId,
|
|
160
|
+
line_items: [{ price, quantity: 1 }],
|
|
161
|
+
success_url: `${appUrl}/app/settings?tab=billing&checkout=success`,
|
|
162
|
+
cancel_url: `${appUrl}/pricing`,
|
|
163
|
+
metadata,
|
|
164
|
+
subscription_data: { metadata },
|
|
165
|
+
allow_promotion_codes: true,
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
return res.json({ url: session.url });
|
|
169
|
+
} catch (err) {
|
|
170
|
+
log.error('[billing] checkout error', { error: (err as Error).message });
|
|
171
|
+
return res.status(500).json({ error: 'internal_error', message: 'An unexpected error occurred' });
|
|
172
|
+
}
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
// GET /v1/billing/portal (auth required)
|
|
176
|
+
router.get('/billing/portal', requireWorkspaceSession, async (req, res) => {
|
|
177
|
+
const authReq = req as WorkspaceAuthenticatedRequest;
|
|
178
|
+
const secret = process.env.STRIPE_SECRET_KEY;
|
|
179
|
+
const appUrl = process.env.APP_URL || process.env.FRONTEND_URL || 'http://localhost:3001';
|
|
180
|
+
|
|
181
|
+
if (!secret) {
|
|
182
|
+
return res.status(501).json({
|
|
183
|
+
error: 'billing_not_configured',
|
|
184
|
+
message: 'Stripe is not configured for this environment',
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
try {
|
|
189
|
+
const orgResult = await pool.query('SELECT stripe_customer_id FROM orgs WHERE id = $1', [authReq.org.id]);
|
|
190
|
+
const stripeCustomerId = orgResult.rows[0]?.stripe_customer_id;
|
|
191
|
+
|
|
192
|
+
if (!stripeCustomerId) {
|
|
193
|
+
return res.status(400).json({ error: 'no_stripe_customer', message: 'No billing account found. Subscribe to a plan first.' });
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
const stripe = getStripe(secret);
|
|
197
|
+
const portalSession = await stripe.billingPortal.sessions.create({
|
|
198
|
+
customer: stripeCustomerId,
|
|
199
|
+
return_url: `${appUrl}/app/settings?tab=billing`,
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
return res.json({ url: portalSession.url });
|
|
203
|
+
} catch (err) {
|
|
204
|
+
log.error('[billing] portal error', { error: (err as Error).message });
|
|
205
|
+
return res.status(500).json({ error: 'internal_error', message: 'An unexpected error occurred' });
|
|
206
|
+
}
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
// GET /v1/billing/status (auth required)
|
|
210
|
+
router.get('/billing/status', requireWorkspaceSession, async (req, res) => {
|
|
211
|
+
const authReq = req as WorkspaceAuthenticatedRequest;
|
|
212
|
+
|
|
213
|
+
try {
|
|
214
|
+
const orgResult = await pool.query(
|
|
215
|
+
`SELECT
|
|
216
|
+
plan,
|
|
217
|
+
agent_limit,
|
|
218
|
+
stripe_customer_id,
|
|
219
|
+
stripe_subscription_id,
|
|
220
|
+
subscription_status,
|
|
221
|
+
current_period_end,
|
|
222
|
+
cancel_at_period_end,
|
|
223
|
+
billing_email
|
|
224
|
+
FROM orgs
|
|
225
|
+
WHERE id = $1`,
|
|
226
|
+
[authReq.org.id],
|
|
227
|
+
);
|
|
228
|
+
const org = orgResult.rows[0];
|
|
229
|
+
const plan = parsePlan(org.plan);
|
|
230
|
+
const usage = await getPlanUsage(authReq.org.id);
|
|
231
|
+
const limits = serializableLimits(plan);
|
|
232
|
+
|
|
233
|
+
const response: Record<string, unknown> = {
|
|
234
|
+
plan,
|
|
235
|
+
subscription_status: org.subscription_status ?? (plan === 'free' ? 'free' : 'active'),
|
|
236
|
+
renewal_date: org.current_period_end?.toISOString?.() ?? null,
|
|
237
|
+
cancel_at_period_end: Boolean(org.cancel_at_period_end),
|
|
238
|
+
billing_email: org.billing_email,
|
|
239
|
+
limits,
|
|
240
|
+
usage: {
|
|
241
|
+
...usage,
|
|
242
|
+
activity_retention_days: limits.activity_retention_days,
|
|
243
|
+
},
|
|
244
|
+
upgrade_reasons: upgradeReasons(plan, usage),
|
|
245
|
+
agents_used: usage.agents,
|
|
246
|
+
agent_limit: getPlanConfig(plan).db_agent_limit,
|
|
247
|
+
stripe_customer_id: Boolean(org.stripe_customer_id),
|
|
248
|
+
stripe_subscription_id: Boolean(org.stripe_subscription_id),
|
|
249
|
+
billing_upgrades_enabled: billingUpgradesEnabled(),
|
|
250
|
+
};
|
|
251
|
+
|
|
252
|
+
if (!response.renewal_date && org.stripe_subscription_id && process.env.STRIPE_SECRET_KEY) {
|
|
253
|
+
try {
|
|
254
|
+
const stripe = getStripe(process.env.STRIPE_SECRET_KEY);
|
|
255
|
+
const sub = await stripe.subscriptions.retrieve(org.stripe_subscription_id) as unknown as { current_period_end: number };
|
|
256
|
+
response.renewal_date = new Date(sub.current_period_end * 1000).toISOString();
|
|
257
|
+
} catch {
|
|
258
|
+
// Non-fatal — just omit renewal_date
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
return res.json(response);
|
|
263
|
+
} catch (err) {
|
|
264
|
+
log.error('[billing] status error', { error: (err as Error).message });
|
|
265
|
+
return res.status(500).json({ error: 'internal_error', message: 'An unexpected error occurred' });
|
|
266
|
+
}
|
|
267
|
+
});
|
|
268
|
+
|
|
269
|
+
// GET /v1/billing/subscription/:org_id (legacy, kept for compatibility)
|
|
270
|
+
router.get('/billing/subscription/:org_id', async (req, res) => {
|
|
271
|
+
const org = await pool.query('SELECT id, plan, agent_limit FROM orgs WHERE id = $1', [
|
|
272
|
+
req.params.org_id,
|
|
273
|
+
]);
|
|
274
|
+
if (org.rows.length === 0) {
|
|
275
|
+
return res.status(404).json({ error: 'org_not_found', message: 'Organization not found' });
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
return res.json({
|
|
279
|
+
org_id: org.rows[0].id,
|
|
280
|
+
status: org.rows[0].plan === 'free' ? 'free' : 'active',
|
|
281
|
+
plan: org.rows[0].plan,
|
|
282
|
+
agent_limit: org.rows[0].agent_limit,
|
|
283
|
+
});
|
|
284
|
+
});
|
|
285
|
+
|
|
286
|
+
// Webhook handler (exported for use in index.ts with raw body)
|
|
287
|
+
export async function handleStripeWebhook(req: express.Request, res: express.Response) {
|
|
288
|
+
const secret = process.env.STRIPE_SECRET_KEY;
|
|
289
|
+
const webhookSecret = process.env.STRIPE_WEBHOOK_SECRET;
|
|
290
|
+
const signature = req.header('stripe-signature');
|
|
291
|
+
|
|
292
|
+
if (!secret || !webhookSecret) {
|
|
293
|
+
return res.status(501).json({
|
|
294
|
+
error: 'billing_not_configured',
|
|
295
|
+
message: 'Stripe webhook is not configured for this environment',
|
|
296
|
+
});
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
if (!signature) {
|
|
300
|
+
return res.status(400).json({ error: 'missing_signature' });
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
const stripe = getStripe(secret);
|
|
304
|
+
let event: StripeEvent;
|
|
305
|
+
try {
|
|
306
|
+
event = stripe.webhooks.constructEvent(req.body, signature, webhookSecret) as StripeEvent;
|
|
307
|
+
} catch {
|
|
308
|
+
return res.status(400).json({ error: 'invalid_signature' });
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
try {
|
|
312
|
+
log.info('[billing] webhook received', {
|
|
313
|
+
request_id: requestIdFrom(res),
|
|
314
|
+
event_type: event.type,
|
|
315
|
+
event_id: (event as { id?: string }).id ?? null,
|
|
316
|
+
});
|
|
317
|
+
|
|
318
|
+
if (event.type === 'checkout.session.completed') {
|
|
319
|
+
const obj = event.data.object;
|
|
320
|
+
const metadata = parsePlanMetadata(obj.metadata);
|
|
321
|
+
if (metadata) {
|
|
322
|
+
await updateSubscriptionState({
|
|
323
|
+
org_id: metadata.orgId,
|
|
324
|
+
plan: parsePlan(metadata.plan),
|
|
325
|
+
subscription_status: 'active',
|
|
326
|
+
stripe_customer_id: typeof obj.customer === 'string' ? obj.customer : null,
|
|
327
|
+
stripe_subscription_id: typeof obj.subscription === 'string' ? obj.subscription : null,
|
|
328
|
+
billing_email: obj.customer_details?.email ?? obj.customer_email ?? null,
|
|
329
|
+
});
|
|
330
|
+
|
|
331
|
+
log.info('[billing] checkout completed', {
|
|
332
|
+
request_id: requestIdFrom(res),
|
|
333
|
+
org_id: metadata.orgId,
|
|
334
|
+
plan: metadata.plan,
|
|
335
|
+
event_type: event.type,
|
|
336
|
+
});
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
if (event.type === 'customer.subscription.updated') {
|
|
341
|
+
const subscription = event.data.object;
|
|
342
|
+
const metadata = parsePlanMetadata(subscription.metadata);
|
|
343
|
+
if (metadata) {
|
|
344
|
+
const status = subscription.status ?? 'active';
|
|
345
|
+
await updateSubscriptionState({
|
|
346
|
+
org_id: metadata.orgId,
|
|
347
|
+
plan: parsePlan(metadata.plan),
|
|
348
|
+
subscription_status: status,
|
|
349
|
+
stripe_customer_id: typeof subscription.customer === 'string' ? subscription.customer : null,
|
|
350
|
+
stripe_subscription_id: subscription.id ?? null,
|
|
351
|
+
current_period_start: stripeTimestamp(subscription.current_period_start),
|
|
352
|
+
current_period_end: stripeTimestamp(subscription.current_period_end),
|
|
353
|
+
cancel_at_period_end: Boolean(subscription.cancel_at_period_end),
|
|
354
|
+
});
|
|
355
|
+
log.info('[billing] subscription updated', {
|
|
356
|
+
request_id: requestIdFrom(res),
|
|
357
|
+
org_id: metadata.orgId,
|
|
358
|
+
status,
|
|
359
|
+
event_type: event.type,
|
|
360
|
+
});
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
if (event.type === 'customer.subscription.deleted') {
|
|
365
|
+
const subscription = event.data.object;
|
|
366
|
+
const metadata = parsePlanMetadata(subscription.metadata);
|
|
367
|
+
if (metadata) {
|
|
368
|
+
await applyPlanToOrg(pool, metadata.orgId, 'free');
|
|
369
|
+
await pool.query(
|
|
370
|
+
`UPDATE orgs
|
|
371
|
+
SET stripe_subscription_id = NULL,
|
|
372
|
+
subscription_status = 'canceled',
|
|
373
|
+
current_period_start = NULL,
|
|
374
|
+
current_period_end = NULL,
|
|
375
|
+
cancel_at_period_end = false
|
|
376
|
+
WHERE id = $1`,
|
|
377
|
+
[metadata.orgId],
|
|
378
|
+
);
|
|
379
|
+
log.info('[billing] subscription deleted', {
|
|
380
|
+
request_id: requestIdFrom(res),
|
|
381
|
+
org_id: metadata.orgId,
|
|
382
|
+
event_type: event.type,
|
|
383
|
+
});
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
if (event.type === 'invoice.payment_failed') {
|
|
388
|
+
const invoice = event.data.object;
|
|
389
|
+
log.warn('[billing] invoice payment failed', {
|
|
390
|
+
request_id: requestIdFrom(res),
|
|
391
|
+
customer: invoice.customer,
|
|
392
|
+
event_type: event.type,
|
|
393
|
+
});
|
|
394
|
+
}
|
|
395
|
+
} catch (err) {
|
|
396
|
+
log.error('[billing] webhook processing error', {
|
|
397
|
+
request_id: requestIdFrom(res),
|
|
398
|
+
error: (err as Error).message,
|
|
399
|
+
event_type: event.type,
|
|
400
|
+
});
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
return res.json({ received: true });
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
export default router;
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import express from 'express';
|
|
2
|
+
import { addDays } from 'date-fns';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
import pool from '../db/client';
|
|
5
|
+
import { getAvailableSlots } from '../core/availability';
|
|
6
|
+
import { previewConflict } from '../core/conflict';
|
|
7
|
+
import {
|
|
8
|
+
canAccessAgent,
|
|
9
|
+
requireWorkspaceOrAgent,
|
|
10
|
+
type AnyAuthenticatedRequest,
|
|
11
|
+
} from '../middleware/auth';
|
|
12
|
+
import { log } from '../lib/logger';
|
|
13
|
+
import { actorFromAuth, durationSince, logActivity } from '../lib/activity';
|
|
14
|
+
import { enforcePlanLimit } from '../lib/plans';
|
|
15
|
+
import type { Hold } from '../types';
|
|
16
|
+
|
|
17
|
+
const router = express.Router();
|
|
18
|
+
|
|
19
|
+
const ConflictCheckSchema = z
|
|
20
|
+
.object({
|
|
21
|
+
agent_id: z.string().uuid(),
|
|
22
|
+
start_at: z.string().datetime({ offset: true }),
|
|
23
|
+
end_at: z.string().datetime({ offset: true }),
|
|
24
|
+
reason: z.string().max(500).optional(),
|
|
25
|
+
metadata: z.record(z.string(), z.unknown()).optional(),
|
|
26
|
+
})
|
|
27
|
+
.refine((data) => new Date(data.end_at) > new Date(data.start_at), {
|
|
28
|
+
path: ['end_at'],
|
|
29
|
+
message: 'end_at must be after start_at',
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
async function getAgentInOrg(agentId: string, orgId: string) {
|
|
33
|
+
const result = await pool.query('SELECT * FROM agents WHERE id = $1 AND org_id = $2', [
|
|
34
|
+
agentId,
|
|
35
|
+
orgId,
|
|
36
|
+
]);
|
|
37
|
+
return result.rows[0];
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function explanation(status: 'available' | 'would_win' | 'would_lose', rule: string) {
|
|
41
|
+
if (status === 'available') return 'No confirmed holds overlap this request.';
|
|
42
|
+
if (status === 'would_win') return `This agent would win the overlap by ${rule}.`;
|
|
43
|
+
return `An existing hold would keep the slot by ${rule}.`;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
router.post('/conflicts/check', requireWorkspaceOrAgent, async (req, res) => {
|
|
47
|
+
const startedAt = Date.now();
|
|
48
|
+
const parsed = ConflictCheckSchema.safeParse(req.body);
|
|
49
|
+
if (!parsed.success) {
|
|
50
|
+
return res.status(422).json({ error: 'validation_error', details: parsed.error.flatten() });
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const authReq = req as AnyAuthenticatedRequest;
|
|
54
|
+
const startAt = new Date(parsed.data.start_at);
|
|
55
|
+
const endAt = new Date(parsed.data.end_at);
|
|
56
|
+
|
|
57
|
+
try {
|
|
58
|
+
if (!(await getAgentInOrg(parsed.data.agent_id, authReq.org.id))) {
|
|
59
|
+
return res.status(403).json({ error: 'forbidden', message: 'Agent is outside your org' });
|
|
60
|
+
}
|
|
61
|
+
if (!canAccessAgent(authReq, parsed.data.agent_id)) {
|
|
62
|
+
return res.status(403).json({ error: 'forbidden', message: 'Agent key cannot act for another agent' });
|
|
63
|
+
}
|
|
64
|
+
if (!(await enforcePlanLimit({
|
|
65
|
+
org_id: authReq.org.id,
|
|
66
|
+
limit_type: 'api_calls_month',
|
|
67
|
+
res,
|
|
68
|
+
}))) {
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const newHold: Omit<Hold, 'id' | 'created_at'> = {
|
|
73
|
+
agent_id: parsed.data.agent_id,
|
|
74
|
+
org_id: authReq.org.id,
|
|
75
|
+
start_at: startAt,
|
|
76
|
+
end_at: endAt,
|
|
77
|
+
reason: parsed.data.reason,
|
|
78
|
+
status: 'confirmed',
|
|
79
|
+
metadata: parsed.data.metadata,
|
|
80
|
+
};
|
|
81
|
+
const result = await previewConflict(newHold, pool as never);
|
|
82
|
+
const alternatives =
|
|
83
|
+
result.status === 'would_lose'
|
|
84
|
+
? await getAvailableSlots({
|
|
85
|
+
agent_id: parsed.data.agent_id,
|
|
86
|
+
org_id: authReq.org.id,
|
|
87
|
+
from: startAt,
|
|
88
|
+
to: addDays(startAt, 7),
|
|
89
|
+
duration_minutes: Math.ceil((endAt.getTime() - startAt.getTime()) / 60000),
|
|
90
|
+
include_competing_agents: true,
|
|
91
|
+
})
|
|
92
|
+
: [];
|
|
93
|
+
|
|
94
|
+
await logActivity({
|
|
95
|
+
org_id: authReq.org.id,
|
|
96
|
+
agent_id: parsed.data.agent_id,
|
|
97
|
+
activity_type: 'conflict_preview',
|
|
98
|
+
endpoint: '/v1/conflicts/check',
|
|
99
|
+
method: 'POST',
|
|
100
|
+
status_code: 200,
|
|
101
|
+
status: 'success',
|
|
102
|
+
...actorFromAuth(authReq),
|
|
103
|
+
latency_ms: durationSince(startedAt),
|
|
104
|
+
metadata: {
|
|
105
|
+
start_at: startAt.toISOString(),
|
|
106
|
+
end_at: endAt.toISOString(),
|
|
107
|
+
result_status: result.status,
|
|
108
|
+
rule_applied: result.rule_applied,
|
|
109
|
+
},
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
return res.json({
|
|
113
|
+
status: result.status,
|
|
114
|
+
would_create_hold: result.status !== 'would_lose',
|
|
115
|
+
winning_hold_id: result.winning_hold_id,
|
|
116
|
+
losing_hold_ids: result.losing_hold_ids,
|
|
117
|
+
rule_applied: result.rule_applied,
|
|
118
|
+
explanation: explanation(result.status, result.rule_applied),
|
|
119
|
+
suggested_alternatives: alternatives.slice(0, 3).map((slot) => ({
|
|
120
|
+
start: slot.start.toISOString(),
|
|
121
|
+
end: slot.end.toISOString(),
|
|
122
|
+
confidence: slot.confidence,
|
|
123
|
+
})),
|
|
124
|
+
});
|
|
125
|
+
} catch (err) {
|
|
126
|
+
log.error('[conflicts] unexpected error', { error: (err as Error).message });
|
|
127
|
+
return res.status(500).json({ error: 'internal_error', message: 'An unexpected error occurred' });
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
export default router;
|