@final-commerce/common 2.0.3 → 2.0.5-beta.1

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.d.mts CHANGED
@@ -189,7 +189,8 @@ declare enum Platform {
189
189
  }
190
190
  declare enum OrderPlatform {
191
191
  POS = "in-store",
192
- WOO_COMMERCE = "woo-commerce"
192
+ WOO_COMMERCE = "woo-commerce",
193
+ PUBLIC_API = "public-api"
193
194
  }
194
195
  declare enum CustomerPlatform {
195
196
  POS = "in-store",
@@ -899,7 +900,6 @@ declare const DEFAULT_CONFIG: StoredStateConfig;
899
900
  declare function buildResolvedConfig(config: StoredStateConfig): StateConfig;
900
901
  declare const DEFAULT_RESOLVED_CONFIG: StateConfig;
901
902
 
902
- declare const POS_CROSS_AXIS_RULES: readonly CrossAxisRule[];
903
903
  declare const POS_VALID_INITIAL_STATES: readonly StatePair[];
904
904
  declare function buildPosPresetConfig(companyId?: string): StoredStateConfig;
905
905
 
@@ -933,6 +933,40 @@ declare function setOrderState(order: OrderStateWritable, paymentState: PaymentS
933
933
 
934
934
  declare function inferStatesFromLegacyStatus(order: OrderLikeForLegacyInference): StatePair;
935
935
 
936
+ interface OrderMutationData extends OrderStateWritable {
937
+ total?: number;
938
+ balance?: number;
939
+ paymentMethods?: {
940
+ amount?: number;
941
+ [key: string]: unknown;
942
+ }[];
943
+ refunds?: {
944
+ quantity?: number;
945
+ [key: string]: unknown;
946
+ }[];
947
+ refund?: {
948
+ quantity?: number;
949
+ [key: string]: unknown;
950
+ }[];
951
+ lineItems?: {
952
+ quantity?: number;
953
+ fulfilledQuantity?: number;
954
+ returnedQuantity?: number;
955
+ [key: string]: unknown;
956
+ }[];
957
+ }
958
+ interface OrderWriteStrategy {
959
+ applyState(order: OrderMutationData): void;
960
+ }
961
+ declare class LegacyWriteStrategy implements OrderWriteStrategy {
962
+ applyState(_order: OrderMutationData): void;
963
+ }
964
+ declare class DualWriteStrategy implements OrderWriteStrategy {
965
+ private readonly config;
966
+ constructor(config: StoredStateConfig);
967
+ applyState(order: OrderMutationData): void;
968
+ }
969
+
936
970
  interface ResolveTemplateResult {
937
971
  fragment: StateConfigFragment;
938
972
  resolvedValues: Record<string, unknown>;
@@ -1059,4 +1093,4 @@ declare const EUFixedRates: Record<string, CurrencyRate>;
1059
1093
  declare const OtherFixedRates: Record<string, CurrencyRate>;
1060
1094
  declare const COUNTRY_CURRENCIES: Record<string, string>;
1061
1095
 
1062
- export { type Amount, AttributeType, type AvailableTransition, CONDITION_OPERATORS, COUNTRY_CURRENCIES, CURRENCY_CONFIG, type CartDiscountBucket, type CartFeeBucket, type CashDrawer, type CashRoundingTuple, CompanyType, type Condition, type ConditionGroup, type ConditionOperator, type ConfigUpdatedPayload, type ConfigValidationError, type ConfigValidationResult, type ConfigValidationWarning, type CrossAxisRequires, type CrossAxisRule, type CrossAxisTrigger, CurrencyCode, type CurrencyConfig, type CurrencyRate, CustomTableAvailability, CustomerPlatform, DEFAULT_CONFIG, DEFAULT_CROSS_AXIS_RULES, DEFAULT_DISPLAY_STATE_MAP, DEFAULT_RESOLVED_CONFIG, type DeleteStateConfigFragmentParams, type DeleteStateConfigFragmentResponse, type DiscountsBreakdown, type DiscountsTuple, type DisplayStateResult, type DisplayStateRule, EUFixedRates, EUROPE, type EndOfSessionReport, ExtensionCategory, FINANCIAL_INVARIANTS, FULFILLMENT_STATES, type FailedCondition, type FeesBreakdown, FeesCustomBillingStatus, type FeesTuple, type FinancialInvariant, type FragmentParam, type FragmentValidationResult, type FulfillmentState, type FulfillmentStateDefinition, type FulfillmentTransitionPath, type GetAvailableTransitionsParams, type GetAvailableTransitionsResponse, type GetOrderDisplayStateParams, type GetOrderDisplayStateResponse, type GetOrderStateConfigParams, type GetOrderStateConfigResponse, type GetStateConfigFragmentParams, type GetStateConfigFragmentResponse, InventoryBaseActionEnum, type InventoryBaseActionType, InventorySpecificActionType, InvoiceStatus, LibraryItemType, MenuProject, NAFixedRates, NORTH_AMERICA, NonRevenueItemType, ORDER_STATE_ACTIONS, ORDER_STATE_EVENTS, ORDER_STATE_TOPIC, type OrderContext, type OrderLikeForContext, type OrderLikeForLegacyInference, type OrderLineItem, type OrderPaymentMethod, OrderPlatform, type OrderRefund, type OrderStateEventPayload, type OrderStateWritable, OtherFixedRates, OwnerType, PATH_MODES, PAYMENT_STATES, POS_CROSS_AXIS_RULES, POS_VALID_INITIAL_STATES, type PathMode, PaymentMethod, type PaymentState, type PaymentStateDefinition, type PaymentTransitionPath, Platform, PreviewImageMode, PricingLevel, PricingPlanEnum, PricingRegionEnum, type ProductDiscountBucket, type ProductFeeBucket, ProductStatus, ProductType, PublicationAvailability, type PublicationConfig, PublicationStatus, REGION_MAPPING, REPORT_NEGATE_PATHS, ReceiptSendChannel, ReceiptType, type RefundsBreakdown, ResidualPaymentMethod, ResidualStatus, type ResolveTemplateResult, STATE_SCHEMA, STRIPE_SUPPORTED_COUNTRIES, type SalesSummary, type SaveStateConfigFragmentParams, type SaveStateConfigFragmentResponse, type SettlementBreakdown, type SettlementCardSection, type SettlementCashSection, type SettlementCustomEntry, type SplitPayment, type SplitPaymentPayment, type StaffSales, type StaffSalesEntry, type StateConfig, type StateConfigFragment, type StateDefinition, type StatePair, type StateSchema, type StateTransitionBlockedPayload, type StateTransitionCompletedPayload, StationStatus, type StoredStateConfig, StripeCurrencyCode, StripeStatus, type TaxBreakdown, type TaxBreakdownRateEntry, type TaxBreakdownSection, type TaxBreakdownSubtotal, type TaxesTuple, TimePeriod, type TipEntry, type TipsBreakdown, type TipsTuple, TopMetericsSort, type TransitionBlockedBy, type TransitionConditionSet, type TransitionOrderStateParams, type TransitionOrderStateResponse, type TransitionPath, type TransitionRequest, type TransitionResult, UserTypes, addAmounts, amountToString, baseFulfillmentDefinitions, basePaymentDefinitions, buildOrderContext, buildPosPresetConfig, buildResolvedConfig, calculatePercentage, canTransition, conditionSummary, convertFixedFeeToLocalCurrency, createAmount, crossAxisRuleApplies, deriveDisplayState, displayRuleMatchesPair, divideAmount, evaluateCondition, evaluateConditionSet, formatCurrency, formatMinorUnitsToString, fromMinorUnits, generateMongoID, getAvailableTransitions, getCountriesByRegion, getCurrencyConfig, getCurrentISODate, getFinancialInvariantViolations, getMinorUnitMultiplier, getMinorUnits, getPricingRegionFromCountry, inferStatesFromLegacyStatus, isConditionOperator, isFulfillmentState, isPaymentState, isSupportedCurrency, mapToLegacyStatus, mergeFragment, multiplyAmount, normalizeMongoIdString, parseAmountToMinorUnits, parseCurrencyCode, parseStripeCurrencyCode, removeFragment, resolveTemplate, setOrderState, signReportForDisplay, stringifyMinorUnits, subtractAmounts, toMinorUnits, validateConfig, validateFragmentCompatibility, violatesFinancialInvariant };
1096
+ export { type Amount, AttributeType, type AvailableTransition, CONDITION_OPERATORS, COUNTRY_CURRENCIES, CURRENCY_CONFIG, type CartDiscountBucket, type CartFeeBucket, type CashDrawer, type CashRoundingTuple, CompanyType, type Condition, type ConditionGroup, type ConditionOperator, type ConfigUpdatedPayload, type ConfigValidationError, type ConfigValidationResult, type ConfigValidationWarning, type CrossAxisRequires, type CrossAxisRule, type CrossAxisTrigger, CurrencyCode, type CurrencyConfig, type CurrencyRate, CustomTableAvailability, CustomerPlatform, DEFAULT_CONFIG, DEFAULT_CROSS_AXIS_RULES, DEFAULT_DISPLAY_STATE_MAP, DEFAULT_RESOLVED_CONFIG, type DeleteStateConfigFragmentParams, type DeleteStateConfigFragmentResponse, type DiscountsBreakdown, type DiscountsTuple, type DisplayStateResult, type DisplayStateRule, DualWriteStrategy, EUFixedRates, EUROPE, type EndOfSessionReport, ExtensionCategory, FINANCIAL_INVARIANTS, FULFILLMENT_STATES, type FailedCondition, type FeesBreakdown, FeesCustomBillingStatus, type FeesTuple, type FinancialInvariant, type FragmentParam, type FragmentValidationResult, type FulfillmentState, type FulfillmentStateDefinition, type FulfillmentTransitionPath, type GetAvailableTransitionsParams, type GetAvailableTransitionsResponse, type GetOrderDisplayStateParams, type GetOrderDisplayStateResponse, type GetOrderStateConfigParams, type GetOrderStateConfigResponse, type GetStateConfigFragmentParams, type GetStateConfigFragmentResponse, InventoryBaseActionEnum, type InventoryBaseActionType, InventorySpecificActionType, InvoiceStatus, LegacyWriteStrategy, LibraryItemType, MenuProject, NAFixedRates, NORTH_AMERICA, NonRevenueItemType, ORDER_STATE_ACTIONS, ORDER_STATE_EVENTS, ORDER_STATE_TOPIC, type OrderContext, type OrderLikeForContext, type OrderLikeForLegacyInference, type OrderLineItem, type OrderMutationData, type OrderPaymentMethod, OrderPlatform, type OrderRefund, type OrderStateEventPayload, type OrderStateWritable, type OrderWriteStrategy, OtherFixedRates, OwnerType, PATH_MODES, PAYMENT_STATES, POS_VALID_INITIAL_STATES, type PathMode, PaymentMethod, type PaymentState, type PaymentStateDefinition, type PaymentTransitionPath, Platform, PreviewImageMode, PricingLevel, PricingPlanEnum, PricingRegionEnum, type ProductDiscountBucket, type ProductFeeBucket, ProductStatus, ProductType, PublicationAvailability, type PublicationConfig, PublicationStatus, REGION_MAPPING, REPORT_NEGATE_PATHS, ReceiptSendChannel, ReceiptType, type RefundsBreakdown, ResidualPaymentMethod, ResidualStatus, type ResolveTemplateResult, STATE_SCHEMA, STRIPE_SUPPORTED_COUNTRIES, type SalesSummary, type SaveStateConfigFragmentParams, type SaveStateConfigFragmentResponse, type SettlementBreakdown, type SettlementCardSection, type SettlementCashSection, type SettlementCustomEntry, type SplitPayment, type SplitPaymentPayment, type StaffSales, type StaffSalesEntry, type StateConfig, type StateConfigFragment, type StateDefinition, type StatePair, type StateSchema, type StateTransitionBlockedPayload, type StateTransitionCompletedPayload, StationStatus, type StoredStateConfig, StripeCurrencyCode, StripeStatus, type TaxBreakdown, type TaxBreakdownRateEntry, type TaxBreakdownSection, type TaxBreakdownSubtotal, type TaxesTuple, TimePeriod, type TipEntry, type TipsBreakdown, type TipsTuple, TopMetericsSort, type TransitionBlockedBy, type TransitionConditionSet, type TransitionOrderStateParams, type TransitionOrderStateResponse, type TransitionPath, type TransitionRequest, type TransitionResult, UserTypes, addAmounts, amountToString, baseFulfillmentDefinitions, basePaymentDefinitions, buildOrderContext, buildPosPresetConfig, buildResolvedConfig, calculatePercentage, canTransition, conditionSummary, convertFixedFeeToLocalCurrency, createAmount, crossAxisRuleApplies, deriveDisplayState, displayRuleMatchesPair, divideAmount, evaluateCondition, evaluateConditionSet, formatCurrency, formatMinorUnitsToString, fromMinorUnits, generateMongoID, getAvailableTransitions, getCountriesByRegion, getCurrencyConfig, getCurrentISODate, getFinancialInvariantViolations, getMinorUnitMultiplier, getMinorUnits, getPricingRegionFromCountry, inferStatesFromLegacyStatus, isConditionOperator, isFulfillmentState, isPaymentState, isSupportedCurrency, mapToLegacyStatus, mergeFragment, multiplyAmount, normalizeMongoIdString, parseAmountToMinorUnits, parseCurrencyCode, parseStripeCurrencyCode, removeFragment, resolveTemplate, setOrderState, signReportForDisplay, stringifyMinorUnits, subtractAmounts, toMinorUnits, validateConfig, validateFragmentCompatibility, violatesFinancialInvariant };
package/dist/index.d.ts CHANGED
@@ -189,7 +189,8 @@ declare enum Platform {
189
189
  }
190
190
  declare enum OrderPlatform {
191
191
  POS = "in-store",
192
- WOO_COMMERCE = "woo-commerce"
192
+ WOO_COMMERCE = "woo-commerce",
193
+ PUBLIC_API = "public-api"
193
194
  }
194
195
  declare enum CustomerPlatform {
195
196
  POS = "in-store",
@@ -899,7 +900,6 @@ declare const DEFAULT_CONFIG: StoredStateConfig;
899
900
  declare function buildResolvedConfig(config: StoredStateConfig): StateConfig;
900
901
  declare const DEFAULT_RESOLVED_CONFIG: StateConfig;
901
902
 
902
- declare const POS_CROSS_AXIS_RULES: readonly CrossAxisRule[];
903
903
  declare const POS_VALID_INITIAL_STATES: readonly StatePair[];
904
904
  declare function buildPosPresetConfig(companyId?: string): StoredStateConfig;
905
905
 
@@ -933,6 +933,40 @@ declare function setOrderState(order: OrderStateWritable, paymentState: PaymentS
933
933
 
934
934
  declare function inferStatesFromLegacyStatus(order: OrderLikeForLegacyInference): StatePair;
935
935
 
936
+ interface OrderMutationData extends OrderStateWritable {
937
+ total?: number;
938
+ balance?: number;
939
+ paymentMethods?: {
940
+ amount?: number;
941
+ [key: string]: unknown;
942
+ }[];
943
+ refunds?: {
944
+ quantity?: number;
945
+ [key: string]: unknown;
946
+ }[];
947
+ refund?: {
948
+ quantity?: number;
949
+ [key: string]: unknown;
950
+ }[];
951
+ lineItems?: {
952
+ quantity?: number;
953
+ fulfilledQuantity?: number;
954
+ returnedQuantity?: number;
955
+ [key: string]: unknown;
956
+ }[];
957
+ }
958
+ interface OrderWriteStrategy {
959
+ applyState(order: OrderMutationData): void;
960
+ }
961
+ declare class LegacyWriteStrategy implements OrderWriteStrategy {
962
+ applyState(_order: OrderMutationData): void;
963
+ }
964
+ declare class DualWriteStrategy implements OrderWriteStrategy {
965
+ private readonly config;
966
+ constructor(config: StoredStateConfig);
967
+ applyState(order: OrderMutationData): void;
968
+ }
969
+
936
970
  interface ResolveTemplateResult {
937
971
  fragment: StateConfigFragment;
938
972
  resolvedValues: Record<string, unknown>;
@@ -1059,4 +1093,4 @@ declare const EUFixedRates: Record<string, CurrencyRate>;
1059
1093
  declare const OtherFixedRates: Record<string, CurrencyRate>;
1060
1094
  declare const COUNTRY_CURRENCIES: Record<string, string>;
1061
1095
 
1062
- export { type Amount, AttributeType, type AvailableTransition, CONDITION_OPERATORS, COUNTRY_CURRENCIES, CURRENCY_CONFIG, type CartDiscountBucket, type CartFeeBucket, type CashDrawer, type CashRoundingTuple, CompanyType, type Condition, type ConditionGroup, type ConditionOperator, type ConfigUpdatedPayload, type ConfigValidationError, type ConfigValidationResult, type ConfigValidationWarning, type CrossAxisRequires, type CrossAxisRule, type CrossAxisTrigger, CurrencyCode, type CurrencyConfig, type CurrencyRate, CustomTableAvailability, CustomerPlatform, DEFAULT_CONFIG, DEFAULT_CROSS_AXIS_RULES, DEFAULT_DISPLAY_STATE_MAP, DEFAULT_RESOLVED_CONFIG, type DeleteStateConfigFragmentParams, type DeleteStateConfigFragmentResponse, type DiscountsBreakdown, type DiscountsTuple, type DisplayStateResult, type DisplayStateRule, EUFixedRates, EUROPE, type EndOfSessionReport, ExtensionCategory, FINANCIAL_INVARIANTS, FULFILLMENT_STATES, type FailedCondition, type FeesBreakdown, FeesCustomBillingStatus, type FeesTuple, type FinancialInvariant, type FragmentParam, type FragmentValidationResult, type FulfillmentState, type FulfillmentStateDefinition, type FulfillmentTransitionPath, type GetAvailableTransitionsParams, type GetAvailableTransitionsResponse, type GetOrderDisplayStateParams, type GetOrderDisplayStateResponse, type GetOrderStateConfigParams, type GetOrderStateConfigResponse, type GetStateConfigFragmentParams, type GetStateConfigFragmentResponse, InventoryBaseActionEnum, type InventoryBaseActionType, InventorySpecificActionType, InvoiceStatus, LibraryItemType, MenuProject, NAFixedRates, NORTH_AMERICA, NonRevenueItemType, ORDER_STATE_ACTIONS, ORDER_STATE_EVENTS, ORDER_STATE_TOPIC, type OrderContext, type OrderLikeForContext, type OrderLikeForLegacyInference, type OrderLineItem, type OrderPaymentMethod, OrderPlatform, type OrderRefund, type OrderStateEventPayload, type OrderStateWritable, OtherFixedRates, OwnerType, PATH_MODES, PAYMENT_STATES, POS_CROSS_AXIS_RULES, POS_VALID_INITIAL_STATES, type PathMode, PaymentMethod, type PaymentState, type PaymentStateDefinition, type PaymentTransitionPath, Platform, PreviewImageMode, PricingLevel, PricingPlanEnum, PricingRegionEnum, type ProductDiscountBucket, type ProductFeeBucket, ProductStatus, ProductType, PublicationAvailability, type PublicationConfig, PublicationStatus, REGION_MAPPING, REPORT_NEGATE_PATHS, ReceiptSendChannel, ReceiptType, type RefundsBreakdown, ResidualPaymentMethod, ResidualStatus, type ResolveTemplateResult, STATE_SCHEMA, STRIPE_SUPPORTED_COUNTRIES, type SalesSummary, type SaveStateConfigFragmentParams, type SaveStateConfigFragmentResponse, type SettlementBreakdown, type SettlementCardSection, type SettlementCashSection, type SettlementCustomEntry, type SplitPayment, type SplitPaymentPayment, type StaffSales, type StaffSalesEntry, type StateConfig, type StateConfigFragment, type StateDefinition, type StatePair, type StateSchema, type StateTransitionBlockedPayload, type StateTransitionCompletedPayload, StationStatus, type StoredStateConfig, StripeCurrencyCode, StripeStatus, type TaxBreakdown, type TaxBreakdownRateEntry, type TaxBreakdownSection, type TaxBreakdownSubtotal, type TaxesTuple, TimePeriod, type TipEntry, type TipsBreakdown, type TipsTuple, TopMetericsSort, type TransitionBlockedBy, type TransitionConditionSet, type TransitionOrderStateParams, type TransitionOrderStateResponse, type TransitionPath, type TransitionRequest, type TransitionResult, UserTypes, addAmounts, amountToString, baseFulfillmentDefinitions, basePaymentDefinitions, buildOrderContext, buildPosPresetConfig, buildResolvedConfig, calculatePercentage, canTransition, conditionSummary, convertFixedFeeToLocalCurrency, createAmount, crossAxisRuleApplies, deriveDisplayState, displayRuleMatchesPair, divideAmount, evaluateCondition, evaluateConditionSet, formatCurrency, formatMinorUnitsToString, fromMinorUnits, generateMongoID, getAvailableTransitions, getCountriesByRegion, getCurrencyConfig, getCurrentISODate, getFinancialInvariantViolations, getMinorUnitMultiplier, getMinorUnits, getPricingRegionFromCountry, inferStatesFromLegacyStatus, isConditionOperator, isFulfillmentState, isPaymentState, isSupportedCurrency, mapToLegacyStatus, mergeFragment, multiplyAmount, normalizeMongoIdString, parseAmountToMinorUnits, parseCurrencyCode, parseStripeCurrencyCode, removeFragment, resolveTemplate, setOrderState, signReportForDisplay, stringifyMinorUnits, subtractAmounts, toMinorUnits, validateConfig, validateFragmentCompatibility, violatesFinancialInvariant };
1096
+ export { type Amount, AttributeType, type AvailableTransition, CONDITION_OPERATORS, COUNTRY_CURRENCIES, CURRENCY_CONFIG, type CartDiscountBucket, type CartFeeBucket, type CashDrawer, type CashRoundingTuple, CompanyType, type Condition, type ConditionGroup, type ConditionOperator, type ConfigUpdatedPayload, type ConfigValidationError, type ConfigValidationResult, type ConfigValidationWarning, type CrossAxisRequires, type CrossAxisRule, type CrossAxisTrigger, CurrencyCode, type CurrencyConfig, type CurrencyRate, CustomTableAvailability, CustomerPlatform, DEFAULT_CONFIG, DEFAULT_CROSS_AXIS_RULES, DEFAULT_DISPLAY_STATE_MAP, DEFAULT_RESOLVED_CONFIG, type DeleteStateConfigFragmentParams, type DeleteStateConfigFragmentResponse, type DiscountsBreakdown, type DiscountsTuple, type DisplayStateResult, type DisplayStateRule, DualWriteStrategy, EUFixedRates, EUROPE, type EndOfSessionReport, ExtensionCategory, FINANCIAL_INVARIANTS, FULFILLMENT_STATES, type FailedCondition, type FeesBreakdown, FeesCustomBillingStatus, type FeesTuple, type FinancialInvariant, type FragmentParam, type FragmentValidationResult, type FulfillmentState, type FulfillmentStateDefinition, type FulfillmentTransitionPath, type GetAvailableTransitionsParams, type GetAvailableTransitionsResponse, type GetOrderDisplayStateParams, type GetOrderDisplayStateResponse, type GetOrderStateConfigParams, type GetOrderStateConfigResponse, type GetStateConfigFragmentParams, type GetStateConfigFragmentResponse, InventoryBaseActionEnum, type InventoryBaseActionType, InventorySpecificActionType, InvoiceStatus, LegacyWriteStrategy, LibraryItemType, MenuProject, NAFixedRates, NORTH_AMERICA, NonRevenueItemType, ORDER_STATE_ACTIONS, ORDER_STATE_EVENTS, ORDER_STATE_TOPIC, type OrderContext, type OrderLikeForContext, type OrderLikeForLegacyInference, type OrderLineItem, type OrderMutationData, type OrderPaymentMethod, OrderPlatform, type OrderRefund, type OrderStateEventPayload, type OrderStateWritable, type OrderWriteStrategy, OtherFixedRates, OwnerType, PATH_MODES, PAYMENT_STATES, POS_VALID_INITIAL_STATES, type PathMode, PaymentMethod, type PaymentState, type PaymentStateDefinition, type PaymentTransitionPath, Platform, PreviewImageMode, PricingLevel, PricingPlanEnum, PricingRegionEnum, type ProductDiscountBucket, type ProductFeeBucket, ProductStatus, ProductType, PublicationAvailability, type PublicationConfig, PublicationStatus, REGION_MAPPING, REPORT_NEGATE_PATHS, ReceiptSendChannel, ReceiptType, type RefundsBreakdown, ResidualPaymentMethod, ResidualStatus, type ResolveTemplateResult, STATE_SCHEMA, STRIPE_SUPPORTED_COUNTRIES, type SalesSummary, type SaveStateConfigFragmentParams, type SaveStateConfigFragmentResponse, type SettlementBreakdown, type SettlementCardSection, type SettlementCashSection, type SettlementCustomEntry, type SplitPayment, type SplitPaymentPayment, type StaffSales, type StaffSalesEntry, type StateConfig, type StateConfigFragment, type StateDefinition, type StatePair, type StateSchema, type StateTransitionBlockedPayload, type StateTransitionCompletedPayload, StationStatus, type StoredStateConfig, StripeCurrencyCode, StripeStatus, type TaxBreakdown, type TaxBreakdownRateEntry, type TaxBreakdownSection, type TaxBreakdownSubtotal, type TaxesTuple, TimePeriod, type TipEntry, type TipsBreakdown, type TipsTuple, TopMetericsSort, type TransitionBlockedBy, type TransitionConditionSet, type TransitionOrderStateParams, type TransitionOrderStateResponse, type TransitionPath, type TransitionRequest, type TransitionResult, UserTypes, addAmounts, amountToString, baseFulfillmentDefinitions, basePaymentDefinitions, buildOrderContext, buildPosPresetConfig, buildResolvedConfig, calculatePercentage, canTransition, conditionSummary, convertFixedFeeToLocalCurrency, createAmount, crossAxisRuleApplies, deriveDisplayState, displayRuleMatchesPair, divideAmount, evaluateCondition, evaluateConditionSet, formatCurrency, formatMinorUnitsToString, fromMinorUnits, generateMongoID, getAvailableTransitions, getCountriesByRegion, getCurrencyConfig, getCurrentISODate, getFinancialInvariantViolations, getMinorUnitMultiplier, getMinorUnits, getPricingRegionFromCountry, inferStatesFromLegacyStatus, isConditionOperator, isFulfillmentState, isPaymentState, isSupportedCurrency, mapToLegacyStatus, mergeFragment, multiplyAmount, normalizeMongoIdString, parseAmountToMinorUnits, parseCurrencyCode, parseStripeCurrencyCode, removeFragment, resolveTemplate, setOrderState, signReportForDisplay, stringifyMinorUnits, subtractAmounts, toMinorUnits, validateConfig, validateFragmentCompatibility, violatesFinancialInvariant };
package/dist/index.js CHANGED
@@ -31,6 +31,7 @@ __export(index_exports, {
31
31
  DEFAULT_CROSS_AXIS_RULES: () => DEFAULT_CROSS_AXIS_RULES,
32
32
  DEFAULT_DISPLAY_STATE_MAP: () => DEFAULT_DISPLAY_STATE_MAP,
33
33
  DEFAULT_RESOLVED_CONFIG: () => DEFAULT_RESOLVED_CONFIG,
34
+ DualWriteStrategy: () => DualWriteStrategy,
34
35
  EUFixedRates: () => EUFixedRates,
35
36
  EUROPE: () => EUROPE,
36
37
  ExtensionCategory: () => ExtensionCategory,
@@ -40,6 +41,7 @@ __export(index_exports, {
40
41
  InventoryBaseActionEnum: () => InventoryBaseActionEnum,
41
42
  InventorySpecificActionType: () => InventorySpecificActionType,
42
43
  InvoiceStatus: () => InvoiceStatus,
44
+ LegacyWriteStrategy: () => LegacyWriteStrategy,
43
45
  LibraryItemType: () => LibraryItemType,
44
46
  MenuProject: () => MenuProject,
45
47
  NAFixedRates: () => NAFixedRates,
@@ -53,7 +55,6 @@ __export(index_exports, {
53
55
  OwnerType: () => OwnerType,
54
56
  PATH_MODES: () => PATH_MODES,
55
57
  PAYMENT_STATES: () => PAYMENT_STATES,
56
- POS_CROSS_AXIS_RULES: () => POS_CROSS_AXIS_RULES,
57
58
  POS_VALID_INITIAL_STATES: () => POS_VALID_INITIAL_STATES,
58
59
  PaymentMethod: () => PaymentMethod,
59
60
  Platform: () => Platform,
@@ -335,6 +336,7 @@ var Platform = /* @__PURE__ */ ((Platform2) => {
335
336
  var OrderPlatform = /* @__PURE__ */ ((OrderPlatform2) => {
336
337
  OrderPlatform2["POS"] = "in-store";
337
338
  OrderPlatform2["WOO_COMMERCE"] = "woo-commerce";
339
+ OrderPlatform2["PUBLIC_API"] = "public-api";
338
340
  return OrderPlatform2;
339
341
  })(OrderPlatform || {});
340
342
  var CustomerPlatform = /* @__PURE__ */ ((CustomerPlatform2) => {
@@ -1132,10 +1134,7 @@ function negateAtPaths(value, path, paths) {
1132
1134
  function padHex(value, length) {
1133
1135
  return value.toString(16).padStart(length, "0");
1134
1136
  }
1135
- var PROCESS_RANDOM = Array.from(
1136
- { length: 5 },
1137
- () => padHex(Math.floor(Math.random() * 256), 2)
1138
- ).join("");
1137
+ var PROCESS_RANDOM = Array.from({ length: 5 }, () => padHex(Math.floor(Math.random() * 256), 2)).join("");
1139
1138
  var objectIdCounter = Math.floor(Math.random() * 16777215);
1140
1139
  function generateMongoID() {
1141
1140
  const timestamp = padHex(Math.floor(Date.now() / 1e3), 8);
@@ -1353,12 +1352,8 @@ var DEFAULT_CROSS_AXIS_RULES = [
1353
1352
 
1354
1353
  // order-state-machine/default-config.ts
1355
1354
  var DEFAULT_EPOCH = /* @__PURE__ */ new Date(0);
1356
- var PAYMENT_LABELS = new Map(
1357
- basePaymentDefinitions().map((d) => [d.id, d.label])
1358
- );
1359
- var FULFILLMENT_LABELS = new Map(
1360
- baseFulfillmentDefinitions().map((d) => [d.id, d.label])
1361
- );
1355
+ var PAYMENT_LABELS = new Map(basePaymentDefinitions().map((d) => [d.id, d.label]));
1356
+ var FULFILLMENT_LABELS = new Map(baseFulfillmentDefinitions().map((d) => [d.id, d.label]));
1362
1357
  var TERMINAL_PAYMENT_STATES = new Set(
1363
1358
  basePaymentDefinitions().filter((d) => d.isTerminal).map((d) => d.id)
1364
1359
  );
@@ -1402,7 +1397,7 @@ var DEFAULT_CONFIG = {
1402
1397
  fulfillmentPaths: [],
1403
1398
  paymentPathMode: "permissive",
1404
1399
  fulfillmentPathMode: "permissive",
1405
- crossAxisRules: [...DEFAULT_CROSS_AXIS_RULES],
1400
+ crossAxisRules: [],
1406
1401
  transitionConditions: [],
1407
1402
  validInitialStates: [{ payment: "unpaid", fulfillment: "draft" }],
1408
1403
  displayStateMap: [...DEFAULT_DISPLAY_STATE_MAP],
@@ -1419,19 +1414,6 @@ function buildResolvedConfig(config) {
1419
1414
  var DEFAULT_RESOLVED_CONFIG = buildResolvedConfig(DEFAULT_CONFIG);
1420
1415
 
1421
1416
  // order-state-machine/pos-preset.ts
1422
- var POS_CROSS_AXIS_RULES = [
1423
- {
1424
- id: "pos-pay-requires-open-fulfillment",
1425
- label: "Payments only on open fulfillment states",
1426
- description: "POS payments are only valid on orders whose fulfillment is open (draft / pending / on_hold) or auto-fulfilled in lock-step (fulfilled). Returned / cancelled / in-progress fulfillment must use refund flows instead.",
1427
- enabled: true,
1428
- trigger: { axis: "payment", to: ["payment_pending", "paid", "partially_paid"] },
1429
- requires: {
1430
- axis: "fulfillment",
1431
- states: ["draft", "pending", "on_hold", "fulfilled"]
1432
- }
1433
- }
1434
- ];
1435
1417
  var POS_VALID_INITIAL_STATES = [
1436
1418
  { payment: "unpaid", fulfillment: "draft" },
1437
1419
  { payment: "unpaid", fulfillment: "on_hold" },
@@ -1446,7 +1428,7 @@ function buildPosPresetConfig(companyId) {
1446
1428
  _id: "pos-preset",
1447
1429
  companyId: companyId ?? DEFAULT_CONFIG.companyId,
1448
1430
  name: "POS Preset",
1449
- crossAxisRules: [...DEFAULT_CROSS_AXIS_RULES, ...POS_CROSS_AXIS_RULES],
1431
+ crossAxisRules: [],
1450
1432
  validInitialStates: [...POS_VALID_INITIAL_STATES],
1451
1433
  displayStateMap: [...DEFAULT_DISPLAY_STATE_MAP]
1452
1434
  };
@@ -2283,6 +2265,27 @@ function inferStatesFromLegacyStatus(order) {
2283
2265
  return { payment: "unpaid", fulfillment: "pending" };
2284
2266
  }
2285
2267
 
2268
+ // order-state-machine/write-strategy.ts
2269
+ var LegacyWriteStrategy = class {
2270
+ applyState(_order) {
2271
+ }
2272
+ };
2273
+ var DualWriteStrategy = class {
2274
+ constructor(config) {
2275
+ this.config = config;
2276
+ }
2277
+ applyState(order) {
2278
+ if (order.paymentState && order.fulfillmentState) {
2279
+ setOrderState(order, order.paymentState, order.fulfillmentState, this.config);
2280
+ return;
2281
+ }
2282
+ if (order.status) {
2283
+ const inferred = inferStatesFromLegacyStatus(order);
2284
+ setOrderState(order, inferred.payment, inferred.fulfillment, this.config);
2285
+ }
2286
+ }
2287
+ };
2288
+
2286
2289
  // order-state-machine/resolve-template.ts
2287
2290
  function resolveTemplate(templateJson, params, values = {}) {
2288
2291
  const resolvedValues = {};
@@ -2598,6 +2601,7 @@ var ORDER_STATE_EVENTS = {
2598
2601
  DEFAULT_CROSS_AXIS_RULES,
2599
2602
  DEFAULT_DISPLAY_STATE_MAP,
2600
2603
  DEFAULT_RESOLVED_CONFIG,
2604
+ DualWriteStrategy,
2601
2605
  EUFixedRates,
2602
2606
  EUROPE,
2603
2607
  ExtensionCategory,
@@ -2607,6 +2611,7 @@ var ORDER_STATE_EVENTS = {
2607
2611
  InventoryBaseActionEnum,
2608
2612
  InventorySpecificActionType,
2609
2613
  InvoiceStatus,
2614
+ LegacyWriteStrategy,
2610
2615
  LibraryItemType,
2611
2616
  MenuProject,
2612
2617
  NAFixedRates,
@@ -2620,7 +2625,6 @@ var ORDER_STATE_EVENTS = {
2620
2625
  OwnerType,
2621
2626
  PATH_MODES,
2622
2627
  PAYMENT_STATES,
2623
- POS_CROSS_AXIS_RULES,
2624
2628
  POS_VALID_INITIAL_STATES,
2625
2629
  PaymentMethod,
2626
2630
  Platform,