karrio-sapient 2025.5.4__py3-none-any.whl → 2025.5.6__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.
- karrio/providers/sapient/utils.py +32 -18
- {karrio_sapient-2025.5.4.dist-info → karrio_sapient-2025.5.6.dist-info}/METADATA +1 -1
- {karrio_sapient-2025.5.4.dist-info → karrio_sapient-2025.5.6.dist-info}/RECORD +6 -6
- {karrio_sapient-2025.5.4.dist-info → karrio_sapient-2025.5.6.dist-info}/WHEEL +0 -0
- {karrio_sapient-2025.5.4.dist-info → karrio_sapient-2025.5.6.dist-info}/entry_points.txt +0 -0
- {karrio_sapient-2025.5.4.dist-info → karrio_sapient-2025.5.6.dist-info}/top_level.txt +0 -0
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import base64
|
|
2
1
|
import datetime
|
|
3
2
|
import karrio.lib as lib
|
|
4
3
|
import karrio.core as core
|
|
5
4
|
import karrio.core.errors as errors
|
|
5
|
+
import karrio.core.models as models
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
SapientCarrierCode = lib.units.create_enum(
|
|
@@ -46,30 +46,18 @@ class Settings(core.Settings):
|
|
|
46
46
|
option_type=ConnectionConfig,
|
|
47
47
|
)
|
|
48
48
|
|
|
49
|
-
"""uncomment the following code block to implement the oauth login."""
|
|
50
|
-
|
|
51
49
|
@property
|
|
52
50
|
def access_token(self):
|
|
53
51
|
"""Retrieve the access_token using the client_id|client_secret pair
|
|
54
52
|
or collect it from the cache if an unexpired access_token exist.
|
|
55
53
|
"""
|
|
56
54
|
cache_key = f"{self.carrier_name}|{self.client_id}|{self.client_secret}"
|
|
57
|
-
now = datetime.datetime.now() + datetime.timedelta(minutes=30)
|
|
58
|
-
|
|
59
|
-
auth = self.connection_cache.get(cache_key) or {}
|
|
60
|
-
token = auth.get("access_token")
|
|
61
|
-
expiry = lib.to_date(auth.get("expiry"), current_format="%Y-%m-%d %H:%M:%S")
|
|
62
|
-
|
|
63
|
-
if token is not None and expiry is not None and expiry > now:
|
|
64
|
-
return token
|
|
65
|
-
|
|
66
|
-
self.connection_cache.set(cache_key, lambda: login(self))
|
|
67
|
-
new_auth = self.connection_cache.get(cache_key)
|
|
68
|
-
|
|
69
|
-
return new_auth["access_token"]
|
|
70
55
|
|
|
71
|
-
|
|
72
|
-
|
|
56
|
+
return self.connection_cache.thread_safe(
|
|
57
|
+
refresh_func=lambda: login(self),
|
|
58
|
+
cache_key=cache_key,
|
|
59
|
+
buffer_minutes=30,
|
|
60
|
+
).get_state()
|
|
73
61
|
|
|
74
62
|
|
|
75
63
|
def login(settings: Settings):
|
|
@@ -100,11 +88,37 @@ def login(settings: Settings):
|
|
|
100
88
|
if not response and isinstance(result, str):
|
|
101
89
|
response = {"error": result}
|
|
102
90
|
|
|
91
|
+
# Handle OAuth error response format (error, error_description)
|
|
92
|
+
if "error" in response:
|
|
93
|
+
raise errors.ParsedMessagesError(
|
|
94
|
+
messages=[
|
|
95
|
+
models.Message(
|
|
96
|
+
carrier_name=settings.carrier_name,
|
|
97
|
+
carrier_id=settings.carrier_id,
|
|
98
|
+
message=response.get("error_description", response.get("error")),
|
|
99
|
+
code=response.get("error", "AUTH_ERROR"),
|
|
100
|
+
)
|
|
101
|
+
]
|
|
102
|
+
)
|
|
103
|
+
|
|
103
104
|
messages = error.parse_error_response(response, settings)
|
|
104
105
|
|
|
105
106
|
if any(messages):
|
|
106
107
|
raise errors.ParsedMessagesError(messages)
|
|
107
108
|
|
|
109
|
+
# Validate that access_token is present in the response
|
|
110
|
+
if "access_token" not in response:
|
|
111
|
+
raise errors.ParsedMessagesError(
|
|
112
|
+
messages=[
|
|
113
|
+
models.Message(
|
|
114
|
+
carrier_name=settings.carrier_name,
|
|
115
|
+
carrier_id=settings.carrier_id,
|
|
116
|
+
message="Authentication failed: No access token received",
|
|
117
|
+
code="AUTH_ERROR",
|
|
118
|
+
)
|
|
119
|
+
]
|
|
120
|
+
)
|
|
121
|
+
|
|
108
122
|
expiry = datetime.datetime.now() + datetime.timedelta(
|
|
109
123
|
seconds=float(response.get("expires_in", 0))
|
|
110
124
|
)
|
|
@@ -6,7 +6,7 @@ karrio/plugins/sapient/__init__.py,sha256=_4xkqTPpUoq8KixCdNqNxcMVH52s5xH6L-s9c5
|
|
|
6
6
|
karrio/providers/sapient/__init__.py,sha256=Zu7FIaPsCzXgIsrmEtluHQJSj3UnFDpz-oiB93P-xK0,476
|
|
7
7
|
karrio/providers/sapient/error.py,sha256=hkpy86gWOjKLNhtmBoe7NkHq330kRqrtgDxsspLaxGQ,870
|
|
8
8
|
karrio/providers/sapient/units.py,sha256=ZUGl0IVKOA8vLVRWJGY2X9JBOR8H5OBr9s17Fx22EcM,34880
|
|
9
|
-
karrio/providers/sapient/utils.py,sha256=
|
|
9
|
+
karrio/providers/sapient/utils.py,sha256=4lRjA5gDiHwJjadHfTeE5eP64g-rkbBhKwjyUnSRx90,4714
|
|
10
10
|
karrio/providers/sapient/pickup/__init__.py,sha256=qT64wGr8J6pkLNa9Y0Zou5mYshoI7W-R0Pp7nWEhQ08,296
|
|
11
11
|
karrio/providers/sapient/pickup/cancel.py,sha256=0laDCfdhjOYHpOEN7l6u1o79nexaxT8GXMM5pJU3Xow,1763
|
|
12
12
|
karrio/providers/sapient/pickup/create.py,sha256=5S-h9qQuDFqxvqrmd2l0-SGQMi86O38sfjfqRVPGgo8,2776
|
|
@@ -20,8 +20,8 @@ karrio/schemas/sapient/pickup_request.py,sha256=gzZZ3Bxr_pYWxw28vDRr-aDgtzJIQptU
|
|
|
20
20
|
karrio/schemas/sapient/pickup_response.py,sha256=xcl3ofB2L2RNksMSRccvFbBdBcK1hVDDPVB-oAu4I54,195
|
|
21
21
|
karrio/schemas/sapient/shipment_requests.py,sha256=3sjensnLiiF7mTIpwS4FyrdEe-xMh5YC1ekj69qI6XM,4618
|
|
22
22
|
karrio/schemas/sapient/shipment_response.py,sha256=457ULt-exxAJ0Drqn2Pnj9pl_4JWMZ-cesuJW9NWBAs,702
|
|
23
|
-
karrio_sapient-2025.5.
|
|
24
|
-
karrio_sapient-2025.5.
|
|
25
|
-
karrio_sapient-2025.5.
|
|
26
|
-
karrio_sapient-2025.5.
|
|
27
|
-
karrio_sapient-2025.5.
|
|
23
|
+
karrio_sapient-2025.5.6.dist-info/METADATA,sha256=UFu6NreHdhZf3kEKtMehUsJqJ_4TPhKdTLrtFl9KghE,989
|
|
24
|
+
karrio_sapient-2025.5.6.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
25
|
+
karrio_sapient-2025.5.6.dist-info/entry_points.txt,sha256=rPF-WjVKk-3suhX4-zi9hTkwr0Qxb4ZW-Tjoyzi_Cy8,59
|
|
26
|
+
karrio_sapient-2025.5.6.dist-info/top_level.txt,sha256=FZCY8Nwft8oEGHdl--xku8P3TrnOxu5dETEU_fWpRSM,20
|
|
27
|
+
karrio_sapient-2025.5.6.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|