1 # TSDoc: Events
2
3 Event constants live in `packages/core/utils/src/core-flows/events.ts`. They are grouped into namespace objects (e.g. `CartWorkflowEvents`, `OrderWorkflowEvents`) exported as `const`.
4
5 ## Rules
6
7 - Document every event constant with a description of when it is emitted
8 - Always include `@eventPayload` showing the shape of the emitted data
9 - Add `@since` when the event is new in the commit diff (version from prompt)
10 - Add `@featureFlag` when the event is behind a feature flag
11 - Do NOT document the namespace object itself unless it lacks a description — the individual event constants are what matters
12
13 ## Event Constant Format
14
15 ```typescript
16 /**
17 * Emitted when [resource] is [action].
18 *
19 * @eventPayload
20 * ```ts
21 * {
22 * id, // The ID of the [resource]
23 * }
24 * ```
25 */
26 CREATED: "resource.created",
27 ```
28
29 ## @eventPayload — Payload Shape
30
31 `@eventPayload` uses a TypeScript code block listing the properties emitted with the event. Each property gets an inline comment:
32
33 ```typescript
34 /**
35 * Emitted when a cart is created.
36 *
37 * @eventPayload
38 * ```ts
39 * {
40 * id, // The ID of the cart
41 * }
42 * ```
43 */
44 CREATED: "cart.created",
45 ```
46
47 For events with richer payloads, including non-string fields — annotate the type in parentheses:
48
49 ```typescript
50 /**
51 * Emitted when the customer in the cart is transferred.
52 *
53 * @eventPayload
54 * ```ts
55 * {
56 * id, // The ID of the cart
57 * customer_id, // The ID of the customer
58 * }
59 * ```
60 */
61 CUSTOMER_TRANSFERRED: "cart.customer_transferred",
62
63 /**
64 * Emitted when an order's fulfillment is created.
65 *
66 * @eventPayload
67 * ```ts
68 * {
69 * order_id, // The ID of the order
70 * fulfillment_id, // The ID of the fulfillment
71 * no_notification, // (boolean) Whether to notify the customer
72 * }
73 * ```
74 */
75 FULFILLMENT_CREATED: "order.fulfillment_created",
76 ```
77
78 > Use `(type)` in the inline comment whenever the value is not a string — e.g. `// (boolean) ...`, `// (number) ...`, `// (array) ...`. Omit the type annotation for plain string IDs.
79
80 ## @since — New Events
81
82 Add `@since` when the event is new in this commit's diff:
83
84 ```typescript
85 /**
86 * Emitted when a translation is created.
87 *
88 * @since 2.14.0
89 *
90 * @eventPayload
91 * ```ts
92 * {
93 * id, // The ID of the translation
94 * }
95 * ```
96 */
97 TRANSLATIONS_CREATED: "translations.created",
98 ```
99
100 > Place `@since` before `@eventPayload` so version information appears first.
101
102 ## @featureFlag — Feature-Gated Events
103
104 Add `@featureFlag` for events that are only emitted when a feature flag is enabled:
105
106 ```typescript
107 /**
108 * Emitted when a translation is created.
109 *
110 * @since 2.14.0
111 * @featureFlag translation
112 *
113 * @eventPayload
114 * ```ts
115 * {
116 * id, // The ID of the translation
117 * }
118 * ```
119 */
120 TRANSLATIONS_CREATED: "translations.created",
121 ```
122
123 ## Namespace Object
124
125 If the namespace object (e.g. `CartWorkflowEvents`) itself lacks a TSDoc, add one with `@customNamespace` and `@category` if used consistently elsewhere in the file:
126
127 ```typescript
128 /**
129 * @category Cart
130 * @customNamespace Cart
131 */
132 export const CartWorkflowEvents = {
133 ```
134
135 Only add this if sibling namespaces in the file already use this pattern. Do not introduce it on namespaces that don't already follow it.
136
137 ## Full Before/After Example
138
139 **Before:**
140
141 ```typescript
142 export const OrderWorkflowEvents = {
143 PLACED: "order.placed",
144 CANCELED: "order.canceled",
145 COMPLETED: "order.completed",
146 }
147 ```
148
149 **After:**
150
151 ```typescript
152 export const OrderWorkflowEvents = {
153 /**
154 * Emitted when an order is placed.
155 *
156 * @eventPayload
157 * ```ts
158 * {
159 * id, // The ID of the order
160 * }
161 * ```
162 */
163 PLACED: "order.placed",
164
165 /**
166 * Emitted when an order is cancelled.
167 *
168 * @eventPayload
169 * ```ts
170 * {
171 * id, // The ID of the order
172 * }
173 * ```
174 */
175 CANCELED: "order.canceled",
176
177 /**
178 * Emitted when an order is completed.
179 *
180 * @eventPayload
181 * ```ts
182 * {
183 * id, // The ID of the order
184 * }
185 * ```
186 */
187 COMPLETED: "order.completed",
188 }
189 ```