@jaicome/contracts 0.0.75 → 0.0.76

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.
@@ -1,7 +1,8 @@
1
- import { i as FulfillmentState$1 } from "./orders-Dr9SO3_e.mjs";
1
+ import { Y as orderFulfillmentTypes, i as FulfillmentState$1 } from "./orders-CHXvc7L7.mjs";
2
2
 
3
3
  //#region src/fulfillment-states.d.ts
4
4
  type FulfillmentState = FulfillmentState$1;
5
+ type OrderFulfillmentType = (typeof orderFulfillmentTypes)[number];
5
6
  /**
6
7
  * All valid fulfillment states in order
7
8
  *
@@ -111,6 +112,44 @@ declare function getAllowedUserTransitions(from: FulfillmentState | null): Fulfi
111
112
  * ```
112
113
  */
113
114
  declare function isTerminalState(state: FulfillmentState): boolean;
115
+ /**
116
+ * Human-readable labels for fulfillment states
117
+ * Used for translation keys and UI display
118
+ */
119
+ declare const STATUS_LABELS: Readonly<Record<FulfillmentState, string>>;
120
+ /**
121
+ * Gets available user transitions for a fulfillment, filtered by fulfillment type
122
+ * This is the recommended function for UI components to determine which state transitions to show
123
+ *
124
+ * Filtering rules:
125
+ * - REFUNDED is always excluded (handled via separate refund flow)
126
+ * - AWAITING_DELIVERY and ON_THE_WAY are excluded for non-delivery orders (PICKUP, DINEIN, CURBSIDE)
127
+ * - AWAITING_DELIVERY and ON_THE_WAY are included for DELIVERY and SHIPPING orders
128
+ *
129
+ * @param from - Current state (null treated as NEW)
130
+ * @param fulfillmentType - The fulfillment type (DELIVERY, PICKUP, SHIPPING, DINEIN, CURBSIDE)
131
+ * @returns Array of allowed next states appropriate for the fulfillment type
132
+ *
133
+ * @example
134
+ * ```ts
135
+ * // PICKUP order - no delivery states
136
+ * getAvailableUserTransitions("NEW", "PICKUP")
137
+ * // ["CONFIRMED", "READY", "COMPLETED", "CANCELLED"]
138
+ *
139
+ * // DELIVERY order - includes delivery states
140
+ * getAvailableUserTransitions("NEW", "DELIVERY")
141
+ * // ["AWAITING_DELIVERY", "CONFIRMED", "READY", "ON_THE_WAY", "COMPLETED", "CANCELLED"]
142
+ *
143
+ * // SHIPPING order - same as DELIVERY
144
+ * getAvailableUserTransitions("NEW", "SHIPPING")
145
+ * // ["AWAITING_DELIVERY", "CONFIRMED", "READY", "ON_THE_WAY", "COMPLETED", "CANCELLED"]
146
+ *
147
+ * // Terminal state - no transitions
148
+ * getAvailableUserTransitions("CANCELLED", "DELIVERY")
149
+ * // []
150
+ * ```
151
+ */
152
+ declare function getAvailableUserTransitions(from: FulfillmentState | null, fulfillmentType?: OrderFulfillmentType | string | null): FulfillmentState[];
114
153
  /**
115
154
  * Namespace containing all fulfillment state machine operations
116
155
  * Provides a unified API for state machine functionality
@@ -120,9 +159,11 @@ declare const FulfillmentStateMachine: {
120
159
  readonly assertCanTransition: typeof assertCanTransition;
121
160
  readonly getAllowedTransitions: typeof getAllowedTransitions;
122
161
  readonly getAllowedUserTransitions: typeof getAllowedUserTransitions;
162
+ readonly getAvailableUserTransitions: typeof getAvailableUserTransitions;
123
163
  readonly isTerminalState: typeof isTerminalState;
124
164
  readonly values: readonly ["NEW", "AWAITING_DELIVERY", "CONFIRMED", "READY", "ON_THE_WAY", "COMPLETED", "CANCELLED", "FAILED", "REFUNDED"];
125
165
  readonly terminalStates: ReadonlySet<"NEW" | "AWAITING_DELIVERY" | "CONFIRMED" | "READY" | "ON_THE_WAY" | "COMPLETED" | "CANCELLED" | "FAILED" | "REFUNDED">;
166
+ readonly statusLabels: Readonly<Record<"NEW" | "AWAITING_DELIVERY" | "CONFIRMED" | "READY" | "ON_THE_WAY" | "COMPLETED" | "CANCELLED" | "FAILED" | "REFUNDED", string>>;
126
167
  };
127
168
  //#endregion
128
- export { Actor, FulfillmentState, FulfillmentStateMachine, FulfillmentStateValues, TerminalStates, assertCanTransition, canTransition, getAllowedTransitions, getAllowedUserTransitions, isTerminalState };
169
+ export { Actor, FulfillmentState, FulfillmentStateMachine, FulfillmentStateValues, OrderFulfillmentType, STATUS_LABELS, TerminalStates, assertCanTransition, canTransition, getAllowedTransitions, getAllowedUserTransitions, getAvailableUserTransitions, isTerminalState };
@@ -208,6 +208,69 @@ function isTerminalState(state) {
208
208
  return TerminalStates.has(state);
209
209
  }
210
210
  /**
211
+ * Fulfillment types that support delivery-specific states (AWAITING_DELIVERY, ON_THE_WAY)
212
+ */
213
+ const DELIVERY_FULFILLMENT_TYPES = new Set(["DELIVERY", "SHIPPING"]);
214
+ /**
215
+ * States that are only applicable to delivery/shipping orders
216
+ */
217
+ const DELIVERY_ONLY_STATES = new Set(["AWAITING_DELIVERY", "ON_THE_WAY"]);
218
+ /**
219
+ * Human-readable labels for fulfillment states
220
+ * Used for translation keys and UI display
221
+ */
222
+ const STATUS_LABELS = {
223
+ NEW: "New",
224
+ AWAITING_DELIVERY: "Awaiting Delivery",
225
+ CONFIRMED: "Confirmed",
226
+ READY: "Ready",
227
+ ON_THE_WAY: "On The Way",
228
+ COMPLETED: "Completed",
229
+ CANCELLED: "Cancelled",
230
+ FAILED: "Failed",
231
+ REFUNDED: "Refunded"
232
+ };
233
+ /**
234
+ * Gets available user transitions for a fulfillment, filtered by fulfillment type
235
+ * This is the recommended function for UI components to determine which state transitions to show
236
+ *
237
+ * Filtering rules:
238
+ * - REFUNDED is always excluded (handled via separate refund flow)
239
+ * - AWAITING_DELIVERY and ON_THE_WAY are excluded for non-delivery orders (PICKUP, DINEIN, CURBSIDE)
240
+ * - AWAITING_DELIVERY and ON_THE_WAY are included for DELIVERY and SHIPPING orders
241
+ *
242
+ * @param from - Current state (null treated as NEW)
243
+ * @param fulfillmentType - The fulfillment type (DELIVERY, PICKUP, SHIPPING, DINEIN, CURBSIDE)
244
+ * @returns Array of allowed next states appropriate for the fulfillment type
245
+ *
246
+ * @example
247
+ * ```ts
248
+ * // PICKUP order - no delivery states
249
+ * getAvailableUserTransitions("NEW", "PICKUP")
250
+ * // ["CONFIRMED", "READY", "COMPLETED", "CANCELLED"]
251
+ *
252
+ * // DELIVERY order - includes delivery states
253
+ * getAvailableUserTransitions("NEW", "DELIVERY")
254
+ * // ["AWAITING_DELIVERY", "CONFIRMED", "READY", "ON_THE_WAY", "COMPLETED", "CANCELLED"]
255
+ *
256
+ * // SHIPPING order - same as DELIVERY
257
+ * getAvailableUserTransitions("NEW", "SHIPPING")
258
+ * // ["AWAITING_DELIVERY", "CONFIRMED", "READY", "ON_THE_WAY", "COMPLETED", "CANCELLED"]
259
+ *
260
+ * // Terminal state - no transitions
261
+ * getAvailableUserTransitions("CANCELLED", "DELIVERY")
262
+ * // []
263
+ * ```
264
+ */
265
+ function getAvailableUserTransitions(from, fulfillmentType) {
266
+ const isDelivery = DELIVERY_FULFILLMENT_TYPES.has(fulfillmentType ?? "");
267
+ return getAllowedUserTransitions(from).filter((state) => {
268
+ if (state === "REFUNDED") return false;
269
+ if (!isDelivery && DELIVERY_ONLY_STATES.has(state)) return false;
270
+ return true;
271
+ });
272
+ }
273
+ /**
211
274
  * Namespace containing all fulfillment state machine operations
212
275
  * Provides a unified API for state machine functionality
213
276
  */
@@ -216,10 +279,12 @@ const FulfillmentStateMachine = {
216
279
  assertCanTransition,
217
280
  getAllowedTransitions,
218
281
  getAllowedUserTransitions,
282
+ getAvailableUserTransitions,
219
283
  isTerminalState,
220
284
  values: FulfillmentStateValues,
221
- terminalStates: TerminalStates
285
+ terminalStates: TerminalStates,
286
+ statusLabels: STATUS_LABELS
222
287
  };
223
288
 
224
289
  //#endregion
225
- export { FulfillmentStateMachine, FulfillmentStateValues, TerminalStates, assertCanTransition, canTransition, getAllowedTransitions, getAllowedUserTransitions, isTerminalState };
290
+ export { FulfillmentStateMachine, FulfillmentStateValues, STATUS_LABELS, TerminalStates, assertCanTransition, canTransition, getAllowedTransitions, getAllowedUserTransitions, getAvailableUserTransitions, isTerminalState };