hyper-sdk 0.9.1__tar.gz → 0.11.0__tar.gz

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 (29) hide show
  1. {hyper_sdk-0.9.1 → hyper_sdk-0.11.0}/PKG-INFO +1 -1
  2. {hyper_sdk-0.9.1 → hyper_sdk-0.11.0}/hyper_sdk/__init__.py +1 -0
  3. {hyper_sdk-0.9.1 → hyper_sdk-0.11.0}/hyper_sdk/akamai_input.py +2 -1
  4. hyper_sdk-0.11.0/hyper_sdk/incapsula/__init__.py +2 -0
  5. hyper_sdk-0.11.0/hyper_sdk/incapsula/dynamic.py +48 -0
  6. {hyper_sdk-0.9.1 → hyper_sdk-0.11.0}/hyper_sdk/session.py +51 -8
  7. {hyper_sdk-0.9.1 → hyper_sdk-0.11.0}/hyper_sdk.egg-info/PKG-INFO +1 -1
  8. {hyper_sdk-0.9.1 → hyper_sdk-0.11.0}/hyper_sdk.egg-info/SOURCES.txt +1 -0
  9. {hyper_sdk-0.9.1 → hyper_sdk-0.11.0}/pyproject.toml +1 -1
  10. hyper_sdk-0.9.1/hyper_sdk/incapsula/__init__.py +0 -1
  11. {hyper_sdk-0.9.1 → hyper_sdk-0.11.0}/LICENSE +0 -0
  12. {hyper_sdk-0.9.1 → hyper_sdk-0.11.0}/README.md +0 -0
  13. {hyper_sdk-0.9.1 → hyper_sdk-0.11.0}/hyper_sdk/akamai/__init__.py +0 -0
  14. {hyper_sdk-0.9.1 → hyper_sdk-0.11.0}/hyper_sdk/akamai/pixel.py +0 -0
  15. {hyper_sdk-0.9.1 → hyper_sdk-0.11.0}/hyper_sdk/akamai/script_path.py +0 -0
  16. {hyper_sdk-0.9.1 → hyper_sdk-0.11.0}/hyper_sdk/akamai/sec_cpt.py +0 -0
  17. {hyper_sdk-0.9.1 → hyper_sdk-0.11.0}/hyper_sdk/akamai/stop_signal.py +0 -0
  18. {hyper_sdk-0.9.1 → hyper_sdk-0.11.0}/hyper_sdk/datadome/__init__.py +0 -0
  19. {hyper_sdk-0.9.1 → hyper_sdk-0.11.0}/hyper_sdk/datadome/parse.py +0 -0
  20. {hyper_sdk-0.9.1 → hyper_sdk-0.11.0}/hyper_sdk/datadome_input.py +0 -0
  21. {hyper_sdk-0.9.1 → hyper_sdk-0.11.0}/hyper_sdk/incapsula/utmvc.py +0 -0
  22. {hyper_sdk-0.9.1 → hyper_sdk-0.11.0}/hyper_sdk/incapsula_input.py +0 -0
  23. {hyper_sdk-0.9.1 → hyper_sdk-0.11.0}/hyper_sdk/kasada/__init__.py +0 -0
  24. {hyper_sdk-0.9.1 → hyper_sdk-0.11.0}/hyper_sdk/kasada/parse.py +0 -0
  25. {hyper_sdk-0.9.1 → hyper_sdk-0.11.0}/hyper_sdk/kasada_input.py +0 -0
  26. {hyper_sdk-0.9.1 → hyper_sdk-0.11.0}/hyper_sdk.egg-info/dependency_links.txt +0 -0
  27. {hyper_sdk-0.9.1 → hyper_sdk-0.11.0}/hyper_sdk.egg-info/requires.txt +0 -0
  28. {hyper_sdk-0.9.1 → hyper_sdk-0.11.0}/hyper_sdk.egg-info/top_level.txt +0 -0
  29. {hyper_sdk-0.9.1 → hyper_sdk-0.11.0}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: hyper_sdk
3
- Version: 0.9.1
3
+ Version: 0.11.0
4
4
  Summary: Hyper Solutions Python SDK
5
5
  License: MIT License
6
6
 
@@ -3,6 +3,7 @@ from .akamai.script_path import *
3
3
  from .akamai.sec_cpt import *
4
4
  from .akamai.stop_signal import *
5
5
  from .incapsula.utmvc import *
6
+ from .incapsula.dynamic import *
6
7
  from .session import *
7
8
  from .kasada.parse import *
8
9
  from .datadome.parse import *
@@ -1,5 +1,5 @@
1
1
  class SensorInput:
2
- def __init__(self, abck: str, bmsz: str, version: str, page_url: str, user_agent: str, ip: str, acceptLanguage: str, script_hash="", dynamic_values=""):
2
+ def __init__(self, abck: str, bmsz: str, version: str, page_url: str, user_agent: str, ip: str, acceptLanguage: str, context: str, script_hash="", dynamic_values=""):
3
3
  self.abck = abck
4
4
  self.bmsz = bmsz
5
5
  self.version = version
@@ -7,6 +7,7 @@ class SensorInput:
7
7
  self.user_agent = user_agent
8
8
  self.script_hash = script_hash
9
9
  self.dynamic_values = dynamic_values
10
+ self.context = context
10
11
  self.ip = ip
11
12
  self.acceptLanguage = acceptLanguage
12
13
 
@@ -0,0 +1,2 @@
1
+ from .utmvc import *
2
+ from .dynamic import *
@@ -0,0 +1,48 @@
1
+ import re
2
+ from urllib.parse import urlparse
3
+
4
+ # Precompiled regular expressions
5
+ reese_script_regex = re.compile(r'src\s*=\s*"((/[^/]+/\d+)(?:\?.*)?)"')
6
+
7
+
8
+ def parse_dynamic_reese_script(html_content: str, url_str: str) -> tuple[str, str]:
9
+ """
10
+ Parses the sensor path and script path from the given HTML content.
11
+
12
+ This function searches the provided HTML for a script element containing a specific pattern
13
+ and extracts both the sensor path (shortened path) and script path (the full path).
14
+ It requires that the HTML contains "Pardon Our Interruption" to confirm it's the correct page type.
15
+ It also takes a URL string, extracts the hostname, and appends it to the sensor path.
16
+
17
+ Args:
18
+ html_content (str): The HTML content to parse.
19
+ url_str (str): The URL string to extract the hostname from.
20
+
21
+ Returns:
22
+ tuple[str, str]: A tuple containing the sensor path (with hostname) and script path.
23
+
24
+ Raises:
25
+ ValueError: If the URL is invalid.
26
+ Exception: If the page is not an interruption page or if the Reese script is not found.
27
+ """
28
+ # Parse the URL to extract hostname
29
+ try:
30
+ parsed_url = urlparse(url_str)
31
+ hostname = parsed_url.netloc
32
+ except Exception:
33
+ raise ValueError("hyper-sdk: invalid URL")
34
+
35
+ # Verify this is an interruption page
36
+ if "Pardon Our Interruption" not in html_content:
37
+ raise Exception("hyper-sdk: not an interruption page")
38
+
39
+ # Find the Reese script
40
+ match = reese_script_regex.search(html_content)
41
+ if not match or len(match.groups()) < 2:
42
+ raise Exception("hyper-sdk: reese script not found")
43
+
44
+ script_path = match.group(1)
45
+ sensor_path = match.group(2)
46
+
47
+ # Append the hostname to the sensor path
48
+ return f"{sensor_path}?d={hostname}", script_path
@@ -17,7 +17,7 @@ class Session:
17
17
  self.jwt_key = jwt_key
18
18
  self.client = requests.Session() if client is None else client
19
19
 
20
- def generate_sensor_data(self, input_data: SensorInput) -> str:
20
+ def generate_sensor_data(self, input_data: SensorInput) -> tuple[str, str]:
21
21
  """
22
22
  Returns the sensor data required to generate valid akamai cookies using the Hyper Solutions API.
23
23
 
@@ -26,9 +26,23 @@ class Session:
26
26
 
27
27
  Returns:
28
28
  str: Sensor data as a string.
29
+ str: Context data as a string.
29
30
  """
30
- sensor_endpoint = "https://akm.justhyped.dev/sensor"
31
- return self._send_request(sensor_endpoint, {
31
+ sensor_endpoint = "https://akm.justhyped.dev/v2/sensor"
32
+ if not self.api_key:
33
+ raise ValueError("Missing API key")
34
+
35
+ headers = {
36
+ 'Content-Type': 'application/json',
37
+ 'Accept-Encoding': 'gzip',
38
+ 'X-Api-Key': self.api_key
39
+ }
40
+
41
+ if self.jwt_key:
42
+ signature = self.generate_signature()
43
+ headers['X-Signature'] = signature
44
+
45
+ response = self.client.post(sensor_endpoint, headers=headers, json={
32
46
  'userAgent': input_data.user_agent,
33
47
  'abck': input_data.abck,
34
48
  'bmsz': input_data.bmsz,
@@ -40,6 +54,16 @@ class Session:
40
54
  'acceptLanguage': input_data.acceptLanguage,
41
55
  })
42
56
 
57
+ response_data = response.json()
58
+
59
+ if "error" in response_data and response_data["error"]:
60
+ raise Exception(f"API returned with error: {response_data['error']}")
61
+
62
+ if response.status_code != 200:
63
+ raise Exception(f"API returned with status code: {response.status_code}")
64
+
65
+ return response_data["payload"], response_data["context"]
66
+
43
67
  def generate_sbsd_data(self, input_data: SbsdInput) -> str:
44
68
  """
45
69
  Returns the sbsd data required to solve SBSD using the Hyper Solutions API.
@@ -133,22 +157,41 @@ class Session:
133
157
 
134
158
  Returns:
135
159
  str: The utmvc cookie as a string.
160
+ str: The swhanedl parameter.
136
161
 
137
162
  Raises:
138
163
  ValueError: If the script attribute or session IDs in input_data are empty.
139
164
  """
140
- if not input_data.script:
141
- raise ValueError("script must be non empty")
165
+ if not self.api_key:
166
+ raise ValueError("Missing API key")
142
167
 
143
- if not input_data.session_ids:
144
- raise ValueError("no session ids set")
168
+ headers = {
169
+ 'Content-Type': 'application/json',
170
+ 'Accept-Encoding': 'gzip',
171
+ 'X-Api-Key': self.api_key
172
+ }
173
+
174
+ if self.jwt_key:
175
+ signature = self.generate_signature()
176
+ headers['X-Signature'] = signature
145
177
 
146
- return self._send_request("https://incapsula.justhyped.dev/utmvc", {
178
+ response = self.client.post("https://incapsula.justhyped.dev/utmvc", headers=headers, json={
147
179
  'userAgent': input_data.user_agent,
148
180
  'sessionIds': input_data.session_ids,
149
181
  'script': input_data.script,
150
182
  })
151
183
 
184
+ response_data = response.json()
185
+
186
+ if "error" in response_data and response_data["error"]:
187
+ raise Exception(f"API returned with error: {response_data['error']}")
188
+
189
+ if response.status_code != 200:
190
+ raise Exception(f"API returned with status code: {response.status_code}")
191
+
192
+ return response_data["payload"], response_data["swhanedl"]
193
+
194
+
152
195
  def generate_kasada_pow(self, input_data: KasadaPowInput) -> str:
153
196
  """
154
197
  Returns the x-kpsdk-cd value using the Hyper Solutions API.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: hyper_sdk
3
- Version: 0.9.1
3
+ Version: 0.11.0
4
4
  Summary: Hyper Solutions Python SDK
5
5
  License: MIT License
6
6
 
@@ -20,6 +20,7 @@ hyper_sdk/akamai/stop_signal.py
20
20
  hyper_sdk/datadome/__init__.py
21
21
  hyper_sdk/datadome/parse.py
22
22
  hyper_sdk/incapsula/__init__.py
23
+ hyper_sdk/incapsula/dynamic.py
23
24
  hyper_sdk/incapsula/utmvc.py
24
25
  hyper_sdk/kasada/__init__.py
25
26
  hyper_sdk/kasada/parse.py
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "hyper_sdk"
7
- version = "0.9.1"
7
+ version = "0.11.0"
8
8
  description = "Hyper Solutions Python SDK"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.6"
@@ -1 +0,0 @@
1
- from .utmvc import *
File without changes
File without changes
File without changes