stigg-api-client-v2 0.693.0__py3-none-any.whl → 5.9.0__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.
Files changed (75) hide show
  1. stigg/_edge_utils.py +58 -0
  2. stigg/client.py +97 -21
  3. stigg/generated/__init__.py +734 -42
  4. stigg/generated/apply_subscription.py +4 -12
  5. stigg/generated/archive_customer.py +2 -3
  6. stigg/generated/async_base_client.py +187 -29
  7. stigg/generated/async_client.py +3659 -620
  8. stigg/generated/base_client.py +144 -23
  9. stigg/generated/base_model.py +16 -47
  10. stigg/generated/cancel_subscription.py +2 -3
  11. stigg/generated/cancel_subscription_updates.py +1 -4
  12. stigg/generated/client.py +3661 -616
  13. stigg/generated/create_payment_session.py +20 -0
  14. stigg/generated/create_subscription.py +2 -3
  15. stigg/generated/delegate_subscription_to_customer.py +22 -0
  16. stigg/generated/detach_customer_payment_method.py +20 -0
  17. stigg/generated/enums.py +426 -7
  18. stigg/generated/estimate_subscription.py +2 -3
  19. stigg/generated/estimate_subscription_update.py +2 -3
  20. stigg/generated/exceptions.py +9 -5
  21. stigg/generated/fragments.py +1864 -701
  22. stigg/generated/get_active_subscriptions.py +2 -3
  23. stigg/generated/get_active_subscriptions_list.py +22 -0
  24. stigg/generated/get_checkout_state.py +2 -3
  25. stigg/generated/get_coupons.py +4 -5
  26. stigg/generated/get_credit_balance.py +20 -0
  27. stigg/generated/get_credit_grants.py +36 -0
  28. stigg/generated/get_credit_ledger.py +25 -0
  29. stigg/generated/get_credit_usage.py +18 -0
  30. stigg/generated/get_customer_by_id.py +2 -3
  31. stigg/generated/get_customer_portal_by_ref_id.py +2 -3
  32. stigg/generated/get_customer_statistics.py +2 -3
  33. stigg/generated/get_entitlement.py +2 -3
  34. stigg/generated/get_entitlements.py +2 -3
  35. stigg/generated/get_entitlements_state.py +31 -0
  36. stigg/generated/get_mock_paywall.py +3 -5
  37. stigg/generated/get_paywall.py +2 -3
  38. stigg/generated/get_products.py +4 -5
  39. stigg/generated/get_sdk_configuration.py +3 -3
  40. stigg/generated/get_subscription.py +18 -0
  41. stigg/generated/get_subscriptions.py +35 -0
  42. stigg/generated/get_usage_history.py +2 -3
  43. stigg/generated/get_usage_history_v_2.py +18 -0
  44. stigg/generated/grant_credits.py +20 -0
  45. stigg/generated/grant_promotional_entitlements.py +2 -3
  46. stigg/generated/grant_promotional_entitlements_group.py +24 -0
  47. stigg/generated/import_customer.py +2 -3
  48. stigg/generated/import_customer_bulk.py +1 -4
  49. stigg/generated/import_subscriptions_bulk.py +1 -4
  50. stigg/generated/input_types.py +3871 -1878
  51. stigg/generated/migrate_subscription_to_latest.py +2 -3
  52. stigg/generated/preview_next_invoice.py +20 -0
  53. stigg/generated/preview_subscription.py +2 -3
  54. stigg/generated/provision_customer.py +4 -22
  55. stigg/generated/provision_subscription.py +4 -15
  56. stigg/generated/report_entitlement_check_requested.py +1 -4
  57. stigg/generated/report_event.py +1 -4
  58. stigg/generated/report_usage.py +6 -13
  59. stigg/generated/report_usage_bulk.py +22 -0
  60. stigg/generated/revoke_promotional_entitlement.py +5 -4
  61. stigg/generated/revoke_promotional_entitlements_group.py +24 -0
  62. stigg/generated/transfer_subscription.py +2 -3
  63. stigg/generated/transfer_subscription_to_resource.py +22 -0
  64. stigg/generated/unarchive_customer.py +2 -3
  65. stigg/generated/unlink_promotional_entitlements_group.py +24 -0
  66. stigg/generated/update_customer.py +2 -3
  67. stigg/generated/update_subscription.py +2 -3
  68. stigg/generated/void_credit_grant.py +18 -0
  69. {stigg_api_client_v2-0.693.0.dist-info → stigg_api_client_v2-5.9.0.dist-info}/METADATA +3 -4
  70. stigg_api_client_v2-5.9.0.dist-info/RECORD +73 -0
  71. stigg/edge_utils.py +0 -28
  72. stigg/generated/scalars.py +0 -6
  73. stigg_api_client_v2-0.693.0.dist-info/RECORD +0 -54
  74. {stigg_api_client_v2-0.693.0.dist-info → stigg_api_client_v2-5.9.0.dist-info}/LICENSE +0 -0
  75. {stigg_api_client_v2-0.693.0.dist-info → stigg_api_client_v2-5.9.0.dist-info}/WHEEL +0 -0
@@ -1,17 +1,17 @@
1
- # Generated by ariadne-codegen on 2023-12-07 19:22
1
+ # Generated by ariadne-codegen
2
2
 
3
3
  import json
4
- from typing import Any, Dict, Optional, TypeVar, cast
4
+ from typing import IO, Any, Dict, List, Optional, Tuple, TypeVar, cast
5
5
 
6
6
  import httpx
7
7
  from pydantic import BaseModel
8
- from pydantic.json import pydantic_encoder
8
+ from pydantic_core import to_jsonable_python
9
9
 
10
- from .base_model import UNSET
10
+ from .base_model import UNSET, Upload
11
11
  from .exceptions import (
12
12
  GraphQLClientGraphQLMultiError,
13
13
  GraphQLClientHttpError,
14
- GraphQlClientInvalidResponseError,
14
+ GraphQLClientInvalidResponseError,
15
15
  )
16
16
 
17
17
  Self = TypeVar("Self", bound="BaseClient")
@@ -41,15 +41,32 @@ class BaseClient:
41
41
  self.http_client.close()
42
42
 
43
43
  def execute(
44
- self, query: str, variables: Optional[Dict[str, Any]] = None
44
+ self,
45
+ query: str,
46
+ operation_name: Optional[str] = None,
47
+ variables: Optional[Dict[str, Any]] = None,
48
+ **kwargs: Any,
45
49
  ) -> httpx.Response:
46
- payload: Dict[str, Any] = {"query": query}
47
- if variables:
48
- payload["variables"] = self._convert_dict_to_json_serializable(variables)
49
- content = json.dumps(payload, default=pydantic_encoder)
50
- return self.http_client.post(url=self.url, content=content)
50
+ processed_variables, files, files_map = self._process_variables(variables)
51
+
52
+ if files and files_map:
53
+ return self._execute_multipart(
54
+ query=query,
55
+ operation_name=operation_name,
56
+ variables=processed_variables,
57
+ files=files,
58
+ files_map=files_map,
59
+ **kwargs,
60
+ )
51
61
 
52
- def get_data(self, response: httpx.Response) -> dict[str, Any]:
62
+ return self._execute_json(
63
+ query=query,
64
+ operation_name=operation_name,
65
+ variables=processed_variables,
66
+ **kwargs,
67
+ )
68
+
69
+ def get_data(self, response: httpx.Response) -> Dict[str, Any]:
53
70
  if not response.is_success:
54
71
  raise GraphQLClientHttpError(
55
72
  status_code=response.status_code, response=response
@@ -58,12 +75,14 @@ class BaseClient:
58
75
  try:
59
76
  response_json = response.json()
60
77
  except ValueError as exc:
61
- raise GraphQlClientInvalidResponseError(response=response) from exc
78
+ raise GraphQLClientInvalidResponseError(response=response) from exc
62
79
 
63
- if (not isinstance(response_json, dict)) or ("data" not in response_json):
64
- raise GraphQlClientInvalidResponseError(response=response)
80
+ if (not isinstance(response_json, dict)) or (
81
+ "data" not in response_json and "errors" not in response_json
82
+ ):
83
+ raise GraphQLClientInvalidResponseError(response=response)
65
84
 
66
- data = response_json["data"]
85
+ data = response_json.get("data")
67
86
  errors = response_json.get("errors")
68
87
 
69
88
  if errors:
@@ -71,14 +90,18 @@ class BaseClient:
71
90
  errors_dicts=errors, data=data
72
91
  )
73
92
 
74
- return cast(dict[str, Any], data)
93
+ return cast(Dict[str, Any], data)
75
94
 
76
- def _convert_value(self, value: Any) -> Any:
77
- if isinstance(value, BaseModel):
78
- return value.dict(by_alias=True, exclude_unset=True)
79
- if isinstance(value, list):
80
- return [self._convert_value(item) for item in value]
81
- return value
95
+ def _process_variables(
96
+ self, variables: Optional[Dict[str, Any]]
97
+ ) -> Tuple[
98
+ Dict[str, Any], Dict[str, Tuple[str, IO[bytes], str]], Dict[str, List[str]]
99
+ ]:
100
+ if not variables:
101
+ return {}, {}, {}
102
+
103
+ serializable_variables = self._convert_dict_to_json_serializable(variables)
104
+ return self._get_files_from_variables(serializable_variables)
82
105
 
83
106
  def _convert_dict_to_json_serializable(
84
107
  self, dict_: Dict[str, Any]
@@ -88,3 +111,101 @@ class BaseClient:
88
111
  for key, value in dict_.items()
89
112
  if value is not UNSET
90
113
  }
114
+
115
+ def _convert_value(self, value: Any) -> Any:
116
+ if isinstance(value, BaseModel):
117
+ return value.model_dump(by_alias=True, exclude_unset=True)
118
+ if isinstance(value, list):
119
+ return [self._convert_value(item) for item in value]
120
+ return value
121
+
122
+ def _get_files_from_variables(
123
+ self, variables: Dict[str, Any]
124
+ ) -> Tuple[
125
+ Dict[str, Any], Dict[str, Tuple[str, IO[bytes], str]], Dict[str, List[str]]
126
+ ]:
127
+ files_map: Dict[str, List[str]] = {}
128
+ files_list: List[Upload] = []
129
+
130
+ def separate_files(path: str, obj: Any) -> Any:
131
+ if isinstance(obj, list):
132
+ nulled_list = []
133
+ for index, value in enumerate(obj):
134
+ value = separate_files(f"{path}.{index}", value)
135
+ nulled_list.append(value)
136
+ return nulled_list
137
+
138
+ if isinstance(obj, dict):
139
+ nulled_dict = {}
140
+ for key, value in obj.items():
141
+ value = separate_files(f"{path}.{key}", value)
142
+ nulled_dict[key] = value
143
+ return nulled_dict
144
+
145
+ if isinstance(obj, Upload):
146
+ if obj in files_list:
147
+ file_index = files_list.index(obj)
148
+ files_map[str(file_index)].append(path)
149
+ else:
150
+ file_index = len(files_list)
151
+ files_list.append(obj)
152
+ files_map[str(file_index)] = [path]
153
+ return None
154
+
155
+ return obj
156
+
157
+ nulled_variables = separate_files("variables", variables)
158
+ files: Dict[str, Tuple[str, IO[bytes], str]] = {
159
+ str(i): (file_.filename, cast(IO[bytes], file_.content), file_.content_type)
160
+ for i, file_ in enumerate(files_list)
161
+ }
162
+ return nulled_variables, files, files_map
163
+
164
+ def _execute_multipart(
165
+ self,
166
+ query: str,
167
+ operation_name: Optional[str],
168
+ variables: Dict[str, Any],
169
+ files: Dict[str, Tuple[str, IO[bytes], str]],
170
+ files_map: Dict[str, List[str]],
171
+ **kwargs: Any,
172
+ ) -> httpx.Response:
173
+ data = {
174
+ "operations": json.dumps(
175
+ {
176
+ "query": query,
177
+ "operationName": operation_name,
178
+ "variables": variables,
179
+ },
180
+ default=to_jsonable_python,
181
+ ),
182
+ "map": json.dumps(files_map, default=to_jsonable_python),
183
+ }
184
+
185
+ return self.http_client.post(url=self.url, data=data, files=files, **kwargs)
186
+
187
+ def _execute_json(
188
+ self,
189
+ query: str,
190
+ operation_name: Optional[str],
191
+ variables: Dict[str, Any],
192
+ **kwargs: Any,
193
+ ) -> httpx.Response:
194
+ headers: Dict[str, str] = {"Content-Type": "application/json"}
195
+ headers.update(kwargs.get("headers", {}))
196
+
197
+ merged_kwargs: Dict[str, Any] = kwargs.copy()
198
+ merged_kwargs["headers"] = headers
199
+
200
+ return self.http_client.post(
201
+ url=self.url,
202
+ content=json.dumps(
203
+ {
204
+ "query": query,
205
+ "operationName": operation_name,
206
+ "variables": variables,
207
+ },
208
+ default=to_jsonable_python,
209
+ ),
210
+ **merged_kwargs,
211
+ )
@@ -1,12 +1,8 @@
1
- # Generated by ariadne-codegen on 2023-12-07 19:22
1
+ # Generated by ariadne-codegen
2
2
 
3
- from typing import Any, Dict, Type, Union, get_args, get_origin
3
+ from io import IOBase
4
4
 
5
- from pydantic import BaseModel as PydanticBaseModel
6
- from pydantic.class_validators import validator
7
- from pydantic.fields import ModelField
8
-
9
- from .scalars import SCALARS_PARSE_FUNCTIONS, SCALARS_SERIALIZE_FUNCTIONS
5
+ from pydantic import BaseModel as PydanticBaseModel, ConfigDict
10
6
 
11
7
 
12
8
  class UnsetType:
@@ -18,43 +14,16 @@ UNSET = UnsetType()
18
14
 
19
15
 
20
16
  class BaseModel(PydanticBaseModel):
21
- class Config:
22
- allow_population_by_field_name = True
23
- validate_assignment = True
24
- arbitrary_types_allowed = True
25
-
26
- # pylint: disable=no-self-argument
27
- @validator("*", pre=True)
28
- def parse_custom_scalars(cls, value: Any, field: ModelField) -> Any:
29
- return cls._parse_custom_scalar_value(value, field.annotation)
30
-
31
- @classmethod
32
- def _parse_custom_scalar_value(cls, value: Any, type_: Type[Any]) -> Any:
33
- origin = get_origin(type_)
34
- args = get_args(type_)
35
- if origin is list and isinstance(value, list):
36
- return [cls._parse_custom_scalar_value(item, args[0]) for item in value]
37
-
38
- if origin is Union and type(None) in args:
39
- sub_type: Any = list(filter(None, args))[0]
40
- return cls._parse_custom_scalar_value(value, sub_type)
41
-
42
- decode = SCALARS_PARSE_FUNCTIONS.get(type_)
43
- if value and decode and callable(decode):
44
- return decode(value)
45
-
46
- return value
47
-
48
- def dict(self, **kwargs: Any) -> Dict[str, Any]:
49
- dict_ = super().dict(**kwargs)
50
- return {key: self._serialize_value(value) for key, value in dict_.items()}
51
-
52
- def _serialize_value(self, value: Any) -> Any:
53
- serialize = SCALARS_SERIALIZE_FUNCTIONS.get(type(value))
54
- if serialize and callable(serialize):
55
- return serialize(value)
56
-
57
- if isinstance(value, list):
58
- return [self._serialize_value(item) for item in value]
59
-
60
- return value
17
+ model_config = ConfigDict(
18
+ populate_by_name=True,
19
+ validate_assignment=True,
20
+ arbitrary_types_allowed=True,
21
+ protected_namespaces=(),
22
+ )
23
+
24
+
25
+ class Upload:
26
+ def __init__(self, filename: str, content: IOBase, content_type: str):
27
+ self.filename = filename
28
+ self.content = content
29
+ self.content_type = content_type
@@ -1,4 +1,4 @@
1
- # Generated by ariadne-codegen on 2023-12-07 19:22
1
+ # Generated by ariadne-codegen
2
2
  # Source: operations.graphql
3
3
 
4
4
  from pydantic import Field
@@ -17,5 +17,4 @@ class CancelSubscriptionCancelSubscription(SlimSubscriptionFragment):
17
17
  pass
18
18
 
19
19
 
20
- CancelSubscription.update_forward_refs()
21
- CancelSubscriptionCancelSubscription.update_forward_refs()
20
+ CancelSubscription.model_rebuild()
@@ -1,4 +1,4 @@
1
- # Generated by ariadne-codegen on 2023-12-07 19:22
1
+ # Generated by ariadne-codegen
2
2
  # Source: operations.graphql
3
3
 
4
4
  from pydantic import Field
@@ -8,6 +8,3 @@ from .base_model import BaseModel
8
8
 
9
9
  class CancelSubscriptionUpdates(BaseModel):
10
10
  cancel_schedule: str = Field(alias="cancelSchedule")
11
-
12
-
13
- CancelSubscriptionUpdates.update_forward_refs()