@girardmedia/bootspring 1.2.0 → 2.0.3

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.
Files changed (253) hide show
  1. package/README.md +107 -14
  2. package/bin/bootspring.js +166 -27
  3. package/cli/agent.js +189 -17
  4. package/cli/analyze.js +499 -0
  5. package/cli/audit.js +557 -0
  6. package/cli/auth.js +495 -38
  7. package/cli/billing.js +302 -0
  8. package/cli/build.js +695 -0
  9. package/cli/business.js +109 -26
  10. package/cli/checkpoint-utils.js +168 -0
  11. package/cli/checkpoint.js +639 -0
  12. package/cli/cloud-sync.js +447 -0
  13. package/cli/content.js +198 -0
  14. package/cli/context.js +1 -1
  15. package/cli/deploy.js +543 -0
  16. package/cli/fundraise.js +112 -50
  17. package/cli/github-cmd.js +435 -0
  18. package/cli/health.js +477 -0
  19. package/cli/init.js +84 -13
  20. package/cli/legal.js +107 -95
  21. package/cli/log.js +2 -2
  22. package/cli/loop.js +976 -73
  23. package/cli/manager.js +711 -0
  24. package/cli/metrics.js +480 -0
  25. package/cli/monitor.js +812 -0
  26. package/cli/onboard.js +521 -0
  27. package/cli/orchestrator.js +12 -24
  28. package/cli/prd.js +594 -0
  29. package/cli/preseed-start.js +1483 -0
  30. package/cli/preseed.js +2302 -0
  31. package/cli/project.js +436 -0
  32. package/cli/quality.js +233 -0
  33. package/cli/security.js +913 -0
  34. package/cli/seed.js +1441 -5
  35. package/cli/skill.js +273 -211
  36. package/cli/suggest.js +989 -0
  37. package/cli/switch.js +453 -0
  38. package/cli/visualize.js +527 -0
  39. package/cli/watch.js +769 -0
  40. package/cli/workspace.js +607 -0
  41. package/core/analyze-workflow.js +1134 -0
  42. package/core/api-client.js +535 -22
  43. package/core/audit-workflow.js +1350 -0
  44. package/core/build-orchestrator.js +480 -0
  45. package/core/build-state.js +577 -0
  46. package/core/checkpoint-engine.js +408 -0
  47. package/core/config.js +1109 -26
  48. package/core/context-loader.js +21 -1
  49. package/core/deploy-workflow.js +836 -0
  50. package/core/entitlements.js +93 -22
  51. package/core/github-sync.js +610 -0
  52. package/core/index.js +8 -1
  53. package/core/ingest.js +1111 -0
  54. package/core/metrics-engine.js +768 -0
  55. package/core/onboard-workflow.js +1007 -0
  56. package/core/preseed-workflow.js +934 -0
  57. package/core/preseed.js +1617 -0
  58. package/core/project-context.js +325 -0
  59. package/core/project-state.js +694 -0
  60. package/core/r2-sync.js +583 -0
  61. package/core/scaffold.js +525 -7
  62. package/core/session.js +258 -0
  63. package/core/task-extractor.js +758 -0
  64. package/core/telemetry.js +28 -6
  65. package/core/tier-enforcement.js +737 -0
  66. package/core/utils.js +38 -14
  67. package/generators/questionnaire.js +15 -12
  68. package/generators/sections/ai.js +7 -7
  69. package/generators/sections/content.js +300 -0
  70. package/generators/sections/index.js +3 -0
  71. package/generators/sections/plugins.js +7 -6
  72. package/generators/templates/build-planning.template.js +596 -0
  73. package/generators/templates/content.template.js +819 -0
  74. package/generators/templates/index.js +2 -1
  75. package/hooks/git-autopilot.js +1250 -0
  76. package/hooks/index.js +9 -0
  77. package/intelligence/agent-collab.js +2057 -0
  78. package/intelligence/auto-suggest.js +634 -0
  79. package/intelligence/content-gen.js +1589 -0
  80. package/intelligence/cross-project.js +1647 -0
  81. package/intelligence/index.js +184 -0
  82. package/intelligence/learning/insights.json +517 -7
  83. package/intelligence/learning/pattern-learner.js +1008 -14
  84. package/intelligence/memory/decision-tracker.js +1431 -31
  85. package/intelligence/memory/decisions.jsonl +0 -0
  86. package/intelligence/orchestrator.js +2896 -1
  87. package/intelligence/prd.js +92 -1
  88. package/intelligence/recommendation-weights.json +14 -2
  89. package/intelligence/recommendations.js +463 -9
  90. package/intelligence/workflow-composer.js +1451 -0
  91. package/marketplace/index.d.ts +324 -0
  92. package/marketplace/index.js +1921 -0
  93. package/mcp/contracts/mcp-contract.v1.json +342 -4
  94. package/mcp/registry.js +680 -3
  95. package/mcp/response-formatter.js +23 -0
  96. package/mcp/tools/assist-tool.js +78 -4
  97. package/mcp/tools/autopilot-tool.js +408 -0
  98. package/mcp/tools/content-tool.js +571 -0
  99. package/mcp/tools/dashboard-tool.js +251 -5
  100. package/mcp/tools/mvp-tool.js +344 -0
  101. package/mcp/tools/plugin-tool.js +23 -1
  102. package/mcp/tools/prd-tool.js +579 -0
  103. package/mcp/tools/seed-tool.js +447 -0
  104. package/mcp/tools/skill-tool.js +43 -14
  105. package/mcp/tools/suggest-tool.js +147 -0
  106. package/package.json +15 -6
  107. package/agents/README.md +0 -93
  108. package/agents/ai-integration-expert/context.md +0 -386
  109. package/agents/api-expert/context.md +0 -416
  110. package/agents/architecture-expert/context.md +0 -454
  111. package/agents/auth-expert/context.md +0 -399
  112. package/agents/backend-expert/context.md +0 -483
  113. package/agents/business-strategy-expert/context.md +0 -180
  114. package/agents/code-review-expert/context.md +0 -365
  115. package/agents/competitive-analysis-expert/context.md +0 -239
  116. package/agents/data-modeling-expert/context.md +0 -352
  117. package/agents/database-expert/context.md +0 -250
  118. package/agents/devops-expert/context.md +0 -446
  119. package/agents/email-expert/context.md +0 -379
  120. package/agents/financial-expert/context.md +0 -213
  121. package/agents/frontend-expert/context.md +0 -364
  122. package/agents/fundraising-expert/context.md +0 -257
  123. package/agents/growth-expert/context.md +0 -249
  124. package/agents/index.js +0 -140
  125. package/agents/investor-relations-expert/context.md +0 -266
  126. package/agents/legal-expert/context.md +0 -284
  127. package/agents/marketing-expert/context.md +0 -236
  128. package/agents/monitoring-expert/context.md +0 -362
  129. package/agents/operations-expert/context.md +0 -279
  130. package/agents/partnerships-expert/context.md +0 -286
  131. package/agents/payment-expert/context.md +0 -340
  132. package/agents/performance-expert/context.md +0 -377
  133. package/agents/private-equity-expert/context.md +0 -246
  134. package/agents/railway-expert/context.md +0 -284
  135. package/agents/research-expert/context.md +0 -245
  136. package/agents/sales-expert/context.md +0 -241
  137. package/agents/security-expert/context.md +0 -343
  138. package/agents/testing-expert/context.md +0 -414
  139. package/agents/ui-ux-expert/context.md +0 -448
  140. package/agents/vercel-expert/context.md +0 -426
  141. package/skills/index.js +0 -787
  142. package/skills/patterns/README.md +0 -163
  143. package/skills/patterns/ai/agents.md +0 -281
  144. package/skills/patterns/ai/claude.md +0 -138
  145. package/skills/patterns/ai/embeddings.md +0 -150
  146. package/skills/patterns/ai/rag.md +0 -266
  147. package/skills/patterns/ai/streaming.md +0 -170
  148. package/skills/patterns/ai/structured-output.md +0 -162
  149. package/skills/patterns/ai/tools.md +0 -154
  150. package/skills/patterns/analytics/tracking.md +0 -220
  151. package/skills/patterns/api/errors.md +0 -296
  152. package/skills/patterns/api/graphql.md +0 -440
  153. package/skills/patterns/api/middleware.md +0 -279
  154. package/skills/patterns/api/openapi.md +0 -285
  155. package/skills/patterns/api/rate-limiting.md +0 -231
  156. package/skills/patterns/api/route-handler.md +0 -217
  157. package/skills/patterns/api/server-action.md +0 -249
  158. package/skills/patterns/api/versioning.md +0 -443
  159. package/skills/patterns/api/webhooks.md +0 -247
  160. package/skills/patterns/auth/clerk.md +0 -132
  161. package/skills/patterns/auth/mfa.md +0 -313
  162. package/skills/patterns/auth/nextauth.md +0 -140
  163. package/skills/patterns/auth/oauth.md +0 -237
  164. package/skills/patterns/auth/rbac.md +0 -152
  165. package/skills/patterns/auth/session-management.md +0 -367
  166. package/skills/patterns/auth/session.md +0 -120
  167. package/skills/patterns/database/audit.md +0 -177
  168. package/skills/patterns/database/migrations.md +0 -177
  169. package/skills/patterns/database/pagination.md +0 -230
  170. package/skills/patterns/database/pooling.md +0 -357
  171. package/skills/patterns/database/prisma.md +0 -180
  172. package/skills/patterns/database/relations.md +0 -187
  173. package/skills/patterns/database/seeding.md +0 -246
  174. package/skills/patterns/database/soft-delete.md +0 -153
  175. package/skills/patterns/database/transactions.md +0 -162
  176. package/skills/patterns/deployment/ci-cd.md +0 -231
  177. package/skills/patterns/deployment/docker.md +0 -188
  178. package/skills/patterns/deployment/monitoring.md +0 -387
  179. package/skills/patterns/deployment/vercel.md +0 -160
  180. package/skills/patterns/email/resend.md +0 -143
  181. package/skills/patterns/email/templates.md +0 -245
  182. package/skills/patterns/email/transactional.md +0 -503
  183. package/skills/patterns/email/verification.md +0 -176
  184. package/skills/patterns/files/download.md +0 -243
  185. package/skills/patterns/files/upload.md +0 -239
  186. package/skills/patterns/i18n/nextintl.md +0 -188
  187. package/skills/patterns/logging/structured.md +0 -292
  188. package/skills/patterns/notifications/email-queue.md +0 -248
  189. package/skills/patterns/notifications/push.md +0 -279
  190. package/skills/patterns/payments/checkout.md +0 -303
  191. package/skills/patterns/payments/invoices.md +0 -287
  192. package/skills/patterns/payments/portal.md +0 -245
  193. package/skills/patterns/payments/stripe.md +0 -272
  194. package/skills/patterns/payments/subscriptions.md +0 -300
  195. package/skills/patterns/payments/usage.md +0 -279
  196. package/skills/patterns/performance/caching.md +0 -276
  197. package/skills/patterns/performance/code-splitting.md +0 -233
  198. package/skills/patterns/performance/edge.md +0 -254
  199. package/skills/patterns/performance/isr.md +0 -266
  200. package/skills/patterns/performance/lazy-loading.md +0 -281
  201. package/skills/patterns/realtime/sse.md +0 -327
  202. package/skills/patterns/realtime/websockets.md +0 -336
  203. package/skills/patterns/search/filtering.md +0 -329
  204. package/skills/patterns/search/fulltext.md +0 -260
  205. package/skills/patterns/security/audit-logging.md +0 -444
  206. package/skills/patterns/security/csrf.md +0 -234
  207. package/skills/patterns/security/headers.md +0 -252
  208. package/skills/patterns/security/sanitization.md +0 -258
  209. package/skills/patterns/security/secrets.md +0 -261
  210. package/skills/patterns/security/validation.md +0 -268
  211. package/skills/patterns/security/xss.md +0 -229
  212. package/skills/patterns/seo/metadata.md +0 -252
  213. package/skills/patterns/state/context.md +0 -349
  214. package/skills/patterns/state/react-query.md +0 -313
  215. package/skills/patterns/state/url-state.md +0 -482
  216. package/skills/patterns/state/zustand.md +0 -262
  217. package/skills/patterns/testing/api.md +0 -259
  218. package/skills/patterns/testing/component.md +0 -233
  219. package/skills/patterns/testing/coverage.md +0 -207
  220. package/skills/patterns/testing/fixtures.md +0 -225
  221. package/skills/patterns/testing/integration.md +0 -436
  222. package/skills/patterns/testing/mocking.md +0 -177
  223. package/skills/patterns/testing/playwright.md +0 -162
  224. package/skills/patterns/testing/snapshot.md +0 -175
  225. package/skills/patterns/testing/vitest.md +0 -307
  226. package/skills/patterns/ui/accordions.md +0 -395
  227. package/skills/patterns/ui/cards.md +0 -299
  228. package/skills/patterns/ui/dropdowns.md +0 -476
  229. package/skills/patterns/ui/empty-states.md +0 -320
  230. package/skills/patterns/ui/forms.md +0 -405
  231. package/skills/patterns/ui/inputs.md +0 -319
  232. package/skills/patterns/ui/layouts.md +0 -282
  233. package/skills/patterns/ui/loading.md +0 -291
  234. package/skills/patterns/ui/modals.md +0 -338
  235. package/skills/patterns/ui/navigation.md +0 -374
  236. package/skills/patterns/ui/tables.md +0 -407
  237. package/skills/patterns/ui/toasts.md +0 -300
  238. package/skills/patterns/ui/tooltips.md +0 -396
  239. package/skills/patterns/utils/dates.md +0 -435
  240. package/skills/patterns/utils/errors.md +0 -451
  241. package/skills/patterns/utils/formatting.md +0 -345
  242. package/skills/patterns/utils/validation.md +0 -434
  243. package/templates/bootspring.config.js +0 -83
  244. package/templates/business/business-model-canvas.md +0 -246
  245. package/templates/business/business-plan.md +0 -266
  246. package/templates/business/competitive-analysis.md +0 -312
  247. package/templates/fundraising/data-room-checklist.md +0 -300
  248. package/templates/fundraising/investor-research.md +0 -243
  249. package/templates/fundraising/pitch-deck-outline.md +0 -253
  250. package/templates/legal/gdpr-checklist.md +0 -339
  251. package/templates/legal/privacy-policy.md +0 -285
  252. package/templates/legal/terms-of-service.md +0 -222
  253. package/templates/mcp.json +0 -9
@@ -1,286 +0,0 @@
1
- # Partnerships Expert Agent
2
-
3
- ## Role
4
- Specialized in strategic partnerships, integrations, channel partnerships, and building partnership ecosystems for startups.
5
-
6
- ## Core Expertise
7
-
8
- ### Partnership Types
9
-
10
- ```markdown
11
- ## Partnership Categories
12
-
13
- ### 1. Technology/Integration Partners
14
- - **What**: Integrate products together
15
- - **Value**: Better user experience, expanded capabilities
16
- - **Examples**: Slack + Salesforce, Stripe + Shopify
17
- - **Revenue**: Usually co-marketing, no rev share
18
-
19
- ### 2. Channel/Reseller Partners
20
- - **What**: Partner sells your product
21
- - **Value**: Extended sales reach
22
- - **Examples**: MSPs, agencies, consultants
23
- - **Revenue**: 15-30% commission
24
-
25
- ### 3. Strategic/OEM Partners
26
- - **What**: Deep product integration
27
- - **Value**: Access to customer base
28
- - **Examples**: White-label, embedded solutions
29
- - **Revenue**: Revenue share or licensing
30
-
31
- ### 4. Affiliate Partners
32
- - **What**: Referral for commission
33
- - **Value**: Low-cost customer acquisition
34
- - **Examples**: Influencers, content creators
35
- - **Revenue**: 10-30% of first year
36
-
37
- ### 5. Co-Marketing Partners
38
- - **What**: Joint marketing efforts
39
- - **Value**: Audience sharing
40
- - **Examples**: Webinars, content, events
41
- - **Revenue**: Leads, no direct revenue
42
- ```
43
-
44
- ### Partnership Evaluation
45
-
46
- ```markdown
47
- ## Partner Evaluation Framework
48
-
49
- ### Strategic Fit (1-10)
50
- - [ ] Complementary products?
51
- - [ ] Shared target customer?
52
- - [ ] Aligned values/culture?
53
- - [ ] Similar growth stage?
54
-
55
- ### Market Opportunity (1-10)
56
- - [ ] Partner's customer base size?
57
- - [ ] Overlap with our ICP?
58
- - [ ] Growth trajectory?
59
- - [ ] Geographic coverage?
60
-
61
- ### Execution Ability (1-10)
62
- - [ ] Technical capability?
63
- - [ ] Dedicated partnership team?
64
- - [ ] Track record of partnerships?
65
- - [ ] Bandwidth to execute?
66
-
67
- ### Risk Assessment (1-10)
68
- - [ ] Competitive risk?
69
- - [ ] Dependency risk?
70
- - [ ] Brand risk?
71
- - [ ] Technical risk?
72
-
73
- ### Scoring
74
- | Factor | Weight | Score |
75
- |--------|--------|-------|
76
- | Strategic Fit | 30% | X |
77
- | Market Opportunity | 30% | X |
78
- | Execution Ability | 25% | X |
79
- | Risk (inverted) | 15% | X |
80
- | **Total** | 100% | X |
81
- ```
82
-
83
- ### Integration Partnership Playbook
84
-
85
- ```markdown
86
- ## Integration Partnership Process
87
-
88
- ### Phase 1: Discovery
89
- - [ ] Identify potential partners
90
- - [ ] Research their ecosystem
91
- - [ ] Find internal champion
92
- - [ ] Initial outreach
93
-
94
- ### Phase 2: Alignment
95
- - [ ] Discovery call
96
- - [ ] Share integration concept
97
- - [ ] Understand their requirements
98
- - [ ] Define mutual value
99
-
100
- ### Phase 3: Planning
101
- - [ ] Technical requirements
102
- - [ ] Timeline and milestones
103
- - [ ] Resource allocation
104
- - [ ] Success metrics
105
-
106
- ### Phase 4: Build
107
- - [ ] API/integration development
108
- - [ ] Documentation
109
- - [ ] Testing
110
- - [ ] Security review
111
-
112
- ### Phase 5: Launch
113
- - [ ] Marketplace listing
114
- - [ ] Co-marketing announcement
115
- - [ ] Customer communication
116
- - [ ] Sales enablement
117
-
118
- ### Phase 6: Ongoing
119
- - [ ] Monitor usage
120
- - [ ] Gather feedback
121
- - [ ] Iterate and improve
122
- - [ ] Expand collaboration
123
-
124
- ## Integration Checklist
125
- - OAuth/authentication setup
126
- - API documentation
127
- - Sandbox/test environment
128
- - Marketplace listing content
129
- - Launch blog post
130
- - Demo video
131
- ```
132
-
133
- ### Partner Agreement Essentials
134
-
135
- ```markdown
136
- ## Partnership Agreement Key Terms
137
-
138
- ### Scope
139
- - Partnership type and activities
140
- - Geographic territory
141
- - Customer segments
142
- - Exclusivity (if any)
143
-
144
- ### Commercial Terms
145
- | Item | Detail |
146
- |------|--------|
147
- | Revenue share | X% of revenue generated |
148
- | Payment terms | Net 30/60/90 |
149
- | Minimum commitment | $X or X customers |
150
- | Term | X years with renewal |
151
-
152
- ### Responsibilities
153
-
154
- **Your Responsibilities**
155
- - Provide product/API access
156
- - Technical support for integration
157
- - Marketing materials
158
- - Training and enablement
159
-
160
- **Partner Responsibilities**
161
- - Integration development
162
- - Customer support (tier 1)
163
- - Marketing activities
164
- - Sales/referral activities
165
-
166
- ### Termination
167
- - Notice period: 30/60/90 days
168
- - Cause termination events
169
- - Wind-down obligations
170
- - Customer transition
171
-
172
- ### IP and Branding
173
- - Trademark usage rights
174
- - Co-branding guidelines
175
- - Customer data ownership
176
- - Integration IP ownership
177
- ```
178
-
179
- ### Partner Program Structure
180
-
181
- ```markdown
182
- ## Partner Program Tiers
183
-
184
- ### Registered Partner
185
- - **Requirements**: Sign up, complete training
186
- - **Benefits**:
187
- - Partner portal access
188
- - Basic co-marketing
189
- - 10% referral commission
190
-
191
- ### Silver Partner
192
- - **Requirements**: 5 referrals/year, certified
193
- - **Benefits**:
194
- - Listed in directory
195
- - Lead sharing
196
- - 15% commission
197
- - Quarterly business review
198
-
199
- ### Gold Partner
200
- - **Requirements**: 15 referrals/year, 2+ certified
201
- - **Benefits**:
202
- - Premium listing
203
- - Co-marketing fund ($X)
204
- - 20% commission
205
- - Dedicated partner manager
206
- - Early access to features
207
-
208
- ### Platinum Partner
209
- - **Requirements**: 30+ referrals/year, strategic fit
210
- - **Benefits**:
211
- - Featured partner status
212
- - Joint sales opportunities
213
- - 25% commission
214
- - Executive sponsor
215
- - Custom integration support
216
-
217
- ## Partner Enablement
218
- - Partner portal with resources
219
- - Certification program
220
- - Sales playbooks
221
- - Technical training
222
- - Marketing assets
223
- ```
224
-
225
- ### Co-Marketing Activities
226
-
227
- ```markdown
228
- ## Co-Marketing Playbook
229
-
230
- ### Joint Content
231
- - [ ] Co-authored blog post
232
- - [ ] Joint webinar
233
- - [ ] Case study featuring both
234
- - [ ] Integration guide
235
-
236
- ### Social Amplification
237
- - [ ] Launch announcement tweets
238
- - [ ] LinkedIn posts
239
- - [ ] Newsletter inclusion
240
- - [ ] Community posts
241
-
242
- ### Events
243
- - [ ] Joint booth at conference
244
- - [ ] Co-hosted meetup
245
- - [ ] Partner spotlight at event
246
-
247
- ### Campaigns
248
- - [ ] Joint email campaign
249
- - [ ] Landing page
250
- - [ ] Promotional offer
251
-
252
- ## Co-Marketing Brief Template
253
- ```markdown
254
- ### Campaign: [Name]
255
-
256
- **Partners**: [Company A] + [Company B]
257
- **Goal**: [Leads, awareness, etc.]
258
- **Timeline**: [Dates]
259
-
260
- **Assets Needed**
261
- - [ ] Asset 1 - Owner - Due
262
- - [ ] Asset 2 - Owner - Due
263
-
264
- **Distribution**
265
- - Channel 1: [Owner]
266
- - Channel 2: [Owner]
267
-
268
- **Success Metrics**
269
- - Metric 1: Target
270
- - Metric 2: Target
271
- ```
272
- ```
273
-
274
- ## Partnerships Checklist
275
-
276
- - [ ] Partnership strategy defined
277
- - [ ] Target partners identified
278
- - [ ] Outreach templates created
279
- - [ ] Agreement template ready
280
- - [ ] Partner portal set up
281
- - [ ] Enablement materials created
282
- - [ ] Tracking system in place
283
- - [ ] Success metrics defined
284
-
285
- ## Trigger Keywords
286
- partnership, integration, partner, channel, reseller, affiliate, co-marketing, ecosystem, API, marketplace, alliance, collaboration
@@ -1,340 +0,0 @@
1
- # Payment Expert Agent
2
-
3
- ## Role
4
- Specialized in payment processing, subscription management, Stripe integration, and billing systems for SaaS applications.
5
-
6
- ## Core Expertise
7
-
8
- ### Stripe Integration
9
-
10
- ```typescript
11
- // lib/stripe.ts
12
- import Stripe from 'stripe';
13
-
14
- export const stripe = new Stripe(process.env.STRIPE_SECRET_KEY!, {
15
- apiVersion: '2024-12-18.acacia',
16
- typescript: true,
17
- });
18
-
19
- // Price IDs from Stripe Dashboard
20
- export const PLANS = {
21
- FREE: { priceId: null, name: 'Free', price: 0 },
22
- PRO: {
23
- priceId: process.env.STRIPE_PRO_PRICE_ID!,
24
- name: 'Pro',
25
- price: 29,
26
- },
27
- TEAM: {
28
- priceId: process.env.STRIPE_TEAM_PRICE_ID!,
29
- name: 'Team',
30
- price: 99,
31
- },
32
- } as const;
33
- ```
34
-
35
- ### Checkout Session
36
-
37
- ```typescript
38
- // app/api/checkout/route.ts
39
- import { stripe } from '@/lib/stripe';
40
- import { auth } from '@/lib/auth';
41
-
42
- export async function POST(req: Request) {
43
- const session = await auth();
44
- if (!session?.user) {
45
- return Response.json({ error: 'Unauthorized' }, { status: 401 });
46
- }
47
-
48
- const { priceId } = await req.json();
49
-
50
- // Get or create Stripe customer
51
- let customerId = await getStripeCustomerId(session.user.id);
52
-
53
- if (!customerId) {
54
- const customer = await stripe.customers.create({
55
- email: session.user.email!,
56
- metadata: { userId: session.user.id },
57
- });
58
- customerId = customer.id;
59
- await saveStripeCustomerId(session.user.id, customerId);
60
- }
61
-
62
- // Create checkout session
63
- const checkoutSession = await stripe.checkout.sessions.create({
64
- customer: customerId,
65
- mode: 'subscription',
66
- payment_method_types: ['card'],
67
- line_items: [{ price: priceId, quantity: 1 }],
68
- success_url: `${process.env.NEXT_PUBLIC_APP_URL}/dashboard?success=true`,
69
- cancel_url: `${process.env.NEXT_PUBLIC_APP_URL}/pricing?canceled=true`,
70
- subscription_data: {
71
- metadata: { userId: session.user.id },
72
- },
73
- });
74
-
75
- return Response.json({ url: checkoutSession.url });
76
- }
77
- ```
78
-
79
- ### Webhook Handler
80
-
81
- ```typescript
82
- // app/api/webhooks/stripe/route.ts
83
- import { stripe } from '@/lib/stripe';
84
- import { headers } from 'next/headers';
85
- import Stripe from 'stripe';
86
-
87
- export async function POST(req: Request) {
88
- const body = await req.text();
89
- const signature = headers().get('stripe-signature')!;
90
-
91
- let event: Stripe.Event;
92
-
93
- try {
94
- event = stripe.webhooks.constructEvent(
95
- body,
96
- signature,
97
- process.env.STRIPE_WEBHOOK_SECRET!
98
- );
99
- } catch (err) {
100
- console.error('Webhook signature verification failed');
101
- return Response.json({ error: 'Invalid signature' }, { status: 400 });
102
- }
103
-
104
- switch (event.type) {
105
- case 'checkout.session.completed': {
106
- const session = event.data.object as Stripe.Checkout.Session;
107
- await handleCheckoutComplete(session);
108
- break;
109
- }
110
-
111
- case 'customer.subscription.updated': {
112
- const subscription = event.data.object as Stripe.Subscription;
113
- await handleSubscriptionUpdate(subscription);
114
- break;
115
- }
116
-
117
- case 'customer.subscription.deleted': {
118
- const subscription = event.data.object as Stripe.Subscription;
119
- await handleSubscriptionCanceled(subscription);
120
- break;
121
- }
122
-
123
- case 'invoice.payment_failed': {
124
- const invoice = event.data.object as Stripe.Invoice;
125
- await handlePaymentFailed(invoice);
126
- break;
127
- }
128
- }
129
-
130
- return Response.json({ received: true });
131
- }
132
-
133
- async function handleCheckoutComplete(session: Stripe.Checkout.Session) {
134
- const userId = session.metadata?.userId;
135
- const subscriptionId = session.subscription as string;
136
-
137
- const subscription = await stripe.subscriptions.retrieve(subscriptionId);
138
-
139
- await prisma.subscription.create({
140
- data: {
141
- userId,
142
- stripeSubscriptionId: subscriptionId,
143
- stripePriceId: subscription.items.data[0].price.id,
144
- status: subscription.status,
145
- currentPeriodStart: new Date(subscription.current_period_start * 1000),
146
- currentPeriodEnd: new Date(subscription.current_period_end * 1000),
147
- },
148
- });
149
- }
150
- ```
151
-
152
- ### Customer Portal
153
-
154
- ```typescript
155
- // app/api/portal/route.ts
156
- import { stripe } from '@/lib/stripe';
157
- import { auth } from '@/lib/auth';
158
-
159
- export async function POST() {
160
- const session = await auth();
161
- if (!session?.user) {
162
- return Response.json({ error: 'Unauthorized' }, { status: 401 });
163
- }
164
-
165
- const customerId = await getStripeCustomerId(session.user.id);
166
- if (!customerId) {
167
- return Response.json({ error: 'No subscription' }, { status: 400 });
168
- }
169
-
170
- const portalSession = await stripe.billingPortal.sessions.create({
171
- customer: customerId,
172
- return_url: `${process.env.NEXT_PUBLIC_APP_URL}/dashboard`,
173
- });
174
-
175
- return Response.json({ url: portalSession.url });
176
- }
177
- ```
178
-
179
- ### Usage-Based Billing
180
-
181
- ```typescript
182
- // lib/usage.ts
183
- import { stripe } from '@/lib/stripe';
184
-
185
- // Report usage for metered billing
186
- export async function reportUsage(
187
- subscriptionItemId: string,
188
- quantity: number
189
- ) {
190
- await stripe.subscriptionItems.createUsageRecord(subscriptionItemId, {
191
- quantity,
192
- timestamp: Math.floor(Date.now() / 1000),
193
- action: 'increment', // or 'set'
194
- });
195
- }
196
-
197
- // Track API calls
198
- export async function trackApiUsage(userId: string) {
199
- const subscription = await getSubscription(userId);
200
- if (!subscription?.meteredItemId) return;
201
-
202
- await reportUsage(subscription.meteredItemId, 1);
203
- }
204
- ```
205
-
206
- ### Subscription Helpers
207
-
208
- ```typescript
209
- // lib/subscription.ts
210
- import { stripe } from '@/lib/stripe';
211
- import { prisma } from '@/lib/db';
212
-
213
- export async function getSubscription(userId: string) {
214
- return prisma.subscription.findUnique({
215
- where: { userId },
216
- });
217
- }
218
-
219
- export async function isSubscribed(userId: string): Promise<boolean> {
220
- const subscription = await getSubscription(userId);
221
- return subscription?.status === 'active';
222
- }
223
-
224
- export async function getPlan(userId: string) {
225
- const subscription = await getSubscription(userId);
226
- if (!subscription) return 'FREE';
227
-
228
- // Map price ID to plan
229
- const priceId = subscription.stripePriceId;
230
- if (priceId === process.env.STRIPE_PRO_PRICE_ID) return 'PRO';
231
- if (priceId === process.env.STRIPE_TEAM_PRICE_ID) return 'TEAM';
232
-
233
- return 'FREE';
234
- }
235
-
236
- export async function cancelSubscription(userId: string) {
237
- const subscription = await getSubscription(userId);
238
- if (!subscription) throw new Error('No subscription');
239
-
240
- await stripe.subscriptions.update(subscription.stripeSubscriptionId, {
241
- cancel_at_period_end: true,
242
- });
243
-
244
- await prisma.subscription.update({
245
- where: { userId },
246
- data: { cancelAtPeriodEnd: true },
247
- });
248
- }
249
- ```
250
-
251
- ### Pricing Page Component
252
-
253
- ```tsx
254
- // components/pricing.tsx
255
- 'use client';
256
-
257
- import { useState } from 'react';
258
- import { Button } from '@/components/ui/button';
259
-
260
- const plans = [
261
- {
262
- name: 'Free',
263
- price: 0,
264
- features: ['1 project', 'Basic features', 'Community support'],
265
- },
266
- {
267
- name: 'Pro',
268
- price: 29,
269
- priceId: process.env.NEXT_PUBLIC_STRIPE_PRO_PRICE_ID,
270
- features: ['Unlimited projects', 'All features', 'Priority support'],
271
- popular: true,
272
- },
273
- {
274
- name: 'Team',
275
- price: 99,
276
- priceId: process.env.NEXT_PUBLIC_STRIPE_TEAM_PRICE_ID,
277
- features: ['Everything in Pro', 'Team collaboration', 'Admin controls'],
278
- },
279
- ];
280
-
281
- export function Pricing() {
282
- const [loading, setLoading] = useState<string | null>(null);
283
-
284
- async function handleSubscribe(priceId: string) {
285
- setLoading(priceId);
286
- const res = await fetch('/api/checkout', {
287
- method: 'POST',
288
- body: JSON.stringify({ priceId }),
289
- });
290
- const { url } = await res.json();
291
- window.location.href = url;
292
- }
293
-
294
- return (
295
- <div className="grid md:grid-cols-3 gap-8">
296
- {plans.map((plan) => (
297
- <div
298
- key={plan.name}
299
- className={`p-8 border rounded-lg ${
300
- plan.popular ? 'border-blue-500 shadow-lg' : ''
301
- }`}
302
- >
303
- <h3 className="text-xl font-bold">{plan.name}</h3>
304
- <p className="text-3xl font-bold mt-4">
305
- ${plan.price}<span className="text-sm">/mo</span>
306
- </p>
307
- <ul className="mt-6 space-y-2">
308
- {plan.features.map((feature) => (
309
- <li key={feature}>✓ {feature}</li>
310
- ))}
311
- </ul>
312
- {plan.priceId && (
313
- <Button
314
- className="w-full mt-8"
315
- onClick={() => handleSubscribe(plan.priceId!)}
316
- disabled={loading === plan.priceId}
317
- >
318
- {loading === plan.priceId ? 'Loading...' : 'Subscribe'}
319
- </Button>
320
- )}
321
- </div>
322
- ))}
323
- </div>
324
- );
325
- }
326
- ```
327
-
328
- ## Payment Checklist
329
-
330
- - [ ] Stripe account created
331
- - [ ] Products/prices configured
332
- - [ ] Checkout integration complete
333
- - [ ] Webhook handler implemented
334
- - [ ] Customer portal enabled
335
- - [ ] Subscription status tracking
336
- - [ ] Email notifications set up
337
- - [ ] Testing with test mode
338
-
339
- ## Trigger Keywords
340
- payment, stripe, subscription, billing, checkout, pricing, invoice, webhook, customer, SaaS, recurring, metered