@final-commerce/common 2.8.1-preprod.2 → 2.8.1-preprod.3

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/index.mjs CHANGED
@@ -2896,6 +2896,39 @@ function isInCart(order) {
2896
2896
  return (order.status ?? "").trim().toLowerCase() === "in-cart";
2897
2897
  }
2898
2898
 
2899
+ // order-state-machine/assigned-users.ts
2900
+ function orderAssignments(order) {
2901
+ const value = order?.assignedUser;
2902
+ if (Array.isArray(value)) return value.filter((entry) => entry?.userId);
2903
+ return value?.userId ? [value] : [];
2904
+ }
2905
+ var sameLabel = (entry, label) => (entry.label ?? null) === (label ?? null);
2906
+ function currentAssignees(order, label) {
2907
+ return orderAssignments(order).filter(
2908
+ (entry) => !entry.unassignedAt && (label === void 0 || sameLabel(entry, label))
2909
+ );
2910
+ }
2911
+ function applyAssignment(order, change) {
2912
+ const { userId, at } = change;
2913
+ const label = change.label?.trim() || null;
2914
+ const entries = orderAssignments(order);
2915
+ if (userId === null) {
2916
+ const all = change.label === void 0;
2917
+ return entries.map(
2918
+ (entry) => !entry.unassignedAt && (all || sameLabel(entry, label)) ? { ...entry, unassignedAt: at } : entry
2919
+ );
2920
+ }
2921
+ if (entries.some((entry) => !entry.unassignedAt && entry.userId === userId && sameLabel(entry, label))) {
2922
+ return entries;
2923
+ }
2924
+ return [
2925
+ ...entries.map(
2926
+ (entry) => !entry.unassignedAt && sameLabel(entry, label) ? { ...entry, unassignedAt: at } : entry
2927
+ ),
2928
+ { userId, assignedAt: at, ...label ? { label } : {} }
2929
+ ];
2930
+ }
2931
+
2899
2932
  // order-state-machine/order-status.ts
2900
2933
  var STATUS_KEY = /^[a-z0-9][a-z0-9_-]*$/;
2901
2934
  function validateOrderStatuses(statuses) {
@@ -4169,6 +4202,7 @@ export {
4169
4202
  adyenTaxNumberFormat,
4170
4203
  amountToString,
4171
4204
  ancestorChain,
4205
+ applyAssignment,
4172
4206
  assertUnitSane,
4173
4207
  availableIn,
4174
4208
  baseFor,
@@ -4194,6 +4228,7 @@ export {
4194
4228
  convertFixedFeeToLocalCurrency,
4195
4229
  createAmount,
4196
4230
  crossAxisRuleApplies,
4231
+ currentAssignees,
4197
4232
  deriveDisplayState,
4198
4233
  deriveFamilyCode,
4199
4234
  deriveUnitId,
@@ -4255,6 +4290,7 @@ export {
4255
4290
  normalizePostCode,
4256
4291
  normalizeProvince,
4257
4292
  occupancyIn,
4293
+ orderAssignments,
4258
4294
  parseAmountToMinorUnits,
4259
4295
  parseCurrencyCode,
4260
4296
  parseStripeCurrencyCode,