@flipdish/events 1.26007.0 → 1.26009.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/ai-chat-agent.js +89 -0
- package/ai-chat-agent.ts +104 -0
- package/package.json +1 -1
- package/rms/menus/schemas/menu.js +4 -0
- package/rms/menus/schemas/menu.ts +4 -0
package/ai-chat-agent.js
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { extendZodWithOpenApi } from '@asteasolutions/zod-to-openapi';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { orgIdSchema, propertyIdSchema } from './common-schemas.js';
|
|
4
|
+
extendZodWithOpenApi(z);
|
|
5
|
+
export const eventTypes = {
|
|
6
|
+
AI_CHAT_AGENT_BASKET_UPDATED_V1: 'ai.chat_agent.basket.updated.v1',
|
|
7
|
+
AI_CHAT_AGENT_ORDER_SUBMITTED_V1: 'ai.chat_agent.order.submitted.v1',
|
|
8
|
+
AI_CHAT_AGENT_ORDER_FAILED_V1: 'ai.chat_agent.order.failed.v1',
|
|
9
|
+
};
|
|
10
|
+
export const commonAIChatAgentSchema = z.object({
|
|
11
|
+
chatId: z.string().openapi({
|
|
12
|
+
description: 'Unique identifier for the chat session',
|
|
13
|
+
example: 'chat_123e4567-e89b-12d3-a456-426614174000',
|
|
14
|
+
}),
|
|
15
|
+
orgIdSchema: orgIdSchema,
|
|
16
|
+
brandIdSchema: z.string().openapi({
|
|
17
|
+
description: 'Brand ID identifier',
|
|
18
|
+
example: 'brand123',
|
|
19
|
+
}),
|
|
20
|
+
propertyId: propertyIdSchema,
|
|
21
|
+
restaurantName: z.string().openapi({
|
|
22
|
+
description: 'Name of the restaurant',
|
|
23
|
+
example: "Joe's Pizza",
|
|
24
|
+
}),
|
|
25
|
+
});
|
|
26
|
+
export const basketMenuItemOptionSchema = z.object({
|
|
27
|
+
name: z.string().openapi({
|
|
28
|
+
description: 'Name of the menu item option',
|
|
29
|
+
example: 'Extra Cheese',
|
|
30
|
+
}),
|
|
31
|
+
menuItemOptionSetId: z.number().openapi({
|
|
32
|
+
description: 'ID of the menu item option set this option belongs to',
|
|
33
|
+
example: 123,
|
|
34
|
+
}),
|
|
35
|
+
menuItemOptionSetItemId: z.number().openapi({
|
|
36
|
+
description: 'ID of the specific option item within the option set',
|
|
37
|
+
example: 456,
|
|
38
|
+
}),
|
|
39
|
+
});
|
|
40
|
+
export const menuItemSchema = z.object({
|
|
41
|
+
menuItemId: z.number().openapi({
|
|
42
|
+
description: 'Unique identifier for the menu item',
|
|
43
|
+
example: 789,
|
|
44
|
+
}),
|
|
45
|
+
name: z.string().openapi({
|
|
46
|
+
description: 'Name of the menu item',
|
|
47
|
+
example: 'Margherita Pizza',
|
|
48
|
+
}),
|
|
49
|
+
quantity: z.number().min(1).positive().openapi({
|
|
50
|
+
description: 'The quantity of the menu item',
|
|
51
|
+
example: 1,
|
|
52
|
+
}),
|
|
53
|
+
options: z.array(basketMenuItemOptionSchema).openapi({
|
|
54
|
+
description: 'Array of options selected for this menu item',
|
|
55
|
+
}),
|
|
56
|
+
});
|
|
57
|
+
export const aiChatAgentBasketUpdatedV1Schema = commonAIChatAgentSchema.extend({
|
|
58
|
+
eventName: z.literal(eventTypes.AI_CHAT_AGENT_BASKET_UPDATED_V1),
|
|
59
|
+
basket: z.array(menuItemSchema).openapi({
|
|
60
|
+
description: 'Array of menu items currently in the basket',
|
|
61
|
+
}),
|
|
62
|
+
});
|
|
63
|
+
export const aiChatAgentOrderSubmittedV1Schema = commonAIChatAgentSchema.extend({
|
|
64
|
+
eventName: z.literal(eventTypes.AI_CHAT_AGENT_ORDER_SUBMITTED_V1),
|
|
65
|
+
orderId: z.number().openapi({
|
|
66
|
+
description: 'Unique identifier for the submitted order',
|
|
67
|
+
example: 12345,
|
|
68
|
+
}),
|
|
69
|
+
});
|
|
70
|
+
export const aiChatAgentOrderFailedV1Schema = commonAIChatAgentSchema.extend({
|
|
71
|
+
eventName: z.literal(eventTypes.AI_CHAT_AGENT_ORDER_FAILED_V1),
|
|
72
|
+
error: z.string().openapi({
|
|
73
|
+
description: 'Error message describing why the order submission failed',
|
|
74
|
+
example: 'Payment processing failed',
|
|
75
|
+
}),
|
|
76
|
+
});
|
|
77
|
+
// ================================
|
|
78
|
+
// Event Schemas
|
|
79
|
+
// ================================
|
|
80
|
+
export const aiChatAgentEventSchema = z.discriminatedUnion('eventName', [
|
|
81
|
+
aiChatAgentBasketUpdatedV1Schema,
|
|
82
|
+
aiChatAgentOrderSubmittedV1Schema,
|
|
83
|
+
aiChatAgentOrderFailedV1Schema,
|
|
84
|
+
]);
|
|
85
|
+
export const eventSchemaMap = Object.fromEntries([
|
|
86
|
+
[eventTypes.AI_CHAT_AGENT_BASKET_UPDATED_V1, aiChatAgentBasketUpdatedV1Schema],
|
|
87
|
+
[eventTypes.AI_CHAT_AGENT_ORDER_SUBMITTED_V1, aiChatAgentOrderSubmittedV1Schema],
|
|
88
|
+
[eventTypes.AI_CHAT_AGENT_ORDER_FAILED_V1, aiChatAgentOrderFailedV1Schema],
|
|
89
|
+
]);
|
package/ai-chat-agent.ts
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { extendZodWithOpenApi } from '@asteasolutions/zod-to-openapi';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { orgIdSchema, propertyIdSchema } from './common-schemas.js';
|
|
4
|
+
|
|
5
|
+
extendZodWithOpenApi(z);
|
|
6
|
+
|
|
7
|
+
export const eventTypes = {
|
|
8
|
+
AI_CHAT_AGENT_BASKET_UPDATED_V1: 'ai.chat_agent.basket.updated.v1',
|
|
9
|
+
AI_CHAT_AGENT_ORDER_SUBMITTED_V1: 'ai.chat_agent.order.submitted.v1',
|
|
10
|
+
AI_CHAT_AGENT_ORDER_FAILED_V1: 'ai.chat_agent.order.failed.v1',
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export const commonAIChatAgentSchema = z.object({
|
|
14
|
+
chatId: z.string().openapi({
|
|
15
|
+
description: 'Unique identifier for the chat session',
|
|
16
|
+
example: 'chat_123e4567-e89b-12d3-a456-426614174000',
|
|
17
|
+
}),
|
|
18
|
+
orgIdSchema: orgIdSchema,
|
|
19
|
+
brandIdSchema: z.string().openapi({
|
|
20
|
+
description: 'Brand ID identifier',
|
|
21
|
+
example: 'brand123',
|
|
22
|
+
}),
|
|
23
|
+
propertyId: propertyIdSchema,
|
|
24
|
+
restaurantName: z.string().openapi({
|
|
25
|
+
description: 'Name of the restaurant',
|
|
26
|
+
example: "Joe's Pizza",
|
|
27
|
+
}),
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
export const basketMenuItemOptionSchema = z.object({
|
|
31
|
+
name: z.string().openapi({
|
|
32
|
+
description: 'Name of the menu item option',
|
|
33
|
+
example: 'Extra Cheese',
|
|
34
|
+
}),
|
|
35
|
+
menuItemOptionSetId: z.number().openapi({
|
|
36
|
+
description: 'ID of the menu item option set this option belongs to',
|
|
37
|
+
example: 123,
|
|
38
|
+
}),
|
|
39
|
+
menuItemOptionSetItemId: z.number().openapi({
|
|
40
|
+
description: 'ID of the specific option item within the option set',
|
|
41
|
+
example: 456,
|
|
42
|
+
}),
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
export const menuItemSchema = z.object({
|
|
46
|
+
menuItemId: z.number().openapi({
|
|
47
|
+
description: 'Unique identifier for the menu item',
|
|
48
|
+
example: 789,
|
|
49
|
+
}),
|
|
50
|
+
name: z.string().openapi({
|
|
51
|
+
description: 'Name of the menu item',
|
|
52
|
+
example: 'Margherita Pizza',
|
|
53
|
+
}),
|
|
54
|
+
quantity: z.number().min(1).positive().openapi({
|
|
55
|
+
description: 'The quantity of the menu item',
|
|
56
|
+
example: 1,
|
|
57
|
+
}),
|
|
58
|
+
options: z.array(basketMenuItemOptionSchema).openapi({
|
|
59
|
+
description: 'Array of options selected for this menu item',
|
|
60
|
+
}),
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
export const aiChatAgentBasketUpdatedV1Schema = commonAIChatAgentSchema.extend({
|
|
64
|
+
eventName: z.literal(eventTypes.AI_CHAT_AGENT_BASKET_UPDATED_V1),
|
|
65
|
+
basket: z.array(menuItemSchema).openapi({
|
|
66
|
+
description: 'Array of menu items currently in the basket',
|
|
67
|
+
}),
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
export const aiChatAgentOrderSubmittedV1Schema = commonAIChatAgentSchema.extend({
|
|
71
|
+
eventName: z.literal(eventTypes.AI_CHAT_AGENT_ORDER_SUBMITTED_V1),
|
|
72
|
+
orderId: z.number().openapi({
|
|
73
|
+
description: 'Unique identifier for the submitted order',
|
|
74
|
+
example: 12345,
|
|
75
|
+
}),
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
export const aiChatAgentOrderFailedV1Schema = commonAIChatAgentSchema.extend({
|
|
79
|
+
eventName: z.literal(eventTypes.AI_CHAT_AGENT_ORDER_FAILED_V1),
|
|
80
|
+
error: z.string().openapi({
|
|
81
|
+
description: 'Error message describing why the order submission failed',
|
|
82
|
+
example: 'Payment processing failed',
|
|
83
|
+
}),
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
// ================================
|
|
87
|
+
// Event Schemas
|
|
88
|
+
// ================================
|
|
89
|
+
export const aiChatAgentEventSchema = z.discriminatedUnion('eventName', [
|
|
90
|
+
aiChatAgentBasketUpdatedV1Schema,
|
|
91
|
+
aiChatAgentOrderSubmittedV1Schema,
|
|
92
|
+
aiChatAgentOrderFailedV1Schema,
|
|
93
|
+
]);
|
|
94
|
+
|
|
95
|
+
export const eventSchemaMap = Object.fromEntries([
|
|
96
|
+
[eventTypes.AI_CHAT_AGENT_BASKET_UPDATED_V1, aiChatAgentBasketUpdatedV1Schema],
|
|
97
|
+
[eventTypes.AI_CHAT_AGENT_ORDER_SUBMITTED_V1, aiChatAgentOrderSubmittedV1Schema],
|
|
98
|
+
[eventTypes.AI_CHAT_AGENT_ORDER_FAILED_V1, aiChatAgentOrderFailedV1Schema],
|
|
99
|
+
]);
|
|
100
|
+
|
|
101
|
+
export type AIChatAgentEvent = z.infer<typeof aiChatAgentEventSchema>;
|
|
102
|
+
export type AIChatAgentBasketUpdatedEventV1 = z.infer<typeof aiChatAgentBasketUpdatedV1Schema>;
|
|
103
|
+
export type AIChatAgentOrderSubmittedEventV1 = z.infer<typeof aiChatAgentOrderSubmittedV1Schema>;
|
|
104
|
+
export type AIChatAgentOrderFailedEventV1 = z.infer<typeof aiChatAgentOrderFailedV1Schema>;
|
package/package.json
CHANGED
|
@@ -117,6 +117,10 @@ export const PublicMenuSchema = BaseMenuSchema.merge(AutoGeneratedMenuFieldsSche
|
|
|
117
117
|
});
|
|
118
118
|
export const EventMenuSchema = BaseMenuSchema.merge(AutoGeneratedMenuFieldsSchema)
|
|
119
119
|
.extend({
|
|
120
|
+
isVatInclusive: z.boolean().nullable().optional().openapi({
|
|
121
|
+
description: 'Whether the menu is VAT inclusive',
|
|
122
|
+
example: false,
|
|
123
|
+
}),
|
|
120
124
|
categories: z.array(CategorySchemas.EventCategorySchema).nullable().openapi({
|
|
121
125
|
description: 'Categories for the menu',
|
|
122
126
|
example: [],
|
|
@@ -124,6 +124,10 @@ export const PublicMenuSchema = BaseMenuSchema.merge(AutoGeneratedMenuFieldsSche
|
|
|
124
124
|
|
|
125
125
|
export const EventMenuSchema = BaseMenuSchema.merge(AutoGeneratedMenuFieldsSchema)
|
|
126
126
|
.extend({
|
|
127
|
+
isVatInclusive: z.boolean().nullable().optional().openapi({
|
|
128
|
+
description: 'Whether the menu is VAT inclusive',
|
|
129
|
+
example: false,
|
|
130
|
+
}),
|
|
127
131
|
categories: z.array(CategorySchemas.EventCategorySchema).nullable().openapi({
|
|
128
132
|
description: 'Categories for the menu',
|
|
129
133
|
example: [],
|