vtexpy 0.0.0b9__py3-none-any.whl → 0.0.0b11__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.
Potentially problematic release.
This version of vtexpy might be problematic. Click here for more details.
- vtex/__init__.py +6 -6
- vtex/_api/base.py +25 -48
- vtex/_api/catalog.py +29 -21
- vtex/_api/checkout.py +6 -5
- vtex/_api/custom.py +33 -2
- vtex/_api/license_manager.py +5 -4
- vtex/_api/logistics.py +27 -22
- vtex/_api/master_data.py +9 -9
- vtex/_api/orders.py +16 -16
- vtex/_api/payments_gateway.py +30 -25
- vtex/_api/promotions_and_taxes.py +23 -10
- vtex/_api/types/__init__.py +0 -0
- vtex/_api/types/license_manager.py +17 -0
- vtex/_config.py +6 -7
- vtex/_dto.py +58 -65
- vtex/_exceptions.py +1 -3
- vtex/_types.py +2 -18
- vtex/_utils.py +30 -3
- vtex/_vtex.py +54 -35
- {vtexpy-0.0.0b9.dist-info → vtexpy-0.0.0b11.dist-info}/METADATA +22 -4
- vtexpy-0.0.0b11.dist-info/RECORD +28 -0
- vtexpy-0.0.0b9.dist-info/RECORD +0 -26
- {vtexpy-0.0.0b9.dist-info → vtexpy-0.0.0b11.dist-info}/LICENSE +0 -0
- {vtexpy-0.0.0b9.dist-info → vtexpy-0.0.0b11.dist-info}/WHEEL +0 -0
vtex/__init__.py
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
from . import _constants as VTEXConstants # noqa: N812
|
|
2
2
|
from ._dto import (
|
|
3
3
|
VTEXCartItem,
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
VTEXDataResponse,
|
|
5
|
+
VTEXItemsResponse,
|
|
6
|
+
VTEXPaginatedItemsResponse,
|
|
6
7
|
VTEXResponse,
|
|
7
|
-
VTEXScrollListResponse,
|
|
8
8
|
)
|
|
9
9
|
from ._exceptions import VTEXError, VTEXRequestError, VTEXResponseError
|
|
10
10
|
from ._vtex import VTEX
|
|
@@ -14,12 +14,12 @@ __all__ = [
|
|
|
14
14
|
"VTEXCartItem",
|
|
15
15
|
"VTEXConstants",
|
|
16
16
|
"VTEXError",
|
|
17
|
-
"
|
|
18
|
-
"
|
|
17
|
+
"VTEXDataResponse",
|
|
18
|
+
"VTEXItemsResponse",
|
|
19
|
+
"VTEXPaginatedItemsResponse",
|
|
19
20
|
"VTEXRequestError",
|
|
20
21
|
"VTEXResponse",
|
|
21
22
|
"VTEXResponseError",
|
|
22
|
-
"VTEXScrollListResponse",
|
|
23
23
|
]
|
|
24
24
|
|
|
25
25
|
|
vtex/_api/base.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
from http import HTTPStatus
|
|
2
2
|
from json import JSONDecodeError
|
|
3
|
-
from logging import WARNING
|
|
3
|
+
from logging import WARNING
|
|
4
4
|
from typing import Any, Type, Union, cast
|
|
5
5
|
from urllib.parse import urljoin
|
|
6
6
|
|
|
@@ -28,27 +28,24 @@ from tenacity import (
|
|
|
28
28
|
|
|
29
29
|
from .._config import Config # type: ignore[attr-defined]
|
|
30
30
|
from .._constants import APP_KEY_HEADER, APP_TOKEN_HEADER
|
|
31
|
-
from .._dto import
|
|
31
|
+
from .._dto import VTEXDataResponse, VTEXResponseType
|
|
32
32
|
from .._exceptions import VTEXRequestError, VTEXResponseError
|
|
33
33
|
from .._logging import get_logger, log_before_retry
|
|
34
34
|
from .._types import HTTPMethodType
|
|
35
35
|
from .._utils import redact_headers, to_snake_case, to_snake_case_deep
|
|
36
|
+
from .._vtex import VTEX
|
|
36
37
|
|
|
37
38
|
|
|
38
39
|
class BaseAPI:
|
|
39
40
|
"""
|
|
40
|
-
Base client for VTEX API.
|
|
41
|
+
Base client for a VTEX API.
|
|
41
42
|
"""
|
|
42
43
|
|
|
43
|
-
def __init__(
|
|
44
|
-
self
|
|
45
|
-
|
|
46
|
-
logger: Union[Logger, None] = None,
|
|
47
|
-
) -> None:
|
|
48
|
-
self._config = config or Config()
|
|
49
|
-
self._logger = get_logger(
|
|
44
|
+
def __init__(self, client: VTEX) -> None:
|
|
45
|
+
self.client = client
|
|
46
|
+
self.logger = get_logger(
|
|
50
47
|
name=to_snake_case(type(self).__name__),
|
|
51
|
-
parent=logger,
|
|
48
|
+
parent=self.client.logger,
|
|
52
49
|
)
|
|
53
50
|
|
|
54
51
|
def _request(
|
|
@@ -66,14 +63,18 @@ class BaseAPI:
|
|
|
66
63
|
config: Union[Config, None] = None,
|
|
67
64
|
response_class: Union[Type[VTEXResponseType], None] = None,
|
|
68
65
|
) -> VTEXResponseType:
|
|
69
|
-
request_config = self.
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
environment
|
|
73
|
-
endpoint
|
|
66
|
+
request_config = config or self.client.config
|
|
67
|
+
|
|
68
|
+
url = urljoin(
|
|
69
|
+
f"https://{request_config.get_account_name()}.{environment}.com.br",
|
|
70
|
+
endpoint,
|
|
74
71
|
)
|
|
75
|
-
|
|
76
|
-
|
|
72
|
+
|
|
73
|
+
headers = Headers(headers=headers)
|
|
74
|
+
headers[APP_KEY_HEADER] = request_config.get_app_key()
|
|
75
|
+
headers[APP_TOKEN_HEADER] = request_config.get_app_token()
|
|
76
|
+
headers["Content-Type"] = "application/json; charset=utf-8"
|
|
77
|
+
headers["Accept"] = "application/json"
|
|
77
78
|
|
|
78
79
|
@retry(
|
|
79
80
|
stop=stop_after_attempt(
|
|
@@ -86,7 +87,7 @@ class BaseAPI:
|
|
|
86
87
|
),
|
|
87
88
|
retry=retry_if_exception_type(exception_types=HTTPError),
|
|
88
89
|
before_sleep=(
|
|
89
|
-
log_before_retry(logger=self.
|
|
90
|
+
log_before_retry(logger=self.logger, log_level=WARNING)
|
|
90
91
|
if request_config.get_retry_logs()
|
|
91
92
|
else None
|
|
92
93
|
),
|
|
@@ -110,7 +111,7 @@ class BaseAPI:
|
|
|
110
111
|
redact_headers(dict(response.request.headers)),
|
|
111
112
|
)
|
|
112
113
|
response.headers = Headers(redact_headers(dict(response.headers)))
|
|
113
|
-
if response.status_code in
|
|
114
|
+
if response.status_code in request_config.get_retry_statuses():
|
|
114
115
|
response.raise_for_status()
|
|
115
116
|
|
|
116
117
|
return response
|
|
@@ -129,7 +130,7 @@ class BaseAPI:
|
|
|
129
130
|
"headers": headers,
|
|
130
131
|
}
|
|
131
132
|
|
|
132
|
-
self.
|
|
133
|
+
self.logger.error(str(exception), extra=details, exc_info=True)
|
|
133
134
|
|
|
134
135
|
raise VTEXRequestError(**details) from None # type: ignore[arg-type]
|
|
135
136
|
|
|
@@ -137,33 +138,9 @@ class BaseAPI:
|
|
|
137
138
|
|
|
138
139
|
return cast(
|
|
139
140
|
VTEXResponseType,
|
|
140
|
-
(response_class or
|
|
141
|
+
(response_class or VTEXDataResponse).factory(response),
|
|
141
142
|
)
|
|
142
143
|
|
|
143
|
-
def _get_config(self, config: Union[Config, None]) -> Config:
|
|
144
|
-
return config or self._config
|
|
145
|
-
|
|
146
|
-
def _get_url(self, config: Config, environment: str, endpoint: str) -> str:
|
|
147
|
-
return urljoin(
|
|
148
|
-
f"https://{config.get_account_name()}.{environment}.com.br",
|
|
149
|
-
endpoint,
|
|
150
|
-
)
|
|
151
|
-
|
|
152
|
-
def _get_headers(
|
|
153
|
-
self,
|
|
154
|
-
config: Config,
|
|
155
|
-
headers: Union[HeaderTypes, None] = None,
|
|
156
|
-
) -> Headers:
|
|
157
|
-
request_headers = Headers(headers=headers)
|
|
158
|
-
|
|
159
|
-
request_headers[APP_KEY_HEADER] = config.get_app_key()
|
|
160
|
-
request_headers[APP_TOKEN_HEADER] = config.get_app_token()
|
|
161
|
-
|
|
162
|
-
request_headers["Content-Type"] = "application/json; charset=utf-8"
|
|
163
|
-
request_headers["Accept"] = "application/json"
|
|
164
|
-
|
|
165
|
-
return request_headers
|
|
166
|
-
|
|
167
144
|
def _raise_from_response(self, response: Response, config: Config) -> None:
|
|
168
145
|
if response.is_error and config.get_raise_for_status():
|
|
169
146
|
try:
|
|
@@ -182,8 +159,8 @@ class BaseAPI:
|
|
|
182
159
|
)
|
|
183
160
|
|
|
184
161
|
if response.is_server_error:
|
|
185
|
-
self.
|
|
162
|
+
self.logger.error(data, extra=error.to_dict())
|
|
186
163
|
else:
|
|
187
|
-
self.
|
|
164
|
+
self.logger.warning(data, extra=error.to_dict())
|
|
188
165
|
|
|
189
166
|
raise error from None
|
vtex/_api/catalog.py
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
from typing import Any, Union
|
|
1
|
+
from typing import Any, List, Union
|
|
2
2
|
|
|
3
|
-
from .. import VTEXPaginatedListResponse
|
|
4
3
|
from .._constants import (
|
|
5
4
|
GET_CATEGORY_TREE_MAX_LEVELS,
|
|
6
5
|
LIST_CATEGORIES_MAX_PAGE_SIZE,
|
|
@@ -9,8 +8,9 @@ from .._constants import (
|
|
|
9
8
|
LIST_SKU_IDS_START_PAGE,
|
|
10
9
|
MIN_PAGE_SIZE,
|
|
11
10
|
)
|
|
12
|
-
from .._dto import
|
|
11
|
+
from .._dto import VTEXDataResponse, VTEXItemsResponse, VTEXPaginatedItemsResponse
|
|
13
12
|
from .._sentinels import UNDEFINED, UndefinedSentinel
|
|
13
|
+
from .._types import DictType
|
|
14
14
|
from .._utils import exclude_undefined_values
|
|
15
15
|
from .base import BaseAPI
|
|
16
16
|
|
|
@@ -29,7 +29,7 @@ class CatalogAPI(BaseAPI):
|
|
|
29
29
|
seller_type: Union[int, UndefinedSentinel] = UNDEFINED,
|
|
30
30
|
is_better_scope: Union[bool, UndefinedSentinel] = UNDEFINED,
|
|
31
31
|
**kwargs: Any,
|
|
32
|
-
) ->
|
|
32
|
+
) -> VTEXItemsResponse[DictType, DictType]:
|
|
33
33
|
return self._request(
|
|
34
34
|
method="GET",
|
|
35
35
|
environment=self.ENVIRONMENT,
|
|
@@ -39,8 +39,8 @@ class CatalogAPI(BaseAPI):
|
|
|
39
39
|
"sellerType": seller_type,
|
|
40
40
|
"isBetterScope": is_better_scope,
|
|
41
41
|
}),
|
|
42
|
-
config=self.
|
|
43
|
-
response_class=
|
|
42
|
+
config=self.client.config.with_overrides(**kwargs),
|
|
43
|
+
response_class=VTEXItemsResponse[DictType, DictType],
|
|
44
44
|
)
|
|
45
45
|
|
|
46
46
|
def list_sku_ids(
|
|
@@ -48,7 +48,7 @@ class CatalogAPI(BaseAPI):
|
|
|
48
48
|
page: int = LIST_SKU_IDS_START_PAGE,
|
|
49
49
|
page_size: int = LIST_SKU_IDS_MAX_PAGE_SIZE,
|
|
50
50
|
**kwargs: Any,
|
|
51
|
-
) ->
|
|
51
|
+
) -> VTEXItemsResponse[List[str], str]:
|
|
52
52
|
return self._request(
|
|
53
53
|
method="GET",
|
|
54
54
|
environment=self.ENVIRONMENT,
|
|
@@ -60,17 +60,21 @@ class CatalogAPI(BaseAPI):
|
|
|
60
60
|
MIN_PAGE_SIZE,
|
|
61
61
|
),
|
|
62
62
|
},
|
|
63
|
-
config=self.
|
|
64
|
-
response_class=
|
|
63
|
+
config=self.client.config.with_overrides(**kwargs),
|
|
64
|
+
response_class=VTEXItemsResponse[List[str], str],
|
|
65
65
|
)
|
|
66
66
|
|
|
67
|
-
def get_sku_with_context(
|
|
67
|
+
def get_sku_with_context(
|
|
68
|
+
self,
|
|
69
|
+
sku_id: int,
|
|
70
|
+
**kwargs: Any,
|
|
71
|
+
) -> VTEXDataResponse[DictType]:
|
|
68
72
|
return self._request(
|
|
69
73
|
method="GET",
|
|
70
74
|
environment=self.ENVIRONMENT,
|
|
71
75
|
endpoint=f"/api/catalog_system/pvt/sku/stockkeepingunitbyid/{sku_id}",
|
|
72
|
-
config=self.
|
|
73
|
-
response_class=
|
|
76
|
+
config=self.client.config.with_overrides(**kwargs),
|
|
77
|
+
response_class=VTEXDataResponse[DictType],
|
|
74
78
|
)
|
|
75
79
|
|
|
76
80
|
def list_categories(
|
|
@@ -78,7 +82,7 @@ class CatalogAPI(BaseAPI):
|
|
|
78
82
|
page: int = LIST_SKU_IDS_START_PAGE,
|
|
79
83
|
page_size: int = LIST_SKU_IDS_MAX_PAGE_SIZE,
|
|
80
84
|
**kwargs: Any,
|
|
81
|
-
) ->
|
|
85
|
+
) -> VTEXPaginatedItemsResponse[DictType, DictType]:
|
|
82
86
|
return self._request(
|
|
83
87
|
method="GET",
|
|
84
88
|
environment=self.ENVIRONMENT,
|
|
@@ -90,28 +94,32 @@ class CatalogAPI(BaseAPI):
|
|
|
90
94
|
MIN_PAGE_SIZE,
|
|
91
95
|
),
|
|
92
96
|
},
|
|
93
|
-
config=self.
|
|
94
|
-
response_class=
|
|
97
|
+
config=self.client.config.with_overrides(**kwargs),
|
|
98
|
+
response_class=VTEXPaginatedItemsResponse[DictType, DictType],
|
|
95
99
|
)
|
|
96
100
|
|
|
97
101
|
def get_category_tree(
|
|
98
102
|
self,
|
|
99
103
|
levels: int = GET_CATEGORY_TREE_MAX_LEVELS,
|
|
100
104
|
**kwargs: Any,
|
|
101
|
-
) ->
|
|
105
|
+
) -> VTEXDataResponse[DictType]:
|
|
102
106
|
return self._request(
|
|
103
107
|
method="GET",
|
|
104
108
|
environment=self.ENVIRONMENT,
|
|
105
109
|
endpoint=f"/api/catalog_system/pub/category/tree/{levels}",
|
|
106
|
-
config=self.
|
|
107
|
-
response_class=
|
|
110
|
+
config=self.client.config.with_overrides(**kwargs),
|
|
111
|
+
response_class=VTEXDataResponse[DictType],
|
|
108
112
|
)
|
|
109
113
|
|
|
110
|
-
def get_category(
|
|
114
|
+
def get_category(
|
|
115
|
+
self,
|
|
116
|
+
category_id: str,
|
|
117
|
+
**kwargs: Any,
|
|
118
|
+
) -> VTEXDataResponse[DictType]:
|
|
111
119
|
return self._request(
|
|
112
120
|
method="GET",
|
|
113
121
|
environment=self.ENVIRONMENT,
|
|
114
122
|
endpoint=f"/api/catalog/pvt/category/{category_id}",
|
|
115
|
-
config=self.
|
|
116
|
-
response_class=
|
|
123
|
+
config=self.client.config.with_overrides(**kwargs),
|
|
124
|
+
response_class=VTEXDataResponse[DictType],
|
|
117
125
|
)
|
vtex/_api/checkout.py
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
from typing import Any, List, Union
|
|
2
2
|
|
|
3
|
-
from .._dto import VTEXCartItem,
|
|
3
|
+
from .._dto import VTEXCartItem, VTEXDataResponse
|
|
4
4
|
from .._sentinels import UNDEFINED, UndefinedSentinel
|
|
5
|
+
from .._types import DictType
|
|
5
6
|
from .._utils import exclude_undefined_values
|
|
6
7
|
from .base import BaseAPI
|
|
7
8
|
|
|
@@ -14,7 +15,7 @@ class CheckoutAPI(BaseAPI):
|
|
|
14
15
|
|
|
15
16
|
ENVIRONMENT = "vtexcommercestable"
|
|
16
17
|
|
|
17
|
-
def
|
|
18
|
+
def run_cart_simulation(
|
|
18
19
|
self,
|
|
19
20
|
cart: List[VTEXCartItem],
|
|
20
21
|
country: Union[str, UndefinedSentinel] = UNDEFINED,
|
|
@@ -24,7 +25,7 @@ class CheckoutAPI(BaseAPI):
|
|
|
24
25
|
sales_channel: Union[int, UndefinedSentinel] = UNDEFINED,
|
|
25
26
|
individual_shipping_estimates: Union[bool, UndefinedSentinel] = UNDEFINED,
|
|
26
27
|
**kwargs: Any,
|
|
27
|
-
) ->
|
|
28
|
+
) -> VTEXDataResponse[DictType]:
|
|
28
29
|
return self._request(
|
|
29
30
|
method="POST",
|
|
30
31
|
environment=self.ENVIRONMENT,
|
|
@@ -40,6 +41,6 @@ class CheckoutAPI(BaseAPI):
|
|
|
40
41
|
"postalCode": postal_code,
|
|
41
42
|
"geoCoordinates": geo_coordinates,
|
|
42
43
|
}),
|
|
43
|
-
config=self.
|
|
44
|
-
response_class=
|
|
44
|
+
config=self.client.config.with_overrides(**kwargs),
|
|
45
|
+
response_class=VTEXDataResponse[DictType],
|
|
45
46
|
)
|
vtex/_api/custom.py
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
from
|
|
1
|
+
from datetime import datetime
|
|
2
|
+
from typing import Any, List, Type, Union
|
|
2
3
|
|
|
3
4
|
from httpx._types import (
|
|
4
5
|
CookieTypes,
|
|
@@ -11,6 +12,7 @@ from httpx._types import (
|
|
|
11
12
|
|
|
12
13
|
from .._dto import VTEXResponseType
|
|
13
14
|
from .._types import HTTPMethodType
|
|
15
|
+
from .._utils import to_datetime
|
|
14
16
|
from .base import BaseAPI
|
|
15
17
|
|
|
16
18
|
|
|
@@ -46,6 +48,35 @@ class CustomAPI(BaseAPI):
|
|
|
46
48
|
data=data,
|
|
47
49
|
content=content,
|
|
48
50
|
files=files,
|
|
49
|
-
config=self.
|
|
51
|
+
config=self.client.config.with_overrides(**kwargs),
|
|
50
52
|
response_class=response_class,
|
|
51
53
|
)
|
|
54
|
+
|
|
55
|
+
def get_account_name(self) -> str:
|
|
56
|
+
return self.client.license_manager.get_account().data["account_name"]
|
|
57
|
+
|
|
58
|
+
def get_account_creation_date(self) -> datetime:
|
|
59
|
+
return to_datetime(
|
|
60
|
+
self.client.license_manager.get_account().data["creation_date"],
|
|
61
|
+
)
|
|
62
|
+
|
|
63
|
+
def get_account_site_names(self) -> datetime:
|
|
64
|
+
return to_datetime(
|
|
65
|
+
self.client.license_manager.get_account().data["creation_date"],
|
|
66
|
+
)
|
|
67
|
+
|
|
68
|
+
def get_main_seller(self) -> str:
|
|
69
|
+
return "1"
|
|
70
|
+
|
|
71
|
+
def get_market_place_sellers(self) -> List[str]:
|
|
72
|
+
return [
|
|
73
|
+
seller["seller_id"]
|
|
74
|
+
for seller in self.client.catalog.list_sellers(seller_type=1).items
|
|
75
|
+
if seller["seller_id"] != "1"
|
|
76
|
+
]
|
|
77
|
+
|
|
78
|
+
def get_franchise_sellers(self) -> List[str]:
|
|
79
|
+
return [
|
|
80
|
+
seller["seller_id"]
|
|
81
|
+
for seller in self.client.catalog.list_sellers(seller_type=2).items
|
|
82
|
+
]
|
vtex/_api/license_manager.py
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
from typing import Any
|
|
2
2
|
|
|
3
|
-
from .._dto import
|
|
3
|
+
from .._dto import VTEXDataResponse
|
|
4
4
|
from .base import BaseAPI
|
|
5
|
+
from .types.license_manager import GetAccountData
|
|
5
6
|
|
|
6
7
|
|
|
7
8
|
class LicenseManagerAPI(BaseAPI):
|
|
@@ -12,11 +13,11 @@ class LicenseManagerAPI(BaseAPI):
|
|
|
12
13
|
|
|
13
14
|
ENVIRONMENT = "vtexcommercestable"
|
|
14
15
|
|
|
15
|
-
def get_account(self, **kwargs: Any) ->
|
|
16
|
+
def get_account(self, **kwargs: Any) -> VTEXDataResponse[GetAccountData]:
|
|
16
17
|
return self._request(
|
|
17
18
|
method="GET",
|
|
18
19
|
environment=self.ENVIRONMENT,
|
|
19
20
|
endpoint="/api/vlm/account",
|
|
20
|
-
config=self.
|
|
21
|
-
response_class=
|
|
21
|
+
config=self.client.config.with_overrides(**kwargs),
|
|
22
|
+
response_class=VTEXDataResponse[GetAccountData],
|
|
22
23
|
)
|
vtex/_api/logistics.py
CHANGED
|
@@ -9,7 +9,8 @@ from .._constants import (
|
|
|
9
9
|
LIST_SHIPPING_POLICIES_START_PAGE,
|
|
10
10
|
MIN_PAGE_SIZE,
|
|
11
11
|
)
|
|
12
|
-
from .._dto import
|
|
12
|
+
from .._dto import VTEXDataResponse, VTEXPaginatedItemsResponse
|
|
13
|
+
from .._types import DictType
|
|
13
14
|
from .base import BaseAPI
|
|
14
15
|
|
|
15
16
|
|
|
@@ -26,7 +27,7 @@ class LogisticsAPI(BaseAPI):
|
|
|
26
27
|
page: int = LIST_SHIPPING_POLICIES_START_PAGE,
|
|
27
28
|
page_size: int = LIST_SHIPPING_POLICIES_MAX_PAGE_SIZE,
|
|
28
29
|
**kwargs: Any,
|
|
29
|
-
) ->
|
|
30
|
+
) -> VTEXPaginatedItemsResponse[DictType, DictType]:
|
|
30
31
|
return self._request(
|
|
31
32
|
method="GET",
|
|
32
33
|
environment=self.ENVIRONMENT,
|
|
@@ -38,21 +39,21 @@ class LogisticsAPI(BaseAPI):
|
|
|
38
39
|
MIN_PAGE_SIZE,
|
|
39
40
|
),
|
|
40
41
|
},
|
|
41
|
-
config=self.
|
|
42
|
-
response_class=
|
|
42
|
+
config=self.client.config.with_overrides(**kwargs),
|
|
43
|
+
response_class=VTEXPaginatedItemsResponse[DictType, DictType],
|
|
43
44
|
)
|
|
44
45
|
|
|
45
46
|
def get_shipping_policy(
|
|
46
47
|
self,
|
|
47
48
|
shipping_policy_id: str,
|
|
48
49
|
**kwargs: Any,
|
|
49
|
-
) ->
|
|
50
|
+
) -> VTEXDataResponse[DictType]:
|
|
50
51
|
return self._request(
|
|
51
52
|
method="GET",
|
|
52
53
|
environment=self.ENVIRONMENT,
|
|
53
54
|
endpoint=f"/api/logistics/pvt/shipping-policies/{shipping_policy_id}",
|
|
54
|
-
config=self.
|
|
55
|
-
response_class=
|
|
55
|
+
config=self.client.config.with_overrides(**kwargs),
|
|
56
|
+
response_class=VTEXDataResponse[DictType],
|
|
56
57
|
)
|
|
57
58
|
|
|
58
59
|
def list_carriers(
|
|
@@ -60,7 +61,7 @@ class LogisticsAPI(BaseAPI):
|
|
|
60
61
|
page: int = LIST_CARRIERS_START_PAGE,
|
|
61
62
|
page_size: int = LIST_CARRIERS_MAX_PAGE_SIZE,
|
|
62
63
|
**kwargs: Any,
|
|
63
|
-
) ->
|
|
64
|
+
) -> VTEXPaginatedItemsResponse[DictType, DictType]:
|
|
64
65
|
return self._request(
|
|
65
66
|
method="GET",
|
|
66
67
|
environment=self.ENVIRONMENT,
|
|
@@ -72,21 +73,21 @@ class LogisticsAPI(BaseAPI):
|
|
|
72
73
|
MIN_PAGE_SIZE,
|
|
73
74
|
),
|
|
74
75
|
},
|
|
75
|
-
config=self.
|
|
76
|
-
response_class=
|
|
76
|
+
config=self.client.config.with_overrides(**kwargs),
|
|
77
|
+
response_class=VTEXPaginatedItemsResponse[DictType, DictType],
|
|
77
78
|
)
|
|
78
79
|
|
|
79
80
|
def get_carrier(
|
|
80
81
|
self,
|
|
81
82
|
carrier_id: str,
|
|
82
83
|
**kwargs: Any,
|
|
83
|
-
) ->
|
|
84
|
+
) -> VTEXDataResponse[DictType]:
|
|
84
85
|
return self._request(
|
|
85
86
|
method="GET",
|
|
86
87
|
environment=self.ENVIRONMENT,
|
|
87
88
|
endpoint=f"/api/logistics/pvt/configuration/carriers/{carrier_id}",
|
|
88
|
-
config=self.
|
|
89
|
-
response_class=
|
|
89
|
+
config=self.client.config.with_overrides(**kwargs),
|
|
90
|
+
response_class=VTEXDataResponse[DictType],
|
|
90
91
|
)
|
|
91
92
|
|
|
92
93
|
def list_docks(
|
|
@@ -94,7 +95,7 @@ class LogisticsAPI(BaseAPI):
|
|
|
94
95
|
page: int = LIST_DOCKS_START_PAGE,
|
|
95
96
|
page_size: int = LIST_DOCKS_MAX_PAGE_SIZE,
|
|
96
97
|
**kwargs: Any,
|
|
97
|
-
) ->
|
|
98
|
+
) -> VTEXPaginatedItemsResponse[DictType, DictType]:
|
|
98
99
|
return self._request(
|
|
99
100
|
method="GET",
|
|
100
101
|
environment=self.ENVIRONMENT,
|
|
@@ -106,24 +107,28 @@ class LogisticsAPI(BaseAPI):
|
|
|
106
107
|
MIN_PAGE_SIZE,
|
|
107
108
|
),
|
|
108
109
|
},
|
|
109
|
-
config=self.
|
|
110
|
-
response_class=
|
|
110
|
+
config=self.client.config.with_overrides(**kwargs),
|
|
111
|
+
response_class=VTEXPaginatedItemsResponse[DictType, DictType],
|
|
111
112
|
)
|
|
112
113
|
|
|
113
|
-
def get_dock(self, dock_id: str, **kwargs: Any) ->
|
|
114
|
+
def get_dock(self, dock_id: str, **kwargs: Any) -> VTEXDataResponse[DictType]:
|
|
114
115
|
return self._request(
|
|
115
116
|
method="GET",
|
|
116
117
|
environment=self.ENVIRONMENT,
|
|
117
118
|
endpoint=f"/api/logistics/pvt/configuration/docks/{dock_id}",
|
|
118
|
-
config=self.
|
|
119
|
-
response_class=
|
|
119
|
+
config=self.client.config.with_overrides(**kwargs),
|
|
120
|
+
response_class=VTEXDataResponse[DictType],
|
|
120
121
|
)
|
|
121
122
|
|
|
122
|
-
def get_sku_inventories(
|
|
123
|
+
def get_sku_inventories(
|
|
124
|
+
self,
|
|
125
|
+
sku_id: str,
|
|
126
|
+
**kwargs: Any,
|
|
127
|
+
) -> VTEXDataResponse[DictType]:
|
|
123
128
|
return self._request(
|
|
124
129
|
method="GET",
|
|
125
130
|
environment=self.ENVIRONMENT,
|
|
126
131
|
endpoint=f"/api/logistics/pvt/inventory/skus/{sku_id}",
|
|
127
|
-
config=self.
|
|
128
|
-
response_class=
|
|
132
|
+
config=self.client.config.with_overrides(**kwargs),
|
|
133
|
+
response_class=VTEXDataResponse[DictType],
|
|
129
134
|
)
|
vtex/_api/master_data.py
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
from typing import Any,
|
|
1
|
+
from typing import Any, List, Union
|
|
2
2
|
|
|
3
3
|
from .._constants import (
|
|
4
4
|
MIN_PAGE_SIZE,
|
|
5
5
|
SEARCH_DOCUMENTS_MAX_PAGE_SIZE,
|
|
6
6
|
SEARCH_DOCUMENTS_START_PAGE,
|
|
7
7
|
)
|
|
8
|
-
from .._dto import
|
|
8
|
+
from .._dto import VTEXPaginatedItemsResponse
|
|
9
9
|
from .._sentinels import UNDEFINED, UndefinedSentinel
|
|
10
|
-
from .._types import
|
|
10
|
+
from .._types import DictType, OrderingDirectionType
|
|
11
11
|
from .._utils import exclude_undefined_values
|
|
12
12
|
from .base import BaseAPI
|
|
13
13
|
|
|
@@ -20,17 +20,17 @@ class MasterDataAPI(BaseAPI):
|
|
|
20
20
|
|
|
21
21
|
ENVIRONMENT = "vtexcommercestable"
|
|
22
22
|
|
|
23
|
-
def
|
|
23
|
+
def list_documents(
|
|
24
24
|
self,
|
|
25
25
|
entity_name: str,
|
|
26
26
|
where: Union[str, UndefinedSentinel] = UNDEFINED,
|
|
27
|
-
fields: Union[
|
|
27
|
+
fields: Union[List[str], str, UndefinedSentinel] = UNDEFINED,
|
|
28
28
|
order_by_field: str = "id",
|
|
29
29
|
order_by_direction: OrderingDirectionType = "DESC",
|
|
30
30
|
page: int = SEARCH_DOCUMENTS_START_PAGE,
|
|
31
31
|
page_size: int = SEARCH_DOCUMENTS_MAX_PAGE_SIZE,
|
|
32
32
|
**kwargs: Any,
|
|
33
|
-
) ->
|
|
33
|
+
) -> VTEXPaginatedItemsResponse[DictType, DictType]:
|
|
34
34
|
params = {
|
|
35
35
|
"_where": where,
|
|
36
36
|
"_sort": f"{order_by_field} {order_by_direction.upper()}",
|
|
@@ -38,7 +38,7 @@ class MasterDataAPI(BaseAPI):
|
|
|
38
38
|
|
|
39
39
|
if fields is UNDEFINED:
|
|
40
40
|
params["_fields"] = "all"
|
|
41
|
-
elif not isinstance(fields, str) and isinstance(fields,
|
|
41
|
+
elif not isinstance(fields, str) and isinstance(fields, list):
|
|
42
42
|
params["_fields"] = ",".join(fields)
|
|
43
43
|
else:
|
|
44
44
|
params["_fields"] = fields
|
|
@@ -57,6 +57,6 @@ class MasterDataAPI(BaseAPI):
|
|
|
57
57
|
headers={
|
|
58
58
|
"REST-Range": f"resources={(page - 1) * page_size}-{page * page_size}",
|
|
59
59
|
},
|
|
60
|
-
config=self.
|
|
61
|
-
response_class=
|
|
60
|
+
config=self.client.config.with_overrides(**kwargs),
|
|
61
|
+
response_class=VTEXPaginatedItemsResponse[DictType, DictType],
|
|
62
62
|
)
|
vtex/_api/orders.py
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
from datetime import datetime, timedelta, timezone
|
|
2
|
-
from typing import Any, Dict, Union
|
|
2
|
+
from typing import Any, Dict, List, Union
|
|
3
3
|
|
|
4
4
|
from .._constants import (
|
|
5
5
|
LIST_FEED_ORDERS_MAX_PAGE_SIZE,
|
|
@@ -8,9 +8,9 @@ from .._constants import (
|
|
|
8
8
|
LIST_ORDERS_START_PAGE,
|
|
9
9
|
MIN_PAGE_SIZE,
|
|
10
10
|
)
|
|
11
|
-
from .._dto import
|
|
11
|
+
from .._dto import VTEXDataResponse, VTEXItemsResponse, VTEXPaginatedItemsResponse
|
|
12
12
|
from .._sentinels import UNDEFINED, UndefinedSentinel
|
|
13
|
-
from .._types import
|
|
13
|
+
from .._types import DictType, OrderingDirectionType
|
|
14
14
|
from .._utils import now, three_years_ago
|
|
15
15
|
from .base import BaseAPI
|
|
16
16
|
|
|
@@ -35,7 +35,7 @@ class OrdersAPI(BaseAPI):
|
|
|
35
35
|
page: int = LIST_ORDERS_START_PAGE,
|
|
36
36
|
page_size: int = LIST_ORDERS_MAX_PAGE_SIZE,
|
|
37
37
|
**kwargs: Any,
|
|
38
|
-
) ->
|
|
38
|
+
) -> VTEXPaginatedItemsResponse[DictType, DictType]:
|
|
39
39
|
if page > LIST_ORDERS_MAX_PAGE:
|
|
40
40
|
raise ValueError("List Orders endpoint can only return up to page 30")
|
|
41
41
|
|
|
@@ -83,8 +83,8 @@ class OrdersAPI(BaseAPI):
|
|
|
83
83
|
environment=self.ENVIRONMENT,
|
|
84
84
|
endpoint="/api/oms/pvt/orders/",
|
|
85
85
|
params=params,
|
|
86
|
-
config=self.
|
|
87
|
-
response_class=
|
|
86
|
+
config=self.client.config.with_overrides(**kwargs),
|
|
87
|
+
response_class=VTEXPaginatedItemsResponse[DictType, DictType],
|
|
88
88
|
)
|
|
89
89
|
|
|
90
90
|
pagination = response.pagination
|
|
@@ -93,20 +93,20 @@ class OrdersAPI(BaseAPI):
|
|
|
93
93
|
|
|
94
94
|
return response
|
|
95
95
|
|
|
96
|
-
def get_order(self, order_id: str, **kwargs: Any) ->
|
|
96
|
+
def get_order(self, order_id: str, **kwargs: Any) -> VTEXDataResponse[DictType]:
|
|
97
97
|
return self._request(
|
|
98
98
|
method="GET",
|
|
99
99
|
environment=self.ENVIRONMENT,
|
|
100
100
|
endpoint=f"/api/oms/pvt/orders/{order_id}",
|
|
101
|
-
config=self.
|
|
102
|
-
response_class=
|
|
101
|
+
config=self.client.config.with_overrides(**kwargs),
|
|
102
|
+
response_class=VTEXDataResponse[DictType],
|
|
103
103
|
)
|
|
104
104
|
|
|
105
105
|
def list_feed_orders(
|
|
106
106
|
self,
|
|
107
107
|
page_size: int = LIST_FEED_ORDERS_MAX_PAGE_SIZE,
|
|
108
108
|
**kwargs: Any,
|
|
109
|
-
) ->
|
|
109
|
+
) -> VTEXItemsResponse[DictType, DictType]:
|
|
110
110
|
return self._request(
|
|
111
111
|
method="GET",
|
|
112
112
|
environment=self.ENVIRONMENT,
|
|
@@ -117,15 +117,15 @@ class OrdersAPI(BaseAPI):
|
|
|
117
117
|
MIN_PAGE_SIZE,
|
|
118
118
|
),
|
|
119
119
|
},
|
|
120
|
-
config=self.
|
|
121
|
-
response_class=
|
|
120
|
+
config=self.client.config.with_overrides(**kwargs),
|
|
121
|
+
response_class=VTEXItemsResponse[DictType, DictType],
|
|
122
122
|
)
|
|
123
123
|
|
|
124
124
|
def commit_feed_orders(
|
|
125
125
|
self,
|
|
126
|
-
handles:
|
|
126
|
+
handles: List[str],
|
|
127
127
|
**kwargs: Any,
|
|
128
|
-
) ->
|
|
128
|
+
) -> VTEXDataResponse[DictType]:
|
|
129
129
|
if not handles:
|
|
130
130
|
raise ValueError(
|
|
131
131
|
"At least one handle must be provided to commit to the feed"
|
|
@@ -141,6 +141,6 @@ class OrdersAPI(BaseAPI):
|
|
|
141
141
|
environment=self.ENVIRONMENT,
|
|
142
142
|
endpoint="/api/orders/feed/",
|
|
143
143
|
json={"handles": handles},
|
|
144
|
-
config=self.
|
|
145
|
-
response_class=
|
|
144
|
+
config=self.client.config.with_overrides(**kwargs),
|
|
145
|
+
response_class=VTEXDataResponse[DictType],
|
|
146
146
|
)
|