nitrostack 1.0.74 → 1.0.76

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 +184 -235
  47. package/templates/typescript-oauth/package.json +4 -3
  48. package/templates/typescript-pizzaz/README.md +76 -57
  49. package/templates/typescript-pizzaz/package.json +31 -30
  50. package/templates/typescript-starter/README.md +20 -14
  51. package/templates/typescript-starter/package.json +3 -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,226 @@ 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
34
- ```
44
+ # Create a new project
45
+ nitrostack init my-flight-app --template typescript-oauth
46
+ cd my-flight-app
35
47
 
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
48
+ # Install all dependencies (root + widgets)
49
+ nitrostack install
50
+ ```
41
51
 
42
- ### Run the Project
52
+ ### 2. Get Your Duffel API Key (Free)
43
53
 
44
- ```bash
45
- npm run dev
46
- ```
54
+ [Duffel](https://duffel.com/) provides a free API for flight search and booking:
47
55
 
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
56
+ 1. **Sign up** at [duffel.com](https://duffel.com/) (click "Start now" - it's free!)
57
+ 2. Create a free account (no credit card required)
58
+ 3. Go to your **Dashboard** **Developers** **Access tokens**
59
+ 4. Click **"Create token"** to generate your API key
60
+ 5. Copy the token (starts with `duffel_test_` for sandbox)
52
61
 
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.
62
+ > 💡 **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
63
 
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
64
+ ### 3. Configure Environment
61
65
 
62
- ## 📁 Project Structure
66
+ Copy the example environment file and add your Duffel API key:
63
67
 
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
68
+ ```bash
69
+ cp .env.example .env
78
70
  ```
79
71
 
80
- ## 🛠️ Available Features
72
+ Edit `.env` and update:
81
73
 
82
- ### Health Check: `system`
74
+ ```env
75
+ # Duffel API Configuration
76
+ DUFFEL_API_KEY=duffel_test_your_api_key_here
77
+ ```
83
78
 
84
- Monitors server health and resources:
79
+ ### 4. Run Development Server
85
80
 
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`
81
+ ```bash
82
+ npm run dev
83
+ ```
90
84
 
91
- Check health status in Studio's Health Checks tab!
85
+ This starts:
86
+ - **MCP Server** - Hot reloads on code changes
87
+ - **Studio** on http://localhost:3000 - Visual testing environment
88
+ - **Widget Dev Server** on http://localhost:3001 - Hot module replacement
92
89
 
93
- ### Tool: `calculate`
90
+ ### 5. Test in Studio
94
91
 
95
- Perform basic arithmetic operations:
92
+ Try these prompts in Studio chat:
93
+ - "Search flights from London to New York for next week"
94
+ - "Show me flight details"
95
+ - "I want to select seats"
96
+ - "Show me flights from JFK to LAX"
96
97
 
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
- ```
98
+ ## 📁 Project Structure
112
99
 
113
- **Usage:**
114
100
  ```
115
- User: "Calculate 5 + 3"
116
- AI: [Calls calculate tool]
117
- Result: Beautiful widget showing "5 + 3 = 8"
101
+ typescript-oauth/
102
+ ├── src/
103
+ │ ├── index.ts # Main server entry
104
+ │ ├── app.module.ts # App module
105
+ │ ├── services/
106
+ │ │ └── duffel.service.ts # Duffel API client
107
+ │ └── modules/
108
+ │ └── flights/
109
+ │ ├── flights.module.ts # Module definition
110
+ │ ├── flights.tools.ts # Search & display tools
111
+ │ ├── flights.prompts.ts # AI prompts
112
+ │ ├── flights.resources.ts # Static resources
113
+ │ └── booking.tools.ts # Booking tools
114
+ │ └── widgets/
115
+ │ ├── app/
116
+ │ │ ├── airport-search/ # Airport autocomplete
117
+ │ │ ├── flight-search-results/ # Results list
118
+ │ │ ├── flight-details/ # Flight info
119
+ │ │ ├── seat-selection/ # Seat picker
120
+ │ │ ├── order-summary/ # Booking summary
121
+ │ │ └── payment-confirmation/ # Payment widget
122
+ ├── .env.example # Environment template
123
+ ├── OAUTH_SETUP.md # OAuth configuration guide
124
+ ├── package.json
125
+ └── README.md
118
126
  ```
119
127
 
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
128
  ## 🔧 Commands
154
129
 
155
130
  ```bash
131
+ # Installation
132
+ npm install # Install all dependencies (root + widgets)
133
+ nitrostack install # Same as above
134
+
156
135
  # Development
157
- npm run dev # Start dev server with Studio (auto-builds everything)
136
+ npm run dev # Start dev server with Studio
158
137
  npm run build # Build TypeScript and widgets for production
159
138
  npm start # Run production server
160
139
 
140
+ # Upgrade
141
+ npm run upgrade # Upgrade nitrostack to latest version
142
+
161
143
  # Widget Management
162
144
  npm run widget <command> # Run npm command in widgets directory
163
- npm run widget add <pkg> # Add a widget dependency (e.g., @mui/material)
145
+ npm run widget add <pkg> # Add a widget dependency
164
146
  ```
165
147
 
166
- **Note:** The NitroStack CLI automatically handles building, installing dependencies, and hot reload. You don't need separate commands for widgets anymore!
148
+ ## 🔐 OAuth Setup (Optional)
167
149
 
168
- ## 📝 Example Interactions
150
+ This template includes OAuth 2.1 authentication support. If you want to protect your MCP server with authentication:
169
151
 
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
- ```
152
+ 1. Read the detailed guide: **[OAUTH_SETUP.md](./OAUTH_SETUP.md)**
153
+ 2. Configure Auth0 (or your OAuth provider)
154
+ 3. Update your `.env` with OAuth credentials
176
155
 
177
- ### Get Help
178
- ```
179
- User: "How do I use the calculator?"
180
- AI: Uses calculator_help prompt
181
- Result: Complete usage instructions
182
- ```
156
+ > **Note**: OAuth is optional for local development. The template works without it using Duffel's test API.
183
157
 
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
- ```
158
+ ## 📊 Duffel API Features
190
159
 
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
- ```
160
+ ### Test Mode vs Live Mode
208
161
 
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
- ```
162
+ | Feature | Test Mode (`duffel_test_*`) | Live Mode (`duffel_live_*`) |
163
+ |---------|----------------------------|----------------------------|
164
+ | API Access | Full access | ✅ Full access |
165
+ | Pricing | Mock data | Real prices |
166
+ | Bookings | Simulated | Real bookings |
167
+ | Credit Card | Not charged | Charged |
168
+ | Rate Limits | Generous | Production limits |
230
169
 
231
- ### 3. Prompt Definition
170
+ ### Supported Airlines
232
171
 
233
- ```typescript
234
- @Prompt({
235
- name: 'calculator_help',
236
- arguments: [...]
237
- })
238
- async getHelp(args: any, ctx: ExecutionContext) {
239
- return { messages: [...] };
240
- }
241
- ```
172
+ Duffel provides access to 300+ airlines including:
173
+ - Major carriers (British Airways, Lufthansa, Emirates, etc.)
174
+ - Low-cost carriers (Ryanair, EasyJet, Spirit, etc.)
175
+ - Regional airlines
242
176
 
243
- ### 4. Module Definition
177
+ ### API Capabilities
244
178
 
245
- ```typescript
246
- @Module({
247
- name: 'calculator',
248
- controllers: [CalculatorTools, CalculatorResources, CalculatorPrompts]
249
- })
250
- export class CalculatorModule {}
251
- ```
179
+ - **Search**: Real-time availability and pricing
180
+ - **Ancillaries**: Seats, bags, meals
181
+ - **Booking**: Create and manage orders
182
+ - **Changes**: Modify existing bookings
183
+ - **Cancellations**: Cancel and refund
252
184
 
253
- ### 5. Root Module
185
+ ## 🎨 Widget Features
254
186
 
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
- ```
187
+ ### Airport Search Widget
188
+ - Autocomplete with IATA codes
189
+ - City and airport name search
190
+ - Recent searches
264
191
 
265
- ## 🚀 Extend This Template
192
+ ### Flight Search Results Widget
193
+ - Compare multiple flights
194
+ - Filter by stops, price, time
195
+ - Sort options
196
+ - Airline logos
266
197
 
267
- ### Add More Operations
198
+ ### Flight Details Widget
199
+ - Complete itinerary
200
+ - Fare breakdown
201
+ - Baggage allowance
202
+ - Flight duration and stops
268
203
 
269
- Edit `calculator.tools.ts` and add new operations to the enum and switch statement.
204
+ ### Seat Selection Widget
205
+ - Visual cabin map
206
+ - Seat categories (standard, extra legroom, etc.)
207
+ - Price per seat
208
+ - Real-time availability
270
209
 
271
- ### Add History Feature
210
+ ## 🛠️ Customization
272
211
 
273
- 1. Create a service to store calculations
274
- 2. Add a `get_history` tool
275
- 3. Create a history widget
212
+ ### Adding New Airlines
276
213
 
277
- ### Add More Modules
214
+ Duffel handles airline integrations automatically. You don't need to configure individual airlines.
278
215
 
279
- ```bash
280
- nitrostack generate module converter
281
- ```
216
+ ### Modifying Search Parameters
282
217
 
283
- ## 📚 Next Steps
218
+ Edit `src/modules/flights/flights.tools.ts` to customize:
219
+ - Default passenger counts
220
+ - Cabin class options
221
+ - Date ranges
222
+ - Result limits
284
223
 
285
- Once you understand this template:
224
+ ### Styling Widgets
286
225
 
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
226
+ Each widget in `src/widgets/app/` can be customized:
227
+ - Edit page.tsx for layout
228
+ - Add custom CSS
229
+ - Modify component styles
230
+
231
+ ## 📚 Resources
232
+
233
+ ### Duffel Documentation
234
+ - [Duffel API Docs](https://duffel.com/docs/api)
235
+ - [Duffel SDK (Node.js)](https://github.com/duffel/duffel-api-javascript)
236
+ - [Duffel Postman Collection](https://duffel.com/docs/postman)
237
+
238
+ ### NitroStack Documentation
239
+ - [NitroStack Docs](https://nitrostack.ai/docs)
240
+ - [Widget Development Guide](https://nitrostack.ai/docs/widgets)
291
241
 
292
242
  ## 💡 Tips
293
243
 
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
244
+ - **Use Test Mode**: Start with `duffel_test_*` tokens for development
245
+ - **Check Rate Limits**: Duffel has rate limits - cache searches when possible
246
+ - **Error Handling**: The template includes comprehensive error handling
247
+ - **Responsive Design**: Widgets are mobile-friendly out of the box
298
248
 
299
- ## 🎉 What to Build
249
+ ## 📚 Next Steps
300
250
 
301
- Use this as a starting point for:
251
+ - Try the **Starter Template** - Learn NitroStack basics
252
+ - Try the **Pizza Shop Template** - Interactive maps with Mapbox
253
+ - Read the [Duffel Getting Started Guide](https://duffel.com/docs/guides/getting-started)
302
254
 
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
255
+ ## License
308
256
 
309
- ---
257
+ MIT
310
258
 
311
- **Happy Learning! 📖**
259
+ ---
312
260
 
313
- Start simple, learn the patterns, then build something amazing!
261
+ **Built with ❤️ using NitroStack + Duffel API**
314
262
 
263
+ Need help? Check [Duffel Support](https://duffel.com/docs) or [NitroStack Docs](https://nitrostack.ai/docs)
@@ -1,13 +1,15 @@
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": {
7
8
  "dev": "nitrostack dev",
8
9
  "build": "nitrostack build",
9
10
  "start": "npm run build && nitrostack start",
10
11
  "start:prod": "nitrostack start",
12
+ "upgrade": "nitrostack upgrade",
11
13
  "widget": "npm --prefix src/widgets"
12
14
  },
13
15
  "dependencies": {
@@ -21,6 +23,5 @@
21
23
  "devDependencies": {
22
24
  "typescript": "^5.3.3"
23
25
  },
24
- "description": "NitroStack OAuth 2.1 template with flight booking - demonstrates authentication, API integration, and modern widget development",
25
26
  "author": ""
26
- }
27
+ }