@chanaka_nakandala/integration-agent 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/LICENSE +21 -0
- package/README.md +87 -0
- package/dist/cache/file-cache.d.ts +10 -0
- package/dist/cache/file-cache.d.ts.map +1 -0
- package/dist/cache/file-cache.js +79 -0
- package/dist/cache/file-cache.js.map +1 -0
- package/dist/cli/init-command.d.ts +2 -0
- package/dist/cli/init-command.d.ts.map +1 -0
- package/dist/cli/init-command.js +115 -0
- package/dist/cli/init-command.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +493 -0
- package/dist/index.js.map +1 -0
- package/dist/scrapers/docs-scraper.d.ts +28 -0
- package/dist/scrapers/docs-scraper.d.ts.map +1 -0
- package/dist/scrapers/docs-scraper.js +200 -0
- package/dist/scrapers/docs-scraper.js.map +1 -0
- package/dist/search/keyword-search.d.ts +39 -0
- package/dist/search/keyword-search.d.ts.map +1 -0
- package/dist/search/keyword-search.js +127 -0
- package/dist/search/keyword-search.js.map +1 -0
- package/dist/tools/code-generation-tool.d.ts +33 -0
- package/dist/tools/code-generation-tool.d.ts.map +1 -0
- package/dist/tools/code-generation-tool.js +62 -0
- package/dist/tools/code-generation-tool.js.map +1 -0
- package/dist/tools/search-result-formatter.d.ts +27 -0
- package/dist/tools/search-result-formatter.d.ts.map +1 -0
- package/dist/tools/search-result-formatter.js +89 -0
- package/dist/tools/search-result-formatter.js.map +1 -0
- package/dist/tools/search-tool.d.ts +9 -0
- package/dist/tools/search-tool.d.ts.map +1 -0
- package/dist/tools/search-tool.js +32 -0
- package/dist/tools/search-tool.js.map +1 -0
- package/dist/tools/template-loader.d.ts +54 -0
- package/dist/tools/template-loader.d.ts.map +1 -0
- package/dist/tools/template-loader.js +148 -0
- package/dist/tools/template-loader.js.map +1 -0
- package/dist/types/search.d.ts +21 -0
- package/dist/types/search.d.ts.map +1 -0
- package/dist/types/search.js +2 -0
- package/dist/types/search.js.map +1 -0
- package/package.json +63 -0
- package/templates/README.md +98 -0
- package/templates/authenticate/curl.template +97 -0
- package/templates/authenticate/java.template +155 -0
- package/templates/authenticate/python.template +111 -0
- package/templates/authenticate/typescript.template +98 -0
- package/templates/create_menu/curl.template +145 -0
- package/templates/create_menu/java.template +285 -0
- package/templates/create_menu/python.template +159 -0
- package/templates/create_menu/typescript.template +184 -0
- package/templates/receive_order/curl.template +138 -0
- package/templates/receive_order/java.template +263 -0
- package/templates/receive_order/python.template +157 -0
- package/templates/receive_order/typescript.template +194 -0
- package/templates/update_item_availability/curl.template +143 -0
- package/templates/update_item_availability/java.template +279 -0
- package/templates/update_item_availability/python.template +203 -0
- package/templates/update_item_availability/typescript.template +194 -0
- package/templates/update_order_status/curl.template +138 -0
- package/templates/update_order_status/java.template +202 -0
- package/templates/update_order_status/python.template +142 -0
- package/templates/update_order_status/typescript.template +139 -0
@@ -0,0 +1,285 @@
|
|
1
|
+
/**
|
2
|
+
* Grubtech Menu Sync - Java (Spring Boot)
|
3
|
+
*
|
4
|
+
* This example demonstrates how to push menu data to Grubtech API.
|
5
|
+
*
|
6
|
+
* Prerequisites:
|
7
|
+
* - Java 17+
|
8
|
+
* - Spring Boot 3.x
|
9
|
+
* - Spring WebFlux (for WebClient)
|
10
|
+
*
|
11
|
+
* Replace the following placeholders:
|
12
|
+
* - {{AUTH_TOKEN}}: Access token from authentication step
|
13
|
+
* - {{MENU_DATA}}: Your menu data in the required format
|
14
|
+
*/
|
15
|
+
|
16
|
+
package com.example.grubtech;
|
17
|
+
|
18
|
+
import org.springframework.http.HttpHeaders;
|
19
|
+
import org.springframework.http.MediaType;
|
20
|
+
import org.springframework.web.reactive.function.client.WebClient;
|
21
|
+
import reactor.core.publisher.Mono;
|
22
|
+
|
23
|
+
import java.util.ArrayList;
|
24
|
+
import java.util.List;
|
25
|
+
import java.util.Map;
|
26
|
+
|
27
|
+
public class GrubtechMenuSync {
|
28
|
+
|
29
|
+
private static final String AUTH_TOKEN = "{{AUTH_TOKEN}}";
|
30
|
+
private static final String BASE_URL = "https://api.grubtech.io";
|
31
|
+
|
32
|
+
private final WebClient webClient;
|
33
|
+
|
34
|
+
public GrubtechMenuSync() {
|
35
|
+
this.webClient = WebClient.builder()
|
36
|
+
.baseUrl(BASE_URL)
|
37
|
+
.build();
|
38
|
+
}
|
39
|
+
|
40
|
+
/**
|
41
|
+
* Push menu data to Grubtech API
|
42
|
+
*
|
43
|
+
* @param menuData Menu data object
|
44
|
+
* @return Menu ID from response
|
45
|
+
*/
|
46
|
+
public String createMenu(MenuData menuData) {
|
47
|
+
try {
|
48
|
+
// Validate menu data
|
49
|
+
if (menuData.getCategories() == null || menuData.getCategories().isEmpty()) {
|
50
|
+
throw new IllegalArgumentException("Menu must have at least one category");
|
51
|
+
}
|
52
|
+
|
53
|
+
// Make menu creation request
|
54
|
+
MenuResponse response = webClient.post()
|
55
|
+
.uri("/v1/menus")
|
56
|
+
.header(HttpHeaders.AUTHORIZATION, "Bearer " + AUTH_TOKEN)
|
57
|
+
.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)
|
58
|
+
.bodyValue(menuData)
|
59
|
+
.retrieve()
|
60
|
+
.onStatus(
|
61
|
+
status -> !status.is2xxSuccessful(),
|
62
|
+
clientResponse -> clientResponse.bodyToMono(String.class)
|
63
|
+
.flatMap(errorBody -> Mono.error(
|
64
|
+
new RuntimeException(
|
65
|
+
"Menu creation failed: " +
|
66
|
+
clientResponse.statusCode() +
|
67
|
+
" - " + errorBody
|
68
|
+
)
|
69
|
+
))
|
70
|
+
)
|
71
|
+
.bodyToMono(MenuResponse.class)
|
72
|
+
.block();
|
73
|
+
|
74
|
+
if (response == null || response.getMenuId() == null) {
|
75
|
+
throw new RuntimeException("No menu ID received from response");
|
76
|
+
}
|
77
|
+
|
78
|
+
System.out.println("✅ Menu created successfully!");
|
79
|
+
System.out.println("Menu ID: " + response.getMenuId());
|
80
|
+
System.out.println("Status: " + response.getStatus());
|
81
|
+
|
82
|
+
return response.getMenuId();
|
83
|
+
|
84
|
+
} catch (Exception e) {
|
85
|
+
System.err.println("❌ Menu creation error: " + e.getMessage());
|
86
|
+
throw e;
|
87
|
+
}
|
88
|
+
}
|
89
|
+
|
90
|
+
/**
|
91
|
+
* Update existing menu
|
92
|
+
*
|
93
|
+
* @param menuId ID of the menu to update
|
94
|
+
* @param menuData Updated menu data
|
95
|
+
*/
|
96
|
+
public void updateMenu(String menuId, MenuData menuData) {
|
97
|
+
try {
|
98
|
+
webClient.put()
|
99
|
+
.uri("/v1/menus/" + menuId)
|
100
|
+
.header(HttpHeaders.AUTHORIZATION, "Bearer " + AUTH_TOKEN)
|
101
|
+
.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)
|
102
|
+
.bodyValue(menuData)
|
103
|
+
.retrieve()
|
104
|
+
.onStatus(
|
105
|
+
status -> !status.is2xxSuccessful(),
|
106
|
+
clientResponse -> Mono.error(
|
107
|
+
new RuntimeException("Menu update failed: " + clientResponse.statusCode())
|
108
|
+
)
|
109
|
+
)
|
110
|
+
.toBodilessEntity()
|
111
|
+
.block();
|
112
|
+
|
113
|
+
System.out.println("✅ Menu updated successfully!");
|
114
|
+
|
115
|
+
} catch (Exception e) {
|
116
|
+
System.err.println("❌ Menu update error: " + e.getMessage());
|
117
|
+
throw e;
|
118
|
+
}
|
119
|
+
}
|
120
|
+
|
121
|
+
/**
|
122
|
+
* Create example menu data
|
123
|
+
*/
|
124
|
+
private static MenuData createExampleMenuData() {
|
125
|
+
MenuData menu = new MenuData();
|
126
|
+
menu.setName("Restaurant Menu");
|
127
|
+
menu.setDescription("Main menu with categories and items");
|
128
|
+
|
129
|
+
List<MenuCategory> categories = new ArrayList<>();
|
130
|
+
|
131
|
+
// Appetizers category
|
132
|
+
MenuCategory appetizers = new MenuCategory();
|
133
|
+
appetizers.setId("cat-1");
|
134
|
+
appetizers.setName("Appetizers");
|
135
|
+
appetizers.setDescription("Start your meal right");
|
136
|
+
appetizers.setSortOrder(1);
|
137
|
+
|
138
|
+
MenuItem springRolls = new MenuItem();
|
139
|
+
springRolls.setId("item-1");
|
140
|
+
springRolls.setName("Spring Rolls");
|
141
|
+
springRolls.setDescription("Crispy vegetable spring rolls");
|
142
|
+
springRolls.setPrice(8.99);
|
143
|
+
springRolls.setAvailable(true);
|
144
|
+
|
145
|
+
Modifier extraSauce = new Modifier();
|
146
|
+
extraSauce.setId("mod-1");
|
147
|
+
extraSauce.setName("Extra Sauce");
|
148
|
+
extraSauce.setPrice(1.50);
|
149
|
+
extraSauce.setAvailable(true);
|
150
|
+
|
151
|
+
springRolls.setModifiers(List.of(extraSauce));
|
152
|
+
appetizers.setItems(List.of(springRolls));
|
153
|
+
|
154
|
+
// Main courses category
|
155
|
+
MenuCategory mainCourses = new MenuCategory();
|
156
|
+
mainCourses.setId("cat-2");
|
157
|
+
mainCourses.setName("Main Courses");
|
158
|
+
mainCourses.setDescription("Delicious entrees");
|
159
|
+
mainCourses.setSortOrder(2);
|
160
|
+
|
161
|
+
MenuItem chicken = new MenuItem();
|
162
|
+
chicken.setId("item-2");
|
163
|
+
chicken.setName("Grilled Chicken");
|
164
|
+
chicken.setDescription("Tender chicken with herbs");
|
165
|
+
chicken.setPrice(15.99);
|
166
|
+
chicken.setAvailable(true);
|
167
|
+
chicken.setModifiers(new ArrayList<>());
|
168
|
+
|
169
|
+
mainCourses.setItems(List.of(chicken));
|
170
|
+
|
171
|
+
categories.add(appetizers);
|
172
|
+
categories.add(mainCourses);
|
173
|
+
menu.setCategories(categories);
|
174
|
+
|
175
|
+
return menu;
|
176
|
+
}
|
177
|
+
|
178
|
+
// Data models
|
179
|
+
public static class MenuData {
|
180
|
+
private String name;
|
181
|
+
private String description;
|
182
|
+
private List<MenuCategory> categories;
|
183
|
+
|
184
|
+
// Getters and setters
|
185
|
+
public String getName() { return name; }
|
186
|
+
public void setName(String name) { this.name = name; }
|
187
|
+
public String getDescription() { return description; }
|
188
|
+
public void setDescription(String description) { this.description = description; }
|
189
|
+
public List<MenuCategory> getCategories() { return categories; }
|
190
|
+
public void setCategories(List<MenuCategory> categories) { this.categories = categories; }
|
191
|
+
}
|
192
|
+
|
193
|
+
public static class MenuCategory {
|
194
|
+
private String id;
|
195
|
+
private String name;
|
196
|
+
private String description;
|
197
|
+
private int sortOrder;
|
198
|
+
private List<MenuItem> items;
|
199
|
+
|
200
|
+
// Getters and setters omitted for brevity
|
201
|
+
public String getId() { return id; }
|
202
|
+
public void setId(String id) { this.id = id; }
|
203
|
+
public String getName() { return name; }
|
204
|
+
public void setName(String name) { this.name = name; }
|
205
|
+
public String getDescription() { return description; }
|
206
|
+
public void setDescription(String description) { this.description = description; }
|
207
|
+
public int getSortOrder() { return sortOrder; }
|
208
|
+
public void setSortOrder(int sortOrder) { this.sortOrder = sortOrder; }
|
209
|
+
public List<MenuItem> getItems() { return items; }
|
210
|
+
public void setItems(List<MenuItem> items) { this.items = items; }
|
211
|
+
}
|
212
|
+
|
213
|
+
public static class MenuItem {
|
214
|
+
private String id;
|
215
|
+
private String name;
|
216
|
+
private String description;
|
217
|
+
private double price;
|
218
|
+
private boolean available;
|
219
|
+
private List<Modifier> modifiers;
|
220
|
+
|
221
|
+
// Getters and setters omitted for brevity
|
222
|
+
public String getId() { return id; }
|
223
|
+
public void setId(String id) { this.id = id; }
|
224
|
+
public String getName() { return name; }
|
225
|
+
public void setName(String name) { this.name = name; }
|
226
|
+
public String getDescription() { return description; }
|
227
|
+
public void setDescription(String description) { this.description = description; }
|
228
|
+
public double getPrice() { return price; }
|
229
|
+
public void setPrice(double price) { this.price = price; }
|
230
|
+
public boolean isAvailable() { return available; }
|
231
|
+
public void setAvailable(boolean available) { this.available = available; }
|
232
|
+
public List<Modifier> getModifiers() { return modifiers; }
|
233
|
+
public void setModifiers(List<Modifier> modifiers) { this.modifiers = modifiers; }
|
234
|
+
}
|
235
|
+
|
236
|
+
public static class Modifier {
|
237
|
+
private String id;
|
238
|
+
private String name;
|
239
|
+
private double price;
|
240
|
+
private boolean available;
|
241
|
+
|
242
|
+
// Getters and setters omitted for brevity
|
243
|
+
public String getId() { return id; }
|
244
|
+
public void setId(String id) { this.id = id; }
|
245
|
+
public String getName() { return name; }
|
246
|
+
public void setName(String name) { this.name = name; }
|
247
|
+
public double getPrice() { return price; }
|
248
|
+
public void setPrice(double price) { this.price = price; }
|
249
|
+
public boolean isAvailable() { return available; }
|
250
|
+
public void setAvailable(boolean available) { this.available = available; }
|
251
|
+
}
|
252
|
+
|
253
|
+
public static class MenuResponse {
|
254
|
+
private String menuId;
|
255
|
+
private String status;
|
256
|
+
private String message;
|
257
|
+
|
258
|
+
// Getters and setters
|
259
|
+
public String getMenuId() { return menuId; }
|
260
|
+
public void setMenuId(String menuId) { this.menuId = menuId; }
|
261
|
+
public String getStatus() { return status; }
|
262
|
+
public void setStatus(String status) { this.status = status; }
|
263
|
+
public String getMessage() { return message; }
|
264
|
+
public void setMessage(String message) { this.message = message; }
|
265
|
+
}
|
266
|
+
|
267
|
+
// Main method for testing
|
268
|
+
public static void main(String[] args) {
|
269
|
+
try {
|
270
|
+
GrubtechMenuSync menuSync = new GrubtechMenuSync();
|
271
|
+
|
272
|
+
// Create example menu data
|
273
|
+
MenuData menuData = createExampleMenuData();
|
274
|
+
|
275
|
+
// Create menu
|
276
|
+
String menuId = menuSync.createMenu(menuData);
|
277
|
+
|
278
|
+
// Optionally update the menu
|
279
|
+
// menuSync.updateMenu(menuId, menuData);
|
280
|
+
|
281
|
+
} catch (Exception e) {
|
282
|
+
System.exit(1);
|
283
|
+
}
|
284
|
+
}
|
285
|
+
}
|
@@ -0,0 +1,159 @@
|
|
1
|
+
"""
|
2
|
+
Grubtech Menu Sync - Python
|
3
|
+
|
4
|
+
This example demonstrates how to push menu data to Grubtech API.
|
5
|
+
|
6
|
+
Prerequisites:
|
7
|
+
- Python 3.8+
|
8
|
+
- requests library (pip install requests)
|
9
|
+
- Valid access token from authentication
|
10
|
+
|
11
|
+
Replace the following placeholders:
|
12
|
+
- {{AUTH_TOKEN}}: Access token from authentication step
|
13
|
+
- {{MENU_DATA}}: Your menu data in the required format
|
14
|
+
"""
|
15
|
+
|
16
|
+
import requests
|
17
|
+
import sys
|
18
|
+
from typing import Dict, Any, List
|
19
|
+
|
20
|
+
AUTH_TOKEN = '{{AUTH_TOKEN}}'
|
21
|
+
BASE_URL = 'https://api.grubtech.io'
|
22
|
+
|
23
|
+
# Example menu data structure
|
24
|
+
# Replace this with your actual menu data
|
25
|
+
MENU_DATA: Dict[str, Any] = {
|
26
|
+
'name': 'Restaurant Menu',
|
27
|
+
'description': 'Main menu with categories and items',
|
28
|
+
'categories': [
|
29
|
+
{
|
30
|
+
'id': 'cat-1',
|
31
|
+
'name': 'Appetizers',
|
32
|
+
'description': 'Start your meal right',
|
33
|
+
'sortOrder': 1,
|
34
|
+
'items': [
|
35
|
+
{
|
36
|
+
'id': 'item-1',
|
37
|
+
'name': 'Spring Rolls',
|
38
|
+
'description': 'Crispy vegetable spring rolls',
|
39
|
+
'price': 8.99,
|
40
|
+
'available': True,
|
41
|
+
'modifiers': [
|
42
|
+
{
|
43
|
+
'id': 'mod-1',
|
44
|
+
'name': 'Extra Sauce',
|
45
|
+
'price': 1.50,
|
46
|
+
'available': True,
|
47
|
+
},
|
48
|
+
],
|
49
|
+
},
|
50
|
+
],
|
51
|
+
},
|
52
|
+
{
|
53
|
+
'id': 'cat-2',
|
54
|
+
'name': 'Main Courses',
|
55
|
+
'description': 'Delicious entrees',
|
56
|
+
'sortOrder': 2,
|
57
|
+
'items': [
|
58
|
+
{
|
59
|
+
'id': 'item-2',
|
60
|
+
'name': 'Grilled Chicken',
|
61
|
+
'description': 'Tender chicken with herbs',
|
62
|
+
'price': 15.99,
|
63
|
+
'available': True,
|
64
|
+
'modifiers': [],
|
65
|
+
},
|
66
|
+
],
|
67
|
+
},
|
68
|
+
],
|
69
|
+
}
|
70
|
+
|
71
|
+
|
72
|
+
def create_menu(menu_data: Dict[str, Any]) -> str:
|
73
|
+
"""
|
74
|
+
Push menu data to Grubtech API
|
75
|
+
|
76
|
+
Args:
|
77
|
+
menu_data: Menu data dictionary
|
78
|
+
|
79
|
+
Returns:
|
80
|
+
str: Menu ID from response
|
81
|
+
|
82
|
+
Raises:
|
83
|
+
Exception: If menu creation fails
|
84
|
+
"""
|
85
|
+
try:
|
86
|
+
# Validate menu data before sending
|
87
|
+
if not menu_data.get('categories') or len(menu_data['categories']) == 0:
|
88
|
+
raise ValueError('Menu must have at least one category')
|
89
|
+
|
90
|
+
# Make menu creation request
|
91
|
+
url = f'{BASE_URL}/v1/menus'
|
92
|
+
headers = {
|
93
|
+
'Authorization': f'Bearer {AUTH_TOKEN}',
|
94
|
+
'Content-Type': 'application/json',
|
95
|
+
}
|
96
|
+
|
97
|
+
response = requests.post(url, json=menu_data, headers=headers, timeout=30)
|
98
|
+
|
99
|
+
# Check for errors
|
100
|
+
if not response.ok:
|
101
|
+
raise Exception(
|
102
|
+
f'Menu creation failed: {response.status_code} - {response.text}'
|
103
|
+
)
|
104
|
+
|
105
|
+
# Extract menu ID from response
|
106
|
+
data: Dict[str, Any] = response.json()
|
107
|
+
menu_id = data['menuId']
|
108
|
+
|
109
|
+
print(f'✅ Menu created successfully!')
|
110
|
+
print(f'Menu ID: {menu_id}')
|
111
|
+
print(f'Status: {data.get("status", "unknown")}')
|
112
|
+
|
113
|
+
return menu_id
|
114
|
+
|
115
|
+
except requests.RequestException as e:
|
116
|
+
print(f'❌ Menu creation error: {e}', file=sys.stderr)
|
117
|
+
raise
|
118
|
+
except Exception as e:
|
119
|
+
print(f'❌ Unexpected error: {e}', file=sys.stderr)
|
120
|
+
raise
|
121
|
+
|
122
|
+
|
123
|
+
def update_menu(menu_id: str, menu_data: Dict[str, Any]) -> None:
|
124
|
+
"""
|
125
|
+
Update existing menu
|
126
|
+
|
127
|
+
Args:
|
128
|
+
menu_id: ID of the menu to update
|
129
|
+
menu_data: Updated menu data
|
130
|
+
"""
|
131
|
+
try:
|
132
|
+
url = f'{BASE_URL}/v1/menus/{menu_id}'
|
133
|
+
headers = {
|
134
|
+
'Authorization': f'Bearer {AUTH_TOKEN}',
|
135
|
+
'Content-Type': 'application/json',
|
136
|
+
}
|
137
|
+
|
138
|
+
response = requests.put(url, json=menu_data, headers=headers, timeout=30)
|
139
|
+
|
140
|
+
if not response.ok:
|
141
|
+
raise Exception(f'Menu update failed: {response.status_code} - {response.text}')
|
142
|
+
|
143
|
+
print(f'✅ Menu updated successfully!')
|
144
|
+
|
145
|
+
except Exception as e:
|
146
|
+
print(f'❌ Menu update error: {e}', file=sys.stderr)
|
147
|
+
raise
|
148
|
+
|
149
|
+
|
150
|
+
if __name__ == '__main__':
|
151
|
+
try:
|
152
|
+
# Create new menu
|
153
|
+
menu_id = create_menu(MENU_DATA)
|
154
|
+
|
155
|
+
# Optionally update the menu
|
156
|
+
# update_menu(menu_id, MENU_DATA)
|
157
|
+
|
158
|
+
except Exception as e:
|
159
|
+
sys.exit(1)
|
@@ -0,0 +1,184 @@
|
|
1
|
+
/**
|
2
|
+
* Grubtech Menu Sync - TypeScript
|
3
|
+
*
|
4
|
+
* This example demonstrates how to push menu data to Grubtech API.
|
5
|
+
*
|
6
|
+
* Prerequisites:
|
7
|
+
* - Node.js 18+ with fetch API
|
8
|
+
* - Valid access token from authentication
|
9
|
+
*
|
10
|
+
* Replace the following placeholders:
|
11
|
+
* - {{AUTH_TOKEN}}: Access token from authentication step
|
12
|
+
* - {{MENU_DATA}}: Your menu data in the required format
|
13
|
+
*/
|
14
|
+
|
15
|
+
const AUTH_TOKEN = '{{AUTH_TOKEN}}';
|
16
|
+
const BASE_URL = 'https://api.grubtech.io';
|
17
|
+
|
18
|
+
interface MenuItem {
|
19
|
+
id: string;
|
20
|
+
name: string;
|
21
|
+
description: string;
|
22
|
+
price: number;
|
23
|
+
available: boolean;
|
24
|
+
modifiers?: Modifier[];
|
25
|
+
}
|
26
|
+
|
27
|
+
interface Modifier {
|
28
|
+
id: string;
|
29
|
+
name: string;
|
30
|
+
price: number;
|
31
|
+
available: boolean;
|
32
|
+
}
|
33
|
+
|
34
|
+
interface MenuCategory {
|
35
|
+
id: string;
|
36
|
+
name: string;
|
37
|
+
description: string;
|
38
|
+
sortOrder: number;
|
39
|
+
items: MenuItem[];
|
40
|
+
}
|
41
|
+
|
42
|
+
interface MenuData {
|
43
|
+
name: string;
|
44
|
+
description: string;
|
45
|
+
categories: MenuCategory[];
|
46
|
+
}
|
47
|
+
|
48
|
+
interface MenuResponse {
|
49
|
+
menuId: string;
|
50
|
+
status: string;
|
51
|
+
message: string;
|
52
|
+
}
|
53
|
+
|
54
|
+
/**
|
55
|
+
* Example menu data structure
|
56
|
+
* Replace this with your actual menu data
|
57
|
+
*/
|
58
|
+
const MENU_DATA: MenuData = {
|
59
|
+
name: 'Restaurant Menu',
|
60
|
+
description: 'Main menu with categories and items',
|
61
|
+
categories: [
|
62
|
+
{
|
63
|
+
id: 'cat-1',
|
64
|
+
name: 'Appetizers',
|
65
|
+
description: 'Start your meal right',
|
66
|
+
sortOrder: 1,
|
67
|
+
items: [
|
68
|
+
{
|
69
|
+
id: 'item-1',
|
70
|
+
name: 'Spring Rolls',
|
71
|
+
description: 'Crispy vegetable spring rolls',
|
72
|
+
price: 8.99,
|
73
|
+
available: true,
|
74
|
+
modifiers: [
|
75
|
+
{
|
76
|
+
id: 'mod-1',
|
77
|
+
name: 'Extra Sauce',
|
78
|
+
price: 1.50,
|
79
|
+
available: true,
|
80
|
+
},
|
81
|
+
],
|
82
|
+
},
|
83
|
+
],
|
84
|
+
},
|
85
|
+
{
|
86
|
+
id: 'cat-2',
|
87
|
+
name: 'Main Courses',
|
88
|
+
description: 'Delicious entrees',
|
89
|
+
sortOrder: 2,
|
90
|
+
items: [
|
91
|
+
{
|
92
|
+
id: 'item-2',
|
93
|
+
name: 'Grilled Chicken',
|
94
|
+
description: 'Tender chicken with herbs',
|
95
|
+
price: 15.99,
|
96
|
+
available: true,
|
97
|
+
modifiers: [],
|
98
|
+
},
|
99
|
+
],
|
100
|
+
},
|
101
|
+
],
|
102
|
+
};
|
103
|
+
|
104
|
+
/**
|
105
|
+
* Push menu data to Grubtech API
|
106
|
+
*/
|
107
|
+
async function createMenu(menuData: MenuData): Promise<string> {
|
108
|
+
try {
|
109
|
+
// Validate menu data before sending
|
110
|
+
if (!menuData.categories || menuData.categories.length === 0) {
|
111
|
+
throw new Error('Menu must have at least one category');
|
112
|
+
}
|
113
|
+
|
114
|
+
// Make menu creation request
|
115
|
+
const response = await fetch(`${BASE_URL}/v1/menus`, {
|
116
|
+
method: 'POST',
|
117
|
+
headers: {
|
118
|
+
'Authorization': `Bearer ${AUTH_TOKEN}`,
|
119
|
+
'Content-Type': 'application/json',
|
120
|
+
},
|
121
|
+
body: JSON.stringify(menuData),
|
122
|
+
});
|
123
|
+
|
124
|
+
// Check for errors
|
125
|
+
if (!response.ok) {
|
126
|
+
const errorBody = await response.text();
|
127
|
+
throw new Error(
|
128
|
+
`Menu creation failed: ${response.status} - ${errorBody}`
|
129
|
+
);
|
130
|
+
}
|
131
|
+
|
132
|
+
// Extract menu ID from response
|
133
|
+
const data: MenuResponse = await response.json();
|
134
|
+
const menuId = data.menuId;
|
135
|
+
|
136
|
+
console.log('✅ Menu created successfully!');
|
137
|
+
console.log(`Menu ID: ${menuId}`);
|
138
|
+
console.log(`Status: ${data.status}`);
|
139
|
+
|
140
|
+
return menuId;
|
141
|
+
} catch (error) {
|
142
|
+
console.error('❌ Menu creation error:', error);
|
143
|
+
throw error;
|
144
|
+
}
|
145
|
+
}
|
146
|
+
|
147
|
+
/**
|
148
|
+
* Update existing menu
|
149
|
+
*/
|
150
|
+
async function updateMenu(menuId: string, menuData: MenuData): Promise<void> {
|
151
|
+
try {
|
152
|
+
const response = await fetch(`${BASE_URL}/v1/menus/${menuId}`, {
|
153
|
+
method: 'PUT',
|
154
|
+
headers: {
|
155
|
+
'Authorization': `Bearer ${AUTH_TOKEN}`,
|
156
|
+
'Content-Type': 'application/json',
|
157
|
+
},
|
158
|
+
body: JSON.stringify(menuData),
|
159
|
+
});
|
160
|
+
|
161
|
+
if (!response.ok) {
|
162
|
+
const errorBody = await response.text();
|
163
|
+
throw new Error(`Menu update failed: ${response.status} - ${errorBody}`);
|
164
|
+
}
|
165
|
+
|
166
|
+
console.log('✅ Menu updated successfully!');
|
167
|
+
} catch (error) {
|
168
|
+
console.error('❌ Menu update error:', error);
|
169
|
+
throw error;
|
170
|
+
}
|
171
|
+
}
|
172
|
+
|
173
|
+
// Main execution
|
174
|
+
(async () => {
|
175
|
+
try {
|
176
|
+
// Create new menu
|
177
|
+
const menuId = await createMenu(MENU_DATA);
|
178
|
+
|
179
|
+
// Optionally update the menu
|
180
|
+
// await updateMenu(menuId, MENU_DATA);
|
181
|
+
} catch (error) {
|
182
|
+
process.exit(1);
|
183
|
+
}
|
184
|
+
})();
|