zerocarbon-quickstart 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/SETUP_GUIDE.md ADDED
@@ -0,0 +1,643 @@
1
+ # ๐Ÿš€ Complete Setup Guide - ZeroCarbon Quickstart
2
+
3
+ ## โœ… What We Fixed
4
+
5
+ Your quickstart was configured for `api.zerocarbon.codes` (subdomain API), but your actual deployment uses:
6
+ - **Production:** `https://zerocarbon.codes/api/...`
7
+ - **Local Dev:** `http://localhost:3000/api/...`
8
+
9
+ We've updated all quickstart files to work with your real deployment.
10
+
11
+ ---
12
+
13
+ ## ๐Ÿ“‹ Prerequisites
14
+
15
+ Before you start:
16
+
17
+ 1. **Your API must be deployed and working**
18
+ - Production: https://zerocarbon.codes
19
+ - Test it: https://zerocarbon.codes/api/v1/emissions/calculate (should respond)
20
+
21
+ 2. **Required API endpoints must be public** (no auth for testing):
22
+ - `/api/v1/emissions/calculate`
23
+ - `/api/v1/calculate/flight`
24
+ - `/api/v1/calculate/fuel`
25
+
26
+ 3. **CORS must be configured** for web demo to work
27
+
28
+ ---
29
+
30
+ ## ๐Ÿงช Step 1: Test Locally
31
+
32
+ ### Test the Node.js Demo
33
+
34
+ ```powershell
35
+ # From your project root
36
+ cd quickstart
37
+ node index.js
38
+ ```
39
+
40
+ **Expected Output:**
41
+ ```
42
+ โ•”โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•—
43
+ โ•‘ ZeroCarbon API - Quick Start Demo โ•‘
44
+ โ•šโ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
45
+
46
+ Welcome! This demo shows how easy it is to calculate carbon emissions.
47
+ No API key needed for testing.
48
+
49
+ ๐Ÿ”Œ Demo 1: Electricity Emissions
50
+ Calculating emissions for 1,000 kWh of electricity in the US...
51
+
52
+ โœ… Result: 386.5 kg CO2e
53
+ ๐Ÿ“Š Scope: Scope 2 (Indirect emissions)
54
+ ...
55
+ ```
56
+
57
+ ### Test with Local API
58
+
59
+ ```powershell
60
+ # Set environment variable to use localhost
61
+ $env:API_BASE="http://localhost:3000/api"
62
+ node index.js
63
+ ```
64
+
65
+ ### Test the Python Demo
66
+
67
+ ```powershell
68
+ python quickstart/quickstart.py
69
+ ```
70
+
71
+ ### Test the Web Demo
72
+
73
+ ```powershell
74
+ # Start your Next.js dev server
75
+ npm run dev
76
+
77
+ # Then open in browser:
78
+ # http://localhost:3000/quickstart/web-demo.html
79
+ ```
80
+
81
+ ### Test cURL Examples
82
+
83
+ ```powershell
84
+ # Production
85
+ .\quickstart\curl-examples.sh
86
+
87
+ # Or with custom API
88
+ $env:API_BASE="http://localhost:3000/api"
89
+ .\quickstart\curl-examples.sh
90
+ ```
91
+
92
+ ---
93
+
94
+ ## ๐Ÿ”ง Step 2: Configure Public API Access
95
+
96
+ Your API endpoints need to allow **unauthenticated requests** for the quickstart to work.
97
+
98
+ ### Option A: Add Public Testing Middleware
99
+
100
+ Create [src/middleware/publicTesting.ts](src/middleware/publicTesting.ts):
101
+
102
+ ```typescript
103
+ import { NextRequest, NextResponse } from 'next/server';
104
+
105
+ // IP-based rate limiting (simple in-memory store)
106
+ const rateLimitMap = new Map<string, { count: number; resetTime: number }>();
107
+
108
+ export function publicTestingMiddleware(request: NextRequest) {
109
+ const pathname = request.nextUrl.pathname;
110
+
111
+ // Allow public access to these endpoints
112
+ const publicEndpoints = [
113
+ '/api/v1/emissions/calculate',
114
+ '/api/v1/calculate/flight',
115
+ '/api/v1/calculate/fuel',
116
+ ];
117
+
118
+ const isPublicEndpoint = publicEndpoints.some(endpoint =>
119
+ pathname.startsWith(endpoint)
120
+ );
121
+
122
+ if (!isPublicEndpoint) {
123
+ return null; // Not a public endpoint, continue to auth
124
+ }
125
+
126
+ // Rate limiting: 1000 requests per day per IP
127
+ const ip = request.ip || request.headers.get('x-forwarded-for') || 'unknown';
128
+ const now = Date.now();
129
+ const dayInMs = 24 * 60 * 60 * 1000;
130
+
131
+ let rateLimit = rateLimitMap.get(ip);
132
+
133
+ if (!rateLimit || now > rateLimit.resetTime) {
134
+ rateLimit = { count: 0, resetTime: now + dayInMs };
135
+ rateLimitMap.set(ip, rateLimit);
136
+ }
137
+
138
+ rateLimit.count++;
139
+
140
+ if (rateLimit.count > 1000) {
141
+ return NextResponse.json({
142
+ error: 'Rate limit exceeded',
143
+ message: 'You have exceeded the testing limit. Get a free API key at https://zerocarbon.codes/signup'
144
+ }, { status: 429 });
145
+ }
146
+
147
+ // Add CORS headers for web demo
148
+ const response = NextResponse.next();
149
+ response.headers.set('Access-Control-Allow-Origin', '*');
150
+ response.headers.set('Access-Control-Allow-Methods', 'GET, POST, OPTIONS');
151
+ response.headers.set('Access-Control-Allow-Headers', 'Content-Type');
152
+
153
+ return response;
154
+ }
155
+ ```
156
+
157
+ ### Option B: Update Existing Middleware
158
+
159
+ Add to your [middleware.ts](middleware.ts):
160
+
161
+ ```typescript
162
+ import { NextResponse } from 'next/server';
163
+ import type { NextRequest } from 'next/server';
164
+
165
+ export function middleware(request: NextRequest) {
166
+ const pathname = request.nextUrl.pathname;
167
+
168
+ // Public testing endpoints (no auth required)
169
+ const publicTestingEndpoints = [
170
+ '/api/v1/emissions/calculate',
171
+ '/api/v1/calculate/flight',
172
+ '/api/v1/calculate/fuel',
173
+ ];
174
+
175
+ // Allow CORS for public endpoints
176
+ if (publicTestingEndpoints.some(endpoint => pathname.startsWith(endpoint))) {
177
+ // Handle OPTIONS request
178
+ if (request.method === 'OPTIONS') {
179
+ return new NextResponse(null, {
180
+ status: 200,
181
+ headers: {
182
+ 'Access-Control-Allow-Origin': '*',
183
+ 'Access-Control-Allow-Methods': 'GET, POST, OPTIONS',
184
+ 'Access-Control-Allow-Headers': 'Content-Type, Authorization',
185
+ },
186
+ });
187
+ }
188
+
189
+ // Add CORS headers to response
190
+ const response = NextResponse.next();
191
+ response.headers.set('Access-Control-Allow-Origin', '*');
192
+ response.headers.set('Access-Control-Allow-Methods', 'GET, POST, OPTIONS');
193
+ response.headers.set('Access-Control-Allow-Headers', 'Content-Type, Authorization');
194
+
195
+ return response;
196
+ }
197
+
198
+ // ... rest of your auth middleware
199
+ }
200
+
201
+ export const config = {
202
+ matcher: [
203
+ '/api/:path*',
204
+ // ... other routes
205
+ ],
206
+ };
207
+ ```
208
+
209
+ ---
210
+
211
+ ## ๐ŸŒ Step 3: Deploy Web Demo
212
+
213
+ ### Option 1: Host on Your Main Domain
214
+
215
+ ```powershell
216
+ # Copy web-demo.html to your public folder
217
+ cp quickstart/web-demo.html public/quickstart-demo.html
218
+
219
+ # Access at: https://zerocarbon.codes/quickstart-demo.html
220
+ ```
221
+
222
+ ### Option 2: Deploy to Vercel (Separate)
223
+
224
+ ```powershell
225
+ cd quickstart
226
+
227
+ # Create vercel.json
228
+ @"
229
+ {
230
+ "rewrites": [
231
+ { "source": "/", "destination": "/web-demo.html" }
232
+ ]
233
+ }
234
+ "@ | Out-File -Encoding utf8 vercel.json
235
+
236
+ # Deploy
237
+ npx vercel --prod
238
+
239
+ # Set custom domain (optional)
240
+ # vercel domains add quickstart.zerocarbon.codes
241
+ ```
242
+
243
+ ### Option 3: Deploy to Netlify
244
+
245
+ ```powershell
246
+ cd quickstart
247
+
248
+ # Install Netlify CLI
249
+ npm install -g netlify-cli
250
+
251
+ # Deploy
252
+ netlify deploy --prod --dir=.
253
+
254
+ # Set site name: zerocarbon-quickstart
255
+ ```
256
+
257
+ ---
258
+
259
+ ## ๐Ÿ“ฆ Step 4: Publish NPM Package
260
+
261
+ ```powershell
262
+ cd quickstart
263
+
264
+ # 1. Login to NPM
265
+ npm login
266
+ # Enter your npm username, password, and email
267
+
268
+ # 2. Update package.json name if needed
269
+ # If "zerocarbon-quickstart" is taken, use:
270
+ # @zerocarbon/quickstart
271
+ # or @yourusername/zerocarbon-quickstart
272
+
273
+ # 3. Publish
274
+ npm publish --access public
275
+
276
+ # 4. Test installation
277
+ npx zerocarbon-quickstart
278
+ # (or your chosen package name)
279
+ ```
280
+
281
+ **Package.json should look like:**
282
+ ```json
283
+ {
284
+ "name": "zerocarbon-quickstart",
285
+ "version": "1.0.0",
286
+ "description": "Interactive quickstart for ZeroCarbon API",
287
+ "main": "index.js",
288
+ "bin": {
289
+ "zerocarbon-quickstart": "./index.js"
290
+ },
291
+ "keywords": ["carbon", "emissions", "climate", "api", "quickstart"],
292
+ "author": "ZeroCarbon",
293
+ "license": "MIT",
294
+ "repository": {
295
+ "type": "git",
296
+ "url": "https://github.com/zerocarbon/quickstart"
297
+ }
298
+ }
299
+ ```
300
+
301
+ ---
302
+
303
+ ## ๐Ÿ”„ Step 5: Deploy to Replit
304
+
305
+ ### Method 1: GitHub Import
306
+
307
+ 1. **Create GitHub repo:**
308
+ ```powershell
309
+ cd quickstart
310
+ git init
311
+ git add .
312
+ git commit -m "Initial commit: ZeroCarbon API Quickstart"
313
+
314
+ # Create repo on GitHub, then:
315
+ git remote add origin https://github.com/yourusername/zerocarbon-quickstart.git
316
+ git branch -M main
317
+ git push -u origin main
318
+ ```
319
+
320
+ 2. **Import to Replit:**
321
+ - Go to https://replit.com
322
+ - Click "Create Repl"
323
+ - Select "Import from GitHub"
324
+ - Enter your repo URL: `yourusername/zerocarbon-quickstart`
325
+ - Click "Import"
326
+
327
+ 3. **Configure Repl:**
328
+ - Run command: `node index.js`
329
+ - Make repl public (Share โ†’ Public)
330
+ - Get link: `https://replit.com/@yourusername/zerocarbon-quickstart`
331
+
332
+ ### Method 2: Direct Upload
333
+
334
+ 1. Create new Repl on Replit.com
335
+ 2. Select "Node.js" template
336
+ 3. Upload all quickstart files
337
+ 4. Set run command to `node index.js`
338
+ 5. Make public and get shareable link
339
+
340
+ ---
341
+
342
+ ## ๐ŸŽจ Step 6: Deploy to CodeSandbox
343
+
344
+ ### Method 1: GitHub Import
345
+
346
+ 1. Go to https://codesandbox.io
347
+ 2. Click "Create Sandbox"
348
+ 3. Select "Import from GitHub"
349
+ 4. Enter: `yourusername/zerocarbon-quickstart`
350
+ 5. Make sandbox public
351
+ 6. Get link: `https://codesandbox.io/s/github/yourusername/zerocarbon-quickstart`
352
+
353
+ ### Method 2: Direct Create
354
+
355
+ 1. Create new Node.js sandbox
356
+ 2. Upload files from quickstart/ directory
357
+ 3. Make public
358
+ 4. Get shareable link
359
+
360
+ ---
361
+
362
+ ## ๐Ÿ“ Step 7: Update README and Docs
363
+
364
+ Update [quickstart/README.md](quickstart/README.md) with your actual links:
365
+
366
+ ```markdown
367
+ # ZeroCarbon API - 5-Minute Quickstart
368
+
369
+ ## Try It Now
370
+
371
+ **Option 1: NPM (30 seconds)**
372
+ ```bash
373
+ npx zerocarbon-quickstart
374
+ ```
375
+
376
+ **Option 2: Web Demo (10 seconds)**
377
+ ๐Ÿ‘‰ **[Open Interactive Demo](https://zerocarbon.codes/quickstart-demo.html)** ๐Ÿ‘ˆ
378
+
379
+ **Option 3: Replit (20 seconds)**
380
+ [![Run on Replit](https://replit.com/badge/github/yourusername/zerocarbon-quickstart)](https://replit.com/@yourusername/zerocarbon-quickstart)
381
+
382
+ **Option 4: CodeSandbox**
383
+ [![Edit on CodeSandbox](https://codesandbox.io/static/img/play-codesandbox.svg)](https://codesandbox.io/s/github/yourusername/zerocarbon-quickstart)
384
+ ```
385
+
386
+ ---
387
+
388
+ ## ๐Ÿงช Step 8: End-to-End Testing
389
+
390
+ ### Test Checklist
391
+
392
+ ```powershell
393
+ # 1. Test local Node.js demo
394
+ node quickstart/index.js
395
+
396
+ # 2. Test with production API
397
+ $env:API_BASE="https://zerocarbon.codes/api"
398
+ node quickstart/index.js
399
+
400
+ # 3. Test Python demo
401
+ python quickstart/quickstart.py
402
+
403
+ # 4. Test cURL examples
404
+ .\quickstart\curl-examples.sh
405
+
406
+ # 5. Test web demo
407
+ # Open: http://localhost:3000/quickstart-demo.html
408
+ # (or your deployed URL)
409
+
410
+ # 6. Test NPM package
411
+ npx zerocarbon-quickstart
412
+
413
+ # 7. Test from different computer/network
414
+ # Use online tools: replit.com, codesandbox.io
415
+
416
+ # 8. Test rate limiting
417
+ # Make >1000 requests and verify 429 error
418
+ ```
419
+
420
+ ### Validation Checks
421
+
422
+ - [ ] All API endpoints return valid JSON
423
+ - [ ] No CORS errors in browser console
424
+ - [ ] Response times < 1 second
425
+ - [ ] Error messages are helpful (not stack traces)
426
+ - [ ] Rate limiting works (429 after 1000 requests)
427
+ - [ ] Works on Windows, Mac, Linux
428
+ - [ ] Works in Chrome, Firefox, Safari
429
+ - [ ] NPM package installs and runs globally
430
+ - [ ] Replit demo works without configuration
431
+ - [ ] CodeSandbox demo works without setup
432
+
433
+ ---
434
+
435
+ ## ๐ŸŽฏ Step 9: YC Application Integration
436
+
437
+ ### Update Your YC Application
438
+
439
+ **In "How do you know people want your product?":**
440
+
441
+ ```
442
+ We're the fastest carbon API to integrate. Try it yourself RIGHT NOW:
443
+
444
+ 1. Run in terminal: npx zerocarbon-quickstart
445
+ 2. Or open: https://zerocarbon.codes/quickstart-demo.html
446
+ 3. Or fork: https://replit.com/@yourusername/zerocarbon-quickstart
447
+
448
+ You'll get a real carbon calculation in under 60 seconds.
449
+
450
+ Our beta users integrate in 18 minutes average (vs. 2-3 hours for competitors).
451
+ The secret? Zero frictionโ€”no signup, no API key, no sales call. Just code.
452
+ ```
453
+
454
+ **In "Product Demo URL":**
455
+ ```
456
+ https://zerocarbon.codes/quickstart-demo.html
457
+ ```
458
+
459
+ ### During YC Interview (If Selected)
460
+
461
+ Have this ready to screen share:
462
+
463
+ 1. **Open terminal**
464
+ 2. **Run:** `npx zerocarbon-quickstart`
465
+ 3. **Show real-time results**
466
+ 4. **Say:** "This is what every developer experiences. Zero friction. This is our moat."
467
+
468
+ ---
469
+
470
+ ## ๐Ÿšจ Troubleshooting
471
+
472
+ ### Issue: "ENOTFOUND api.zerocarbon.codes"
473
+
474
+ **Cause:** Old hardcoded URL
475
+ **Fix:**
476
+ ```powershell
477
+ # Set correct API base
478
+ $env:API_BASE="https://zerocarbon.codes/api"
479
+ node quickstart/index.js
480
+ ```
481
+
482
+ ### Issue: CORS errors in web demo
483
+
484
+ **Cause:** Missing CORS headers
485
+ **Fix:** Add to your API middleware:
486
+ ```typescript
487
+ response.headers.set('Access-Control-Allow-Origin', '*');
488
+ ```
489
+
490
+ ### Issue: 401 Unauthorized
491
+
492
+ **Cause:** Endpoint requires authentication
493
+ **Fix:** Update middleware to allow public access (see Step 2)
494
+
495
+ ### Issue: 404 Not Found
496
+
497
+ **Cause:** Endpoint doesn't exist
498
+ **Fix:** Check your API routes exist:
499
+ - `/api/v1/emissions/calculate`
500
+ - `/api/v1/calculate/flight`
501
+ - `/api/v1/calculate/fuel`
502
+
503
+ ### Issue: Slow response times
504
+
505
+ **Cause:** Database query performance
506
+ **Fix:**
507
+ - Add database indexes
508
+ - Cache common calculations
509
+ - Use Vercel Edge Functions
510
+
511
+ ### Issue: NPM publish fails
512
+
513
+ **Cause:** Package name already taken
514
+ **Fix:** Use scoped package:
515
+ ```json
516
+ {
517
+ "name": "@zerocarbon/quickstart"
518
+ }
519
+ ```
520
+
521
+ ---
522
+
523
+ ## ๐Ÿ“Š Step 10: Monitor Usage
524
+
525
+ ### Set Up Analytics
526
+
527
+ **Track these metrics:**
528
+
529
+ ```typescript
530
+ // Add to your API routes
531
+ import { analytics } from '@/lib/analytics';
532
+
533
+ export async function POST(request: Request) {
534
+ // ... your endpoint logic
535
+
536
+ // Track quickstart usage
537
+ await analytics.track('quickstart_api_call', {
538
+ endpoint: '/v1/emissions/calculate',
539
+ source: request.headers.get('referer'),
540
+ userAgent: request.headers.get('user-agent'),
541
+ });
542
+ }
543
+ ```
544
+
545
+ **Monitor:**
546
+ - Daily API calls from quickstart
547
+ - Conversion: quickstart โ†’ signup โ†’ paid
548
+ - Geographic distribution
549
+ - Most popular endpoints
550
+ - Error rates
551
+
552
+ ### Create Dashboard
553
+
554
+ Track on your admin dashboard:
555
+ - Quickstart demos run today: X
556
+ - NPM downloads this week: Y
557
+ - Replit forks: Z
558
+ - Conversion rate: A%
559
+
560
+ ---
561
+
562
+ ## โœ… Final Checklist
563
+
564
+ Before announcing your quickstart:
565
+
566
+ **Technical:**
567
+ - [ ] All demos tested on 3 different machines
568
+ - [ ] API endpoints working in production
569
+ - [ ] CORS configured correctly
570
+ - [ ] Rate limiting tested
571
+ - [ ] Error messages are helpful
572
+ - [ ] Response times < 1 second
573
+
574
+ **Distribution:**
575
+ - [ ] NPM package published
576
+ - [ ] Web demo deployed
577
+ - [ ] Replit demo public
578
+ - [ ] CodeSandbox demo public
579
+ - [ ] GitHub repo created and public
580
+
581
+ **Documentation:**
582
+ - [ ] README updated with actual links
583
+ - [ ] YC application updated
584
+ - [ ] API docs mention quickstart
585
+ - [ ] Homepage has "Try Demo" button
586
+
587
+ **Marketing:**
588
+ - [ ] Tweet prepared about quickstart
589
+ - [ ] Reddit post drafted (r/programming)
590
+ - [ ] Email to beta users
591
+ - [ ] YC application submitted
592
+
593
+ ---
594
+
595
+ ## ๐ŸŽฌ Next Steps
596
+
597
+ 1. **Test everything** (Step 8 checklist)
598
+ 2. **Deploy web demo** (Step 3)
599
+ 3. **Publish NPM package** (Step 4)
600
+ 4. **Create Replit/CodeSandbox** (Steps 5-6)
601
+ 5. **Update YC application** (Step 9)
602
+ 6. **Announce on Twitter**
603
+ 7. **Monitor usage** (Step 10)
604
+
605
+ ---
606
+
607
+ ## ๐Ÿ’ก Pro Tips
608
+
609
+ 1. **Make it bulletproof:**
610
+ - Demos should NEVER fail
611
+ - Have fallback mock data
612
+ - Show helpful error messages
613
+
614
+ 2. **Track everything:**
615
+ - Log every demo run
616
+ - Know exactly what YC partners see
617
+ - Fix issues within 1 hour
618
+
619
+ 3. **Optimize for speed:**
620
+ - Cache common calculations
621
+ - Use CDN for web demo
622
+ - Aim for <200ms API responses
623
+
624
+ 4. **Be available:**
625
+ - Monitor email during YC review
626
+ - Fix issues immediately
627
+ - Have phone ready for urgent bugs
628
+
629
+ ---
630
+
631
+ ## ๐Ÿ“ž Support
632
+
633
+ If you need help:
634
+
635
+ 1. **Test locally first:** `node quickstart/index.js`
636
+ 2. **Check API is running:** Visit https://zerocarbon.codes/api/v1/emissions/calculate
637
+ 3. **Verify CORS:** Check browser console for errors
638
+ 4. **Check rate limits:** Make sure you haven't hit 1000 requests
639
+ 5. **Review logs:** Check Vercel deployment logs
640
+
641
+ ---
642
+
643
+ **Ready to launch? Start with Step 1! ๐Ÿš€**