Skip to content

Commit

Permalink
Merge pull request #454 from karrioapi/patch-2023.9.5
Browse files Browse the repository at this point in the history
[patch] 2023.9.5
  • Loading branch information
danh91 authored Dec 13, 2023
2 parents 07561a6 + 62cab8c commit 41e407b
Show file tree
Hide file tree
Showing 31 changed files with 192 additions and 144 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,12 @@ We are an open-source alternative to expensive in-house carrier integration and
### Shipping for platforms

With Karrio, you can extend your platform with native shipping capabilities. Improve merchants and customers experience on your Marketplace, eCommerce, ERP, WMS, OMS, 3PL and Logistics platform.
With Karrio, 3PLs and large volume shippers regain control over their shipping tech stack and processes.

### Shipping for enterprise

Karrio makes modern shipping accessible to brands, retailers as well as enterprises in regulated industries.
Karrio makes modern shipping accessible to brands, retailers as well as businesses in regulated industries.
Ideal for pharmacy shipping where compliance is a must.

## Support

Expand Down
2 changes: 1 addition & 1 deletion apps/api/karrio/server/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2023.9.4
2023.9.5
2 changes: 1 addition & 1 deletion apps/dashboard/src/modules/Developers/graphiql.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export default function Page(pageProps: any) {
return (
<div className="playground-wrapper" style={{ position: 'absolute', top: 0, left: 0, bottom: 0, right: 0 }}>

<GraphiQL fetcher={fetcher} />
<GraphiQL fetcher={fetcher} editorTheme="light" />

</div>
);
Expand Down
4 changes: 2 additions & 2 deletions bin/deploy-hobby
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

set -e

export KARRIO_TAG="${KARRIO_TAG:-2023.9.4}"
export KARRIO_TAG="${KARRIO_TAG:-2023.9.5}"
export SENTRY_DSN="${SENTRY_DSN:-'https://public@sentry.example.com/1'}"

SECRET_KEY=$(head -c 28 /dev/urandom | sha224sum -b | head -c 56)
Expand All @@ -23,7 +23,7 @@ if ! [ -z "$1" ]
then
export KARRIO_TAG=$1
else
echo "What version of Karrio would you like to install? (We default to '2023.9.4')"
echo "What version of Karrio would you like to install? (We default to '2023.9.5')"
echo "You can check out available versions here: https://hub.docker.com/r/karrio/server/tags"
read -r KARRIO_TAG_READ
if [ -z "$KARRIO_TAG_READ" ]
Expand Down
2 changes: 1 addition & 1 deletion bin/upgrade-hobby
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ else
fi

[[ -f ".env" ]] && export $(cat .env | xargs) || ( echo "No .env file found. Please create it with SECRET_KEY and DOMAIN set." && exit 1)
export KARRIO_TAG="${KARRIO_TAG:-2023.9.4}"
export KARRIO_TAG="${KARRIO_TAG:-2023.9.5}"

# get karrio scripts
mkdir -p ./karrio
Expand Down
6 changes: 3 additions & 3 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ version: "3"
services:
api:
container_name: karrio.api
image: karrio.docker.scarf.sh/karrio/server:2023.9.4
image: karrio.docker.scarf.sh/karrio/server:2023.9.5
restart: unless-stopped
ports:
- ${KARRIO_HTTP_PORT}:${KARRIO_HTTP_PORT}
Expand All @@ -25,7 +25,7 @@ services:

worker:
container_name: karrio.worker
image: karrio.docker.scarf.sh/karrio/server:2023.9.4
image: karrio.docker.scarf.sh/karrio/server:2023.9.5
restart: unless-stopped
depends_on:
- db
Expand All @@ -46,7 +46,7 @@ services:

dashboard:
container_name: karrio.dashboard
image: karrio.docker.scarf.sh/karrio/dashboard:2023.9.4
image: karrio.docker.scarf.sh/karrio/dashboard:2023.9.5
restart: unless-stopped
ports:
- ${DASHBOARD_PORT}:3000/tcp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,7 @@ def rate_request(
is_document = all([parcel.is_document for parcel in payload.parcels])
is_from_EU = payload.shipper.country_code in units.EUCountry
is_to_EU = payload.recipient.country_code in units.EUCountry
is_dutiable = (
is_international
and not is_document
and not (is_from_EU and is_to_EU)
)
is_dutiable = is_international and not is_document and not (is_from_EU and is_to_EU)

services = lib.to_services(
payload.services,
Expand All @@ -120,9 +116,7 @@ def rate_request(
)
options = lib.to_shipping_options(
payload.options,
is_dutiable=is_dutiable,
package_options=packages.options,
shipper_country=payload.shipper.country_code,
initializer=provider_units.shipping_options_initializer,
)

Expand Down Expand Up @@ -205,7 +199,7 @@ def rate_request(
)
for svc in services
]
if any(options.items())
if any([_.value for _ in services])
else None
),
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,16 +102,10 @@ def shipment_request(
is_international = shipper.country_code != recipient.country_code
is_from_EU = payload.shipper.country_code in units.EUCountry
is_to_EU = payload.recipient.country_code in units.EUCountry
is_dutiable = (
is_international
and not is_document
and not (is_from_EU and is_to_EU)
)
is_dutiable = is_international and not is_document and not (is_from_EU and is_to_EU)
options = lib.to_shipping_options(
payload.options,
is_dutiable=is_dutiable,
package_options=packages.options,
shipper_country=payload.shipper.country_code,
initializer=provider_units.shipping_options_initializer,
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ class ConnectionConfig(lib.Enum):
shipping_services = lib.OptionEnum("shipping_services", list)


class ShippingService(lib.StrEnum):
class ShippingService(lib.Enum):
dhl_logistics_services = "0"
dhl_domestic_express_12_00 = "1"
dhl_express_choice = "2"
Expand Down Expand Up @@ -326,7 +326,7 @@ class ShippingService(lib.StrEnum):
dhl_express_envelope = "X"
dhl_express_12_00_nondoc = "Y"
dhl_destination_charges = "Z"
dhl_express_all = ""
dhl_express_all = None


def shipping_services_initializer(
Expand Down Expand Up @@ -597,23 +597,13 @@ class ShippingOption(lib.Enum):

def shipping_options_initializer(
options: dict,
is_dutiable: bool = False,
package_options: lib.units.Options = None,
shipper_country: str = "",
) -> lib.units.Options:
"""
Apply default values to the given options.
"""
_options = options.copy()

if (
is_dutiable
and ShippingOption.paperless_trade.name not in options
and ShippingOption.dhl_paperless_trade.name not in options
and shipper_country not in UNSUPPORTED_PAPERLESS_COUNTRIES
):
_options.update({ShippingOption.dhl_paperless_trade.name: True})

if package_options is not None:
_options.update(package_options.content)

Expand Down
2 changes: 1 addition & 1 deletion modules/connectors/dhl_express/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setup(
name="karrio.dhl_express",
version="2023.9.3",
version="2023.9.5",
description="Karrio - DHL Express Shipping Extension",
long_description=long_description,
long_description_content_type="text/markdown",
Expand Down
3 changes: 0 additions & 3 deletions modules/connectors/dhl_express/tests/dhl_express/test_rate.py
Original file line number Diff line number Diff line change
Expand Up @@ -444,9 +444,6 @@ def test_parse_rate_vol_weight_higher_response(self):
<QtdShp>
<GlobalProductCode>P</GlobalProductCode>
<LocalProductCode>P</LocalProductCode>
<QtdShpExChrg>
<SpecialServiceType>WY</SpecialServiceType>
</QtdShpExChrg>
</QtdShp>
</BkgDetails>
<To>
Expand Down
55 changes: 29 additions & 26 deletions modules/connectors/easypost/karrio/mappers/easypost/proxy.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,27 @@
from typing import List, Tuple
from karrio.core.utils import DP, request as http
from karrio.api.proxy import Proxy as BaseProxy
from karrio.core.utils.helpers import exec_async
from karrio.mappers.easypost.settings import Settings
from karrio.core.utils.serializable import Serializable, Deserializable
import typing
import karrio.lib as lib
import karrio.api.proxy as base
import karrio.mappers.easypost.settings as provider_settings


class Proxy(BaseProxy):
settings: Settings
class Proxy(base.Proxy):
settings: provider_settings.Settings

def get_rates(self, request: Serializable) -> Deserializable:
def get_rates(self, request: lib.Serializable) -> lib.Deserializable:
response = self._send_request(
path="/shipments", request=Serializable(request.serialize(), DP.jsonify)
path="/shipments",
request=lib.Serializable(request.serialize(), lib.to_json),
)

return Deserializable(response, DP.to_dict)
return lib.Deserializable(response, lib.to_dict)

def create_shipment(self, request: Serializable) -> Deserializable:
def create_shipment(self, request: lib.Serializable) -> lib.Deserializable:
payload = request.serialize()

def create(request) -> str:
response = DP.to_dict(
response = lib.to_dict(
self._send_request(
path="/shipments", request=Serializable(request, DP.jsonify)
path="/shipments", request=lib.Serializable(request, lib.to_json)
)
)

Expand All @@ -38,7 +37,7 @@ def create(request) -> str:
),
None,
)
data = DP.to_dict(
data = lib.to_dict(
{
"rate": {"id": rate_id},
"insurance": payload.get("insurance"),
Expand All @@ -50,40 +49,44 @@ def create(request) -> str:

return self._send_request(
path=f"/shipments/{response['id']}/buy",
request=Serializable(data, DP.jsonify),
request=lib.Serializable(data, lib.to_json),
)

response = create(payload["data"])
return Deserializable(response, DP.to_dict)
return lib.Deserializable(response, lib.to_dict)

def cancel_shipment(self, request: Serializable) -> Deserializable:
def cancel_shipment(self, request: lib.Serializable) -> lib.Deserializable:
response = self._send_request(path=f"/shipments/{request.serialize()}/refund")

return Deserializable(response, DP.to_dict)
return lib.Deserializable(response, lib.to_dict)

def get_tracking(self, requests: Serializable) -> Deserializable:
def get_tracking(self, requests: lib.Serializable) -> lib.Deserializable:
track = lambda request: (
request["tracking_code"],
self._send_request(
**(
dict(path="/trackers", request=Serializable(request, DP.jsonify))
dict(
path="/trackers", request=lib.Serializable(request, lib.to_json)
)
if request.get("tracker_id") is None
else dict(path=f"/trackers/{request['tracker_id']}", method="GET")
)
),
)

responses: List[Tuple[str, str]] = exec_async(track, requests.serialize())
return Deserializable(
responses: typing.List[typing.Tuple[str, str]] = lib.run_asynchronously(
track, requests.serialize()
)
return lib.Deserializable(
responses,
lambda res: [(key, DP.to_dict(response)) for key, response in res],
lambda res: [(key, lib.to_dict(response)) for key, response in res],
)

def _send_request(
self, path: str, request: Serializable = None, method: str = "POST"
self, path: str, request: lib.Serializable = None, method: str = "POST"
) -> str:
data: dict = dict(data=request.serialize()) if request is not None else dict()
return http(
return lib.request(
**{
"url": f"{self.settings.server_url}{path}",
"trace": self.trace_as("json"),
Expand Down
44 changes: 27 additions & 17 deletions modules/connectors/easypost/karrio/providers/easypost/error.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,31 @@
from karrio.schemas.easypost.error_response import Error
from karrio.core.utils import DP
from karrio.core.models import Message
from karrio.providers.easypost.utils import Settings
import typing
import karrio.lib as lib
import karrio.core.models as models
import karrio.providers.easypost.utils as provider_utils


def parse_error_response(
response: dict, settings: Settings, details: dict = None
) -> Message:
error = DP.to_object(Error, response.get("error"))
response: dict, settings: provider_utils.Settings, **kwargs
) -> typing.List[models.Message]:
errors = [
*response.get("messages", []),
*([response.get("error")] if "error" in response else []),
]

return Message(
carrier_id=settings.carrier_id,
carrier_name=settings.carrier_name,
code=error.code,
message=error.message,
details={
"errors": error.errors or [],
**(details or {}),
},
)
return [
models.Message(
carrier_id=settings.carrier_id,
carrier_name=settings.carrier_name,
code=(error.get("code") or error.get("type")),
message=error.get("message"),
details=lib.to_dict(
{
"errors": error.get("errors"),
"carrier": error.get("carrier"),
"carrier_account_id": error.get("carrier_account_id"),
**kwargs,
}
),
)
for error in errors
]
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,7 @@ def parse_rate_response(
settings: provider_utils.Settings,
) -> typing.Tuple[models.RateDetails, typing.List[models.Message]]:
response = _response.deserialize()
errors = (
[provider_error.parse_error_response(response, settings)]
if "error" in response
else []
)
errors = provider_error.parse_error_response(response, settings)
rates = _extract_details(response, settings) if "error" not in response else []

return rates, errors
Expand Down
Loading

0 comments on commit 41e407b

Please sign in to comment.