nitrostack 1.0.74 → 1.0.75

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 (52) hide show
  1. package/dist/auth/__tests__/pkce.test.js +53 -4
  2. package/dist/auth/__tests__/pkce.test.js.map +1 -1
  3. package/dist/auth/__tests__/simple-jwt.test.js +153 -2
  4. package/dist/auth/__tests__/simple-jwt.test.js.map +1 -1
  5. package/dist/cli/commands/install.d.ts +10 -0
  6. package/dist/cli/commands/install.d.ts.map +1 -0
  7. package/dist/cli/commands/install.js +79 -0
  8. package/dist/cli/commands/install.js.map +1 -0
  9. package/dist/cli/index.d.ts.map +1 -1
  10. package/dist/cli/index.js +8 -0
  11. package/dist/cli/index.js.map +1 -1
  12. package/dist/core/__tests__/errors.test.d.ts +2 -0
  13. package/dist/core/__tests__/errors.test.d.ts.map +1 -0
  14. package/dist/core/__tests__/errors.test.js +109 -0
  15. package/dist/core/__tests__/errors.test.js.map +1 -0
  16. package/dist/core/__tests__/logger.test.d.ts +2 -0
  17. package/dist/core/__tests__/logger.test.d.ts.map +1 -0
  18. package/dist/core/__tests__/logger.test.js +83 -0
  19. package/dist/core/__tests__/logger.test.js.map +1 -0
  20. package/dist/core/__tests__/prompt.test.d.ts +2 -0
  21. package/dist/core/__tests__/prompt.test.d.ts.map +1 -0
  22. package/dist/core/__tests__/prompt.test.js +126 -0
  23. package/dist/core/__tests__/prompt.test.js.map +1 -0
  24. package/dist/core/__tests__/resource.test.d.ts +2 -0
  25. package/dist/core/__tests__/resource.test.d.ts.map +1 -0
  26. package/dist/core/__tests__/resource.test.js +173 -0
  27. package/dist/core/__tests__/resource.test.js.map +1 -0
  28. package/dist/core/pipes/__tests__/pipes.test.js +113 -1
  29. package/dist/core/pipes/__tests__/pipes.test.js.map +1 -1
  30. package/dist/widgets/hooks/__tests__/hooks.test.d.ts +2 -0
  31. package/dist/widgets/hooks/__tests__/hooks.test.d.ts.map +1 -0
  32. package/dist/widgets/hooks/__tests__/hooks.test.js +129 -0
  33. package/dist/widgets/hooks/__tests__/hooks.test.js.map +1 -0
  34. package/dist/widgets/hooks/__tests__/use-widget-state.test.d.ts +2 -0
  35. package/dist/widgets/hooks/__tests__/use-widget-state.test.d.ts.map +1 -0
  36. package/dist/widgets/hooks/__tests__/use-widget-state.test.js +66 -0
  37. package/dist/widgets/hooks/__tests__/use-widget-state.test.js.map +1 -0
  38. package/dist/widgets/runtime/__tests__/widget-polyfill.test.d.ts +2 -0
  39. package/dist/widgets/runtime/__tests__/widget-polyfill.test.d.ts.map +1 -0
  40. package/dist/widgets/runtime/__tests__/widget-polyfill.test.js +66 -0
  41. package/dist/widgets/runtime/__tests__/widget-polyfill.test.js.map +1 -0
  42. package/package.json +6 -2
  43. package/src/studio/app/chat/page.tsx +21 -0
  44. package/src/studio/lib/llm-service.ts +77 -10
  45. package/templates/typescript-oauth/OAUTH_SETUP.md +592 -0
  46. package/templates/typescript-oauth/README.md +186 -235
  47. package/templates/typescript-oauth/package.json +5 -3
  48. package/templates/typescript-pizzaz/README.md +78 -57
  49. package/templates/typescript-pizzaz/package.json +32 -30
  50. package/templates/typescript-starter/README.md +22 -14
  51. package/templates/typescript-starter/package.json +4 -1
  52. package/templates/typescript-starter/package-lock.json +0 -4112
@@ -1,18 +1,30 @@
1
- # NitroStack Starter Template
2
-
3
- **The simple starter template** - Learn NitroStack v3.0 fundamentals with a clean calculator example.
4
-
5
- ## 🎯 What's Inside
6
-
7
- This template demonstrates core NitroStack v3.0 features:
8
-
9
- - **One Module** - Calculator module with all features
10
- - **One Tool** - `calculate` - Perform arithmetic operations
11
- - **One Resource** - `calculator://operations` - List of operations
12
- - **One Prompt** - `calculator_help` - Get usage help
13
- - **Two Widgets** - Beautiful UI for results and operations list
14
- - **No Authentication** - Focus on learning the basics
15
- - **No Database** - Pure computation example
1
+ # ✈️ NitroStack Flight Booking
2
+
3
+ A production-ready NitroStack template showcasing real-time flight search and booking with **Duffel API** integration. Search flights, view details, select seats, and book - all through beautiful interactive widgets.
4
+
5
+ ## Features
6
+
7
+ ### 🔌 **Duffel API Integration**
8
+ - Real-time flight search across 300+ airlines
9
+ - Live pricing and availability
10
+ - Seat selection with cabin maps
11
+ - Booking and order management
12
+
13
+ ### 🎨 **Interactive Widgets**
14
+ - **Airport Search** - Autocomplete airport selection
15
+ - **Flight Search Results** - Compare flights with prices
16
+ - **Flight Details** - Comprehensive flight information
17
+ - **Seat Selection** - Visual cabin map with seat picker
18
+ - **Order Summary** - Complete booking overview
19
+ - **Payment Confirmation** - Secure payment flow
20
+
21
+ ### 🛠️ **MCP Tools**
22
+ - `search_airports` - Find airports by name/code
23
+ - `search_flights` - Search available flights
24
+ - `show_flight_details` - Detailed flight information
25
+ - `select_seats` - Interactive seat selection
26
+ - `create_booking` - Book flights
27
+ - `get_order` - Retrieve booking details
16
28
 
17
29
  ## 🚀 Quick Start
18
30
 
@@ -26,289 +38,228 @@ npm install -g nitrostack
26
38
  npx nitrostack --version
27
39
  ```
28
40
 
29
- ### Setup Your Project
41
+ ### 1. Create Your Project
30
42
 
31
43
  ```bash
32
- nitrostack init my-calculator --template typescript-starter
33
- cd my-calculator
44
+ # Create a new project
45
+ nitrostack init my-flight-app --template typescript-oauth
46
+ cd my-flight-app
47
+
48
+ # Install all dependencies (root + widgets)
49
+ npm install
50
+ # or
51
+ nitrostack install
34
52
  ```
35
53
 
36
- That's it! The CLI automatically:
37
- - ✅ Installs all dependencies
38
- - ✅ Installs widget dependencies
39
- - ✅ Builds the widgets
40
- - ✅ Sets up the project structure
54
+ ### 2. Get Your Duffel API Key (Free)
41
55
 
42
- ### Run the Project
43
-
44
- ```bash
45
- npm run dev
46
- ```
56
+ [Duffel](https://duffel.com/) provides a free API for flight search and booking:
47
57
 
48
- This starts:
49
- - **MCP Server** (dual transport: STDIO + HTTP on port 3002) - Hot reloads on code changes
50
- - **Studio** on http://localhost:3000 - Visual testing environment
51
- - **Widget Dev Server** on http://localhost:3001 - Hot module replacement
58
+ 1. **Sign up** at [duffel.com](https://duffel.com/) (click "Start now" - it's free!)
59
+ 2. Create a free account (no credit card required)
60
+ 3. Go to your **Dashboard** **Developers** **Access tokens**
61
+ 4. Click **"Create token"** to generate your API key
62
+ 5. Copy the token (starts with `duffel_test_` for sandbox)
52
63
 
53
- > 💡 **Dual Transport**: Your server exposes tools via both STDIO (for direct connections) and HTTP (for remote access on port 3002). Switch between transports in Studio → Settings.
64
+ > 💡 **Tip**: The test mode (`duffel_test_*` tokens) gives you access to realistic mock data for development. Production tokens (`duffel_live_*`) connect to real airlines.
54
65
 
55
- The `nitrostack dev` command handles everything automatically:
56
- - ✅ Auto-detects widget directory
57
- - ✅ Installs dependencies (if needed)
58
- - ✅ Builds widgets (on first run)
59
- - ✅ Starts all services concurrently
60
- - ✅ Hot reload for TypeScript and widgets
66
+ ### 3. Configure Environment
61
67
 
62
- ## 📁 Project Structure
68
+ Copy the example environment file and add your Duffel API key:
63
69
 
64
- ```
65
- src/
66
- ├── modules/
67
- │ └── calculator/
68
- │ ├── calculator.module.ts # @Module definition
69
- │ ├── calculator.tools.ts # @Tool with examples
70
- │ ├── calculator.resources.ts # @Resource
71
- │ └── calculator.prompts.ts # @Prompt
72
- ├── widgets/ # Next.js UI widgets
73
- │ └── app/
74
- │ ├── calculator-result/ # Tool result widget
75
- │ └── calculator-operations/ # Resource widget
76
- ├── app.module.ts # Root @McpApp module
77
- └── index.ts # Application bootstrap
70
+ ```bash
71
+ cp .env.example .env
78
72
  ```
79
73
 
80
- ## 🛠️ Available Features
74
+ Edit `.env` and update:
81
75
 
82
- ### Health Check: `system`
76
+ ```env
77
+ # Duffel API Configuration
78
+ DUFFEL_API_KEY=duffel_test_your_api_key_here
79
+ ```
83
80
 
84
- Monitors server health and resources:
81
+ ### 4. Run Development Server
85
82
 
86
- - **Uptime**: Server running time
87
- - **Memory Usage**: Heap memory consumption
88
- - **Process Info**: PID and Node.js version
89
- - **Status**: `up`, `degraded`, or `down`
83
+ ```bash
84
+ npm run dev
85
+ ```
90
86
 
91
- Check health status in Studio's Health Checks tab!
87
+ This starts:
88
+ - **MCP Server** - Hot reloads on code changes
89
+ - **Studio** on http://localhost:3000 - Visual testing environment
90
+ - **Widget Dev Server** on http://localhost:3001 - Hot module replacement
92
91
 
93
- ### Tool: `calculate`
92
+ ### 5. Test in Studio
94
93
 
95
- Perform basic arithmetic operations:
94
+ Try these prompts in Studio chat:
95
+ - "Search flights from London to New York for next week"
96
+ - "Show me flight details"
97
+ - "I want to select seats"
98
+ - "Show me flights from JFK to LAX"
96
99
 
97
- ```typescript
98
- @Tool({
99
- name: 'calculate',
100
- description: 'Perform basic arithmetic calculations',
101
- inputSchema: z.object({
102
- operation: z.enum(['add', 'subtract', 'multiply', 'divide']),
103
- a: z.number(),
104
- b: z.number()
105
- }),
106
- examples: {
107
- request: { operation: 'add', a: 5, b: 3 },
108
- response: { result: 8, expression: '5 + 3 = 8' }
109
- }
110
- })
111
- ```
100
+ ## 📁 Project Structure
112
101
 
113
- **Usage:**
114
102
  ```
115
- User: "Calculate 5 + 3"
116
- AI: [Calls calculate tool]
117
- Result: Beautiful widget showing "5 + 3 = 8"
103
+ typescript-oauth/
104
+ ├── src/
105
+ │ ├── index.ts # Main server entry
106
+ │ ├── app.module.ts # App module
107
+ │ ├── services/
108
+ │ │ └── duffel.service.ts # Duffel API client
109
+ │ └── modules/
110
+ │ └── flights/
111
+ │ ├── flights.module.ts # Module definition
112
+ │ ├── flights.tools.ts # Search & display tools
113
+ │ ├── flights.prompts.ts # AI prompts
114
+ │ ├── flights.resources.ts # Static resources
115
+ │ └── booking.tools.ts # Booking tools
116
+ │ └── widgets/
117
+ │ ├── app/
118
+ │ │ ├── airport-search/ # Airport autocomplete
119
+ │ │ ├── flight-search-results/ # Results list
120
+ │ │ ├── flight-details/ # Flight info
121
+ │ │ ├── seat-selection/ # Seat picker
122
+ │ │ ├── order-summary/ # Booking summary
123
+ │ │ └── payment-confirmation/ # Payment widget
124
+ ├── .env.example # Environment template
125
+ ├── OAUTH_SETUP.md # OAuth configuration guide
126
+ ├── package.json
127
+ └── README.md
118
128
  ```
119
129
 
120
- ### Resource: `calculator://operations`
121
-
122
- Lists all available operations with examples.
123
-
124
- ### Prompt: `calculator_help`
125
-
126
- Get help on how to use the calculator.
127
-
128
- ## 🎨 Widgets
129
-
130
- ### Calculator Result Widget
131
- - Gradient background
132
- - Operation icon
133
- - Breakdown of numbers
134
- - Beautiful animations
135
-
136
- ### Calculator Operations Widget
137
- - Grid of all operations
138
- - Color-coded by type
139
- - Examples for each operation
140
-
141
- ## 💡 Learning Path
142
-
143
- This template is perfect for learning:
144
-
145
- 1. **Module Organization** - How to structure a feature module
146
- 2. **Tools** - How to create a tool with `@Tool` decorator
147
- 3. **Resources** - How to expose data with `@Resource`
148
- 4. **Prompts** - How to create conversation templates
149
- 5. **Widgets** - How to build UI components
150
- 6. **Examples** - How to include request/response examples
151
- 7. **Validation** - How to use Zod schemas
152
-
153
130
  ## 🔧 Commands
154
131
 
155
132
  ```bash
133
+ # Installation
134
+ npm install # Install all dependencies (root + widgets)
135
+ nitrostack install # Same as above
136
+
156
137
  # Development
157
- npm run dev # Start dev server with Studio (auto-builds everything)
138
+ npm run dev # Start dev server with Studio
158
139
  npm run build # Build TypeScript and widgets for production
159
140
  npm start # Run production server
160
141
 
142
+ # Upgrade
143
+ npm run upgrade # Upgrade nitrostack to latest version
144
+
161
145
  # Widget Management
162
146
  npm run widget <command> # Run npm command in widgets directory
163
- npm run widget add <pkg> # Add a widget dependency (e.g., @mui/material)
147
+ npm run widget add <pkg> # Add a widget dependency
164
148
  ```
165
149
 
166
- **Note:** The NitroStack CLI automatically handles building, installing dependencies, and hot reload. You don't need separate commands for widgets anymore!
150
+ ## 🔐 OAuth Setup (Optional)
167
151
 
168
- ## 📝 Example Interactions
152
+ This template includes OAuth 2.1 authentication support. If you want to protect your MCP server with authentication:
169
153
 
170
- ### Basic Calculation
171
- ```
172
- User: "What's 12 times 8?"
173
- AI: Calls calculate(operation="multiply", a=12, b=8)
174
- Result: Widget showing "12 × 8 = 96"
175
- ```
154
+ 1. Read the detailed guide: **[OAUTH_SETUP.md](./OAUTH_SETUP.md)**
155
+ 2. Configure Auth0 (or your OAuth provider)
156
+ 3. Update your `.env` with OAuth credentials
176
157
 
177
- ### Get Help
178
- ```
179
- User: "How do I use the calculator?"
180
- AI: Uses calculator_help prompt
181
- Result: Complete usage instructions
182
- ```
158
+ > **Note**: OAuth is optional for local development. The template works without it using Duffel's test API.
183
159
 
184
- ### List Operations
185
- ```
186
- User: "What operations are available?"
187
- AI: Fetches calculator://operations resource
188
- Result: Widget showing all 4 operations with examples
189
- ```
160
+ ## 📊 Duffel API Features
190
161
 
191
- ## 🎓 Code Walkthrough
192
-
193
- ### 1. Tool Definition
194
-
195
- ```typescript
196
- @Tool({
197
- name: 'calculate',
198
- description: 'Perform basic arithmetic calculations',
199
- inputSchema: z.object({...}),
200
- examples: {...}
201
- })
202
- @Widget('calculator-result') // Link UI widget
203
- async calculate(input: any, ctx: ExecutionContext) {
204
- // Your logic here
205
- return { result, expression };
206
- }
207
- ```
162
+ ### Test Mode vs Live Mode
208
163
 
209
- **Key Points:**
210
- - `@Tool` decorator defines the tool
211
- - `inputSchema` validates input with Zod
212
- - `examples` help AI understand usage
213
- - `@Widget` links the UI component
214
- - `ExecutionContext` provides logger, metadata
215
-
216
- ### 2. Resource Definition
217
-
218
- ```typescript
219
- @Resource({
220
- uri: 'calculator://operations',
221
- name: 'Calculator Operations',
222
- mimeType: 'application/json',
223
- examples: {...}
224
- })
225
- @Widget('calculator-operations')
226
- async getOperations(uri: string, ctx: ExecutionContext) {
227
- return { contents: [{...}] };
228
- }
229
- ```
164
+ | Feature | Test Mode (`duffel_test_*`) | Live Mode (`duffel_live_*`) |
165
+ |---------|----------------------------|----------------------------|
166
+ | API Access | Full access | ✅ Full access |
167
+ | Pricing | Mock data | Real prices |
168
+ | Bookings | Simulated | Real bookings |
169
+ | Credit Card | Not charged | Charged |
170
+ | Rate Limits | Generous | Production limits |
230
171
 
231
- ### 3. Prompt Definition
172
+ ### Supported Airlines
232
173
 
233
- ```typescript
234
- @Prompt({
235
- name: 'calculator_help',
236
- arguments: [...]
237
- })
238
- async getHelp(args: any, ctx: ExecutionContext) {
239
- return { messages: [...] };
240
- }
241
- ```
174
+ Duffel provides access to 300+ airlines including:
175
+ - Major carriers (British Airways, Lufthansa, Emirates, etc.)
176
+ - Low-cost carriers (Ryanair, EasyJet, Spirit, etc.)
177
+ - Regional airlines
242
178
 
243
- ### 4. Module Definition
179
+ ### API Capabilities
244
180
 
245
- ```typescript
246
- @Module({
247
- name: 'calculator',
248
- controllers: [CalculatorTools, CalculatorResources, CalculatorPrompts]
249
- })
250
- export class CalculatorModule {}
251
- ```
181
+ - **Search**: Real-time availability and pricing
182
+ - **Ancillaries**: Seats, bags, meals
183
+ - **Booking**: Create and manage orders
184
+ - **Changes**: Modify existing bookings
185
+ - **Cancellations**: Cancel and refund
252
186
 
253
- ### 5. Root Module
187
+ ## 🎨 Widget Features
254
188
 
255
- ```typescript
256
- @McpApp({
257
- server: { name: 'calculator-server', version: '1.0.0' }
258
- })
259
- @Module({
260
- imports: [ConfigModule.forRoot(), CalculatorModule]
261
- })
262
- export class AppModule {}
263
- ```
189
+ ### Airport Search Widget
190
+ - Autocomplete with IATA codes
191
+ - City and airport name search
192
+ - Recent searches
264
193
 
265
- ## 🚀 Extend This Template
194
+ ### Flight Search Results Widget
195
+ - Compare multiple flights
196
+ - Filter by stops, price, time
197
+ - Sort options
198
+ - Airline logos
266
199
 
267
- ### Add More Operations
200
+ ### Flight Details Widget
201
+ - Complete itinerary
202
+ - Fare breakdown
203
+ - Baggage allowance
204
+ - Flight duration and stops
268
205
 
269
- Edit `calculator.tools.ts` and add new operations to the enum and switch statement.
206
+ ### Seat Selection Widget
207
+ - Visual cabin map
208
+ - Seat categories (standard, extra legroom, etc.)
209
+ - Price per seat
210
+ - Real-time availability
270
211
 
271
- ### Add History Feature
212
+ ## 🛠️ Customization
272
213
 
273
- 1. Create a service to store calculations
274
- 2. Add a `get_history` tool
275
- 3. Create a history widget
214
+ ### Adding New Airlines
276
215
 
277
- ### Add More Modules
216
+ Duffel handles airline integrations automatically. You don't need to configure individual airlines.
278
217
 
279
- ```bash
280
- nitrostack generate module converter
281
- ```
218
+ ### Modifying Search Parameters
282
219
 
283
- ## 📚 Next Steps
220
+ Edit `src/modules/flights/flights.tools.ts` to customize:
221
+ - Default passenger counts
222
+ - Cabin class options
223
+ - Date ranges
224
+ - Result limits
284
225
 
285
- Once you understand this template:
226
+ ### Styling Widgets
286
227
 
287
- 1. Try the [E-commerce Template](/templates/ecommerce) - Advanced features with auth
288
- 2. Read [Server Concepts](/sdk/typescript/server) - Deep dive into modules
289
- 3. Read [Tools Guide](/sdk/typescript/tools) - Advanced tool patterns
290
- 4. Read [Widgets Guide](/sdk/typescript/ui/widgets) - Build better UIs
228
+ Each widget in `src/widgets/app/` can be customized:
229
+ - Edit page.tsx for layout
230
+ - Add custom CSS
231
+ - Modify component styles
232
+
233
+ ## 📚 Resources
234
+
235
+ ### Duffel Documentation
236
+ - [Duffel API Docs](https://duffel.com/docs/api)
237
+ - [Duffel SDK (Node.js)](https://github.com/duffel/duffel-api-javascript)
238
+ - [Duffel Postman Collection](https://duffel.com/docs/postman)
239
+
240
+ ### NitroStack Documentation
241
+ - [NitroStack Docs](https://nitrostack.ai/docs)
242
+ - [Widget Development Guide](https://nitrostack.ai/docs/widgets)
291
243
 
292
244
  ## 💡 Tips
293
245
 
294
- - **Keep it Simple** - This template shows the minimum needed
295
- - **Study the Code** - Each file has clear examples
296
- - **Test in Studio** - Use the chat to test your tools
297
- - **Check Examples** - The `examples` field helps AI understand your tools
246
+ - **Use Test Mode**: Start with `duffel_test_*` tokens for development
247
+ - **Check Rate Limits**: Duffel has rate limits - cache searches when possible
248
+ - **Error Handling**: The template includes comprehensive error handling
249
+ - **Responsive Design**: Widgets are mobile-friendly out of the box
298
250
 
299
- ## 🎉 What to Build
251
+ ## 📚 Next Steps
300
252
 
301
- Use this as a starting point for:
253
+ - Try the **Starter Template** - Learn NitroStack basics
254
+ - Try the **Pizza Shop Template** - Interactive maps with Mapbox
255
+ - Read the [Duffel Getting Started Guide](https://duffel.com/docs/guides/getting-started)
302
256
 
303
- - **Unit Converters** - Temperature, currency, etc.
304
- - **Text Tools** - String manipulation, formatting
305
- - **Data Processors** - JSON, CSV, XML parsing
306
- - **Simple APIs** - Weather, jokes, facts
307
- - **Utilities** - Date/time, UUID generation
257
+ ## License
308
258
 
309
- ---
259
+ MIT
310
260
 
311
- **Happy Learning! 📖**
261
+ ---
312
262
 
313
- Start simple, learn the patterns, then build something amazing!
263
+ **Built with ❤️ using NitroStack + Duffel API**
314
264
 
265
+ Need help? Check [Duffel Support](https://duffel.com/docs) or [NitroStack Docs](https://nitrostack.ai/docs)
@@ -1,13 +1,16 @@
1
1
  {
2
- "name": "nitrostack-typescript-oauth",
2
+ "name": "nitrostack-flight-booking",
3
3
  "version": "1.0.0",
4
4
  "private": true,
5
5
  "type": "module",
6
+ "description": "NitroStack Flight Booking - Real-time flight search and booking with Duffel API integration",
6
7
  "scripts": {
8
+ "postinstall": "nitrostack install --skip-widgets || true",
7
9
  "dev": "nitrostack dev",
8
10
  "build": "nitrostack build",
9
11
  "start": "npm run build && nitrostack start",
10
12
  "start:prod": "nitrostack start",
13
+ "upgrade": "nitrostack upgrade",
11
14
  "widget": "npm --prefix src/widgets"
12
15
  },
13
16
  "dependencies": {
@@ -21,6 +24,5 @@
21
24
  "devDependencies": {
22
25
  "typescript": "^5.3.3"
23
26
  },
24
- "description": "NitroStack OAuth 2.1 template with flight booking - demonstrates authentication, API integration, and modern widget development",
25
27
  "author": ""
26
- }
28
+ }