unique_toolkit 0.5.43__py3-none-any.whl → 0.5.44__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.
- unique_toolkit/app/verification.py +9 -8
- {unique_toolkit-0.5.43.dist-info → unique_toolkit-0.5.44.dist-info}/METADATA +3 -2
- {unique_toolkit-0.5.43.dist-info → unique_toolkit-0.5.44.dist-info}/RECORD +5 -5
- {unique_toolkit-0.5.43.dist-info → unique_toolkit-0.5.44.dist-info}/LICENSE +0 -0
- {unique_toolkit-0.5.43.dist-info → unique_toolkit-0.5.44.dist-info}/WHEEL +0 -0
@@ -1,4 +1,5 @@
|
|
1
1
|
import logging
|
2
|
+
from typing import Callable, TypeVar
|
2
3
|
|
3
4
|
import unique_sdk
|
4
5
|
|
@@ -11,12 +12,16 @@ class WebhookVerificationError(Exception):
|
|
11
12
|
pass
|
12
13
|
|
13
14
|
|
15
|
+
T = TypeVar("T")
|
16
|
+
|
17
|
+
|
14
18
|
def verify_signature_and_construct_event(
|
15
19
|
headers: dict[str, str],
|
16
20
|
payload: bytes,
|
17
21
|
endpoint_secret: str,
|
18
22
|
logger: logging.Logger = logging.getLogger(__name__),
|
19
|
-
|
23
|
+
event_constructor: Callable[..., T] = Event,
|
24
|
+
) -> T:
|
20
25
|
"""
|
21
26
|
Verify the signature of a webhook and construct an event object.
|
22
27
|
|
@@ -25,18 +30,14 @@ def verify_signature_and_construct_event(
|
|
25
30
|
payload (bytes): The raw payload of the webhook request.
|
26
31
|
endpoint_secret (str): The secret used to verify the webhook signature.
|
27
32
|
logger (logging.Logger): A logger instance for logging messages.
|
28
|
-
|
33
|
+
event_constructor (Callable[..., T]): A callable that constructs an event object.
|
29
34
|
Returns:
|
30
|
-
|
31
|
-
If successful, returns an Event object.
|
32
|
-
If unsuccessful, returns a tuple with an error response and HTTP status code.
|
35
|
+
T: The constructed event object.
|
33
36
|
|
34
37
|
Raises:
|
35
38
|
WebhookVerificationError: If there's an error during verification or event construction.
|
36
39
|
"""
|
37
40
|
|
38
|
-
# Only verify the event if there is an endpoint secret defined
|
39
|
-
# Otherwise use the basic event deserialized with json
|
40
41
|
sig_header = headers.get("X-Unique-Signature")
|
41
42
|
timestamp = headers.get("X-Unique-Created-At")
|
42
43
|
|
@@ -52,7 +53,7 @@ def verify_signature_and_construct_event(
|
|
52
53
|
endpoint_secret,
|
53
54
|
)
|
54
55
|
logger.info("✅ Webhook signature verification successful.")
|
55
|
-
return
|
56
|
+
return event_constructor(**event)
|
56
57
|
except unique_sdk.SignatureVerificationError as e:
|
57
58
|
logger.error("⚠️ Webhook signature verification failed. " + str(e))
|
58
59
|
raise WebhookVerificationError(f"Signature verification failed: {str(e)}")
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: unique_toolkit
|
3
|
-
Version: 0.5.
|
3
|
+
Version: 0.5.44
|
4
4
|
Summary:
|
5
5
|
License: Proprietary
|
6
6
|
Author: Martin Fadler
|
@@ -100,7 +100,8 @@ All notable changes to this project will be documented in this file.
|
|
100
100
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
101
101
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
102
102
|
|
103
|
-
|
103
|
+
## [0.5.44] - 2024-12-18
|
104
|
+
- Add `event_constructor` to `verify_signature_and_construct_event` to allow for custom event construction.
|
104
105
|
|
105
106
|
## [0.5.43] - 2024-12-13
|
106
107
|
- Add `Prompt` class to handle templated prompts that can be formatted into LanguageModelSystemMessage and LanguageModelUserMessage.
|
@@ -9,7 +9,7 @@ unique_toolkit/app/init_sdk.py,sha256=Nv4Now4pMfM0AgRhbtatLpm_39rKxn0WmRLwmPhRl-
|
|
9
9
|
unique_toolkit/app/performance/async_tasks.py,sha256=H0l3OAcosLwNHZ8d2pd-Di4wHIXfclEvagi5kfqLFPA,1941
|
10
10
|
unique_toolkit/app/performance/async_wrapper.py,sha256=yVVcRDkcdyfjsxro-N29SBvi-7773wnfDplef6-y8xw,1077
|
11
11
|
unique_toolkit/app/schemas.py,sha256=6RY7Ex-B3pOnFILlitHEi9sqJvupbpdxlN9xt33qRsM,1571
|
12
|
-
unique_toolkit/app/verification.py,sha256=
|
12
|
+
unique_toolkit/app/verification.py,sha256=mffa6wm0i4hJbwzofePrkaia46xumMzECwQ0T3eKAx0,1929
|
13
13
|
unique_toolkit/chat/__init__.py,sha256=1prdTVfLOf6NgU-Aa1VIO-XiR6OYuRm51LaVRfKDCqc,267
|
14
14
|
unique_toolkit/chat/schemas.py,sha256=IHOnb3pWlRlSPoEUWBTl6LK8YeMdlg2iXi9ghyBeiLw,1495
|
15
15
|
unique_toolkit/chat/service.py,sha256=lFcwCKHRHVLkMIO1cBHwH_Py0uZ4mmvgkUwQuZkpsxI,21438
|
@@ -41,7 +41,7 @@ unique_toolkit/language_model/prompt.py,sha256=JSawaLjQg3VR-E2fK8engFyJnNdk21zaO
|
|
41
41
|
unique_toolkit/language_model/schemas.py,sha256=MBwEAFnnCYjSpbZDUYLrqkCc-0bsarsepSQEj1v6YEY,6991
|
42
42
|
unique_toolkit/language_model/service.py,sha256=brNCPRA0XxgqHi2rI5i2lyFCkUiw4MNMe1VaR3UgWmY,15500
|
43
43
|
unique_toolkit/language_model/utils.py,sha256=bPQ4l6_YO71w-zaIPanUUmtbXC1_hCvLK0tAFc3VCRc,1902
|
44
|
-
unique_toolkit-0.5.
|
45
|
-
unique_toolkit-0.5.
|
46
|
-
unique_toolkit-0.5.
|
47
|
-
unique_toolkit-0.5.
|
44
|
+
unique_toolkit-0.5.44.dist-info/LICENSE,sha256=GlN8wHNdh53xwOPg44URnwag6TEolCjoq3YD_KrWgss,193
|
45
|
+
unique_toolkit-0.5.44.dist-info/METADATA,sha256=IXHGnl23ctzUc3Pm2BXVwDoHyScGkgd7dBawlOkEAZ4,15154
|
46
|
+
unique_toolkit-0.5.44.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
|
47
|
+
unique_toolkit-0.5.44.dist-info/RECORD,,
|
File without changes
|
File without changes
|