stateset_embedded 0.1.7 → 0.1.9

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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/Cargo.toml +1 -1
  3. data/src/lib.rs +43 -29
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0fc4a1572ef2951935acd2e63a27611d97151372895d06e92eac27c8d58228a8
4
- data.tar.gz: e0a5ae23bcf0f5719b643806e106f9679b8d4071907dc6521bad5eb9f4ce1902
3
+ metadata.gz: 90bc03db87ee9d6aae7e53996ad67e9e4b9b85216be0360f52fea8b696d5c3a3
4
+ data.tar.gz: 7f46e4d91c2863ba38cbc704e4eef3e54623eb2ef286b1aa60101975c0318cfc
5
5
  SHA512:
6
- metadata.gz: 215702b966954fcbc954fed5ad790052987b7cb0ab9a9a2096369e5cf241dbd04486eb6c4147d7f50c0928ac118dc853606d0cf282d0277d668da94011615522
7
- data.tar.gz: e4e079955b052f3f903452689b408482ce6c3c50e9d24a4718beca60539f88d346a5f9135c64bc99b2c01e8ae8ab90b978dd1f5550fc633873cc5411df8c5a23
6
+ metadata.gz: 2897e8ec4960df34cc126356790ded18352c7b0ff74ffafcaf7658d524b8ea032e0294ba1460dc05048b87b1db2a69a1e51e6e9f12c6518d044877b7439929ea
7
+ data.tar.gz: f23912919bdcf202fda78881bee2d2913465b3ff3ff12846be6fd9320deceae5e6ed02a53fe3b58f26dbc300b5c5db30c7456d61b9302c258cfe31b166dfd852
data/Cargo.toml CHANGED
@@ -1,6 +1,6 @@
1
1
  [package]
2
2
  name = "stateset-embedded-ruby"
3
- version = "0.1.7"
3
+ version = "0.1.9"
4
4
  edition = "2021"
5
5
  description = "Ruby bindings for StateSet Embedded Commerce"
6
6
  license = "MIT OR Apache-2.0"
data/src/lib.rs CHANGED
@@ -41,6 +41,20 @@ macro_rules! parse_uuid {
41
41
  };
42
42
  }
43
43
 
44
+ fn to_f64_or_nan<T>(value: T) -> f64
45
+ where
46
+ T: TryInto<f64>,
47
+ <T as TryInto<f64>>::Error: std::fmt::Display,
48
+ {
49
+ match value.try_into() {
50
+ Ok(converted) => converted,
51
+ Err(err) => {
52
+ eprintln!("stateset-embedded: failed to convert to f64: {}", err);
53
+ f64::NAN
54
+ }
55
+ }
56
+ }
57
+
44
58
  // ============================================================================
45
59
  // Commerce
46
60
  // ============================================================================
@@ -474,7 +488,7 @@ impl From<stateset_core::Order> for Order {
474
488
  order_number: o.order_number,
475
489
  customer_id: o.customer_id.to_string(),
476
490
  status: format!("{}", o.status),
477
- total_amount: o.total_amount.to_f64().unwrap_or(0.0),
491
+ total_amount: to_f64_or_nan(o.total_amount),
478
492
  currency: o.currency,
479
493
  payment_status: format!("{}", o.payment_status),
480
494
  fulfillment_status: format!("{}", o.fulfillment_status),
@@ -487,8 +501,8 @@ impl From<stateset_core::Order> for Order {
487
501
  sku: i.sku,
488
502
  name: i.name,
489
503
  quantity: i.quantity,
490
- unit_price: i.unit_price.to_f64().unwrap_or(0.0),
491
- total: i.total.to_f64().unwrap_or(0.0),
504
+ unit_price: to_f64_or_nan(i.unit_price),
505
+ total: to_f64_or_nan(i.total),
492
506
  })
493
507
  .collect(),
494
508
  version: o.version,
@@ -778,7 +792,7 @@ impl From<stateset_core::Product> for Product {
778
792
  id: v.id.to_string(),
779
793
  sku: v.sku,
780
794
  name: v.name,
781
- price: v.price.to_f64().unwrap_or(0.0),
795
+ price: to_f64_or_nan(v.price),
782
796
  compare_at_price: v.compare_at_price.and_then(|p| p.to_f64()),
783
797
  inventory_quantity: v.inventory_quantity,
784
798
  weight: v.weight.and_then(|w| w.to_f64()),
@@ -884,7 +898,7 @@ impl Products {
884
898
  id: v.id.to_string(),
885
899
  sku: v.sku,
886
900
  name: v.name,
887
- price: v.price.to_f64().unwrap_or(0.0),
901
+ price: to_f64_or_nan(v.price),
888
902
  compare_at_price: v.compare_at_price.and_then(|p| p.to_f64()),
889
903
  inventory_quantity: v.inventory_quantity,
890
904
  weight: v.weight.and_then(|w| w.to_f64()),
@@ -1151,7 +1165,7 @@ impl From<stateset_core::Return> for Return {
1151
1165
  customer_id: r.customer_id.to_string(),
1152
1166
  status: format!("{}", r.status),
1153
1167
  reason: r.reason,
1154
- refund_amount: r.refund_amount.to_f64().unwrap_or(0.0),
1168
+ refund_amount: to_f64_or_nan(r.refund_amount),
1155
1169
  created_at: r.created_at.to_rfc3339(),
1156
1170
  updated_at: r.updated_at.to_rfc3339(),
1157
1171
  }
@@ -1901,7 +1915,7 @@ impl From<stateset_core::PurchaseOrder> for PurchaseOrder {
1901
1915
  po_number: p.po_number,
1902
1916
  supplier_id: p.supplier_id.to_string(),
1903
1917
  status: format!("{}", p.status),
1904
- total_amount: p.total_amount.to_f64().unwrap_or(0.0),
1918
+ total_amount: to_f64_or_nan(p.total_amount),
1905
1919
  currency: p.currency,
1906
1920
  expected_delivery: p.expected_delivery.map(|d| d.to_string()),
1907
1921
  created_at: p.created_at.to_rfc3339(),
@@ -2164,11 +2178,11 @@ impl From<stateset_core::Invoice> for Invoice {
2164
2178
  customer_id: i.customer_id.to_string(),
2165
2179
  order_id: i.order_id.map(|o| o.to_string()),
2166
2180
  status: format!("{}", i.status),
2167
- subtotal: i.subtotal.to_f64().unwrap_or(0.0),
2168
- tax_amount: i.tax_amount.to_f64().unwrap_or(0.0),
2169
- total_amount: i.total_amount.to_f64().unwrap_or(0.0),
2170
- amount_paid: i.amount_paid.to_f64().unwrap_or(0.0),
2171
- amount_due: i.amount_due.to_f64().unwrap_or(0.0),
2181
+ subtotal: to_f64_or_nan(i.subtotal),
2182
+ tax_amount: to_f64_or_nan(i.tax_amount),
2183
+ total_amount: to_f64_or_nan(i.total_amount),
2184
+ amount_paid: to_f64_or_nan(i.amount_paid),
2185
+ amount_due: to_f64_or_nan(i.amount_due),
2172
2186
  currency: i.currency,
2173
2187
  due_date: i.due_date.map(|d| d.to_string()),
2174
2188
  created_at: i.created_at.to_rfc3339(),
@@ -2316,7 +2330,7 @@ impl Invoices {
2316
2330
  format!("Failed to get balance: {}", e),
2317
2331
  )
2318
2332
  })?;
2319
- Ok(balance.to_f64().unwrap_or(0.0))
2333
+ Ok(to_f64_or_nan(balance))
2320
2334
  }
2321
2335
 
2322
2336
  fn count(&self) -> Result<i64, Error> {
@@ -2435,7 +2449,7 @@ impl From<stateset_core::BomComponent> for BomComponent {
2435
2449
  bom_id: c.bom_id.to_string(),
2436
2450
  sku: c.sku,
2437
2451
  name: c.name,
2438
- quantity: c.quantity.to_f64().unwrap_or(0.0),
2452
+ quantity: to_f64_or_nan(c.quantity),
2439
2453
  unit: c.unit,
2440
2454
  }
2441
2455
  }
@@ -2655,8 +2669,8 @@ impl From<stateset_core::WorkOrder> for WorkOrder {
2655
2669
  bom_id: w.bom_id.map(|b| b.to_string()),
2656
2670
  product_id: w.product_id.map(|p| p.to_string()),
2657
2671
  status: format!("{}", w.status),
2658
- quantity_ordered: w.quantity_ordered.to_f64().unwrap_or(0.0),
2659
- quantity_completed: w.quantity_completed.to_f64().unwrap_or(0.0),
2672
+ quantity_ordered: to_f64_or_nan(w.quantity_ordered),
2673
+ quantity_completed: to_f64_or_nan(w.quantity_completed),
2660
2674
  priority: format!("{}", w.priority),
2661
2675
  started_at: w.started_at.map(|d| d.to_rfc3339()),
2662
2676
  completed_at: w.completed_at.map(|d| d.to_rfc3339()),
@@ -2906,12 +2920,12 @@ impl From<stateset_core::Cart> for Cart {
2906
2920
  sku: i.sku,
2907
2921
  name: i.name,
2908
2922
  quantity: i.quantity,
2909
- unit_price: i.unit_price.to_f64().unwrap_or(0.0),
2910
- total: i.total.to_f64().unwrap_or(0.0),
2923
+ unit_price: to_f64_or_nan(i.unit_price),
2924
+ total: to_f64_or_nan(i.total),
2911
2925
  })
2912
2926
  .collect(),
2913
- subtotal: c.subtotal.to_f64().unwrap_or(0.0),
2914
- total: c.total.to_f64().unwrap_or(0.0),
2927
+ subtotal: to_f64_or_nan(c.subtotal),
2928
+ total: to_f64_or_nan(c.total),
2915
2929
  currency: c.currency,
2916
2930
  created_at: c.created_at.to_rfc3339(),
2917
2931
  updated_at: c.updated_at.to_rfc3339(),
@@ -3072,9 +3086,9 @@ impl Analytics {
3072
3086
  })?;
3073
3087
 
3074
3088
  Ok(SalesSummary {
3075
- total_revenue: summary.total_revenue.to_f64().unwrap_or(0.0),
3089
+ total_revenue: to_f64_or_nan(summary.total_revenue),
3076
3090
  total_orders: summary.total_orders,
3077
- average_order_value: summary.average_order_value.to_f64().unwrap_or(0.0),
3091
+ average_order_value: to_f64_or_nan(summary.average_order_value),
3078
3092
  total_items_sold: summary.total_items_sold,
3079
3093
  })
3080
3094
  }
@@ -3122,7 +3136,7 @@ impl From<stateset_core::ExchangeRate> for ExchangeRate {
3122
3136
  id: r.id.to_string(),
3123
3137
  from_currency: format!("{}", r.from_currency),
3124
3138
  to_currency: format!("{}", r.to_currency),
3125
- rate: r.rate.to_f64().unwrap_or(0.0),
3139
+ rate: to_f64_or_nan(r.rate),
3126
3140
  effective_date: r.effective_date.to_string(),
3127
3141
  created_at: r.created_at.to_rfc3339(),
3128
3142
  }
@@ -3200,7 +3214,7 @@ impl CurrencyOps {
3200
3214
  format!("Failed to convert: {}", e),
3201
3215
  )
3202
3216
  })?;
3203
- Ok(result.to_f64().unwrap_or(0.0))
3217
+ Ok(to_f64_or_nan(result))
3204
3218
  }
3205
3219
 
3206
3220
  fn base_currency(&self) -> Result<String, Error> {
@@ -3297,7 +3311,7 @@ impl From<stateset_core::SubscriptionPlan> for SubscriptionPlan {
3297
3311
  code: p.code,
3298
3312
  name: p.name,
3299
3313
  description: p.description,
3300
- price: p.price.to_f64().unwrap_or(0.0),
3314
+ price: to_f64_or_nan(p.price),
3301
3315
  currency: p.currency,
3302
3316
  billing_interval: format!("{}", p.billing_interval),
3303
3317
  trial_days: p.trial_days,
@@ -3649,7 +3663,7 @@ impl From<stateset_core::Promotion> for Promotion {
3649
3663
  name: p.name,
3650
3664
  description: p.description,
3651
3665
  discount_type: format!("{}", p.discount_type),
3652
- discount_value: p.discount_value.to_f64().unwrap_or(0.0),
3666
+ discount_value: to_f64_or_nan(p.discount_value),
3653
3667
  min_purchase: p.min_purchase.and_then(|m| m.to_f64()),
3654
3668
  max_uses: p.max_uses,
3655
3669
  times_used: p.times_used,
@@ -3879,7 +3893,7 @@ impl From<stateset_core::TaxRate> for TaxRate {
3879
3893
  id: r.id.to_string(),
3880
3894
  jurisdiction_id: r.jurisdiction_id.to_string(),
3881
3895
  name: r.name,
3882
- rate: r.rate.to_f64().unwrap_or(0.0),
3896
+ rate: to_f64_or_nan(r.rate),
3883
3897
  category: format!("{}", r.category),
3884
3898
  created_at: r.created_at.to_rfc3339(),
3885
3899
  }
@@ -3923,7 +3937,7 @@ impl Tax {
3923
3937
  format!("Failed to calculate: {}", e),
3924
3938
  )
3925
3939
  })?;
3926
- Ok(result.to_f64().unwrap_or(0.0))
3940
+ Ok(to_f64_or_nan(result))
3927
3941
  }
3928
3942
 
3929
3943
  fn get_effective_rate(
@@ -3949,7 +3963,7 @@ impl Tax {
3949
3963
  format!("Failed to get rate: {}", e),
3950
3964
  )
3951
3965
  })?;
3952
- Ok(rate.to_f64().unwrap_or(0.0))
3966
+ Ok(to_f64_or_nan(rate))
3953
3967
  }
3954
3968
 
3955
3969
  fn list_jurisdictions(&self) -> Result<Vec<TaxJurisdiction>, Error> {
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stateset_embedded
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
4
+ version: 0.1.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - StateSet
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-12-20 00:00:00.000000000 Z
11
+ date: 2026-01-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake