@jaicome/contracts 0.0.73 → 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.
- package/dist/fulfillment-states.d.mts +43 -3
- package/dist/fulfillment-states.mjs +67 -2
- package/dist/index.d.mts +2673 -317
- package/dist/index.mjs +450 -68
- package/dist/{orders-yFOPRYZw.d.mts → orders-CHXvc7L7.d.mts} +810 -255
- package/dist/payments-Qea5Yb_X.d.mts +387 -0
- package/dist/schema/index.d.mts +1266 -554
- package/dist/schema/index.mjs +2 -2
- package/dist/utils/payment-resolver.d.mts +87 -0
- package/dist/utils/payment-resolver.mjs +118 -0
- package/dist/{schema-0qCwa7QX.mjs → zatca-CEInGWOH.mjs} +761 -274
- package/package.json +9 -3
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { i as FulfillmentState$1 } from "./orders-
|
|
1
|
+
import { Y as orderFulfillmentTypes, i as FulfillmentState$1 } from "./orders-CHXvc7L7.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/fulfillment-states.d.ts
|
|
4
|
-
|
|
5
4
|
type FulfillmentState = FulfillmentState$1;
|
|
5
|
+
type OrderFulfillmentType = (typeof orderFulfillmentTypes)[number];
|
|
6
6
|
/**
|
|
7
7
|
* All valid fulfillment states in order
|
|
8
8
|
*
|
|
@@ -112,6 +112,44 @@ declare function getAllowedUserTransitions(from: FulfillmentState | null): Fulfi
|
|
|
112
112
|
* ```
|
|
113
113
|
*/
|
|
114
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[];
|
|
115
153
|
/**
|
|
116
154
|
* Namespace containing all fulfillment state machine operations
|
|
117
155
|
* Provides a unified API for state machine functionality
|
|
@@ -121,9 +159,11 @@ declare const FulfillmentStateMachine: {
|
|
|
121
159
|
readonly assertCanTransition: typeof assertCanTransition;
|
|
122
160
|
readonly getAllowedTransitions: typeof getAllowedTransitions;
|
|
123
161
|
readonly getAllowedUserTransitions: typeof getAllowedUserTransitions;
|
|
162
|
+
readonly getAvailableUserTransitions: typeof getAvailableUserTransitions;
|
|
124
163
|
readonly isTerminalState: typeof isTerminalState;
|
|
125
164
|
readonly values: readonly ["NEW", "AWAITING_DELIVERY", "CONFIRMED", "READY", "ON_THE_WAY", "COMPLETED", "CANCELLED", "FAILED", "REFUNDED"];
|
|
126
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>>;
|
|
127
167
|
};
|
|
128
168
|
//#endregion
|
|
129
|
-
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 };
|