tap-belvo 0.0.1b4__py3-none-any.whl → 0.0.1b6__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 tap-belvo might be problematic. Click here for more details.

tap_belvo/client.py CHANGED
@@ -3,13 +3,14 @@
3
3
  from __future__ import annotations
4
4
 
5
5
  from abc import ABCMeta, abstractmethod
6
+ from copy import deepcopy
6
7
  from typing import TYPE_CHECKING, Any
7
8
  from urllib.parse import ParseResult, parse_qsl
8
9
 
10
+ from requests.auth import HTTPBasicAuth
9
11
  from requests_cache import install_cache
10
12
  from singer_sdk import RESTStream
11
13
  from singer_sdk._singerlib import resolve_schema_references
12
- from singer_sdk.authenticators import BasicAuthenticator
13
14
  from singer_sdk.helpers._typing import is_date_or_datetime_type
14
15
  from singer_sdk.pagination import BaseHATEOASPaginator
15
16
 
@@ -24,6 +25,37 @@ PAGE_SIZE = 1000
24
25
  install_cache("tap_belvo_cache", backend="sqlite", expire_after=3600)
25
26
 
26
27
 
28
+ def _handle_schema_nullable(schema: dict[str, Any]) -> dict[str, Any]:
29
+ """Resolve x-nullable properties to standard JSON Schema nullable type.
30
+
31
+ Args:
32
+ schema: A JSON Schema dictionary.
33
+
34
+ Returns:
35
+ A new JSON Schema dictionary with 'x-nullable' resolved to [<type>, "null"].
36
+ """
37
+ result = deepcopy(schema)
38
+
39
+ if "object" in result["type"]:
40
+ for prop, prop_schema in result.get("properties", {}).items():
41
+ prop_type: str | list[str] = prop_schema.get("type", [])
42
+ types = [prop_type] if isinstance(prop_type, str) else prop_type
43
+ nullable: bool = prop_schema.get("nullable", False)
44
+
45
+ if nullable:
46
+ prop_schema["type"] = [*types, "null"]
47
+
48
+ result["properties"][prop] = _handle_schema_nullable(prop_schema)
49
+
50
+ elif "array" in result["type"]:
51
+ result["items"] = _handle_schema_nullable(result["items"])
52
+
53
+ if "enum" in result and None not in result["enum"]:
54
+ result["enum"].append(None)
55
+
56
+ return result
57
+
58
+
27
59
  class BelvoPaginator(BaseHATEOASPaginator):
28
60
  """Belvo API paginator class."""
29
61
 
@@ -36,10 +68,10 @@ class BelvoPaginator(BaseHATEOASPaginator):
36
68
  Returns:
37
69
  The next URL.
38
70
  """
39
- return response.json().get("next")
71
+ return response.json().get("next") # type: ignore[no-any-return]
40
72
 
41
73
 
42
- class BelvoStream(RESTStream, metaclass=ABCMeta):
74
+ class BelvoStream(RESTStream[ParseResult], metaclass=ABCMeta):
43
75
  """Belvo stream class."""
44
76
 
45
77
  records_jsonpath = "$.results[*]" # Or override `parse_response`.
@@ -51,26 +83,19 @@ class BelvoStream(RESTStream, metaclass=ABCMeta):
51
83
  Returns:
52
84
  str: The URL base.
53
85
  """
54
- return self.config["base_url"]
86
+ return self.config["base_url"] # type: ignore[no-any-return]
55
87
 
56
88
  @property
57
- def authenticator(self) -> BasicAuthenticator:
89
+ def authenticator(self) -> HTTPBasicAuth:
58
90
  """Get an authenticator object.
59
91
 
60
92
  Returns:
61
93
  The authenticator instance for this REST stream.
62
94
  """
63
- username = self.config["secret_id"]
64
- password = self.config["password"]
65
-
66
- return BasicAuthenticator.create_for_stream(
67
- self,
68
- username=username,
69
- password=password,
70
- )
95
+ return HTTPBasicAuth(self.config["secret_id"], self.config["password"])
71
96
 
72
97
  @property
73
- def http_headers(self) -> dict:
98
+ def http_headers(self) -> dict[str, str]:
74
99
  """Return the http headers needed.
75
100
 
76
101
  Returns:
@@ -90,7 +115,7 @@ class BelvoStream(RESTStream, metaclass=ABCMeta):
90
115
 
91
116
  def get_url_params(
92
117
  self,
93
- context: dict | None,
118
+ context: dict[Any, Any] | None,
94
119
  next_page_token: ParseResult | None,
95
120
  ) -> dict[str, Any]:
96
121
  """Get URL query parameters.
@@ -146,7 +171,7 @@ class BelvoStream(RESTStream, metaclass=ABCMeta):
146
171
  Returns:
147
172
  The schema for this stream.
148
173
  """
149
- return self._resolve_openapi_ref()
174
+ return _handle_schema_nullable(self._resolve_openapi_ref())
150
175
 
151
176
  @property
152
177
  @abstractmethod