karrio-eshipper 2025.5.4__py3-none-any.whl → 2025.5.5__py3-none-any.whl

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.
@@ -2,6 +2,7 @@ import datetime
2
2
  import karrio.lib as lib
3
3
  import karrio.core as core
4
4
  import karrio.core.errors as errors
5
+ import karrio.core.models as models
5
6
 
6
7
 
7
8
  class Settings(core.Settings):
@@ -26,19 +27,13 @@ class Settings(core.Settings):
26
27
  or collect it from the cache if an unexpired "token" exist.
27
28
  """
28
29
  cache_key = f"{self.carrier_name}|{self.principal}|{self.credential}"
29
- now = datetime.datetime.now() + datetime.timedelta(minutes=30)
30
30
 
31
- auth = self.connection_cache.get(cache_key) or {}
32
- token = auth.get("token")
33
- expiry = lib.to_date(auth.get("expiry"), current_format="%Y-%m-%d %H:%M:%S")
34
-
35
- if token is not None and expiry is not None and expiry > now:
36
- return token
37
-
38
- self.connection_cache.set(cache_key, lambda: login(self))
39
- new_auth = self.connection_cache.get(cache_key)
40
-
41
- return new_auth["token"]
31
+ return self.connection_cache.thread_safe(
32
+ refresh_func=lambda: login(self),
33
+ cache_key=cache_key,
34
+ buffer_minutes=30,
35
+ token_field="token",
36
+ ).get_state()
42
37
 
43
38
 
44
39
  def login(settings: Settings):
@@ -70,6 +65,19 @@ def login(settings: Settings):
70
65
  if any(messages):
71
66
  raise errors.ParsedMessagesError(messages=messages)
72
67
 
68
+ # Validate that token is present in the response
69
+ if "token" not in response:
70
+ raise errors.ParsedMessagesError(
71
+ messages=[
72
+ models.Message(
73
+ carrier_name=settings.carrier_name,
74
+ carrier_id=settings.carrier_id,
75
+ message="Authentication failed: No token received",
76
+ code="AUTH_ERROR",
77
+ )
78
+ ]
79
+ )
80
+
73
81
  expiry = datetime.datetime.now() + datetime.timedelta(
74
82
  seconds=float(response.get("expires_in", 0))
75
83
  )
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: karrio_eshipper
3
- Version: 2025.5.4
3
+ Version: 2025.5.5
4
4
  Summary: Karrio - eShipper Shipping Extension
5
5
  Author-email: karrio <hello@karrio.io>
6
6
  License-Expression: LGPL-3.0
@@ -9,7 +9,7 @@ karrio/providers/eshipper/metadata.json,sha256=KBae69ntmCIkZ0dKrAX0vjkm1CyE9UwvI
9
9
  karrio/providers/eshipper/rate.py,sha256=r0OTKeXFXmaWdi7XcNDNQ0wL5R1idQAnNhMtXTRfpPM,7184
10
10
  karrio/providers/eshipper/tracking.py,sha256=46DVFj8iMLWSsi0f5irTzFpH0uArZtya4eyYh5LkdFQ,2452
11
11
  karrio/providers/eshipper/units.py,sha256=CTi0NbWEpVc-GwPEKrtGVR7VEEV9Ij0odaQTUacwgyc,9658
12
- karrio/providers/eshipper/utils.py,sha256=kvFkCL1aSAn8gAp3GbKuyPoz0ceVwvsJ0FfgRbjJ0Kw,2187
12
+ karrio/providers/eshipper/utils.py,sha256=0Ok4BNFe4KoNNtCNjp6FLUfR8iwfuaMSh_jZRsPK4KE,2381
13
13
  karrio/providers/eshipper/shipment/__init__.py,sha256=oPCX3bykNDVeczan1tbmSpuOtFYTtd6h8J9otYVDQqQ,233
14
14
  karrio/providers/eshipper/shipment/cancel.py,sha256=vdxMmK7AmI-xOn62NlaMzCCKQ8CBql8QBVPft0VQWn0,1317
15
15
  karrio/providers/eshipper/shipment/create.py,sha256=jL4RWdtYOmpofcGVYn-7l2rstMvXK-DKoIAe_TjCBkY,11632
@@ -26,8 +26,8 @@ karrio/schemas/eshipper/shipping_request.py,sha256=OrqSutwyzTj-iau3LDPJUEGBRzzV9
26
26
  karrio/schemas/eshipper/shipping_response.py,sha256=RdMXh9goyTrH2qdU_5KMDIAWAEDzMchy_e5f45k-zxs,3892
27
27
  karrio/schemas/eshipper/tracking_request.py,sha256=EAE7PJFp2rTYCXMQJ6Kg-hMs3vL-GSTFjhHvzSmMzPg,252
28
28
  karrio/schemas/eshipper/tracking_response.py,sha256=2m9doy3y5f6zdA-gbNfsw8rp0oqs3eYrgw8Por_1fjE,2219
29
- karrio_eshipper-2025.5.4.dist-info/METADATA,sha256=fGqds_j7brnLsox7GBd-5imT0as1C2tewcVpnoU_Inc,997
30
- karrio_eshipper-2025.5.4.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
31
- karrio_eshipper-2025.5.4.dist-info/entry_points.txt,sha256=u9RQVmPE2uC3-aL85DnlIHdsHAWYkOnwTAfJvi2--DY,61
32
- karrio_eshipper-2025.5.4.dist-info/top_level.txt,sha256=FZCY8Nwft8oEGHdl--xku8P3TrnOxu5dETEU_fWpRSM,20
33
- karrio_eshipper-2025.5.4.dist-info/RECORD,,
29
+ karrio_eshipper-2025.5.5.dist-info/METADATA,sha256=E87qoZTFew46VEoaeEAmfLUjq8hGN2FCHAEcn4qzIOk,997
30
+ karrio_eshipper-2025.5.5.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
31
+ karrio_eshipper-2025.5.5.dist-info/entry_points.txt,sha256=u9RQVmPE2uC3-aL85DnlIHdsHAWYkOnwTAfJvi2--DY,61
32
+ karrio_eshipper-2025.5.5.dist-info/top_level.txt,sha256=FZCY8Nwft8oEGHdl--xku8P3TrnOxu5dETEU_fWpRSM,20
33
+ karrio_eshipper-2025.5.5.dist-info/RECORD,,