@chanaka_nakandala/integration-agent 1.1.0 → 2.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/README.md +369 -60
- package/dist/index.js +22 -486
- package/dist/index.js.map +1 -1
- package/dist/{cli/init-command.d.ts → init-command.d.ts} +2 -2
- package/dist/init-command.d.ts.map +1 -0
- package/dist/{cli/init-command.js → init-command.js} +72 -46
- package/dist/init-command.js.map +1 -0
- package/package.json +5 -11
- package/agent-personas/ba-agent.yaml +0 -682
- package/agent-personas/developer-agent.yaml +0 -585
- package/dist/cache/file-cache.d.ts +0 -10
- package/dist/cache/file-cache.d.ts.map +0 -1
- package/dist/cache/file-cache.js +0 -79
- package/dist/cache/file-cache.js.map +0 -1
- package/dist/cli/init-command.d.ts.map +0 -1
- package/dist/cli/init-command.js.map +0 -1
- package/dist/scrapers/docs-scraper.d.ts +0 -28
- package/dist/scrapers/docs-scraper.d.ts.map +0 -1
- package/dist/scrapers/docs-scraper.js +0 -200
- package/dist/scrapers/docs-scraper.js.map +0 -1
- package/dist/search/keyword-search.d.ts +0 -39
- package/dist/search/keyword-search.d.ts.map +0 -1
- package/dist/search/keyword-search.js +0 -127
- package/dist/search/keyword-search.js.map +0 -1
- package/dist/tools/code-generation-tool.d.ts +0 -33
- package/dist/tools/code-generation-tool.d.ts.map +0 -1
- package/dist/tools/code-generation-tool.js +0 -62
- package/dist/tools/code-generation-tool.js.map +0 -1
- package/dist/tools/search-result-formatter.d.ts +0 -27
- package/dist/tools/search-result-formatter.d.ts.map +0 -1
- package/dist/tools/search-result-formatter.js +0 -89
- package/dist/tools/search-result-formatter.js.map +0 -1
- package/dist/tools/search-tool.d.ts +0 -9
- package/dist/tools/search-tool.d.ts.map +0 -1
- package/dist/tools/search-tool.js +0 -32
- package/dist/tools/search-tool.js.map +0 -1
- package/dist/tools/template-loader.d.ts +0 -54
- package/dist/tools/template-loader.d.ts.map +0 -1
- package/dist/tools/template-loader.js +0 -148
- package/dist/tools/template-loader.js.map +0 -1
- package/dist/types/search.d.ts +0 -21
- package/dist/types/search.d.ts.map +0 -1
- package/dist/types/search.js +0 -2
- package/dist/types/search.js.map +0 -1
- package/templates/README.md +0 -98
- package/templates/authenticate/curl.template +0 -97
- package/templates/authenticate/java.template +0 -155
- package/templates/authenticate/python.template +0 -111
- package/templates/authenticate/typescript.template +0 -98
- package/templates/create_menu/curl.template +0 -145
- package/templates/create_menu/java.template +0 -285
- package/templates/create_menu/python.template +0 -159
- package/templates/create_menu/typescript.template +0 -184
- package/templates/receive_order/curl.template +0 -138
- package/templates/receive_order/java.template +0 -263
- package/templates/receive_order/python.template +0 -157
- package/templates/receive_order/typescript.template +0 -194
- package/templates/update_item_availability/curl.template +0 -143
- package/templates/update_item_availability/java.template +0 -279
- package/templates/update_item_availability/python.template +0 -203
- package/templates/update_item_availability/typescript.template +0 -194
- package/templates/update_order_status/curl.template +0 -138
- package/templates/update_order_status/java.template +0 -202
- package/templates/update_order_status/python.template +0 -142
- package/templates/update_order_status/typescript.template +0 -139
@@ -1,143 +0,0 @@
|
|
1
|
-
#!/bin/bash
|
2
|
-
|
3
|
-
# Grubtech Item Availability Update - cURL
|
4
|
-
#
|
5
|
-
# This example demonstrates how to update menu item availability in Grubtech.
|
6
|
-
#
|
7
|
-
# Prerequisites:
|
8
|
-
# - curl command-line tool
|
9
|
-
# - jq (for JSON parsing, optional)
|
10
|
-
# - Valid access token from authentication
|
11
|
-
#
|
12
|
-
# Replace the following placeholders:
|
13
|
-
# - {{AUTH_TOKEN}}: Access token from authentication step
|
14
|
-
# - {{ITEM_ID}}: The menu item ID to update
|
15
|
-
# - {{AVAILABLE_STATUS}}: Boolean availability status (true/false)
|
16
|
-
|
17
|
-
AUTH_TOKEN="{{AUTH_TOKEN}}"
|
18
|
-
ITEM_ID="{{ITEM_ID}}"
|
19
|
-
AVAILABLE_STATUS={{AVAILABLE_STATUS}} # true or false
|
20
|
-
BASE_URL="https://api.grubtech.io"
|
21
|
-
|
22
|
-
# Update single item availability
|
23
|
-
update_item_availability() {
|
24
|
-
local item_id=$1
|
25
|
-
local available=$2
|
26
|
-
local reason=$3
|
27
|
-
|
28
|
-
echo "Updating item ${item_id}: available=${available}"
|
29
|
-
|
30
|
-
# Construct payload
|
31
|
-
TIMESTAMP=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
|
32
|
-
PAYLOAD=$(cat <<EOF
|
33
|
-
{
|
34
|
-
"itemId": "${item_id}",
|
35
|
-
"available": ${available},
|
36
|
-
"timestamp": "${TIMESTAMP}",
|
37
|
-
"reason": "${reason}"
|
38
|
-
}
|
39
|
-
EOF
|
40
|
-
)
|
41
|
-
|
42
|
-
# Make availability update request
|
43
|
-
RESPONSE=$(curl -s -w "\n%{http_code}" -X PUT \
|
44
|
-
"${BASE_URL}/v1/items/${item_id}/availability" \
|
45
|
-
-H "Authorization: Bearer ${AUTH_TOKEN}" \
|
46
|
-
-H "Content-Type: application/json" \
|
47
|
-
-d "$PAYLOAD")
|
48
|
-
|
49
|
-
# Extract HTTP status code and body
|
50
|
-
HTTP_CODE=$(echo "$RESPONSE" | tail -n 1)
|
51
|
-
BODY=$(echo "$RESPONSE" | sed '$d')
|
52
|
-
|
53
|
-
# Check for errors
|
54
|
-
if [ "$HTTP_CODE" -ne 200 ]; then
|
55
|
-
echo "❌ Availability update failed: HTTP $HTTP_CODE"
|
56
|
-
echo "Response: $BODY"
|
57
|
-
return 1
|
58
|
-
fi
|
59
|
-
|
60
|
-
echo "✅ Item availability updated successfully!"
|
61
|
-
echo "$BODY" | jq '.' 2>/dev/null || echo "$BODY"
|
62
|
-
}
|
63
|
-
|
64
|
-
# Update multiple items in bulk
|
65
|
-
update_bulk_availability() {
|
66
|
-
echo "Updating multiple items availability..."
|
67
|
-
|
68
|
-
# Construct bulk payload
|
69
|
-
TIMESTAMP=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
|
70
|
-
PAYLOAD=$(cat <<'EOF'
|
71
|
-
{
|
72
|
-
"updates": [
|
73
|
-
{
|
74
|
-
"itemId": "item-123",
|
75
|
-
"available": false,
|
76
|
-
"reason": "Out of stock"
|
77
|
-
},
|
78
|
-
{
|
79
|
-
"itemId": "item-456",
|
80
|
-
"available": true,
|
81
|
-
"reason": "Back in stock"
|
82
|
-
},
|
83
|
-
{
|
84
|
-
"itemId": "item-789",
|
85
|
-
"available": true,
|
86
|
-
"reason": "In stock"
|
87
|
-
}
|
88
|
-
],
|
89
|
-
"timestamp": "TIMESTAMP_PLACEHOLDER"
|
90
|
-
}
|
91
|
-
EOF
|
92
|
-
)
|
93
|
-
|
94
|
-
# Replace timestamp placeholder
|
95
|
-
PAYLOAD=$(echo "$PAYLOAD" | sed "s/TIMESTAMP_PLACEHOLDER/$TIMESTAMP/")
|
96
|
-
|
97
|
-
# Make bulk availability update request
|
98
|
-
RESPONSE=$(curl -s -w "\n%{http_code}" -X PUT \
|
99
|
-
"${BASE_URL}/v1/items/availability/bulk" \
|
100
|
-
-H "Authorization: Bearer ${AUTH_TOKEN}" \
|
101
|
-
-H "Content-Type: application/json" \
|
102
|
-
-d "$PAYLOAD")
|
103
|
-
|
104
|
-
# Extract HTTP status code and body
|
105
|
-
HTTP_CODE=$(echo "$RESPONSE" | tail -n 1)
|
106
|
-
BODY=$(echo "$RESPONSE" | sed '$d')
|
107
|
-
|
108
|
-
# Check for errors
|
109
|
-
if [ "$HTTP_CODE" -ne 200 ]; then
|
110
|
-
echo "❌ Bulk availability update failed: HTTP $HTTP_CODE"
|
111
|
-
echo "Response: $BODY"
|
112
|
-
return 1
|
113
|
-
fi
|
114
|
-
|
115
|
-
echo "✅ Bulk availability updated successfully!"
|
116
|
-
echo "$BODY" | jq '.' 2>/dev/null || echo "$BODY"
|
117
|
-
}
|
118
|
-
|
119
|
-
# Helper functions
|
120
|
-
mark_out_of_stock() {
|
121
|
-
update_item_availability "$1" false "Out of stock"
|
122
|
-
}
|
123
|
-
|
124
|
-
mark_in_stock() {
|
125
|
-
update_item_availability "$1" true "Back in stock"
|
126
|
-
}
|
127
|
-
|
128
|
-
# Main execution
|
129
|
-
main() {
|
130
|
-
# Example 1: Single item update
|
131
|
-
update_item_availability "$ITEM_ID" "$AVAILABLE_STATUS" "Inventory sync"
|
132
|
-
|
133
|
-
echo ""
|
134
|
-
|
135
|
-
# Example 2: Mark item out of stock
|
136
|
-
# mark_out_of_stock "item-123"
|
137
|
-
|
138
|
-
# Example 3: Bulk update
|
139
|
-
# update_bulk_availability
|
140
|
-
}
|
141
|
-
|
142
|
-
# Run main function
|
143
|
-
main
|
@@ -1,279 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* Grubtech Item Availability Update - Java (Spring Boot)
|
3
|
-
*
|
4
|
-
* This example demonstrates how to update menu item availability in Grubtech
|
5
|
-
* to keep items in sync with your inventory status.
|
6
|
-
*
|
7
|
-
* Prerequisites:
|
8
|
-
* - Java 17+
|
9
|
-
* - Spring Boot 3.x
|
10
|
-
* - Spring WebFlux (for WebClient)
|
11
|
-
*
|
12
|
-
* Replace the following placeholders:
|
13
|
-
* - {{AUTH_TOKEN}}: Access token from authentication step
|
14
|
-
* - {{ITEM_ID}}: The menu item ID to update
|
15
|
-
* - {{AVAILABLE_STATUS}}: Boolean availability status (true/false)
|
16
|
-
*/
|
17
|
-
|
18
|
-
package com.example.grubtech;
|
19
|
-
|
20
|
-
import org.springframework.http.HttpHeaders;
|
21
|
-
import org.springframework.http.MediaType;
|
22
|
-
import org.springframework.stereotype.Service;
|
23
|
-
import org.springframework.web.reactive.function.client.WebClient;
|
24
|
-
import reactor.core.publisher.Mono;
|
25
|
-
|
26
|
-
import java.time.Instant;
|
27
|
-
import java.util.HashMap;
|
28
|
-
import java.util.List;
|
29
|
-
import java.util.Map;
|
30
|
-
import java.util.stream.Collectors;
|
31
|
-
|
32
|
-
@Service
|
33
|
-
public class GrubtechItemAvailabilityService {
|
34
|
-
|
35
|
-
private static final String AUTH_TOKEN = "{{AUTH_TOKEN}}";
|
36
|
-
private static final String BASE_URL = "https://api.grubtech.io";
|
37
|
-
|
38
|
-
private final WebClient webClient;
|
39
|
-
|
40
|
-
public GrubtechItemAvailabilityService() {
|
41
|
-
this.webClient = WebClient.builder()
|
42
|
-
.baseUrl(BASE_URL)
|
43
|
-
.build();
|
44
|
-
}
|
45
|
-
|
46
|
-
/**
|
47
|
-
* Update single item availability
|
48
|
-
*
|
49
|
-
* @param itemId The menu item ID
|
50
|
-
* @param available True if in stock, False if out of stock
|
51
|
-
* @param reason Optional reason for status change
|
52
|
-
* @return Availability update response
|
53
|
-
*/
|
54
|
-
public AvailabilityResponse updateItemAvailability(
|
55
|
-
String itemId,
|
56
|
-
boolean available,
|
57
|
-
String reason
|
58
|
-
) {
|
59
|
-
try {
|
60
|
-
// Construct payload
|
61
|
-
Map<String, Object> payload = new HashMap<>();
|
62
|
-
payload.put("itemId", itemId);
|
63
|
-
payload.put("available", available);
|
64
|
-
payload.put("timestamp", Instant.now().toString());
|
65
|
-
|
66
|
-
if (reason != null && !reason.isEmpty()) {
|
67
|
-
payload.put("reason", reason);
|
68
|
-
}
|
69
|
-
|
70
|
-
System.out.println("Updating item " + itemId + ": available=" + available);
|
71
|
-
|
72
|
-
// Make availability update request
|
73
|
-
AvailabilityResponse response = webClient.put()
|
74
|
-
.uri("/v1/items/" + itemId + "/availability")
|
75
|
-
.header(HttpHeaders.AUTHORIZATION, "Bearer " + AUTH_TOKEN)
|
76
|
-
.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)
|
77
|
-
.bodyValue(payload)
|
78
|
-
.retrieve()
|
79
|
-
.onStatus(
|
80
|
-
status -> !status.is2xxSuccessful(),
|
81
|
-
clientResponse -> clientResponse.bodyToMono(String.class)
|
82
|
-
.flatMap(errorBody -> Mono.error(
|
83
|
-
new RuntimeException(
|
84
|
-
"Availability update failed: " +
|
85
|
-
clientResponse.statusCode() +
|
86
|
-
" - " + errorBody
|
87
|
-
)
|
88
|
-
))
|
89
|
-
)
|
90
|
-
.bodyToMono(AvailabilityResponse.class)
|
91
|
-
.block();
|
92
|
-
|
93
|
-
if (response == null) {
|
94
|
-
throw new RuntimeException("No response received");
|
95
|
-
}
|
96
|
-
|
97
|
-
System.out.println("✅ Item availability updated successfully!");
|
98
|
-
System.out.println("Item ID: " + response.getItemId());
|
99
|
-
System.out.println("Available: " + available);
|
100
|
-
|
101
|
-
return response;
|
102
|
-
|
103
|
-
} catch (Exception e) {
|
104
|
-
System.err.println("❌ Availability update error: " + e.getMessage());
|
105
|
-
throw e;
|
106
|
-
}
|
107
|
-
}
|
108
|
-
|
109
|
-
/**
|
110
|
-
* Update multiple items availability in bulk
|
111
|
-
*
|
112
|
-
* @param updates List of item availability updates
|
113
|
-
* @return Bulk availability update response
|
114
|
-
*/
|
115
|
-
public BulkAvailabilityResponse updateBulkAvailability(
|
116
|
-
List<ItemUpdate> updates
|
117
|
-
) {
|
118
|
-
try {
|
119
|
-
// Construct bulk payload
|
120
|
-
Map<String, Object> payload = new HashMap<>();
|
121
|
-
payload.put("updates", updates);
|
122
|
-
payload.put("timestamp", Instant.now().toString());
|
123
|
-
|
124
|
-
System.out.println("Updating " + updates.size() + " items availability");
|
125
|
-
|
126
|
-
// Make bulk availability update request
|
127
|
-
BulkAvailabilityResponse response = webClient.put()
|
128
|
-
.uri("/v1/items/availability/bulk")
|
129
|
-
.header(HttpHeaders.AUTHORIZATION, "Bearer " + AUTH_TOKEN)
|
130
|
-
.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)
|
131
|
-
.bodyValue(payload)
|
132
|
-
.retrieve()
|
133
|
-
.onStatus(
|
134
|
-
status -> !status.is2xxSuccessful(),
|
135
|
-
clientResponse -> Mono.error(
|
136
|
-
new RuntimeException(
|
137
|
-
"Bulk availability update failed: " +
|
138
|
-
clientResponse.statusCode()
|
139
|
-
)
|
140
|
-
)
|
141
|
-
)
|
142
|
-
.bodyToMono(BulkAvailabilityResponse.class)
|
143
|
-
.block();
|
144
|
-
|
145
|
-
if (response == null) {
|
146
|
-
throw new RuntimeException("No response received");
|
147
|
-
}
|
148
|
-
|
149
|
-
System.out.println("✅ Bulk availability updated successfully!");
|
150
|
-
System.out.println("Updated: " + response.getUpdatedCount() + " items");
|
151
|
-
|
152
|
-
// Report any errors
|
153
|
-
if (response.getErrors() != null && !response.getErrors().isEmpty()) {
|
154
|
-
System.out.println("⚠️ " + response.getErrors().size() + " items had errors:");
|
155
|
-
response.getErrors().forEach(err ->
|
156
|
-
System.out.println(" - " + err.getItemId() + ": " + err.getError())
|
157
|
-
);
|
158
|
-
}
|
159
|
-
|
160
|
-
return response;
|
161
|
-
|
162
|
-
} catch (Exception e) {
|
163
|
-
System.err.println("❌ Bulk availability update error: " + e.getMessage());
|
164
|
-
throw e;
|
165
|
-
}
|
166
|
-
}
|
167
|
-
|
168
|
-
/**
|
169
|
-
* Mark item as out of stock
|
170
|
-
*/
|
171
|
-
public AvailabilityResponse markOutOfStock(String itemId) {
|
172
|
-
return updateItemAvailability(itemId, false, "Out of stock");
|
173
|
-
}
|
174
|
-
|
175
|
-
/**
|
176
|
-
* Mark item as back in stock
|
177
|
-
*/
|
178
|
-
public AvailabilityResponse markInStock(String itemId) {
|
179
|
-
return updateItemAvailability(itemId, true, "Back in stock");
|
180
|
-
}
|
181
|
-
|
182
|
-
/**
|
183
|
-
* Sync inventory with Grubtech
|
184
|
-
*/
|
185
|
-
public BulkAvailabilityResponse syncInventory(Map<String, Boolean> inventory) {
|
186
|
-
List<ItemUpdate> updates = inventory.entrySet().stream()
|
187
|
-
.map(entry -> new ItemUpdate(
|
188
|
-
entry.getKey(),
|
189
|
-
entry.getValue(),
|
190
|
-
entry.getValue() ? "In stock" : "Out of stock"
|
191
|
-
))
|
192
|
-
.collect(Collectors.toList());
|
193
|
-
|
194
|
-
return updateBulkAvailability(updates);
|
195
|
-
}
|
196
|
-
|
197
|
-
// Data models
|
198
|
-
public static class ItemUpdate {
|
199
|
-
private String itemId;
|
200
|
-
private boolean available;
|
201
|
-
private String reason;
|
202
|
-
|
203
|
-
public ItemUpdate(String itemId, boolean available, String reason) {
|
204
|
-
this.itemId = itemId;
|
205
|
-
this.available = available;
|
206
|
-
this.reason = reason;
|
207
|
-
}
|
208
|
-
|
209
|
-
// Getters
|
210
|
-
public String getItemId() { return itemId; }
|
211
|
-
public boolean isAvailable() { return available; }
|
212
|
-
public String getReason() { return reason; }
|
213
|
-
}
|
214
|
-
|
215
|
-
public static class AvailabilityResponse {
|
216
|
-
private boolean success;
|
217
|
-
private String itemId;
|
218
|
-
private String message;
|
219
|
-
|
220
|
-
// Getters and setters
|
221
|
-
public boolean isSuccess() { return success; }
|
222
|
-
public void setSuccess(boolean success) { this.success = success; }
|
223
|
-
public String getItemId() { return itemId; }
|
224
|
-
public void setItemId(String itemId) { this.itemId = itemId; }
|
225
|
-
public String getMessage() { return message; }
|
226
|
-
public void setMessage(String message) { this.message = message; }
|
227
|
-
}
|
228
|
-
|
229
|
-
public static class BulkAvailabilityResponse {
|
230
|
-
private boolean success;
|
231
|
-
private int updatedCount;
|
232
|
-
private List<ItemError> errors;
|
233
|
-
|
234
|
-
// Getters and setters
|
235
|
-
public boolean isSuccess() { return success; }
|
236
|
-
public void setSuccess(boolean success) { this.success = success; }
|
237
|
-
public int getUpdatedCount() { return updatedCount; }
|
238
|
-
public void setUpdatedCount(int updatedCount) { this.updatedCount = updatedCount; }
|
239
|
-
public List<ItemError> getErrors() { return errors; }
|
240
|
-
public void setErrors(List<ItemError> errors) { this.errors = errors; }
|
241
|
-
}
|
242
|
-
|
243
|
-
public static class ItemError {
|
244
|
-
private String itemId;
|
245
|
-
private String error;
|
246
|
-
|
247
|
-
// Getters and setters
|
248
|
-
public String getItemId() { return itemId; }
|
249
|
-
public void setItemId(String itemId) { this.itemId = itemId; }
|
250
|
-
public String getError() { return error; }
|
251
|
-
public void setError(String error) { this.error = error; }
|
252
|
-
}
|
253
|
-
|
254
|
-
// Main method for testing
|
255
|
-
public static void main(String[] args) {
|
256
|
-
try {
|
257
|
-
GrubtechItemAvailabilityService service = new GrubtechItemAvailabilityService();
|
258
|
-
|
259
|
-
String itemId = "{{ITEM_ID}}";
|
260
|
-
boolean available = {{AVAILABLE_STATUS}}; // true or false
|
261
|
-
|
262
|
-
// Example 1: Single item update
|
263
|
-
service.updateItemAvailability(itemId, available, "Inventory sync");
|
264
|
-
|
265
|
-
// Example 2: Mark item out of stock
|
266
|
-
// service.markOutOfStock("item-123");
|
267
|
-
|
268
|
-
// Example 3: Bulk update from inventory
|
269
|
-
// service.syncInventory(Map.of(
|
270
|
-
// "item-123", false, // Out of stock
|
271
|
-
// "item-456", true, // In stock
|
272
|
-
// "item-789", true // In stock
|
273
|
-
// ));
|
274
|
-
|
275
|
-
} catch (Exception e) {
|
276
|
-
System.exit(1);
|
277
|
-
}
|
278
|
-
}
|
279
|
-
}
|
@@ -1,203 +0,0 @@
|
|
1
|
-
"""
|
2
|
-
Grubtech Item Availability Update - Python
|
3
|
-
|
4
|
-
This example demonstrates how to update menu item availability in Grubtech
|
5
|
-
to keep items in sync with your inventory status.
|
6
|
-
|
7
|
-
Prerequisites:
|
8
|
-
- Python 3.8+
|
9
|
-
- requests library (pip install requests)
|
10
|
-
- Valid access token from authentication
|
11
|
-
|
12
|
-
Replace the following placeholders:
|
13
|
-
- {{AUTH_TOKEN}}: Access token from authentication step
|
14
|
-
- {{ITEM_ID}}: The menu item ID to update
|
15
|
-
- {{AVAILABLE_STATUS}}: Boolean availability status (True/False)
|
16
|
-
"""
|
17
|
-
|
18
|
-
import requests
|
19
|
-
import sys
|
20
|
-
from datetime import datetime
|
21
|
-
from typing import Dict, Any, List, Optional
|
22
|
-
|
23
|
-
AUTH_TOKEN = '{{AUTH_TOKEN}}'
|
24
|
-
BASE_URL = 'https://api.grubtech.io'
|
25
|
-
|
26
|
-
|
27
|
-
def update_item_availability(
|
28
|
-
item_id: str,
|
29
|
-
available: bool,
|
30
|
-
reason: Optional[str] = None
|
31
|
-
) -> Dict[str, Any]:
|
32
|
-
"""
|
33
|
-
Update single item availability
|
34
|
-
|
35
|
-
Args:
|
36
|
-
item_id: The menu item ID
|
37
|
-
available: True if in stock, False if out of stock
|
38
|
-
reason: Optional reason for status change
|
39
|
-
|
40
|
-
Returns:
|
41
|
-
Dict: Response from API
|
42
|
-
|
43
|
-
Raises:
|
44
|
-
Exception: If update fails
|
45
|
-
"""
|
46
|
-
try:
|
47
|
-
# Construct payload
|
48
|
-
payload = {
|
49
|
-
'itemId': item_id,
|
50
|
-
'available': available,
|
51
|
-
'timestamp': datetime.utcnow().isoformat() + 'Z',
|
52
|
-
}
|
53
|
-
|
54
|
-
if reason:
|
55
|
-
payload['reason'] = reason
|
56
|
-
|
57
|
-
print(f'Updating item {item_id}: available={available}')
|
58
|
-
|
59
|
-
# Make availability update request
|
60
|
-
url = f'{BASE_URL}/v1/items/{item_id}/availability'
|
61
|
-
headers = {
|
62
|
-
'Authorization': f'Bearer {AUTH_TOKEN}',
|
63
|
-
'Content-Type': 'application/json',
|
64
|
-
}
|
65
|
-
|
66
|
-
response = requests.put(url, json=payload, headers=headers, timeout=10)
|
67
|
-
|
68
|
-
# Check for errors
|
69
|
-
if not response.ok:
|
70
|
-
raise Exception(
|
71
|
-
f'Availability update failed: {response.status_code} - {response.text}'
|
72
|
-
)
|
73
|
-
|
74
|
-
# Parse response
|
75
|
-
data = response.json()
|
76
|
-
|
77
|
-
print(f'✅ Item availability updated successfully!')
|
78
|
-
print(f'Item ID: {data["itemId"]}')
|
79
|
-
print(f'Available: {available}')
|
80
|
-
|
81
|
-
return data
|
82
|
-
|
83
|
-
except requests.RequestException as e:
|
84
|
-
print(f'❌ Availability update error: {e}', file=sys.stderr)
|
85
|
-
raise
|
86
|
-
except Exception as e:
|
87
|
-
print(f'❌ Unexpected error: {e}', file=sys.stderr)
|
88
|
-
raise
|
89
|
-
|
90
|
-
|
91
|
-
def update_bulk_availability(
|
92
|
-
updates: List[Dict[str, Any]]
|
93
|
-
) -> Dict[str, Any]:
|
94
|
-
"""
|
95
|
-
Update multiple items availability in bulk
|
96
|
-
|
97
|
-
Args:
|
98
|
-
updates: List of item availability updates
|
99
|
-
[{'itemId': 'item-1', 'available': False, 'reason': '...'}]
|
100
|
-
|
101
|
-
Returns:
|
102
|
-
Dict: Response from API
|
103
|
-
|
104
|
-
Raises:
|
105
|
-
Exception: If update fails
|
106
|
-
"""
|
107
|
-
try:
|
108
|
-
# Construct bulk payload
|
109
|
-
payload = {
|
110
|
-
'updates': updates,
|
111
|
-
'timestamp': datetime.utcnow().isoformat() + 'Z',
|
112
|
-
}
|
113
|
-
|
114
|
-
print(f'Updating {len(updates)} items availability')
|
115
|
-
|
116
|
-
# Make bulk availability update request
|
117
|
-
url = f'{BASE_URL}/v1/items/availability/bulk'
|
118
|
-
headers = {
|
119
|
-
'Authorization': f'Bearer {AUTH_TOKEN}',
|
120
|
-
'Content-Type': 'application/json',
|
121
|
-
}
|
122
|
-
|
123
|
-
response = requests.put(url, json=payload, headers=headers, timeout=30)
|
124
|
-
|
125
|
-
# Check for errors
|
126
|
-
if not response.ok:
|
127
|
-
raise Exception(
|
128
|
-
f'Bulk availability update failed: {response.status_code} - {response.text}'
|
129
|
-
)
|
130
|
-
|
131
|
-
# Parse response
|
132
|
-
data = response.json()
|
133
|
-
|
134
|
-
print(f'✅ Bulk availability updated successfully!')
|
135
|
-
print(f'Updated: {data.get("updatedCount", 0)} items')
|
136
|
-
|
137
|
-
# Report any errors
|
138
|
-
errors = data.get('errors', [])
|
139
|
-
if errors:
|
140
|
-
print(f'⚠️ {len(errors)} items had errors:')
|
141
|
-
for err in errors:
|
142
|
-
print(f' - {err["itemId"]}: {err["error"]}')
|
143
|
-
|
144
|
-
return data
|
145
|
-
|
146
|
-
except requests.RequestException as e:
|
147
|
-
print(f'❌ Bulk availability update error: {e}', file=sys.stderr)
|
148
|
-
raise
|
149
|
-
except Exception as e:
|
150
|
-
print(f'❌ Unexpected error: {e}', file=sys.stderr)
|
151
|
-
raise
|
152
|
-
|
153
|
-
|
154
|
-
def mark_out_of_stock(item_id: str) -> Dict[str, Any]:
|
155
|
-
"""Mark item as out of stock"""
|
156
|
-
return update_item_availability(item_id, False, 'Out of stock')
|
157
|
-
|
158
|
-
|
159
|
-
def mark_in_stock(item_id: str) -> Dict[str, Any]:
|
160
|
-
"""Mark item as back in stock"""
|
161
|
-
return update_item_availability(item_id, True, 'Back in stock')
|
162
|
-
|
163
|
-
|
164
|
-
def sync_inventory(inventory: Dict[str, bool]) -> Dict[str, Any]:
|
165
|
-
"""
|
166
|
-
Sync inventory with Grubtech
|
167
|
-
|
168
|
-
Args:
|
169
|
-
inventory: Dict mapping item IDs to availability status
|
170
|
-
{'item-123': False, 'item-456': True}
|
171
|
-
"""
|
172
|
-
updates = [
|
173
|
-
{
|
174
|
-
'itemId': item_id,
|
175
|
-
'available': available,
|
176
|
-
'reason': 'In stock' if available else 'Out of stock',
|
177
|
-
}
|
178
|
-
for item_id, available in inventory.items()
|
179
|
-
]
|
180
|
-
|
181
|
-
return update_bulk_availability(updates)
|
182
|
-
|
183
|
-
|
184
|
-
if __name__ == '__main__':
|
185
|
-
try:
|
186
|
-
item_id = '{{ITEM_ID}}'
|
187
|
-
available = {{AVAILABLE_STATUS}} # True or False
|
188
|
-
|
189
|
-
# Example 1: Single item update
|
190
|
-
update_item_availability(item_id, available, 'Inventory sync')
|
191
|
-
|
192
|
-
# Example 2: Mark item out of stock
|
193
|
-
# mark_out_of_stock('item-123')
|
194
|
-
|
195
|
-
# Example 3: Bulk update from inventory
|
196
|
-
# sync_inventory({
|
197
|
-
# 'item-123': False, # Out of stock
|
198
|
-
# 'item-456': True, # In stock
|
199
|
-
# 'item-789': True, # In stock
|
200
|
-
# })
|
201
|
-
|
202
|
-
except Exception as e:
|
203
|
-
sys.exit(1)
|