nitrostack 1.0.55 → 1.0.56

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 (222) hide show
  1. package/dist/cli/commands/init.d.ts.map +1 -1
  2. package/dist/cli/commands/init.js +14 -9
  3. package/dist/cli/commands/init.js.map +1 -1
  4. package/dist/widgets/hooks/index.d.ts +7 -0
  5. package/dist/widgets/hooks/index.d.ts.map +1 -0
  6. package/dist/widgets/hooks/index.js +7 -0
  7. package/dist/widgets/hooks/index.js.map +1 -0
  8. package/dist/widgets/hooks/use-display-mode.d.ts +11 -0
  9. package/dist/widgets/hooks/use-display-mode.d.ts.map +1 -0
  10. package/dist/widgets/hooks/use-display-mode.js +13 -0
  11. package/dist/widgets/hooks/use-display-mode.js.map +1 -0
  12. package/dist/widgets/hooks/use-max-height.d.ts +10 -0
  13. package/dist/widgets/hooks/use-max-height.d.ts.map +1 -0
  14. package/dist/widgets/hooks/use-max-height.js +13 -0
  15. package/dist/widgets/hooks/use-max-height.js.map +1 -0
  16. package/dist/widgets/hooks/use-openai-global.d.ts +12 -0
  17. package/dist/widgets/hooks/use-openai-global.d.ts.map +1 -0
  18. package/dist/widgets/hooks/use-openai-global.js +32 -0
  19. package/dist/widgets/hooks/use-openai-global.js.map +1 -0
  20. package/dist/widgets/hooks/use-theme.d.ts +10 -0
  21. package/dist/widgets/hooks/use-theme.d.ts.map +1 -0
  22. package/dist/widgets/hooks/use-theme.js +12 -0
  23. package/dist/widgets/hooks/use-theme.js.map +1 -0
  24. package/dist/widgets/hooks/use-widget-state.d.ts +18 -0
  25. package/dist/widgets/hooks/use-widget-state.d.ts.map +1 -0
  26. package/dist/widgets/hooks/use-widget-state.js +27 -0
  27. package/dist/widgets/hooks/use-widget-state.js.map +1 -0
  28. package/dist/widgets/hooks/useWidgetSDK.d.ts +47 -0
  29. package/dist/widgets/hooks/useWidgetSDK.d.ts.map +1 -0
  30. package/dist/widgets/hooks/useWidgetSDK.js +67 -0
  31. package/dist/widgets/hooks/useWidgetSDK.js.map +1 -0
  32. package/dist/widgets/index.d.ts +7 -1
  33. package/dist/widgets/index.d.ts.map +1 -1
  34. package/dist/widgets/index.js +11 -1
  35. package/dist/widgets/index.js.map +1 -1
  36. package/dist/widgets/runtime/WidgetLayout.d.ts +32 -0
  37. package/dist/widgets/runtime/WidgetLayout.d.ts.map +1 -0
  38. package/dist/widgets/runtime/WidgetLayout.js +143 -0
  39. package/dist/widgets/runtime/WidgetLayout.js.map +1 -0
  40. package/dist/widgets/runtime/widget-polyfill.d.ts +1 -0
  41. package/dist/widgets/runtime/widget-polyfill.d.ts.map +1 -0
  42. package/dist/widgets/runtime/widget-polyfill.js +28 -0
  43. package/dist/widgets/runtime/widget-polyfill.js.map +1 -0
  44. package/dist/widgets/sdk.d.ts +109 -0
  45. package/dist/widgets/sdk.d.ts.map +1 -0
  46. package/dist/widgets/sdk.js +221 -0
  47. package/dist/widgets/sdk.js.map +1 -0
  48. package/dist/widgets/types.d.ts +89 -0
  49. package/dist/widgets/types.d.ts.map +1 -0
  50. package/dist/widgets/types.js +8 -0
  51. package/dist/widgets/types.js.map +1 -0
  52. package/dist/widgets/utils/media-queries.d.ts +34 -0
  53. package/dist/widgets/utils/media-queries.d.ts.map +1 -0
  54. package/dist/widgets/utils/media-queries.js +42 -0
  55. package/dist/widgets/utils/media-queries.js.map +1 -0
  56. package/package.json +1 -1
  57. package/src/studio/app/chat/page.tsx +274 -137
  58. package/src/studio/app/globals.css +140 -64
  59. package/src/studio/branding.md +807 -0
  60. package/src/studio/components/WidgetRenderer.tsx +222 -16
  61. package/src/studio/lib/llm-service.ts +39 -39
  62. package/templates/typescript-oauth/{env.example → .env.example} +4 -10
  63. package/templates/typescript-oauth/README.md +226 -306
  64. package/templates/typescript-oauth/package-lock.json +4253 -0
  65. package/templates/typescript-oauth/package.json +10 -5
  66. package/templates/typescript-oauth/src/app.module.ts +39 -36
  67. package/templates/typescript-oauth/src/guards/oauth.guard.ts +0 -1
  68. package/templates/typescript-oauth/src/index.ts +22 -30
  69. package/templates/typescript-oauth/src/modules/flights/booking.tools.ts +323 -0
  70. package/templates/typescript-oauth/src/modules/flights/flights.module.ts +14 -0
  71. package/templates/typescript-oauth/src/modules/flights/flights.prompts.ts +231 -0
  72. package/templates/typescript-oauth/src/modules/flights/flights.resources.ts +215 -0
  73. package/templates/typescript-oauth/src/modules/flights/flights.tools.ts +457 -0
  74. package/templates/typescript-oauth/src/services/duffel.service.ts +285 -0
  75. package/templates/typescript-oauth/src/widgets/app/airport-search/page.tsx +270 -0
  76. package/templates/typescript-oauth/src/widgets/app/flight-details/page.tsx +261 -0
  77. package/templates/typescript-oauth/src/widgets/app/flight-search-results/page.tsx +378 -0
  78. package/templates/typescript-oauth/src/widgets/app/globals.css +167 -0
  79. package/templates/typescript-oauth/src/widgets/app/layout.tsx +6 -2
  80. package/templates/typescript-oauth/src/widgets/app/order-cancellation/page.tsx +207 -0
  81. package/templates/typescript-oauth/src/widgets/app/order-summary/page.tsx +245 -0
  82. package/templates/typescript-oauth/src/widgets/app/payment-confirmation/page.tsx +152 -0
  83. package/templates/typescript-oauth/src/widgets/app/seat-selection/page.tsx +486 -0
  84. package/templates/typescript-oauth/src/widgets/next-env.d.ts +5 -0
  85. package/templates/typescript-oauth/src/widgets/package-lock.json +155 -126
  86. package/templates/typescript-oauth/src/widgets/widget-manifest.json +374 -27
  87. package/templates/typescript-pizzaz/IMPLEMENTATION.md +98 -0
  88. package/templates/typescript-pizzaz/README.md +233 -0
  89. package/templates/typescript-pizzaz/package.json +31 -0
  90. package/templates/typescript-pizzaz/src/app.module.ts +28 -0
  91. package/templates/typescript-pizzaz/src/index.ts +30 -0
  92. package/templates/typescript-pizzaz/src/modules/pizzaz/pizzaz.data.ts +106 -0
  93. package/templates/typescript-pizzaz/src/modules/pizzaz/pizzaz.module.ts +11 -0
  94. package/templates/typescript-pizzaz/src/modules/pizzaz/pizzaz.service.ts +60 -0
  95. package/templates/typescript-pizzaz/src/modules/pizzaz/pizzaz.tools.ts +197 -0
  96. package/templates/typescript-pizzaz/src/widgets/app/layout.tsx +18 -0
  97. package/templates/typescript-pizzaz/src/widgets/app/pizza-list/page.tsx +272 -0
  98. package/templates/typescript-pizzaz/src/widgets/app/pizza-map/page.tsx +216 -0
  99. package/templates/typescript-pizzaz/src/widgets/app/pizza-shop/page.tsx +374 -0
  100. package/templates/typescript-pizzaz/src/widgets/components/CompactShopCard.tsx +144 -0
  101. package/templates/typescript-pizzaz/src/widgets/components/PizzaCard.tsx +191 -0
  102. package/templates/typescript-pizzaz/src/widgets/package.json +30 -0
  103. package/templates/typescript-pizzaz/src/widgets/widget-manifest.json +253 -0
  104. package/templates/typescript-pizzaz/tsconfig.json +30 -0
  105. package/templates/typescript-starter/src/modules/calculator/calculator.resources.ts +0 -1
  106. package/templates/typescript-starter/src/widgets/app/calculator-result/page.tsx +102 -56
  107. package/templates/typescript-starter/src/widgets/app/layout.tsx +6 -2
  108. package/templates/typescript-auth/AI_AGENT_CLI_REFERENCE.md +0 -702
  109. package/templates/typescript-auth/AI_AGENT_SDK_REFERENCE.md +0 -1260
  110. package/templates/typescript-auth/README.md +0 -402
  111. package/templates/typescript-auth/env.example +0 -25
  112. package/templates/typescript-auth/package.json +0 -36
  113. package/templates/typescript-auth/src/app.module.ts +0 -103
  114. package/templates/typescript-auth/src/db/database.ts +0 -160
  115. package/templates/typescript-auth/src/db/seed.ts +0 -374
  116. package/templates/typescript-auth/src/db/setup.ts +0 -87
  117. package/templates/typescript-auth/src/events/analytics.service.ts +0 -52
  118. package/templates/typescript-auth/src/events/notification.service.ts +0 -40
  119. package/templates/typescript-auth/src/filters/global-exception.filter.ts +0 -28
  120. package/templates/typescript-auth/src/guards/README.md +0 -75
  121. package/templates/typescript-auth/src/guards/jwt.guard.ts +0 -105
  122. package/templates/typescript-auth/src/health/database.health.ts +0 -41
  123. package/templates/typescript-auth/src/index.ts +0 -29
  124. package/templates/typescript-auth/src/interceptors/transform.interceptor.ts +0 -24
  125. package/templates/typescript-auth/src/middleware/logging.middleware.ts +0 -42
  126. package/templates/typescript-auth/src/modules/addresses/addresses.module.ts +0 -16
  127. package/templates/typescript-auth/src/modules/addresses/addresses.prompts.ts +0 -114
  128. package/templates/typescript-auth/src/modules/addresses/addresses.resources.ts +0 -40
  129. package/templates/typescript-auth/src/modules/addresses/addresses.tools.ts +0 -284
  130. package/templates/typescript-auth/src/modules/auth/auth.module.ts +0 -16
  131. package/templates/typescript-auth/src/modules/auth/auth.prompts.ts +0 -147
  132. package/templates/typescript-auth/src/modules/auth/auth.resources.ts +0 -84
  133. package/templates/typescript-auth/src/modules/auth/auth.tools.ts +0 -139
  134. package/templates/typescript-auth/src/modules/cart/cart.module.ts +0 -16
  135. package/templates/typescript-auth/src/modules/cart/cart.prompts.ts +0 -95
  136. package/templates/typescript-auth/src/modules/cart/cart.resources.ts +0 -44
  137. package/templates/typescript-auth/src/modules/cart/cart.tools.ts +0 -277
  138. package/templates/typescript-auth/src/modules/orders/orders.module.ts +0 -16
  139. package/templates/typescript-auth/src/modules/orders/orders.prompts.ts +0 -88
  140. package/templates/typescript-auth/src/modules/orders/orders.resources.ts +0 -48
  141. package/templates/typescript-auth/src/modules/orders/orders.tools.ts +0 -303
  142. package/templates/typescript-auth/src/modules/products/products.module.ts +0 -16
  143. package/templates/typescript-auth/src/modules/products/products.prompts.ts +0 -146
  144. package/templates/typescript-auth/src/modules/products/products.resources.ts +0 -98
  145. package/templates/typescript-auth/src/modules/products/products.tools.ts +0 -266
  146. package/templates/typescript-auth/src/pipes/validation.pipe.ts +0 -42
  147. package/templates/typescript-auth/src/services/database.service.ts +0 -90
  148. package/templates/typescript-auth/src/widgets/app/add-to-cart/page.tsx +0 -122
  149. package/templates/typescript-auth/src/widgets/app/address-added/page.tsx +0 -116
  150. package/templates/typescript-auth/src/widgets/app/address-deleted/page.tsx +0 -105
  151. package/templates/typescript-auth/src/widgets/app/address-list/page.tsx +0 -139
  152. package/templates/typescript-auth/src/widgets/app/address-updated/page.tsx +0 -153
  153. package/templates/typescript-auth/src/widgets/app/cart-cleared/page.tsx +0 -86
  154. package/templates/typescript-auth/src/widgets/app/cart-updated/page.tsx +0 -116
  155. package/templates/typescript-auth/src/widgets/app/categories/page.tsx +0 -134
  156. package/templates/typescript-auth/src/widgets/app/layout.tsx +0 -21
  157. package/templates/typescript-auth/src/widgets/app/login-result/page.tsx +0 -129
  158. package/templates/typescript-auth/src/widgets/app/order-confirmation/page.tsx +0 -231
  159. package/templates/typescript-auth/src/widgets/app/order-details/page.tsx +0 -225
  160. package/templates/typescript-auth/src/widgets/app/order-history/page.tsx +0 -218
  161. package/templates/typescript-auth/src/widgets/app/product-card/page.tsx +0 -121
  162. package/templates/typescript-auth/src/widgets/app/products-grid/page.tsx +0 -198
  163. package/templates/typescript-auth/src/widgets/app/shopping-cart/page.tsx +0 -187
  164. package/templates/typescript-auth/src/widgets/app/whoami/page.tsx +0 -165
  165. package/templates/typescript-auth/src/widgets/next.config.js +0 -38
  166. package/templates/typescript-auth/src/widgets/package.json +0 -18
  167. package/templates/typescript-auth/src/widgets/styles/ecommerce.ts +0 -169
  168. package/templates/typescript-auth/src/widgets/tsconfig.json +0 -28
  169. package/templates/typescript-auth/src/widgets/types/tool-data.ts +0 -141
  170. package/templates/typescript-auth/src/widgets/widget-manifest.json +0 -464
  171. package/templates/typescript-auth/tsconfig.json +0 -27
  172. package/templates/typescript-auth-api-key/AI_AGENT_CLI_REFERENCE.md +0 -701
  173. package/templates/typescript-auth-api-key/AI_AGENT_SDK_REFERENCE.md +0 -1260
  174. package/templates/typescript-auth-api-key/README.md +0 -485
  175. package/templates/typescript-auth-api-key/env.example +0 -17
  176. package/templates/typescript-auth-api-key/package.json +0 -21
  177. package/templates/typescript-auth-api-key/src/app.module.ts +0 -38
  178. package/templates/typescript-auth-api-key/src/guards/apikey.guard.ts +0 -47
  179. package/templates/typescript-auth-api-key/src/guards/multi-auth.guard.ts +0 -157
  180. package/templates/typescript-auth-api-key/src/index.ts +0 -47
  181. package/templates/typescript-auth-api-key/src/modules/calculator/calculator.module.ts +0 -12
  182. package/templates/typescript-auth-api-key/src/modules/calculator/calculator.prompts.ts +0 -73
  183. package/templates/typescript-auth-api-key/src/modules/calculator/calculator.resources.ts +0 -60
  184. package/templates/typescript-auth-api-key/src/modules/calculator/calculator.tools.ts +0 -71
  185. package/templates/typescript-auth-api-key/src/modules/demo/demo.module.ts +0 -18
  186. package/templates/typescript-auth-api-key/src/modules/demo/demo.tools.ts +0 -155
  187. package/templates/typescript-auth-api-key/src/modules/demo/multi-auth.tools.ts +0 -123
  188. package/templates/typescript-auth-api-key/src/widgets/app/calculator-operations/page.tsx +0 -133
  189. package/templates/typescript-auth-api-key/src/widgets/app/calculator-result/page.tsx +0 -134
  190. package/templates/typescript-auth-api-key/src/widgets/app/layout.tsx +0 -14
  191. package/templates/typescript-auth-api-key/src/widgets/package.json +0 -24
  192. package/templates/typescript-auth-api-key/src/widgets/widget-manifest.json +0 -48
  193. package/templates/typescript-auth-api-key/tsconfig.json +0 -23
  194. package/templates/typescript-oauth/OAUTH_SETUP.md +0 -592
  195. package/templates/typescript-oauth/src/modules/demo/demo.module.ts +0 -16
  196. package/templates/typescript-oauth/src/modules/demo/demo.tools.ts +0 -190
  197. package/templates/typescript-oauth/src/widgets/app/calculator-operations/page.tsx +0 -133
  198. package/templates/typescript-oauth/src/widgets/app/calculator-result/page.tsx +0 -134
  199. package/templates/typescript-oauth/src/widgets/out/404.html +0 -1
  200. package/templates/typescript-oauth/src/widgets/out/_next/static/WU9THacVqL52RZbrZOLS1/_buildManifest.js +0 -1
  201. package/templates/typescript-oauth/src/widgets/out/_next/static/WU9THacVqL52RZbrZOLS1/_ssgManifest.js +0 -1
  202. package/templates/typescript-oauth/src/widgets/out/_next/static/chunks/117-eb57c7ef86f964a4.js +0 -2
  203. package/templates/typescript-oauth/src/widgets/out/_next/static/chunks/app/_not-found/page-dcb83ba3e4d0aafd.js +0 -1
  204. package/templates/typescript-oauth/src/widgets/out/_next/static/chunks/app/calculator-operations/page-b8913a740073ea8a.js +0 -1
  205. package/templates/typescript-oauth/src/widgets/out/_next/static/chunks/app/calculator-result/page-ddaaab2fce95dea2.js +0 -1
  206. package/templates/typescript-oauth/src/widgets/out/_next/static/chunks/app/layout-cbd3ebdc4ecc5247.js +0 -1
  207. package/templates/typescript-oauth/src/widgets/out/_next/static/chunks/fd9d1056-749e5812300142af.js +0 -1
  208. package/templates/typescript-oauth/src/widgets/out/_next/static/chunks/framework-f66176bb897dc684.js +0 -1
  209. package/templates/typescript-oauth/src/widgets/out/_next/static/chunks/main-76df43fcef3db344.js +0 -1
  210. package/templates/typescript-oauth/src/widgets/out/_next/static/chunks/main-app-f9c40224d04023c5.js +0 -1
  211. package/templates/typescript-oauth/src/widgets/out/_next/static/chunks/pages/_app-72b849fbd24ac258.js +0 -1
  212. package/templates/typescript-oauth/src/widgets/out/_next/static/chunks/pages/_error-7ba65e1336b92748.js +0 -1
  213. package/templates/typescript-oauth/src/widgets/out/_next/static/chunks/polyfills-42372ed130431b0a.js +0 -1
  214. package/templates/typescript-oauth/src/widgets/out/_next/static/chunks/webpack-100b9e646d9c912e.js +0 -1
  215. package/templates/typescript-oauth/src/widgets/out/calculator-operations.html +0 -1
  216. package/templates/typescript-oauth/src/widgets/out/calculator-operations.txt +0 -7
  217. package/templates/typescript-oauth/src/widgets/out/calculator-result.html +0 -1
  218. package/templates/typescript-oauth/src/widgets/out/calculator-result.txt +0 -7
  219. package/templates/typescript-starter/src/widgets/app/calculator-operations/page.tsx +0 -133
  220. /package/templates/{typescript-auth-api-key → typescript-oauth}/src/health/system.health.ts +0 -0
  221. /package/templates/{typescript-auth-api-key → typescript-pizzaz}/src/widgets/next.config.js +0 -0
  222. /package/templates/{typescript-auth-api-key → typescript-pizzaz}/src/widgets/tsconfig.json +0 -0
@@ -1,284 +0,0 @@
1
- import { ToolDecorator as Tool, Widget, UseGuards, z, ExecutionContext } from 'nitrostack';
2
- import { v4 as uuidv4 } from 'uuid';
3
- import { getDatabase } from '../../db/database.js';
4
- import { JWTGuard } from '../../guards/jwt.guard.js';
5
-
6
- /**
7
- * Addresses Tools
8
- * Handles user shipping addresses (requires authentication)
9
- */
10
- export class AddressesTools {
11
- /**
12
- * Add new address - Requires authentication
13
- */
14
- @Tool({
15
- name: 'add_address',
16
- description: 'Add a new shipping address. Requires authentication. SMART TIP: If user mentions a well-known city, infer the state and country (e.g., Bangalore → Karnataka, India; New York → NY, USA; London → England, UK).',
17
- inputSchema: z.object({
18
- full_name: z.string().describe('Full name for delivery'),
19
- street: z.string().describe('Street address'),
20
- city: z.string().describe('City name (e.g., Bangalore, San Francisco, London)'),
21
- state: z.string().optional().describe('State/Province (e.g., Karnataka, CA, England). Can be inferred from city in many cases.'),
22
- zip_code: z.string().optional().describe('ZIP/Postal code (optional, can be left empty)'),
23
- country: z.string().default('USA').describe('Country (e.g., India, USA, UK). Can be inferred from well-known cities.'),
24
- phone: z.string().describe('Contact phone number'),
25
- is_default: z.boolean().default(false).describe('Set as default address'),
26
- }),
27
- examples: {
28
- request: {
29
- full_name: 'Emily Johnson',
30
- street: '123 Main Street',
31
- city: 'San Francisco',
32
- state: 'CA',
33
- zip_code: '94102',
34
- country: 'USA',
35
- phone: '+1-555-0100',
36
- is_default: true
37
- },
38
- response: {
39
- message: 'Address added successfully!',
40
- addressId: 'addr-1',
41
- isDefault: true
42
- }
43
- }
44
- })
45
- @Widget('address-added')
46
- @UseGuards(JWTGuard)
47
- async addAddress(input: any, context: ExecutionContext) {
48
- const db = getDatabase();
49
- const userId = context.auth?.subject;
50
- const addressId = uuidv4();
51
-
52
- // Smart defaults for common locations
53
- const cityLower = input.city?.toLowerCase() || '';
54
-
55
- // If state not provided, try to infer from well-known cities
56
- if (!input.state) {
57
- const cityToState: Record<string, { state: string; country: string }> = {
58
- 'bangalore': { state: 'Karnataka', country: 'India' },
59
- 'bengaluru': { state: 'Karnataka', country: 'India' },
60
- 'mumbai': { state: 'Maharashtra', country: 'India' },
61
- 'delhi': { state: 'Delhi', country: 'India' },
62
- 'hyderabad': { state: 'Telangana', country: 'India' },
63
- 'chennai': { state: 'Tamil Nadu', country: 'India' },
64
- 'pune': { state: 'Maharashtra', country: 'India' },
65
- 'kolkata': { state: 'West Bengal', country: 'India' },
66
- 'san francisco': { state: 'CA', country: 'USA' },
67
- 'new york': { state: 'NY', country: 'USA' },
68
- 'los angeles': { state: 'CA', country: 'USA' },
69
- 'chicago': { state: 'IL', country: 'USA' },
70
- 'boston': { state: 'MA', country: 'USA' },
71
- 'seattle': { state: 'WA', country: 'USA' },
72
- 'london': { state: 'England', country: 'UK' },
73
- 'manchester': { state: 'England', country: 'UK' },
74
- 'toronto': { state: 'Ontario', country: 'Canada' },
75
- 'vancouver': { state: 'British Columbia', country: 'Canada' },
76
- };
77
-
78
- const inferred = cityToState[cityLower];
79
- if (inferred) {
80
- input.state = inferred.state;
81
- input.country = inferred.country;
82
- context.logger.info(`Smart inference: ${input.city} → ${input.state}, ${input.country}`);
83
- }
84
- }
85
-
86
- // Set defaults if still missing
87
- input.state = input.state || 'N/A';
88
- input.zip_code = input.zip_code || '000000';
89
-
90
- // If this is set as default, unset other defaults
91
- if (input.is_default) {
92
- db.prepare(`
93
- UPDATE addresses SET is_default = 0 WHERE user_id = ?
94
- `).run(userId);
95
- }
96
-
97
- db.prepare(`
98
- INSERT INTO addresses (id, user_id, full_name, street, city, state, zip_code, country, phone, is_default)
99
- VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
100
- `).run(
101
- addressId,
102
- userId,
103
- input.full_name,
104
- input.street,
105
- input.city,
106
- input.state,
107
- input.zip_code,
108
- input.country,
109
- input.phone,
110
- input.is_default ? 1 : 0
111
- );
112
-
113
- context.logger.info(`Address added: ${input.city}, ${input.state}, ${input.country}`);
114
-
115
- return {
116
- message: 'Address added successfully!',
117
- addressId,
118
- isDefault: input.is_default,
119
- address: {
120
- city: input.city,
121
- state: input.state,
122
- country: input.country,
123
- },
124
- };
125
- }
126
-
127
- /**
128
- * Get all addresses - Requires authentication
129
- */
130
- @Tool({
131
- name: 'get_addresses',
132
- description: 'Get all saved shipping addresses. Requires authentication.',
133
- inputSchema: z.object({}),
134
- examples: {
135
- request: {},
136
- response: {
137
- addresses: [
138
- {
139
- id: 'addr-1',
140
- full_name: 'Emily Johnson',
141
- street: '123 Main Street',
142
- city: 'San Francisco',
143
- state: 'CA',
144
- zip_code: '94102',
145
- country: 'USA',
146
- phone: '+1-555-0100',
147
- is_default: true
148
- },
149
- {
150
- id: 'addr-2',
151
- full_name: 'Emily Johnson',
152
- street: '456 Office Blvd',
153
- city: 'San Francisco',
154
- state: 'CA',
155
- zip_code: '94103',
156
- country: 'USA',
157
- phone: '+1-555-0100',
158
- is_default: false
159
- }
160
- ]
161
- }
162
- }
163
- })
164
- @Widget('address-list')
165
- @UseGuards(JWTGuard)
166
- async getAddresses(input: any, context: ExecutionContext) {
167
- const db = getDatabase();
168
- const userId = context.auth?.subject;
169
-
170
- const addresses: any[] = db.prepare(`
171
- SELECT * FROM addresses WHERE user_id = ? ORDER BY is_default DESC, created_at DESC
172
- `).all(userId);
173
-
174
- context.logger.info(`Retrieved ${addresses.length} addresses`);
175
-
176
- return {
177
- addresses: addresses.map(addr => ({
178
- ...addr,
179
- is_default: addr.is_default === 1,
180
- })),
181
- };
182
- }
183
-
184
- /**
185
- * Set default address - Requires authentication
186
- */
187
- @Tool({
188
- name: 'set_default_address',
189
- description: 'Set an address as the default shipping address. Requires authentication.',
190
- examples: {
191
- request: {
192
- address_id: 'addr-2'
193
- },
194
- response: {
195
- message: 'Default address updated!',
196
- addressId: 'addr-2'
197
- }
198
- },
199
- inputSchema: z.object({
200
- address_id: z.string().describe('The ID of the address to set as default'),
201
- }),
202
- })
203
- @Widget('address-updated')
204
- @UseGuards(JWTGuard)
205
- async setDefaultAddress(input: any, context: ExecutionContext) {
206
- const db = getDatabase();
207
- const userId = context.auth?.subject;
208
-
209
- // Verify address belongs to user
210
- const address: any = db.prepare(`
211
- SELECT * FROM addresses WHERE id = ? AND user_id = ?
212
- `).get(input.address_id, userId);
213
-
214
- if (!address) {
215
- throw new Error('Address not found or you don\'t have access to it.');
216
- }
217
-
218
- // Unset all defaults
219
- db.prepare(`
220
- UPDATE addresses SET is_default = 0 WHERE user_id = ?
221
- `).run(userId);
222
-
223
- // Set new default
224
- db.prepare(`
225
- UPDATE addresses SET is_default = 1 WHERE id = ?
226
- `).run(input.address_id);
227
-
228
- context.logger.info(`Set default address: ${address.city}, ${address.state}`);
229
-
230
- return {
231
- message: 'Default address updated!',
232
- address: {
233
- ...address,
234
- is_default: true,
235
- },
236
- };
237
- }
238
-
239
- /**
240
- * Delete address - Requires authentication
241
- */
242
- @Tool({
243
- name: 'delete_address',
244
- description: 'Delete a shipping address. Requires authentication.',
245
- inputSchema: z.object({
246
- address_id: z.string().describe('The ID of the address to delete'),
247
- }),
248
- examples: {
249
- request: {
250
- address_id: 'addr-2'
251
- },
252
- response: {
253
- message: 'Address deleted successfully!',
254
- addressId: 'addr-2'
255
- }
256
- }
257
- })
258
- @Widget('address-deleted')
259
- @UseGuards(JWTGuard)
260
- async deleteAddress(input: any, context: ExecutionContext) {
261
- const db = getDatabase();
262
- const userId = context.auth?.subject;
263
-
264
- // Verify address belongs to user
265
- const address: any = db.prepare(`
266
- SELECT * FROM addresses WHERE id = ? AND user_id = ?
267
- `).get(input.address_id, userId);
268
-
269
- if (!address) {
270
- throw new Error('Address not found or you don\'t have access to it.');
271
- }
272
-
273
- db.prepare(`
274
- DELETE FROM addresses WHERE id = ?
275
- `).run(input.address_id);
276
-
277
- context.logger.info(`Deleted address: ${address.city}, ${address.state}`);
278
-
279
- return {
280
- message: 'Address deleted successfully!',
281
- };
282
- }
283
- }
284
-
@@ -1,16 +0,0 @@
1
- import { Module } from 'nitrostack';
2
- import { AuthTools } from './auth.tools.js';
3
- import { AuthResources } from './auth.resources.js';
4
- import { AuthPrompts } from './auth.prompts.js';
5
-
6
- /**
7
- * Authentication Module
8
- * Provides login, user profile tools, resources, and prompts
9
- */
10
- @Module({
11
- name: 'auth',
12
- description: 'Authentication and user management',
13
- controllers: [AuthTools, AuthResources, AuthPrompts],
14
- })
15
- export class AuthModule {}
16
-
@@ -1,147 +0,0 @@
1
- import { PromptDecorator as Prompt, ExecutionContext } from 'nitrostack';
2
-
3
- /**
4
- * Authentication Prompts
5
- * Provides helpful prompts for authentication-related tasks
6
- */
7
- export class AuthPrompts {
8
- /**
9
- * Authentication help prompt
10
- */
11
- @Prompt({
12
- name: 'auth-help',
13
- description: 'Get help with authentication and login process',
14
- arguments: [
15
- {
16
- name: 'issue',
17
- description: 'The authentication issue you are facing',
18
- required: false,
19
- },
20
- ],
21
- })
22
- async authHelp(args: Record<string, any>, context: ExecutionContext) {
23
- const issue = args.issue || 'general';
24
-
25
- const baseMessages = [
26
- {
27
- role: 'user' as const,
28
- content: `I need help with authentication in the e-commerce system. My issue: ${issue}`,
29
- },
30
- {
31
- role: 'assistant' as const,
32
- content: `I'll help you with authentication. Here's what you need to know:
33
-
34
- **Login Process:**
35
- 1. Use the \`login\` tool with email and password
36
- 2. You'll receive a JWT token valid for 24 hours
37
- 3. Include this token in subsequent requests
38
-
39
- **Test Accounts:**
40
- - alice@example.com / password123
41
- - bob@example.com / password123
42
- - charlie@example.com / password123
43
-
44
- **Including Token:**
45
- - In Inspector: Paste token in "JWT Token" field
46
- - Or use: Authorization: Bearer <your-token>
47
-
48
- **Protected Tools:**
49
- The following tools require authentication:
50
- - whoami - Get your profile
51
- - add_to_cart - Add items to cart
52
- - view_cart - View your cart
53
- - create_order - Place orders
54
- - get_order_history - View order history
55
- - add_address - Manage addresses
56
-
57
- **Common Issues:**
58
- ${issue === 'invalid-token' ? '- Token expired: Login again to get a new token\n- Invalid format: Ensure you copied the complete token' : ''}
59
- ${issue === 'unauthorized' ? '- Missing token: Make sure to login first\n- Wrong credentials: Check your email and password' : ''}
60
- ${issue === 'general' ? '- Token expired? Login again\n- Forgot which email? Use test accounts above\n- Need to test? All test users have password: password123' : ''}
61
-
62
- **Security Notes:**
63
- - Tokens expire after 24 hours for security
64
- - Passwords are hashed with bcrypt
65
- - Never share your token with others`,
66
- },
67
- ];
68
-
69
- return baseMessages;
70
- }
71
-
72
- /**
73
- * JWT token explanation prompt
74
- */
75
- @Prompt({
76
- name: 'jwt-explained',
77
- description: 'Understand how JWT authentication works in this system',
78
- })
79
- async jwtExplained(args: Record<string, any>, context: ExecutionContext) {
80
- return [
81
- {
82
- role: 'user' as const,
83
- content: 'Explain how JWT authentication works in this e-commerce system',
84
- },
85
- {
86
- role: 'assistant' as const,
87
- content: `**JWT Authentication in E-commerce MCP Server**
88
-
89
- **What is JWT?**
90
- JWT (JSON Web Token) is a secure way to transmit information between parties. It's a token that contains:
91
- - User identity (subject)
92
- - User information (email, name)
93
- - Expiration time
94
- - Digital signature
95
-
96
- **How It Works Here:**
97
-
98
- 1. **Login** (Public)
99
- - User provides email + password
100
- - Server verifies with bcrypt
101
- - Server generates JWT token
102
- - Token valid for 24 hours
103
-
104
- 2. **Using Protected Tools**
105
- - Client includes token in request
106
- - Server automatically validates token
107
- - If valid: grants access
108
- - If invalid/missing: denies access
109
-
110
- 3. **Token Contents**
111
- \`\`\`json
112
- {
113
- "sub": "user-id",
114
- "email": "alice@example.com",
115
- "name": "Alice Johnson",
116
- "iat": 1234567890,
117
- "exp": 1234654290
118
- }
119
- \`\`\`
120
-
121
- **Security Features:**
122
- - ✅ Tokens are signed (can't be tampered)
123
- - ✅ Passwords hashed with bcrypt
124
- - ✅ Tokens expire after 24 hours
125
- - ✅ No password storage in tokens
126
-
127
- **Developer Experience:**
128
- With V3 decorators, authentication is automatic:
129
- \`\`\`typescript
130
- @UseGuards(JWTGuard)
131
- async myProtectedTool(input, context) {
132
- // context.auth is already populated!
133
- const userId = context.auth.subject;
134
- }
135
- \`\`\`
136
-
137
- **No Manual Checking Needed!**
138
- The \`@UseGuards(JWTGuard)\` decorator handles:
139
- - Token extraction
140
- - Signature validation
141
- - Expiry checking
142
- - Context population`,
143
- },
144
- ];
145
- }
146
- }
147
-
@@ -1,84 +0,0 @@
1
- import { ResourceDecorator as Resource, ExecutionContext } from 'nitrostack';
2
- import { getDatabase } from '../../db/database.js';
3
-
4
- /**
5
- * Authentication Resources
6
- * Provides auth-related resource endpoints
7
- */
8
- export class AuthResources {
9
- /**
10
- * User schema resource
11
- */
12
- @Resource({
13
- uri: 'auth://schema/user',
14
- name: 'User Schema',
15
- description: 'Schema definition for user objects in the authentication system',
16
- mimeType: 'application/json',
17
- })
18
- async getUserSchema(context: ExecutionContext) {
19
- return {
20
- type: 'json' as const,
21
- data: {
22
- type: 'object',
23
- properties: {
24
- id: { type: 'string', format: 'uuid', description: 'Unique user identifier' },
25
- email: { type: 'string', format: 'email', description: 'User email address' },
26
- name: { type: 'string', description: 'Full name' },
27
- profile_picture: { type: 'string', format: 'uri', nullable: true, description: 'Profile picture URL' },
28
- created_at: { type: 'string', format: 'date-time', description: 'Account creation timestamp' },
29
- },
30
- required: ['id', 'email', 'name'],
31
- },
32
- };
33
- }
34
-
35
- /**
36
- * Available test users resource
37
- */
38
- @Resource({
39
- uri: 'auth://test-users',
40
- name: 'Test Users',
41
- description: 'List of available test users for the demo',
42
- mimeType: 'application/json',
43
- })
44
- async getTestUsers(context: ExecutionContext) {
45
- return {
46
- type: 'json' as const,
47
- data: {
48
- users: [
49
- { email: 'alice@example.com', password: 'password123', name: 'Alice Johnson' },
50
- { email: 'bob@example.com', password: 'password123', name: 'Bob Smith' },
51
- { email: 'charlie@example.com', password: 'password123', name: 'Charlie Brown' },
52
- ],
53
- note: 'All test users have the same password: password123',
54
- },
55
- };
56
- }
57
-
58
- /**
59
- * Authentication statistics
60
- */
61
- @Resource({
62
- uri: 'auth://stats',
63
- name: 'Auth Statistics',
64
- description: 'Authentication system statistics',
65
- mimeType: 'application/json',
66
- })
67
- async getAuthStats(context: ExecutionContext) {
68
- const db = getDatabase();
69
-
70
- const totalUsers: any = db.prepare('SELECT COUNT(*) as count FROM users').get();
71
- const recentLogins: any[] = db.prepare('SELECT email, created_at FROM users ORDER BY created_at DESC LIMIT 5').all();
72
-
73
- return {
74
- type: 'json' as const,
75
- data: {
76
- totalUsers: totalUsers.count,
77
- recentUsers: recentLogins,
78
- authMethod: 'JWT with bcrypt password hashing',
79
- tokenExpiry: '24 hours',
80
- },
81
- };
82
- }
83
- }
84
-
@@ -1,139 +0,0 @@
1
- import { ToolDecorator as Tool, Widget, UseGuards, z, ExecutionContext } from 'nitrostack';
2
- import bcrypt from 'bcryptjs';
3
- import { getDatabase } from '../../db/database.js';
4
- import { generateJWT } from 'nitrostack';
5
- import { JWTGuard } from '../../guards/jwt.guard.js';
6
-
7
- /**
8
- * Authentication Tools
9
- * Handles user authentication and profile management
10
- */
11
- export class AuthTools {
12
- /**
13
- * Login tool - Authenticate user and return JWT token
14
- * No authentication required (public endpoint)
15
- */
16
- @Tool({
17
- name: 'login',
18
- description: 'Login with email and password to get a JWT token. Use this token in the Authorization header for authenticated requests.',
19
- inputSchema: z.object({
20
- email: z.string().email().describe('User email address'),
21
- password: z.string().describe('User password'),
22
- }),
23
- examples: {
24
- request: {
25
- email: 'emily.johnson@x.dummyjson.com',
26
- password: 'password123'
27
- },
28
- response: {
29
- message: 'Login successful!',
30
- token: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...',
31
- user: {
32
- id: 'user-emily',
33
- email: 'emily.johnson@x.dummyjson.com',
34
- name: 'Emily Johnson'
35
- }
36
- }
37
- }
38
- })
39
- @Widget('login-result')
40
- async login(input: any, context: ExecutionContext) {
41
- const db = getDatabase();
42
-
43
- // Find user
44
- const user: any = db.prepare('SELECT * FROM users WHERE email = ?').get(input.email);
45
-
46
- if (!user) {
47
- throw new Error('Invalid email or password');
48
- }
49
-
50
- // Verify password
51
- const valid = bcrypt.compareSync(input.password, user.password_hash);
52
-
53
- if (!valid) {
54
- throw new Error('Invalid email or password');
55
- }
56
-
57
- // Generate JWT token
58
- const token = generateJWT({
59
- secret: process.env.JWT_SECRET!,
60
- payload: {
61
- sub: user.id,
62
- email: user.email,
63
- name: user.name,
64
- },
65
- expiresIn: '24h',
66
- audience: process.env.JWT_AUDIENCE || 'ecommerce-mcp-server',
67
- issuer: process.env.JWT_ISSUER || 'ecommerce-app',
68
- });
69
-
70
- context.logger.info(`User logged in: ${user.email}`);
71
-
72
- return {
73
- message: 'Login successful!',
74
- token,
75
- user: {
76
- id: user.id,
77
- email: user.email,
78
- name: user.name,
79
- },
80
- instructions: {
81
- step1: 'Copy the token above',
82
- step2: 'In the inspector, go to Chat tab',
83
- step3: 'Paste the token in the "JWT Token" field (if available)',
84
- step4: 'Or use: Authorization: Bearer <token>',
85
- expiresIn: '24 hours',
86
- },
87
- };
88
- }
89
-
90
- /**
91
- * Get current user information
92
- * Requires JWT authentication
93
- */
94
- @Tool({
95
- name: 'whoami',
96
- description: 'Get information about the currently authenticated user. Requires authentication.',
97
- inputSchema: z.object({}),
98
- examples: {
99
- request: {},
100
- response: {
101
- user: {
102
- id: 'user-emily',
103
- email: 'emily.johnson@x.dummyjson.com',
104
- name: 'Emily Johnson',
105
- profile_picture: 'https://dummyjson.com/icon/emilys/128',
106
- memberSince: '2024-01-01T00:00:00Z'
107
- },
108
- authenticated: true
109
- }
110
- }
111
- })
112
- @Widget('whoami')
113
- @UseGuards(JWTGuard)
114
- async whoami(input: any, context: ExecutionContext) {
115
- // User is already authenticated by JWTGuard
116
- const userId = context.auth?.subject;
117
-
118
- const db = getDatabase();
119
- const user: any = db.prepare(`
120
- SELECT id, email, name, profile_picture, created_at FROM users WHERE id = ?
121
- `).get(userId);
122
-
123
- if (!user) {
124
- throw new Error('User not found');
125
- }
126
-
127
- return {
128
- user: {
129
- id: user.id,
130
- email: user.email,
131
- name: user.name,
132
- profile_picture: user.profile_picture,
133
- memberSince: user.created_at,
134
- },
135
- authenticated: true,
136
- };
137
- }
138
- }
139
-
@@ -1,16 +0,0 @@
1
- import { Module } from 'nitrostack';
2
- import { CartTools } from './cart.tools.js';
3
- import { CartResources } from './cart.resources.js';
4
- import { CartPrompts } from './cart.prompts.js';
5
-
6
- /**
7
- * Cart Module
8
- * Provides shopping cart management, resources, and prompts
9
- */
10
- @Module({
11
- name: 'cart',
12
- description: 'Shopping cart management',
13
- controllers: [CartTools, CartResources, CartPrompts],
14
- })
15
- export class CartModule {}
16
-