@l4yercak3/cli 1.0.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/.claude/settings.local.json +18 -0
- package/.cursor/rules.md +203 -0
- package/.eslintrc.js +31 -0
- package/README.md +227 -0
- package/bin/cli.js +61 -0
- package/docs/ADDING_NEW_PROJECT_TYPE.md +156 -0
- package/docs/ARCHITECTURE_RELATIONSHIPS.md +411 -0
- package/docs/CLI_AUTHENTICATION.md +214 -0
- package/docs/DETECTOR_ARCHITECTURE.md +326 -0
- package/docs/DEVELOPMENT.md +194 -0
- package/docs/IMPLEMENTATION_PHASES.md +468 -0
- package/docs/OAUTH_CLARIFICATION.md +258 -0
- package/docs/OAUTH_SETUP_GUIDE_TEMPLATE.md +211 -0
- package/docs/PHASE_0_PROGRESS.md +120 -0
- package/docs/PHASE_1_COMPLETE.md +366 -0
- package/docs/PHASE_SUMMARY.md +149 -0
- package/docs/PLAN.md +511 -0
- package/docs/README.md +56 -0
- package/docs/STRIPE_INTEGRATION.md +447 -0
- package/docs/SUMMARY.md +230 -0
- package/docs/UPDATED_PLAN.md +447 -0
- package/package.json +53 -0
- package/src/api/backend-client.js +148 -0
- package/src/commands/login.js +146 -0
- package/src/commands/logout.js +24 -0
- package/src/commands/spread.js +364 -0
- package/src/commands/status.js +62 -0
- package/src/config/config-manager.js +205 -0
- package/src/detectors/api-client-detector.js +85 -0
- package/src/detectors/base-detector.js +77 -0
- package/src/detectors/github-detector.js +74 -0
- package/src/detectors/index.js +80 -0
- package/src/detectors/nextjs-detector.js +139 -0
- package/src/detectors/oauth-detector.js +122 -0
- package/src/detectors/registry.js +97 -0
- package/src/generators/api-client-generator.js +197 -0
- package/src/generators/env-generator.js +162 -0
- package/src/generators/gitignore-generator.js +92 -0
- package/src/generators/index.js +50 -0
- package/src/generators/nextauth-generator.js +242 -0
- package/src/generators/oauth-guide-generator.js +277 -0
- package/src/logo.js +116 -0
- package/tests/api-client-detector.test.js +214 -0
- package/tests/api-client-generator.test.js +169 -0
- package/tests/backend-client.test.js +361 -0
- package/tests/base-detector.test.js +101 -0
- package/tests/commands/login.test.js +98 -0
- package/tests/commands/logout.test.js +70 -0
- package/tests/commands/status.test.js +167 -0
- package/tests/config-manager.test.js +313 -0
- package/tests/detector-index.test.js +209 -0
- package/tests/detector-registry.test.js +93 -0
- package/tests/env-generator.test.js +278 -0
- package/tests/generators-index.test.js +215 -0
- package/tests/github-detector.test.js +145 -0
- package/tests/gitignore-generator.test.js +109 -0
- package/tests/logo.test.js +96 -0
- package/tests/nextauth-generator.test.js +231 -0
- package/tests/nextjs-detector.test.js +235 -0
- package/tests/oauth-detector.test.js +264 -0
- package/tests/oauth-guide-generator.test.js +273 -0
|
@@ -0,0 +1,447 @@
|
|
|
1
|
+
# Stripe Integration Setup via CLI
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
|
|
5
|
+
The L4YERCAK3 platform uses **Stripe Connect** to allow organizations to connect their own Stripe accounts. This enables organizations to accept payments from their customers while transactions flow through the platform.
|
|
6
|
+
|
|
7
|
+
### Key Concepts
|
|
8
|
+
|
|
9
|
+
1. **Stripe Connect Platform**: Your platform acts as a Stripe Connect platform
|
|
10
|
+
2. **Organization Stripe Accounts**: Each organization connects their own Stripe account
|
|
11
|
+
3. **Transaction Flow**: Customer → Organization's Stripe Account → Platform (for tracking/CRM)
|
|
12
|
+
4. **Webhooks**: Frontend apps need webhook endpoints to receive Stripe events
|
|
13
|
+
5. **Organization Types**:
|
|
14
|
+
- **Regular Organization**: Single Stripe account, owns all transactions
|
|
15
|
+
- **Agency Organization** (future): Can create sub-organizations, each with their own Stripe account
|
|
16
|
+
|
|
17
|
+
---
|
|
18
|
+
|
|
19
|
+
## Current Stripe Connect Flow
|
|
20
|
+
|
|
21
|
+
### Backend Setup (Already Exists)
|
|
22
|
+
|
|
23
|
+
The backend already has:
|
|
24
|
+
- ✅ Stripe Connect OAuth flow (`convex/stripeConnect.ts`)
|
|
25
|
+
- ✅ Webhook handlers (`convex/stripeWebhooks.ts`)
|
|
26
|
+
- ✅ Account status management
|
|
27
|
+
- ✅ Transaction tracking
|
|
28
|
+
|
|
29
|
+
### What Organizations Need to Do (Currently Manual)
|
|
30
|
+
|
|
31
|
+
1. **Connect Stripe Account**:
|
|
32
|
+
- Go to platform UI
|
|
33
|
+
- Click "Connect Stripe"
|
|
34
|
+
- Complete Stripe OAuth flow
|
|
35
|
+
- Stripe account ID stored in backend
|
|
36
|
+
|
|
37
|
+
2. **Frontend Webhook Setup** (if using separate frontend):
|
|
38
|
+
- Configure webhook endpoint in Stripe Dashboard
|
|
39
|
+
- Set webhook URL: `https://your-frontend.com/api/webhooks/stripe`
|
|
40
|
+
- Forward webhooks to backend API
|
|
41
|
+
|
|
42
|
+
3. **Environment Variables**:
|
|
43
|
+
```bash
|
|
44
|
+
STRIPE_PUBLISHABLE_KEY=pk_test_...
|
|
45
|
+
STRIPE_SECRET_KEY=sk_test_... # Organization's secret key (if needed)
|
|
46
|
+
NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY=pk_test_...
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
---
|
|
50
|
+
|
|
51
|
+
## CLI Automation Strategy
|
|
52
|
+
|
|
53
|
+
### What the CLI Can Automate
|
|
54
|
+
|
|
55
|
+
#### 1. **Stripe Connect OAuth Flow** ✅
|
|
56
|
+
- Initiate Stripe Connect onboarding via backend API
|
|
57
|
+
- Open browser for OAuth flow
|
|
58
|
+
- Store account ID automatically
|
|
59
|
+
|
|
60
|
+
#### 2. **Webhook Configuration** 🎯
|
|
61
|
+
- Generate webhook endpoint URL
|
|
62
|
+
- Configure webhook in Stripe Dashboard (via Stripe API)
|
|
63
|
+
- Set up webhook forwarding to backend
|
|
64
|
+
|
|
65
|
+
#### 3. **Environment Variables** ✅
|
|
66
|
+
- Auto-detect from organization's Stripe account
|
|
67
|
+
- Generate `.env.local` with Stripe keys
|
|
68
|
+
- Store webhook secrets securely
|
|
69
|
+
|
|
70
|
+
#### 4. **Code Generation** ✅
|
|
71
|
+
- Generate Stripe integration code
|
|
72
|
+
- Generate webhook handler templates
|
|
73
|
+
- Generate payment components
|
|
74
|
+
|
|
75
|
+
---
|
|
76
|
+
|
|
77
|
+
## CLI Integration Flow
|
|
78
|
+
|
|
79
|
+
### Complete Stripe Setup via CLI
|
|
80
|
+
|
|
81
|
+
```
|
|
82
|
+
1. Developer runs: npx @l4yercak3/cli spread
|
|
83
|
+
↓
|
|
84
|
+
2. CLI asks: "Enable Stripe payments?" (y/n)
|
|
85
|
+
↓
|
|
86
|
+
3. If "Yes":
|
|
87
|
+
a. CLI checks if organization has Stripe account
|
|
88
|
+
- If yes: Use existing account
|
|
89
|
+
- If no: Start OAuth flow
|
|
90
|
+
↓
|
|
91
|
+
4. Stripe OAuth Flow:
|
|
92
|
+
a. CLI calls backend: POST /api/v1/stripe/start-onboarding
|
|
93
|
+
b. Backend returns OAuth URL
|
|
94
|
+
c. CLI opens browser with OAuth URL
|
|
95
|
+
d. User completes Stripe onboarding
|
|
96
|
+
e. Stripe redirects to backend callback
|
|
97
|
+
f. Backend stores account ID
|
|
98
|
+
↓
|
|
99
|
+
5. Webhook Setup:
|
|
100
|
+
a. CLI detects frontend URL (from project config)
|
|
101
|
+
b. CLI generates webhook endpoint: {frontend_url}/api/webhooks/stripe
|
|
102
|
+
c. CLI calls Stripe API to create webhook endpoint
|
|
103
|
+
d. CLI stores webhook secret
|
|
104
|
+
↓
|
|
105
|
+
6. Environment Variables:
|
|
106
|
+
a. CLI fetches Stripe keys from backend API
|
|
107
|
+
b. CLI generates .env.local with:
|
|
108
|
+
- STRIPE_PUBLISHABLE_KEY
|
|
109
|
+
- NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY
|
|
110
|
+
- STRIPE_WEBHOOK_SECRET
|
|
111
|
+
↓
|
|
112
|
+
7. Code Generation:
|
|
113
|
+
a. CLI generates webhook handler: app/api/webhooks/stripe/route.ts
|
|
114
|
+
b. CLI generates Stripe client utilities
|
|
115
|
+
c. CLI generates payment components (if template selected)
|
|
116
|
+
↓
|
|
117
|
+
8. Integration complete! 🎉
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
---
|
|
121
|
+
|
|
122
|
+
## Backend API Endpoints Needed
|
|
123
|
+
|
|
124
|
+
### 1. Start Stripe Onboarding
|
|
125
|
+
```typescript
|
|
126
|
+
POST /api/v1/stripe/start-onboarding
|
|
127
|
+
Authorization: Bearer <api_key>
|
|
128
|
+
Body: {
|
|
129
|
+
returnUrl: string; // Where to redirect after OAuth
|
|
130
|
+
refreshUrl: string; // Where to redirect if onboarding incomplete
|
|
131
|
+
isTestMode?: boolean; // Test vs live mode
|
|
132
|
+
}
|
|
133
|
+
Response: {
|
|
134
|
+
onboardingUrl: string; // Stripe OAuth URL
|
|
135
|
+
state: string; // CSRF token
|
|
136
|
+
}
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
### 2. Get Stripe Account Status
|
|
140
|
+
```typescript
|
|
141
|
+
GET /api/v1/stripe/status
|
|
142
|
+
Authorization: Bearer <api_key>
|
|
143
|
+
Response: {
|
|
144
|
+
isConnected: boolean;
|
|
145
|
+
accountId?: string;
|
|
146
|
+
status: "pending" | "active" | "restricted" | "disabled";
|
|
147
|
+
chargesEnabled: boolean;
|
|
148
|
+
payoutsEnabled: boolean;
|
|
149
|
+
publishableKey?: string; // Organization's publishable key
|
|
150
|
+
}
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
### 3. Get Stripe Keys
|
|
154
|
+
```typescript
|
|
155
|
+
GET /api/v1/stripe/keys
|
|
156
|
+
Authorization: Bearer <api_key>
|
|
157
|
+
Response: {
|
|
158
|
+
publishableKey: string; // Organization's publishable key
|
|
159
|
+
// Note: Secret key is NOT returned (security)
|
|
160
|
+
}
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
### 4. Webhook Forwarding Endpoint
|
|
164
|
+
```typescript
|
|
165
|
+
POST /api/v1/stripe/webhooks/forward
|
|
166
|
+
Authorization: Bearer <api_key>
|
|
167
|
+
Body: {
|
|
168
|
+
eventType: string;
|
|
169
|
+
eventData: object;
|
|
170
|
+
signature: string;
|
|
171
|
+
}
|
|
172
|
+
Response: {
|
|
173
|
+
success: boolean;
|
|
174
|
+
}
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
---
|
|
178
|
+
|
|
179
|
+
## Frontend Webhook Handler Template
|
|
180
|
+
|
|
181
|
+
### Generated Code: `app/api/webhooks/stripe/route.ts`
|
|
182
|
+
|
|
183
|
+
```typescript
|
|
184
|
+
import { NextRequest, NextResponse } from 'next/server';
|
|
185
|
+
import Stripe from 'stripe';
|
|
186
|
+
|
|
187
|
+
const stripe = new Stripe(process.env.STRIPE_SECRET_KEY!, {
|
|
188
|
+
apiVersion: '2025-10-29.clover',
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
const webhookSecret = process.env.STRIPE_WEBHOOK_SECRET!;
|
|
192
|
+
|
|
193
|
+
export async function POST(req: NextRequest) {
|
|
194
|
+
const body = await req.text();
|
|
195
|
+
const signature = req.headers.get('stripe-signature')!;
|
|
196
|
+
|
|
197
|
+
let event: Stripe.Event;
|
|
198
|
+
|
|
199
|
+
try {
|
|
200
|
+
event = stripe.webhooks.constructEvent(body, signature, webhookSecret);
|
|
201
|
+
} catch (err) {
|
|
202
|
+
console.error('Webhook signature verification failed:', err);
|
|
203
|
+
return NextResponse.json({ error: 'Invalid signature' }, { status: 400 });
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
// Forward to backend API
|
|
207
|
+
const backendUrl = process.env.BACKEND_API_URL!;
|
|
208
|
+
const apiKey = process.env.BACKEND_API_KEY!;
|
|
209
|
+
|
|
210
|
+
try {
|
|
211
|
+
const response = await fetch(`${backendUrl}/api/v1/stripe/webhooks/forward`, {
|
|
212
|
+
method: 'POST',
|
|
213
|
+
headers: {
|
|
214
|
+
'Content-Type': 'application/json',
|
|
215
|
+
'Authorization': `Bearer ${apiKey}`,
|
|
216
|
+
},
|
|
217
|
+
body: JSON.stringify({
|
|
218
|
+
eventType: event.type,
|
|
219
|
+
eventData: event.data.object,
|
|
220
|
+
signature,
|
|
221
|
+
}),
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
if (!response.ok) {
|
|
225
|
+
throw new Error('Backend webhook forwarding failed');
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
return NextResponse.json({ received: true });
|
|
229
|
+
} catch (error) {
|
|
230
|
+
console.error('Error forwarding webhook:', error);
|
|
231
|
+
return NextResponse.json({ error: 'Webhook processing failed' }, { status: 500 });
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
---
|
|
237
|
+
|
|
238
|
+
## Organization Types & Stripe Setup
|
|
239
|
+
|
|
240
|
+
### Regular Organization
|
|
241
|
+
|
|
242
|
+
**Setup:**
|
|
243
|
+
- Single Stripe account
|
|
244
|
+
- All transactions go through this account
|
|
245
|
+
- Organization owns all transactions
|
|
246
|
+
|
|
247
|
+
**CLI Flow:**
|
|
248
|
+
```bash
|
|
249
|
+
? Enable Stripe payments? (y/n) y
|
|
250
|
+
? Connect existing Stripe account or create new? [existing/new] new
|
|
251
|
+
✅ Opening Stripe OAuth flow...
|
|
252
|
+
✅ Stripe account connected: acct_1234567890
|
|
253
|
+
✅ Webhook configured: https://your-app.com/api/webhooks/stripe
|
|
254
|
+
✅ Environment variables saved to .env.local
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
### Agency Organization (Future)
|
|
258
|
+
|
|
259
|
+
**Setup:**
|
|
260
|
+
- Parent organization can see all sub-org transactions (read-only)
|
|
261
|
+
- Each Sub-Organization has their own Stripe account
|
|
262
|
+
- Sub-Organizations own their transactions (tax/legal reasons)
|
|
263
|
+
- **CRITICAL:** Agencies CANNOT onboard Sub-Organizations - Sub-Orgs must onboard themselves
|
|
264
|
+
- **NOTE:** CRM Organizations do NOT have Stripe accounts (they're customer data)
|
|
265
|
+
|
|
266
|
+
**CLI Flow (Agency Setting Up Boilerplate):**
|
|
267
|
+
```bash
|
|
268
|
+
? Organization type? [regular/agency] agency
|
|
269
|
+
? Create sub-organization for customer? (y/n) y
|
|
270
|
+
? Customer name: Acme Corp
|
|
271
|
+
? Customer email: contact@acme.com
|
|
272
|
+
✅ Sub-Organization created: sub_org_123
|
|
273
|
+
✅ API key generated: l4y_sub_org_123...
|
|
274
|
+
✅ Boilerplate generated with customer-facing Stripe onboarding
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
**Customer-Facing Stripe Onboarding (Generated in Boilerplate):**
|
|
278
|
+
```typescript
|
|
279
|
+
// Generated: app/stripe/connect/page.tsx
|
|
280
|
+
// Simple UI for Sub-Organization to connect their own Stripe account
|
|
281
|
+
// Sub-Org visits: https://their-site.com/stripe/connect
|
|
282
|
+
// Sub-Org completes OAuth flow themselves
|
|
283
|
+
// Uses Sub-Organization's API key (not Agency's)
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
**Sub-Organization Setup (Customer Self-Service):**
|
|
287
|
+
```
|
|
288
|
+
1. Sub-Organization visits their frontend: /stripe/connect
|
|
289
|
+
2. Sub-Organization clicks "Connect Stripe Account"
|
|
290
|
+
3. Sub-Organization completes Stripe OAuth flow
|
|
291
|
+
4. Stripe account linked to Sub-Organization
|
|
292
|
+
5. Agency can view transactions (read-only)
|
|
293
|
+
```
|
|
294
|
+
|
|
295
|
+
---
|
|
296
|
+
|
|
297
|
+
## Environment Variables Generated
|
|
298
|
+
|
|
299
|
+
### `.env.local` (Generated by CLI)
|
|
300
|
+
|
|
301
|
+
```bash
|
|
302
|
+
# Stripe Connect (Organization's Stripe Account)
|
|
303
|
+
STRIPE_PUBLISHABLE_KEY=pk_test_51Abc123... # From organization's account
|
|
304
|
+
NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY=pk_test_51Abc123...
|
|
305
|
+
STRIPE_WEBHOOK_SECRET=whsec_xyz789... # From webhook endpoint
|
|
306
|
+
|
|
307
|
+
# Backend API (for webhook forwarding)
|
|
308
|
+
BACKEND_API_URL=https://your-backend.convex.site
|
|
309
|
+
BACKEND_API_KEY=l4y_abc123...
|
|
310
|
+
|
|
311
|
+
# Note: STRIPE_SECRET_KEY is NOT stored in frontend
|
|
312
|
+
# Frontend only needs publishable key for client-side operations
|
|
313
|
+
```
|
|
314
|
+
|
|
315
|
+
---
|
|
316
|
+
|
|
317
|
+
## Webhook Configuration
|
|
318
|
+
|
|
319
|
+
### Stripe Dashboard Setup
|
|
320
|
+
|
|
321
|
+
**Manual Steps (Current):**
|
|
322
|
+
1. Go to Stripe Dashboard → Developers → Webhooks
|
|
323
|
+
2. Add endpoint: `https://your-frontend.com/api/webhooks/stripe`
|
|
324
|
+
3. Select events to listen for
|
|
325
|
+
4. Copy webhook signing secret
|
|
326
|
+
|
|
327
|
+
**Automated via CLI (Future):**
|
|
328
|
+
```bash
|
|
329
|
+
? Configure Stripe webhooks? (y/n) y
|
|
330
|
+
? Frontend URL: https://your-app.com
|
|
331
|
+
✅ Creating webhook endpoint in Stripe...
|
|
332
|
+
✅ Webhook endpoint created: https://your-app.com/api/webhooks/stripe
|
|
333
|
+
✅ Webhook secret saved to .env.local
|
|
334
|
+
```
|
|
335
|
+
|
|
336
|
+
**Required Webhook Events:**
|
|
337
|
+
- `account.updated` - Account status changes
|
|
338
|
+
- `account.application.deauthorized` - Account disconnected
|
|
339
|
+
- `payment_intent.succeeded` - Payment completed
|
|
340
|
+
- `charge.refunded` - Refund processed
|
|
341
|
+
- `invoice.payment_succeeded` - Invoice paid
|
|
342
|
+
- `invoice.payment_failed` - Invoice payment failed
|
|
343
|
+
|
|
344
|
+
---
|
|
345
|
+
|
|
346
|
+
## Security Considerations
|
|
347
|
+
|
|
348
|
+
### Frontend Stripe Integration
|
|
349
|
+
|
|
350
|
+
1. **Never Store Secret Keys in Frontend**
|
|
351
|
+
- Only publishable keys in frontend
|
|
352
|
+
- Secret keys stay in backend only
|
|
353
|
+
|
|
354
|
+
2. **Webhook Signature Verification**
|
|
355
|
+
- Always verify webhook signatures
|
|
356
|
+
- Use webhook secret from environment
|
|
357
|
+
|
|
358
|
+
3. **API Key Security**
|
|
359
|
+
- Backend API key stored securely
|
|
360
|
+
- Never commit to git
|
|
361
|
+
- Use environment variables
|
|
362
|
+
|
|
363
|
+
4. **Organization Isolation**
|
|
364
|
+
- Each organization's Stripe account is isolated
|
|
365
|
+
- Transactions scoped to organization
|
|
366
|
+
- Agency orgs can view but not control sub-org accounts
|
|
367
|
+
|
|
368
|
+
---
|
|
369
|
+
|
|
370
|
+
## CLI Commands
|
|
371
|
+
|
|
372
|
+
### Stripe Setup Commands
|
|
373
|
+
|
|
374
|
+
```bash
|
|
375
|
+
# Full Stripe integration setup
|
|
376
|
+
npx @l4yercak3/cli spread --stripe
|
|
377
|
+
|
|
378
|
+
# Connect Stripe account only
|
|
379
|
+
npx @l4yercak3/cli stripe connect
|
|
380
|
+
|
|
381
|
+
# Configure webhooks only
|
|
382
|
+
npx @l4yercak3/cli stripe webhooks
|
|
383
|
+
|
|
384
|
+
# Check Stripe status
|
|
385
|
+
npx @l4yercak3/cli stripe status
|
|
386
|
+
|
|
387
|
+
# Disconnect Stripe account
|
|
388
|
+
npx @l4yercak3/cli stripe disconnect
|
|
389
|
+
```
|
|
390
|
+
|
|
391
|
+
---
|
|
392
|
+
|
|
393
|
+
## Implementation Checklist
|
|
394
|
+
|
|
395
|
+
### Phase 1: Basic Stripe Connect
|
|
396
|
+
- [ ] Backend API endpoint: `POST /api/v1/stripe/start-onboarding`
|
|
397
|
+
- [ ] Backend API endpoint: `GET /api/v1/stripe/status`
|
|
398
|
+
- [ ] Backend API endpoint: `GET /api/v1/stripe/keys`
|
|
399
|
+
- [ ] CLI: Stripe OAuth flow initiation
|
|
400
|
+
- [ ] CLI: Browser opening for OAuth
|
|
401
|
+
- [ ] CLI: Account status checking
|
|
402
|
+
|
|
403
|
+
### Phase 2: Webhook Automation
|
|
404
|
+
- [ ] Stripe API integration for webhook creation
|
|
405
|
+
- [ ] CLI: Auto-detect frontend URL
|
|
406
|
+
- [ ] CLI: Create webhook endpoint via Stripe API
|
|
407
|
+
- [ ] CLI: Store webhook secret securely
|
|
408
|
+
- [ ] CLI: Generate webhook handler code
|
|
409
|
+
|
|
410
|
+
### Phase 3: Code Generation
|
|
411
|
+
- [ ] Generate webhook handler template
|
|
412
|
+
- [ ] Generate Stripe client utilities
|
|
413
|
+
- [ ] Generate payment components (optional)
|
|
414
|
+
- [ ] Generate environment variable templates
|
|
415
|
+
|
|
416
|
+
### Phase 4: Agency Organization Support
|
|
417
|
+
- [ ] Detect agency organization type
|
|
418
|
+
- [ ] Generate customer-facing Stripe onboarding page
|
|
419
|
+
- [ ] Use Sub-Organization's API key (not Agency's)
|
|
420
|
+
- [ ] Support customer self-service onboarding
|
|
421
|
+
- [ ] Parent org transaction viewing (read-only)
|
|
422
|
+
- [ ] Sub-org account isolation
|
|
423
|
+
- [ ] **CRITICAL:** Ensure Sub-Organizations onboard themselves (legal requirement)
|
|
424
|
+
|
|
425
|
+
---
|
|
426
|
+
|
|
427
|
+
## Questions to Resolve
|
|
428
|
+
|
|
429
|
+
1. **Stripe API Access**: Does CLI need Stripe API access to create webhooks?
|
|
430
|
+
- **Answer:** Yes, CLI needs Stripe API key to create webhook endpoints
|
|
431
|
+
- **Security:** Use organization's Stripe API key (from backend)
|
|
432
|
+
|
|
433
|
+
2. **Webhook Secret Storage**: Where to store webhook secrets?
|
|
434
|
+
- **Answer:** In `.env.local` for frontend, backend stores in database
|
|
435
|
+
|
|
436
|
+
3. **Agency Organization Timeline**: When will sub-organizations be available?
|
|
437
|
+
- **Answer:** Future feature, plan for it now but implement later
|
|
438
|
+
|
|
439
|
+
4. **Test vs Live Mode**: How to handle test/live mode selection?
|
|
440
|
+
- **Answer:** Organization chooses during onboarding, stored in backend
|
|
441
|
+
|
|
442
|
+
---
|
|
443
|
+
|
|
444
|
+
**Last Updated:** 2025-01-14
|
|
445
|
+
**Status:** Planning Phase
|
|
446
|
+
**Next Steps:** Implement backend API endpoints, then CLI integration
|
|
447
|
+
|
package/docs/SUMMARY.md
ADDED
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
# 🍰 L4YERCAK3 CLI Tool - Project Summary
|
|
2
|
+
|
|
3
|
+
## What We've Built
|
|
4
|
+
|
|
5
|
+
A comprehensive plan and development setup for the **Icing on the L4yercak3** CLI tool - a universal adapter that connects any frontend application to the L4YERCAK3 backend API platform.
|
|
6
|
+
|
|
7
|
+
## Documents Created
|
|
8
|
+
|
|
9
|
+
### 1. **PLAN.md** - Strategic Plan
|
|
10
|
+
- Complete roadmap for CLI tool development
|
|
11
|
+
- Comparison of CLI vs Deployment Ontology approaches
|
|
12
|
+
- Feature phases and implementation timeline
|
|
13
|
+
- Technical architecture and integration patterns
|
|
14
|
+
- Success metrics and next steps
|
|
15
|
+
|
|
16
|
+
### 2. **.cursor/rules.md** - Development Rules
|
|
17
|
+
- Quality assurance checklist
|
|
18
|
+
- Code standards and best practices
|
|
19
|
+
- Architecture principles
|
|
20
|
+
- Testing and documentation guidelines
|
|
21
|
+
- Security and performance considerations
|
|
22
|
+
|
|
23
|
+
### 3. **DEVELOPMENT.md** - Developer Guide
|
|
24
|
+
- Quick start instructions
|
|
25
|
+
- Development workflow
|
|
26
|
+
- Code style guidelines
|
|
27
|
+
- Testing procedures
|
|
28
|
+
- Publishing guide
|
|
29
|
+
|
|
30
|
+
### 4. **Configuration Files**
|
|
31
|
+
- `.eslintrc.js` - ESLint configuration
|
|
32
|
+
- `.gitignore` - Updated with CLI-specific ignores
|
|
33
|
+
- `package.json` - Enhanced with quality check scripts
|
|
34
|
+
|
|
35
|
+
## Key Decisions
|
|
36
|
+
|
|
37
|
+
### ✅ CLI Tool as Primary Integration Method
|
|
38
|
+
**Rationale:**
|
|
39
|
+
- Works with any project structure
|
|
40
|
+
- Better developer experience
|
|
41
|
+
- More flexible than deployment ontology
|
|
42
|
+
- Easy to discover via npm
|
|
43
|
+
|
|
44
|
+
### ✅ Development Standards Established
|
|
45
|
+
**Quality Checks:**
|
|
46
|
+
- Type checking
|
|
47
|
+
- Linting (ESLint)
|
|
48
|
+
- Build verification
|
|
49
|
+
- All automated via `npm run verify`
|
|
50
|
+
|
|
51
|
+
### ✅ Modular Architecture Planned
|
|
52
|
+
**Structure:**
|
|
53
|
+
- Commands (spread, init, login, etc.)
|
|
54
|
+
- Generators (API client, OAuth, env files)
|
|
55
|
+
- Detectors (project type, existing setup)
|
|
56
|
+
- Config manager
|
|
57
|
+
- Backend API client
|
|
58
|
+
|
|
59
|
+
## Current State
|
|
60
|
+
|
|
61
|
+
### ✅ Completed
|
|
62
|
+
- [x] Strategic plan document
|
|
63
|
+
- [x] Development standards setup
|
|
64
|
+
- [x] ESLint configuration
|
|
65
|
+
- [x] Quality check scripts
|
|
66
|
+
- [x] Cursor AI rules configuration
|
|
67
|
+
- [x] Developer documentation
|
|
68
|
+
|
|
69
|
+
### 🚧 Next Steps (Phase 1)
|
|
70
|
+
- [ ] Implement project detection
|
|
71
|
+
- [ ] Create configuration wizard
|
|
72
|
+
- [ ] Generate API client templates
|
|
73
|
+
- [ ] Generate environment file templates
|
|
74
|
+
- [ ] Test with example projects
|
|
75
|
+
|
|
76
|
+
## Integration Patterns Identified
|
|
77
|
+
|
|
78
|
+
### Pattern 1: Landing Page Integration
|
|
79
|
+
**Location:** `l4yercak3-landing/src/lib/crm-integration/backend-client.ts`
|
|
80
|
+
- Uses `BACKEND_CRM_URL` and `BACKEND_CRM_API_KEY`
|
|
81
|
+
- Contact creation patterns
|
|
82
|
+
- Newsletter, application, appointment integrations
|
|
83
|
+
|
|
84
|
+
### Pattern 2: Client Portal Integration
|
|
85
|
+
**Location:** `freelancer-client-portal/lib/api-client.ts`
|
|
86
|
+
- Uses `NEXT_PUBLIC_BACKEND_API_URL` and `BACKEND_API_URL`
|
|
87
|
+
- NextAuth.js OAuth setup
|
|
88
|
+
- Bearer token authentication
|
|
89
|
+
- Typed API functions
|
|
90
|
+
|
|
91
|
+
## Questions Resolved ✅
|
|
92
|
+
|
|
93
|
+
1. ✅ **Backend API Key Generation**
|
|
94
|
+
- Can be implemented via backend API
|
|
95
|
+
- Endpoint needed: `POST /api/v1/api-keys/generate`
|
|
96
|
+
|
|
97
|
+
2. ✅ **OAuth App Registration**
|
|
98
|
+
- Automate as much as possible (one-click goal)
|
|
99
|
+
- Use provider APIs where available
|
|
100
|
+
- Manual setup as fallback
|
|
101
|
+
|
|
102
|
+
3. ✅ **Backend Schema Access**
|
|
103
|
+
- Schema endpoint preferred (read-only API structure)
|
|
104
|
+
- Endpoint needed: `GET /api/v1/schema`
|
|
105
|
+
|
|
106
|
+
4. ✅ **Publishing Ontology**
|
|
107
|
+
- Located: `vc83-com/convex/publishingOntology.ts`
|
|
108
|
+
- Can be used for env var detection and template discovery
|
|
109
|
+
|
|
110
|
+
5. ✅ **Architecture Relationships**
|
|
111
|
+
- See `docs/ARCHITECTURE_RELATIONSHIPS.md` for complete hierarchy
|
|
112
|
+
- Key: CRM Organization = Customer data (NOT platform organization)
|
|
113
|
+
- Sub-Organization = Platform org (for agencies, boilerplate built FOR this)
|
|
114
|
+
|
|
115
|
+
## Quick Reference
|
|
116
|
+
|
|
117
|
+
### Development Commands
|
|
118
|
+
```bash
|
|
119
|
+
npm install # Install dependencies
|
|
120
|
+
npm start # Run CLI locally
|
|
121
|
+
npm link # Link globally for testing
|
|
122
|
+
npm run verify # Run all quality checks
|
|
123
|
+
npm run lint # Lint code
|
|
124
|
+
npm run lint:fix # Fix linting issues
|
|
125
|
+
npm run type-check # Check types
|
|
126
|
+
npm run build # Verify build
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
### Example Usage (Future)
|
|
130
|
+
```bash
|
|
131
|
+
# Initialize integration
|
|
132
|
+
npx @l4yercak3/cli spread
|
|
133
|
+
|
|
134
|
+
# Initialize with template
|
|
135
|
+
npx @l4yercak3/cli spread --template client-portal
|
|
136
|
+
|
|
137
|
+
# Generate API key
|
|
138
|
+
npx @l4yercak3/cli generate api-key
|
|
139
|
+
|
|
140
|
+
# Test integration
|
|
141
|
+
npx @l4yercak3/cli test
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
## Related Projects
|
|
145
|
+
|
|
146
|
+
### Backend Platform
|
|
147
|
+
- **Location:** `~/Development/vc83-com`
|
|
148
|
+
- **Status:** Full-featured Convex backend
|
|
149
|
+
- **Features:** CRM, OAuth, Projects, Invoices, Stripe Connect, Publishing Ontology
|
|
150
|
+
|
|
151
|
+
### Example Frontend Applications
|
|
152
|
+
- **Landing Page:** `~/Development/l4yercak3-landing`
|
|
153
|
+
- **Client Portal:** `~/Development/freelancer-client-portal`
|
|
154
|
+
|
|
155
|
+
## Architecture Overview
|
|
156
|
+
|
|
157
|
+
```
|
|
158
|
+
┌─────────────────────────────────────────┐
|
|
159
|
+
│ Frontend Applications │
|
|
160
|
+
│ (Landing Page, Client Portal, etc.) │
|
|
161
|
+
└──────────────┬──────────────────────────┘
|
|
162
|
+
│
|
|
163
|
+
│ CLI Tool Integration
|
|
164
|
+
│ (npx @l4yercak3/cli spread)
|
|
165
|
+
▼
|
|
166
|
+
┌─────────────────────────────────────────┐
|
|
167
|
+
│ L4YERCAK3 CLI Tool │
|
|
168
|
+
│ - Project Detection │
|
|
169
|
+
│ - Configuration Wizard │
|
|
170
|
+
│ - Code Generation │
|
|
171
|
+
│ - OAuth Setup │
|
|
172
|
+
└──────────────┬──────────────────────────┘
|
|
173
|
+
│
|
|
174
|
+
│ API Calls
|
|
175
|
+
▼
|
|
176
|
+
┌─────────────────────────────────────────┐
|
|
177
|
+
│ L4YERCAK3 Backend Platform │
|
|
178
|
+
│ - CRM Integration │
|
|
179
|
+
│ - OAuth Authentication │
|
|
180
|
+
│ - Project Management │
|
|
181
|
+
│ - Invoicing System │
|
|
182
|
+
└─────────────────────────────────────────┘
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
## Success Criteria
|
|
186
|
+
|
|
187
|
+
### Phase 1 (MVP)
|
|
188
|
+
- ✅ Developer can run `npx @l4yercak3/cli spread`
|
|
189
|
+
- ✅ CLI detects Next.js project
|
|
190
|
+
- ✅ Interactive setup wizard works
|
|
191
|
+
- ✅ API client code is generated
|
|
192
|
+
- ✅ Environment files are created
|
|
193
|
+
- ✅ Integration works with example projects
|
|
194
|
+
|
|
195
|
+
### Phase 2 (Advanced)
|
|
196
|
+
- ✅ OAuth setup is automated
|
|
197
|
+
- ✅ TypeScript types are generated
|
|
198
|
+
- ✅ Project templates are available
|
|
199
|
+
- ✅ Integration testing works
|
|
200
|
+
|
|
201
|
+
### Phase 3 (Polish)
|
|
202
|
+
- ✅ Documentation is complete
|
|
203
|
+
- ✅ Error handling is robust
|
|
204
|
+
- ✅ Update mechanism works
|
|
205
|
+
- ✅ Published to npm
|
|
206
|
+
|
|
207
|
+
## Implementation Phases
|
|
208
|
+
|
|
209
|
+
See `docs/IMPLEMENTATION_PHASES.md` for complete breakdown:
|
|
210
|
+
- **Phase 0:** Foundation & Backend Prerequisites
|
|
211
|
+
- **Phase 1:** Core Integration (MVP)
|
|
212
|
+
- **Phase 2:** Authentication & OAuth
|
|
213
|
+
- **Phase 3:** Stripe Integration
|
|
214
|
+
- **Phase 4:** Advanced Features
|
|
215
|
+
|
|
216
|
+
## Next Actions
|
|
217
|
+
|
|
218
|
+
1. ✅ **Planning Complete** - All architecture clarified
|
|
219
|
+
2. **Start Phase 0** - Backend endpoints + CLI foundation
|
|
220
|
+
3. **Start Phase 1** - Core integration MVP
|
|
221
|
+
4. **Test with example projects** as we build
|
|
222
|
+
5. **Iterate based on feedback**
|
|
223
|
+
|
|
224
|
+
---
|
|
225
|
+
|
|
226
|
+
**Status:** Planning Complete ✅
|
|
227
|
+
**Next Phase:** Phase 0 - Foundation
|
|
228
|
+
**Last Updated:** 2025-01-14
|
|
229
|
+
**See:** `docs/IMPLEMENTATION_PHASES.md` for detailed phase breakdown
|
|
230
|
+
|