betyebo 0.1.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.
- betyebo/__init__.py +37 -0
- betyebo/errors.py +31 -0
- betyebo/idempotency.py +107 -0
- betyebo/models.py +36 -0
- betyebo/providers/__init__.py +8 -0
- betyebo/providers/base.py +89 -0
- betyebo/providers/generic.py +64 -0
- betyebo/providers/github.py +55 -0
- betyebo/providers/shopify.py +61 -0
- betyebo/providers/slack.py +66 -0
- betyebo/providers/stripe.py +82 -0
- betyebo/py.typed +0 -0
- betyebo/registry.py +93 -0
- betyebo-0.1.0.dist-info/METADATA +168 -0
- betyebo-0.1.0.dist-info/RECORD +18 -0
- betyebo-0.1.0.dist-info/WHEEL +5 -0
- betyebo-0.1.0.dist-info/licenses/LICENSE +21 -0
- betyebo-0.1.0.dist-info/top_level.txt +1 -0
betyebo/__init__.py
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
from .errors import (
|
|
2
|
+
ExpiredTimestamp,
|
|
3
|
+
InvalidSignature,
|
|
4
|
+
MalformedPayload,
|
|
5
|
+
MissingHeader,
|
|
6
|
+
UnknownProvider,
|
|
7
|
+
WebhookError,
|
|
8
|
+
)
|
|
9
|
+
from .idempotency import IdempotencyStore, InMemoryIdempotencyStore, JSONFileIdempotencyStore
|
|
10
|
+
from .models import WebhookEvent
|
|
11
|
+
from .registry import WebhookSDK
|
|
12
|
+
from .providers.generic import GenericHMAC
|
|
13
|
+
from .providers.github import GitHub
|
|
14
|
+
from .providers.shopify import Shopify
|
|
15
|
+
from .providers.slack import Slack
|
|
16
|
+
from .providers.stripe import Stripe
|
|
17
|
+
|
|
18
|
+
__all__ = [
|
|
19
|
+
"WebhookSDK",
|
|
20
|
+
"WebhookEvent",
|
|
21
|
+
"WebhookError",
|
|
22
|
+
"InvalidSignature",
|
|
23
|
+
"ExpiredTimestamp",
|
|
24
|
+
"UnknownProvider",
|
|
25
|
+
"MalformedPayload",
|
|
26
|
+
"MissingHeader",
|
|
27
|
+
"Stripe",
|
|
28
|
+
"GitHub",
|
|
29
|
+
"Shopify",
|
|
30
|
+
"Slack",
|
|
31
|
+
"GenericHMAC",
|
|
32
|
+
"IdempotencyStore",
|
|
33
|
+
"InMemoryIdempotencyStore",
|
|
34
|
+
"JSONFileIdempotencyStore",
|
|
35
|
+
]
|
|
36
|
+
|
|
37
|
+
__version__ = "0.1.0"
|
betyebo/errors.py
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"""Exceptions for webhook verification and parsing."""
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class WebhookError(Exception):
|
|
5
|
+
"""Base error for the webhook SDK."""
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class InvalidSignature(WebhookError):
|
|
9
|
+
"""Raised when a signature is missing or does not match."""
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class ExpiredTimestamp(WebhookError):
|
|
13
|
+
"""Raised when a webhook timestamp is outside the allowed tolerance."""
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class UnknownProvider(WebhookError):
|
|
17
|
+
"""Raised when no provider is registered for the given name."""
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class MalformedPayload(WebhookError):
|
|
21
|
+
"""Raised when a payload cannot be parsed or is missing required fields."""
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
class MissingHeader(WebhookError):
|
|
25
|
+
"""Raised when a required header is missing."""
|
|
26
|
+
|
|
27
|
+
def __init__(self, header: str, provider: str | None = None):
|
|
28
|
+
self.header = header
|
|
29
|
+
self.provider = provider
|
|
30
|
+
where = f" for provider '{provider}'" if provider else ""
|
|
31
|
+
super().__init__(f"Missing required header '{header}'{where}")
|
betyebo/idempotency.py
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
from threading import Lock
|
|
6
|
+
from typing import Protocol
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class IdempotencyStore(Protocol):
|
|
10
|
+
"""Minimal interface for deduping webhook events."""
|
|
11
|
+
|
|
12
|
+
def check_and_mark(self, key: str) -> bool:
|
|
13
|
+
"""Return True if this key was not seen before (and mark it as seen)."""
|
|
14
|
+
...
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class InMemoryIdempotencyStore:
|
|
18
|
+
"""Simple in-memory dedupe store.
|
|
19
|
+
|
|
20
|
+
Good for tests/single-process apps. Use Redis/DB in production.
|
|
21
|
+
"""
|
|
22
|
+
|
|
23
|
+
def __init__(self) -> None:
|
|
24
|
+
self._seen: set[str] = set()
|
|
25
|
+
self._lock = Lock()
|
|
26
|
+
|
|
27
|
+
def seen(self, key: str) -> bool:
|
|
28
|
+
with self._lock:
|
|
29
|
+
return key in self._seen
|
|
30
|
+
|
|
31
|
+
def mark(self, key: str) -> None:
|
|
32
|
+
with self._lock:
|
|
33
|
+
self._seen.add(key)
|
|
34
|
+
|
|
35
|
+
def check_and_mark(self, key: str) -> bool:
|
|
36
|
+
with self._lock:
|
|
37
|
+
if key in self._seen:
|
|
38
|
+
return False
|
|
39
|
+
self._seen.add(key)
|
|
40
|
+
return True
|
|
41
|
+
|
|
42
|
+
def clear(self) -> None:
|
|
43
|
+
with self._lock:
|
|
44
|
+
self._seen.clear()
|
|
45
|
+
|
|
46
|
+
def __len__(self) -> int:
|
|
47
|
+
with self._lock:
|
|
48
|
+
return len(self._seen)
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
class JSONFileIdempotencyStore:
|
|
52
|
+
"""Tiny file-backed dedupe store.
|
|
53
|
+
|
|
54
|
+
Handy for scripts and local workers. For concurrent production workloads,
|
|
55
|
+
use Redis or a database instead.
|
|
56
|
+
"""
|
|
57
|
+
|
|
58
|
+
def __init__(self, path: str | Path):
|
|
59
|
+
self.path = Path(path)
|
|
60
|
+
self._lock = Lock()
|
|
61
|
+
self._seen: set[str] = set()
|
|
62
|
+
self._load()
|
|
63
|
+
|
|
64
|
+
def _load(self) -> None:
|
|
65
|
+
if not self.path.exists():
|
|
66
|
+
return
|
|
67
|
+
try:
|
|
68
|
+
data = json.loads(self.path.read_text(encoding="utf-8"))
|
|
69
|
+
if isinstance(data, list):
|
|
70
|
+
self._seen = {str(x) for x in data}
|
|
71
|
+
except Exception:
|
|
72
|
+
# Corrupt/partial file: start fresh rather than crashing.
|
|
73
|
+
self._seen = set()
|
|
74
|
+
|
|
75
|
+
def _flush(self) -> None:
|
|
76
|
+
self.path.parent.mkdir(parents=True, exist_ok=True)
|
|
77
|
+
tmp = self.path.with_suffix(self.path.suffix + ".tmp")
|
|
78
|
+
tmp.write_text(json.dumps(sorted(self._seen)), encoding="utf-8")
|
|
79
|
+
tmp.replace(self.path)
|
|
80
|
+
|
|
81
|
+
def seen(self, key: str) -> bool:
|
|
82
|
+
with self._lock:
|
|
83
|
+
return key in self._seen
|
|
84
|
+
|
|
85
|
+
def mark(self, key: str) -> None:
|
|
86
|
+
with self._lock:
|
|
87
|
+
if key in self._seen:
|
|
88
|
+
return
|
|
89
|
+
self._seen.add(key)
|
|
90
|
+
self._flush()
|
|
91
|
+
|
|
92
|
+
def check_and_mark(self, key: str) -> bool:
|
|
93
|
+
with self._lock:
|
|
94
|
+
if key in self._seen:
|
|
95
|
+
return False
|
|
96
|
+
self._seen.add(key)
|
|
97
|
+
self._flush()
|
|
98
|
+
return True
|
|
99
|
+
|
|
100
|
+
def clear(self) -> None:
|
|
101
|
+
with self._lock:
|
|
102
|
+
self._seen.clear()
|
|
103
|
+
self._flush()
|
|
104
|
+
|
|
105
|
+
def __len__(self) -> int:
|
|
106
|
+
with self._lock:
|
|
107
|
+
return len(self._seen)
|
betyebo/models.py
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from dataclasses import dataclass, field
|
|
4
|
+
from datetime import datetime
|
|
5
|
+
from typing import Any, Mapping
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
@dataclass(frozen=True)
|
|
9
|
+
class WebhookEvent:
|
|
10
|
+
"""Normalized webhook event."""
|
|
11
|
+
|
|
12
|
+
id: str | None
|
|
13
|
+
type: str
|
|
14
|
+
provider: str
|
|
15
|
+
occurred_at: datetime | None
|
|
16
|
+
data: Any
|
|
17
|
+
raw: Mapping[str, Any]
|
|
18
|
+
headers: Mapping[str, str] = field(default_factory=dict)
|
|
19
|
+
|
|
20
|
+
@property
|
|
21
|
+
def dedupe_key(self) -> str | None:
|
|
22
|
+
"""Stable key for idempotency when the provider supplies an event ID."""
|
|
23
|
+
if not self.id:
|
|
24
|
+
return None
|
|
25
|
+
return f"{self.provider}:{self.id}"
|
|
26
|
+
|
|
27
|
+
def to_dict(self) -> dict[str, Any]:
|
|
28
|
+
return {
|
|
29
|
+
"id": self.id,
|
|
30
|
+
"type": self.type,
|
|
31
|
+
"provider": self.provider,
|
|
32
|
+
"occurred_at": self.occurred_at.isoformat() if self.occurred_at else None,
|
|
33
|
+
"data": self.data,
|
|
34
|
+
"raw": dict(self.raw),
|
|
35
|
+
"dedupe_key": self.dedupe_key,
|
|
36
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import hashlib
|
|
4
|
+
import hmac
|
|
5
|
+
import json
|
|
6
|
+
from abc import ABC, abstractmethod
|
|
7
|
+
from typing import Any, Mapping
|
|
8
|
+
|
|
9
|
+
from ..errors import MalformedPayload, MissingHeader
|
|
10
|
+
from ..models import WebhookEvent
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def _get_header(headers: Mapping[str, str], name: str) -> str | None:
|
|
14
|
+
# HTTP headers are case-insensitive; support common dict types.
|
|
15
|
+
lower = name.lower()
|
|
16
|
+
for k, v in headers.items():
|
|
17
|
+
if k.lower() == lower:
|
|
18
|
+
return v
|
|
19
|
+
return None
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def require_header(headers: Mapping[str, str], name: str, provider: str) -> str:
|
|
23
|
+
value = _get_header(headers, name)
|
|
24
|
+
if value is None or value == "":
|
|
25
|
+
raise MissingHeader(name, provider)
|
|
26
|
+
return value
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def parse_json_payload(payload: bytes | str) -> Mapping[str, Any]:
|
|
30
|
+
if isinstance(payload, bytes):
|
|
31
|
+
try:
|
|
32
|
+
text = payload.decode("utf-8")
|
|
33
|
+
except UnicodeDecodeError as e:
|
|
34
|
+
raise MalformedPayload("Payload is not valid UTF-8") from e
|
|
35
|
+
else:
|
|
36
|
+
text = payload
|
|
37
|
+
try:
|
|
38
|
+
data = json.loads(text)
|
|
39
|
+
except json.JSONDecodeError as e:
|
|
40
|
+
raise MalformedPayload("Payload is not valid JSON") from e
|
|
41
|
+
if not isinstance(data, dict):
|
|
42
|
+
raise MalformedPayload("Payload must be a JSON object")
|
|
43
|
+
return data
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def secure_compare(a: str | bytes, b: str | bytes) -> bool:
|
|
47
|
+
a_bytes = a.encode("utf-8") if isinstance(a, str) else a
|
|
48
|
+
b_bytes = b.encode("utf-8") if isinstance(b, str) else b
|
|
49
|
+
return hmac.compare_digest(a_bytes, b_bytes)
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def hmac_sha256_hex(secret: str | bytes, message: bytes) -> str:
|
|
53
|
+
key = secret.encode("utf-8") if isinstance(secret, str) else secret
|
|
54
|
+
return hmac.new(key, message, hashlib.sha256).hexdigest()
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
class Provider(ABC):
|
|
58
|
+
"""Base webhook provider adapter."""
|
|
59
|
+
|
|
60
|
+
name: str
|
|
61
|
+
|
|
62
|
+
def __init__(self, secret: str, *, tolerance_seconds: int = 300):
|
|
63
|
+
if not secret:
|
|
64
|
+
raise ValueError("secret must not be empty")
|
|
65
|
+
self.secrets = [secret]
|
|
66
|
+
self.tolerance_seconds = tolerance_seconds
|
|
67
|
+
|
|
68
|
+
def add_secret(self, secret: str) -> None:
|
|
69
|
+
"""Add an active secret (supports rotation)."""
|
|
70
|
+
if not secret:
|
|
71
|
+
raise ValueError("secret must not be empty")
|
|
72
|
+
if secret not in self.secrets:
|
|
73
|
+
self.secrets.append(secret)
|
|
74
|
+
|
|
75
|
+
@abstractmethod
|
|
76
|
+
def verify(self, payload: bytes, headers: Mapping[str, str]) -> None:
|
|
77
|
+
"""Raise InvalidSignature/ExpiredTimestamp if the payload is not authentic."""
|
|
78
|
+
|
|
79
|
+
@abstractmethod
|
|
80
|
+
def parse(self, payload: bytes, headers: Mapping[str, str]) -> WebhookEvent:
|
|
81
|
+
"""Parse an already-verified payload into a normalized event."""
|
|
82
|
+
|
|
83
|
+
@abstractmethod
|
|
84
|
+
def sign(self, payload: bytes, *, secret: str | None = None, **kwargs: Any) -> dict[str, str]:
|
|
85
|
+
"""Return headers that would sign this payload (for tests/local replay)."""
|
|
86
|
+
|
|
87
|
+
def verify_and_parse(self, payload: bytes, headers: Mapping[str, str]) -> WebhookEvent:
|
|
88
|
+
self.verify(payload, headers)
|
|
89
|
+
return self.parse(payload, headers)
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import hashlib
|
|
4
|
+
import hmac
|
|
5
|
+
from typing import Any, Mapping
|
|
6
|
+
|
|
7
|
+
from ..errors import InvalidSignature
|
|
8
|
+
from ..models import WebhookEvent
|
|
9
|
+
from .base import Provider, parse_json_payload, require_header, secure_compare
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class GenericHMAC(Provider):
|
|
13
|
+
"""Generic HMAC webhook verifier.
|
|
14
|
+
|
|
15
|
+
Useful for providers that send `hex(hmac_sha256(secret, raw_body))` in a header.
|
|
16
|
+
"""
|
|
17
|
+
|
|
18
|
+
def __init__(
|
|
19
|
+
self,
|
|
20
|
+
secret: str,
|
|
21
|
+
*,
|
|
22
|
+
name: str = "generic",
|
|
23
|
+
signature_header: str = "X-Signature",
|
|
24
|
+
prefix: str = "",
|
|
25
|
+
algorithm: str = "sha256",
|
|
26
|
+
tolerance_seconds: int = 300,
|
|
27
|
+
):
|
|
28
|
+
super().__init__(secret, tolerance_seconds=tolerance_seconds)
|
|
29
|
+
self.name = name
|
|
30
|
+
self.signature_header = signature_header
|
|
31
|
+
self.prefix = prefix
|
|
32
|
+
self.algorithm = algorithm
|
|
33
|
+
|
|
34
|
+
def _digest(self, secret: str, payload: bytes) -> str:
|
|
35
|
+
key = secret.encode("utf-8")
|
|
36
|
+
return hmac.new(key, payload, getattr(hashlib, self.algorithm)).hexdigest()
|
|
37
|
+
|
|
38
|
+
def verify(self, payload: bytes, headers: Mapping[str, str]) -> None:
|
|
39
|
+
header = require_header(headers, self.signature_header, self.name)
|
|
40
|
+
provided = header[len(self.prefix):] if self.prefix and header.startswith(self.prefix) else header
|
|
41
|
+
for secret in self.secrets:
|
|
42
|
+
expected = self._digest(secret, payload)
|
|
43
|
+
if secure_compare(expected, provided):
|
|
44
|
+
return
|
|
45
|
+
raise InvalidSignature(f"{self.name} signature verification failed")
|
|
46
|
+
|
|
47
|
+
def parse(self, payload: bytes, headers: Mapping[str, str]) -> WebhookEvent:
|
|
48
|
+
data = parse_json_payload(payload)
|
|
49
|
+
event_type = data.get("type") if isinstance(data.get("type"), str) else "event"
|
|
50
|
+
event_id = data.get("id") if isinstance(data.get("id"), str) else None
|
|
51
|
+
return WebhookEvent(
|
|
52
|
+
id=event_id,
|
|
53
|
+
type=event_type,
|
|
54
|
+
provider=self.name,
|
|
55
|
+
occurred_at=None,
|
|
56
|
+
data=data,
|
|
57
|
+
raw=data,
|
|
58
|
+
headers={k: v for k, v in headers.items()},
|
|
59
|
+
)
|
|
60
|
+
|
|
61
|
+
def sign(self, payload: bytes, *, secret: str | None = None, **_: Any) -> dict[str, str]:
|
|
62
|
+
key = secret or self.secrets[0]
|
|
63
|
+
sig = self._digest(key, payload)
|
|
64
|
+
return {self.signature_header: f"{self.prefix}{sig}"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from typing import Any, Mapping
|
|
4
|
+
|
|
5
|
+
from ..errors import InvalidSignature, MalformedPayload
|
|
6
|
+
from ..models import WebhookEvent
|
|
7
|
+
from .base import Provider, hmac_sha256_hex, parse_json_payload, require_header, secure_compare
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class GitHub(Provider):
|
|
11
|
+
name = "github"
|
|
12
|
+
|
|
13
|
+
def verify(self, payload: bytes, headers: Mapping[str, str]) -> None:
|
|
14
|
+
header = require_header(headers, "X-Hub-Signature-256", self.name)
|
|
15
|
+
if not header.startswith("sha256="):
|
|
16
|
+
raise InvalidSignature("GitHub signature header must start with 'sha256='")
|
|
17
|
+
provided = header[len("sha256="):]
|
|
18
|
+
for secret in self.secrets:
|
|
19
|
+
expected = hmac_sha256_hex(secret, payload)
|
|
20
|
+
if secure_compare(expected, provided):
|
|
21
|
+
return
|
|
22
|
+
raise InvalidSignature("GitHub signature verification failed")
|
|
23
|
+
|
|
24
|
+
def parse(self, payload: bytes, headers: Mapping[str, str]) -> WebhookEvent:
|
|
25
|
+
data = parse_json_payload(payload)
|
|
26
|
+
event_type = require_header(headers, "X-GitHub-Event", self.name)
|
|
27
|
+
delivery = None
|
|
28
|
+
for k, v in headers.items():
|
|
29
|
+
if k.lower() == "x-github-delivery":
|
|
30
|
+
delivery = v
|
|
31
|
+
break
|
|
32
|
+
# GitHub's payload structure varies by event type.
|
|
33
|
+
action = data.get("action")
|
|
34
|
+
full_type = f"{event_type}.{action}" if isinstance(action, str) and action else event_type
|
|
35
|
+
occurred_at = None
|
|
36
|
+
# Common locations for timestamps; keep None when unavailable.
|
|
37
|
+
# (avoid guessing too much)
|
|
38
|
+
return WebhookEvent(
|
|
39
|
+
id=delivery,
|
|
40
|
+
type=full_type,
|
|
41
|
+
provider=self.name,
|
|
42
|
+
occurred_at=occurred_at,
|
|
43
|
+
data=data,
|
|
44
|
+
raw=data,
|
|
45
|
+
headers={k: v for k, v in headers.items()},
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
def sign(self, payload: bytes, *, secret: str | None = None, event: str = "push", delivery: str = "test-delivery", **_: Any) -> dict[str, str]:
|
|
49
|
+
key = secret or self.secrets[0]
|
|
50
|
+
sig = hmac_sha256_hex(key, payload)
|
|
51
|
+
return {
|
|
52
|
+
"X-Hub-Signature-256": f"sha256={sig}",
|
|
53
|
+
"X-GitHub-Event": event,
|
|
54
|
+
"X-GitHub-Delivery": delivery,
|
|
55
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import base64
|
|
4
|
+
import hashlib
|
|
5
|
+
import hmac
|
|
6
|
+
from typing import Any, Mapping
|
|
7
|
+
|
|
8
|
+
from ..errors import InvalidSignature, MalformedPayload
|
|
9
|
+
from ..models import WebhookEvent
|
|
10
|
+
from .base import Provider, parse_json_payload, require_header, secure_compare
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class Shopify(Provider):
|
|
14
|
+
name = "shopify"
|
|
15
|
+
|
|
16
|
+
def verify(self, payload: bytes, headers: Mapping[str, str]) -> None:
|
|
17
|
+
header = require_header(headers, "X-Shopify-Hmac-Sha256", self.name)
|
|
18
|
+
for secret in self.secrets:
|
|
19
|
+
key = secret.encode("utf-8")
|
|
20
|
+
expected = base64.b64encode(hmac.new(key, payload, hashlib.sha256).digest()).decode("utf-8")
|
|
21
|
+
if secure_compare(expected, header):
|
|
22
|
+
return
|
|
23
|
+
raise InvalidSignature("Shopify HMAC verification failed")
|
|
24
|
+
|
|
25
|
+
def parse(self, payload: bytes, headers: Mapping[str, str]) -> WebhookEvent:
|
|
26
|
+
data = parse_json_payload(payload)
|
|
27
|
+
topic = require_header(headers, "X-Shopify-Topic", self.name)
|
|
28
|
+
event_id = None
|
|
29
|
+
for k, v in headers.items():
|
|
30
|
+
if k.lower() == "x-shopify-event-id":
|
|
31
|
+
event_id = v
|
|
32
|
+
break
|
|
33
|
+
triggered_at = None
|
|
34
|
+
for k, v in headers.items():
|
|
35
|
+
if k.lower() == "x-shopify-triggered-at":
|
|
36
|
+
# Shopify uses ISO8601; keep parsing simple/strict-ish.
|
|
37
|
+
try:
|
|
38
|
+
from datetime import datetime
|
|
39
|
+
triggered_at = datetime.fromisoformat(v.replace("Z", "+00:00"))
|
|
40
|
+
except ValueError:
|
|
41
|
+
triggered_at = None
|
|
42
|
+
break
|
|
43
|
+
# Shopify payload is usually the object itself.
|
|
44
|
+
return WebhookEvent(
|
|
45
|
+
id=event_id,
|
|
46
|
+
type=topic,
|
|
47
|
+
provider=self.name,
|
|
48
|
+
occurred_at=triggered_at,
|
|
49
|
+
data=data,
|
|
50
|
+
raw=data,
|
|
51
|
+
headers={k: v for k, v in headers.items()},
|
|
52
|
+
)
|
|
53
|
+
|
|
54
|
+
def sign(self, payload: bytes, *, secret: str | None = None, topic: str = "orders/create", event_id: str = "test-event", **_: Any) -> dict[str, str]:
|
|
55
|
+
key = (secret or self.secrets[0]).encode("utf-8")
|
|
56
|
+
sig = base64.b64encode(hmac.new(key, payload, hashlib.sha256).digest()).decode("utf-8")
|
|
57
|
+
return {
|
|
58
|
+
"X-Shopify-Hmac-Sha256": sig,
|
|
59
|
+
"X-Shopify-Topic": topic,
|
|
60
|
+
"X-Shopify-Event-Id": event_id,
|
|
61
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import time
|
|
4
|
+
from typing import Any, Mapping
|
|
5
|
+
|
|
6
|
+
from ..errors import ExpiredTimestamp, InvalidSignature, MalformedPayload
|
|
7
|
+
from ..models import WebhookEvent
|
|
8
|
+
from .base import Provider, hmac_sha256_hex, parse_json_payload, require_header, secure_compare
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class Slack(Provider):
|
|
12
|
+
name = "slack"
|
|
13
|
+
|
|
14
|
+
def verify(self, payload: bytes, headers: Mapping[str, str]) -> None:
|
|
15
|
+
timestamp_raw = require_header(headers, "X-Slack-Request-Timestamp", self.name)
|
|
16
|
+
signature = require_header(headers, "X-Slack-Signature", self.name)
|
|
17
|
+
try:
|
|
18
|
+
timestamp = int(timestamp_raw)
|
|
19
|
+
except ValueError as e:
|
|
20
|
+
raise InvalidSignature("Slack timestamp is invalid") from e
|
|
21
|
+
|
|
22
|
+
base = f"v0:{timestamp}:".encode("utf-8") + payload
|
|
23
|
+
matched = False
|
|
24
|
+
for secret in self.secrets:
|
|
25
|
+
expected = "v0=" + hmac_sha256_hex(secret, base)
|
|
26
|
+
if secure_compare(expected, signature):
|
|
27
|
+
matched = True
|
|
28
|
+
break
|
|
29
|
+
if not matched:
|
|
30
|
+
raise InvalidSignature("Slack signature verification failed")
|
|
31
|
+
_check_timestamp(timestamp, self.tolerance_seconds)
|
|
32
|
+
|
|
33
|
+
def parse(self, payload: bytes, headers: Mapping[str, str]) -> WebhookEvent:
|
|
34
|
+
data = parse_json_payload(payload)
|
|
35
|
+
# Slack sends different shapes: event_callback, url_verification, etc.
|
|
36
|
+
event_type = data.get("type", "event")
|
|
37
|
+
if not isinstance(event_type, str):
|
|
38
|
+
event_type = "event"
|
|
39
|
+
inner = data.get("event")
|
|
40
|
+
if isinstance(inner, dict) and isinstance(inner.get("type"), str):
|
|
41
|
+
event_type = f"{event_type}.{inner['type']}"
|
|
42
|
+
event_id = data.get("event_id") if isinstance(data.get("event_id"), str) else None
|
|
43
|
+
return WebhookEvent(
|
|
44
|
+
id=event_id,
|
|
45
|
+
type=event_type,
|
|
46
|
+
provider=self.name,
|
|
47
|
+
occurred_at=None,
|
|
48
|
+
data=inner if isinstance(inner, dict) else data,
|
|
49
|
+
raw=data,
|
|
50
|
+
headers={k: v for k, v in headers.items()},
|
|
51
|
+
)
|
|
52
|
+
|
|
53
|
+
def sign(self, payload: bytes, *, secret: str | None = None, timestamp: int | None = None, **_: Any) -> dict[str, str]:
|
|
54
|
+
ts = int(time.time()) if timestamp is None else int(timestamp)
|
|
55
|
+
key = secret or self.secrets[0]
|
|
56
|
+
sig = "v0=" + hmac_sha256_hex(key, f"v0:{ts}:".encode("utf-8") + payload)
|
|
57
|
+
return {
|
|
58
|
+
"X-Slack-Request-Timestamp": str(ts),
|
|
59
|
+
"X-Slack-Signature": sig,
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def _check_timestamp(timestamp: int, tolerance_seconds: int) -> None:
|
|
64
|
+
now = int(time.time())
|
|
65
|
+
if abs(now - timestamp) > tolerance_seconds:
|
|
66
|
+
raise ExpiredTimestamp(f"Slack timestamp is outside tolerance ({tolerance_seconds}s)")
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import time
|
|
4
|
+
from datetime import datetime, timezone
|
|
5
|
+
from typing import Any, Mapping
|
|
6
|
+
|
|
7
|
+
from ..errors import ExpiredTimestamp, InvalidSignature, MalformedPayload
|
|
8
|
+
from ..models import WebhookEvent
|
|
9
|
+
from .base import Provider, hmac_sha256_hex, parse_json_payload, require_header, secure_compare
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class Stripe(Provider):
|
|
13
|
+
name = "stripe"
|
|
14
|
+
|
|
15
|
+
def verify(self, payload: bytes, headers: Mapping[str, str]) -> None:
|
|
16
|
+
header = require_header(headers, "Stripe-Signature", self.name)
|
|
17
|
+
timestamp, signatures = _parse_stripe_signature(header)
|
|
18
|
+
|
|
19
|
+
signed = str(timestamp).encode("utf-8") + b"." + payload
|
|
20
|
+
matched = False
|
|
21
|
+
for secret in self.secrets:
|
|
22
|
+
expected = hmac_sha256_hex(secret, signed)
|
|
23
|
+
if any(secure_compare(expected, sig) for sig in signatures):
|
|
24
|
+
matched = True
|
|
25
|
+
break
|
|
26
|
+
if not matched:
|
|
27
|
+
raise InvalidSignature("Stripe signature verification failed")
|
|
28
|
+
_check_timestamp(timestamp, self.tolerance_seconds)
|
|
29
|
+
|
|
30
|
+
def parse(self, payload: bytes, headers: Mapping[str, str]) -> WebhookEvent:
|
|
31
|
+
data = parse_json_payload(payload)
|
|
32
|
+
event_type = data.get("type")
|
|
33
|
+
if not isinstance(event_type, str) or not event_type:
|
|
34
|
+
raise MalformedPayload("Stripe payload missing string 'type'")
|
|
35
|
+
created = data.get("created")
|
|
36
|
+
occurred_at = None
|
|
37
|
+
if isinstance(created, (int, float)):
|
|
38
|
+
occurred_at = datetime.fromtimestamp(int(created), tz=timezone.utc)
|
|
39
|
+
inner = data.get("data")
|
|
40
|
+
event_data: Any = inner.get("object") if isinstance(inner, dict) and "object" in inner else inner
|
|
41
|
+
event_id = data.get("id") if isinstance(data.get("id"), str) else None
|
|
42
|
+
return WebhookEvent(
|
|
43
|
+
id=event_id,
|
|
44
|
+
type=event_type,
|
|
45
|
+
provider=self.name,
|
|
46
|
+
occurred_at=occurred_at,
|
|
47
|
+
data=event_data,
|
|
48
|
+
raw=data,
|
|
49
|
+
headers={k: v for k, v in headers.items()},
|
|
50
|
+
)
|
|
51
|
+
|
|
52
|
+
def sign(self, payload: bytes, *, secret: str | None = None, timestamp: int | None = None, **_: Any) -> dict[str, str]:
|
|
53
|
+
ts = int(time.time()) if timestamp is None else int(timestamp)
|
|
54
|
+
key = secret or self.secrets[0]
|
|
55
|
+
sig = hmac_sha256_hex(key, str(ts).encode("utf-8") + b"." + payload)
|
|
56
|
+
return {"Stripe-Signature": f"t={ts},v1={sig}"}
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def _parse_stripe_signature(header: str) -> tuple[int, list[str]]:
|
|
60
|
+
timestamp = None
|
|
61
|
+
signatures: list[str] = []
|
|
62
|
+
for part in header.split(","):
|
|
63
|
+
part = part.strip()
|
|
64
|
+
if "=" not in part:
|
|
65
|
+
continue
|
|
66
|
+
key, value = part.split("=", 1)
|
|
67
|
+
if key == "t":
|
|
68
|
+
try:
|
|
69
|
+
timestamp = int(value)
|
|
70
|
+
except ValueError as e:
|
|
71
|
+
raise InvalidSignature("Stripe signature timestamp is invalid") from e
|
|
72
|
+
elif key == "v1" and value:
|
|
73
|
+
signatures.append(value)
|
|
74
|
+
if timestamp is None or not signatures:
|
|
75
|
+
raise InvalidSignature("Stripe signature header is malformed")
|
|
76
|
+
return timestamp, signatures
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
def _check_timestamp(timestamp: int, tolerance_seconds: int) -> None:
|
|
80
|
+
now = int(time.time())
|
|
81
|
+
if abs(now - timestamp) > tolerance_seconds:
|
|
82
|
+
raise ExpiredTimestamp(f"Stripe timestamp is outside tolerance ({tolerance_seconds}s)")
|
betyebo/py.typed
ADDED
|
File without changes
|
betyebo/registry.py
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from typing import Any, Mapping
|
|
4
|
+
|
|
5
|
+
from .errors import UnknownProvider
|
|
6
|
+
from .idempotency import IdempotencyStore
|
|
7
|
+
from .models import WebhookEvent
|
|
8
|
+
from .providers.base import Provider
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class WebhookSDK:
|
|
12
|
+
"""Registry and facade for webhook providers."""
|
|
13
|
+
|
|
14
|
+
def __init__(self) -> None:
|
|
15
|
+
self._providers: dict[str, Provider] = {}
|
|
16
|
+
self.test = _TestHelpers(self)
|
|
17
|
+
|
|
18
|
+
def register(self, provider: Provider) -> Provider:
|
|
19
|
+
self._providers[provider.name.lower()] = provider
|
|
20
|
+
return provider
|
|
21
|
+
|
|
22
|
+
def register_many(self, *providers: Provider) -> list[Provider]:
|
|
23
|
+
for provider in providers:
|
|
24
|
+
self.register(provider)
|
|
25
|
+
return list(providers)
|
|
26
|
+
|
|
27
|
+
def unregister(self, provider: str) -> bool:
|
|
28
|
+
return self._providers.pop(provider.lower(), None) is not None
|
|
29
|
+
|
|
30
|
+
def get(self, provider: str) -> Provider:
|
|
31
|
+
key = provider.lower()
|
|
32
|
+
if key not in self._providers:
|
|
33
|
+
known = ", ".join(self.providers) or "(none)"
|
|
34
|
+
raise UnknownProvider(f"No provider registered for '{provider}'. Registered: {known}")
|
|
35
|
+
return self._providers[key]
|
|
36
|
+
|
|
37
|
+
def verify(self, provider: str, payload: bytes, headers: Mapping[str, str]) -> None:
|
|
38
|
+
self.get(provider).verify(payload, headers)
|
|
39
|
+
|
|
40
|
+
def parse(self, provider: str, payload: bytes, headers: Mapping[str, str]) -> WebhookEvent:
|
|
41
|
+
return self.get(provider).parse(payload, headers)
|
|
42
|
+
|
|
43
|
+
def verify_and_parse(self, provider: str, payload: bytes, headers: Mapping[str, str]) -> WebhookEvent:
|
|
44
|
+
return self.get(provider).verify_and_parse(payload, headers)
|
|
45
|
+
|
|
46
|
+
def process(
|
|
47
|
+
self,
|
|
48
|
+
provider: str,
|
|
49
|
+
payload: bytes,
|
|
50
|
+
headers: Mapping[str, str],
|
|
51
|
+
*,
|
|
52
|
+
store: IdempotencyStore | None = None,
|
|
53
|
+
) -> tuple[WebhookEvent, bool]:
|
|
54
|
+
"""Verify, parse, and optionally dedupe.
|
|
55
|
+
|
|
56
|
+
Returns `(event, is_new)`. When no store is provided (or the event has
|
|
57
|
+
no dedupe key), `is_new` is True.
|
|
58
|
+
"""
|
|
59
|
+
event = self.verify_and_parse(provider, payload, headers)
|
|
60
|
+
if store is None or not event.dedupe_key:
|
|
61
|
+
return event, True
|
|
62
|
+
return event, store.check_and_mark(event.dedupe_key)
|
|
63
|
+
|
|
64
|
+
def sign(self, provider: str, payload: bytes | str | Mapping[str, Any], **kwargs: Any) -> dict[str, str]:
|
|
65
|
+
"""Convenience alias for `sdk.test.sign(...)`."""
|
|
66
|
+
return self.test.sign(provider, payload, **kwargs)
|
|
67
|
+
|
|
68
|
+
@property
|
|
69
|
+
def providers(self) -> list[str]:
|
|
70
|
+
return sorted(self._providers.keys())
|
|
71
|
+
|
|
72
|
+
def __contains__(self, provider: object) -> bool:
|
|
73
|
+
return isinstance(provider, str) and provider.lower() in self._providers
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
class _TestHelpers:
|
|
77
|
+
def __init__(self, sdk: WebhookSDK):
|
|
78
|
+
self._sdk = sdk
|
|
79
|
+
|
|
80
|
+
def sign(self, provider: str, payload: bytes | str | Mapping[str, Any], **kwargs: Any) -> dict[str, str]:
|
|
81
|
+
"""Generate provider headers for a payload (for local tests)."""
|
|
82
|
+
body = _coerce_payload(payload)
|
|
83
|
+
return self._sdk.get(provider).sign(body, **kwargs)
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
def _coerce_payload(payload: bytes | str | Mapping[str, Any]) -> bytes:
|
|
87
|
+
if isinstance(payload, bytes):
|
|
88
|
+
return payload
|
|
89
|
+
if isinstance(payload, str):
|
|
90
|
+
return payload.encode("utf-8")
|
|
91
|
+
import json
|
|
92
|
+
|
|
93
|
+
return json.dumps(payload, separators=(",", ":"), ensure_ascii=False).encode("utf-8")
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: betyebo
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Unified webhook verification, parsing, and testing for Python
|
|
5
|
+
Author: REDX Contributors
|
|
6
|
+
License: MIT
|
|
7
|
+
Keywords: webhooks,stripe,github,shopify,fastapi,security
|
|
8
|
+
Classifier: Development Status :: 3 - Alpha
|
|
9
|
+
Classifier: Intended Audience :: Developers
|
|
10
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
13
|
+
Classifier: Topic :: Software Development :: Libraries
|
|
14
|
+
Classifier: Typing :: Typed
|
|
15
|
+
Requires-Python: >=3.9
|
|
16
|
+
Description-Content-Type: text/markdown
|
|
17
|
+
License-File: LICENSE
|
|
18
|
+
Provides-Extra: dev
|
|
19
|
+
Requires-Dist: pytest>=7.4; extra == "dev"
|
|
20
|
+
Dynamic: license-file
|
|
21
|
+
|
|
22
|
+
# Betyebo
|
|
23
|
+
|
|
24
|
+
Webhooks sound simple: get a POST, do the thing.
|
|
25
|
+
|
|
26
|
+
Then real life happens. Every provider signs stuff differently, wants different headers, and fails in its own special way.
|
|
27
|
+
|
|
28
|
+
Betyebo gives you one small Python interface for the annoying parts: check the signature safely, parse the payload, and get back a clean event object you can actually work with.
|
|
29
|
+
|
|
30
|
+
## What it’s good for
|
|
31
|
+
|
|
32
|
+
- **Checking signatures properly** (using the raw request body, not JSON you rebuilt yourself).
|
|
33
|
+
- **Not learning every provider’s quirks** — same basic API across providers.
|
|
34
|
+
- **Getting a clean event** (`type`, `id`, `data`, `raw`, etc.) instead of digging through raw payloads everywhere.
|
|
35
|
+
- **Testing without pain** — it can sign test payloads for you, so you don’t have to hand-roll HMAC code in tests.
|
|
36
|
+
|
|
37
|
+
Supported right now: **Stripe**, **GitHub**, **Shopify**, **Slack**, plus a **GenericHMAC** adapter for simple HMAC-signed webhooks.
|
|
38
|
+
|
|
39
|
+
## Install (local/dev)
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
pip install -e .
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## Quick start
|
|
46
|
+
|
|
47
|
+
```python
|
|
48
|
+
from betyebo import WebhookSDK, Stripe, GitHub
|
|
49
|
+
|
|
50
|
+
sdk = WebhookSDK()
|
|
51
|
+
sdk.register(Stripe(secret="whsec_..."))
|
|
52
|
+
sdk.register(GitHub(secret="github_secret"))
|
|
53
|
+
|
|
54
|
+
# Important: pass the raw request body bytes.
|
|
55
|
+
event = sdk.verify_and_parse(
|
|
56
|
+
provider="stripe",
|
|
57
|
+
payload=raw_body_bytes,
|
|
58
|
+
headers=request_headers,
|
|
59
|
+
)
|
|
60
|
+
|
|
61
|
+
print(event.provider) # "stripe"
|
|
62
|
+
print(event.type) # e.g. "invoice.paid"
|
|
63
|
+
print(event.id) # provider event id (when available)
|
|
64
|
+
print(event.data) # the useful payload/object
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
## FastAPI example
|
|
68
|
+
|
|
69
|
+
```python
|
|
70
|
+
from fastapi import FastAPI, HTTPException, Request
|
|
71
|
+
from betyebo import WebhookSDK, Stripe, InvalidSignature, ExpiredTimestamp
|
|
72
|
+
|
|
73
|
+
app = FastAPI()
|
|
74
|
+
sdk = WebhookSDK()
|
|
75
|
+
sdk.register(Stripe(secret="whsec_..."))
|
|
76
|
+
|
|
77
|
+
@app.post("/webhooks/stripe")
|
|
78
|
+
async def stripe_webhook(request: Request):
|
|
79
|
+
body = await request.body() # raw bytes, don't JSON-parse first
|
|
80
|
+
|
|
81
|
+
try:
|
|
82
|
+
event = sdk.verify_and_parse("stripe", body, request.headers)
|
|
83
|
+
except (InvalidSignature, ExpiredTimestamp) as e:
|
|
84
|
+
raise HTTPException(status_code=400, detail=str(e))
|
|
85
|
+
|
|
86
|
+
if event.type == "invoice.paid":
|
|
87
|
+
# handle it
|
|
88
|
+
pass
|
|
89
|
+
|
|
90
|
+
return {"ok": True}
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
## The event object
|
|
94
|
+
|
|
95
|
+
`WebhookEvent` gives you:
|
|
96
|
+
|
|
97
|
+
- `id` – provider event/delivery ID (when present)
|
|
98
|
+
- `type` – normalized event type (e.g. `invoice.paid`, `pull_request.opened`, `orders/create`)
|
|
99
|
+
- `provider` – `stripe`, `github`, or `shopify`
|
|
100
|
+
- `occurred_at` – timestamp when the provider gives one
|
|
101
|
+
- `data` – the main object/payload
|
|
102
|
+
- `raw` – the original parsed JSON payload
|
|
103
|
+
- `headers` – the request headers you passed in
|
|
104
|
+
|
|
105
|
+
## Secret rotation
|
|
106
|
+
|
|
107
|
+
If you’re rotating secrets, you can accept both for a while:
|
|
108
|
+
|
|
109
|
+
```python
|
|
110
|
+
stripe = Stripe(secret="whsec_new")
|
|
111
|
+
stripe.add_secret("whsec_old")
|
|
112
|
+
sdk.register(stripe)
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
## Testing without pain
|
|
116
|
+
|
|
117
|
+
You can generate valid headers for tests:
|
|
118
|
+
|
|
119
|
+
```python
|
|
120
|
+
payload = {
|
|
121
|
+
"id": "evt_1",
|
|
122
|
+
"type": "invoice.paid",
|
|
123
|
+
"created": 1710000000,
|
|
124
|
+
"data": {"object": {"id": "in_1"}},
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
headers = sdk.test.sign("stripe", payload, timestamp=1710000000)
|
|
128
|
+
event = sdk.verify_and_parse("stripe", b'{"id":"evt_1","type":"invoice.paid","created":1710000000,"data":{"object":{"id":"in_1"}}}', headers)
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
## Idempotency helper
|
|
133
|
+
|
|
134
|
+
Webhooks get delivered more than once. Signature checks prove *who* sent it, not *whether you've already handled it*.
|
|
135
|
+
|
|
136
|
+
`python
|
|
137
|
+
from betyebo import InMemoryIdempotencyStore
|
|
138
|
+
|
|
139
|
+
store = InMemoryIdempotencyStore()
|
|
140
|
+
|
|
141
|
+
# One call: verify + parse + dedupe
|
|
142
|
+
event, is_new = sdk.process("stripe", body, request.headers, store=store)
|
|
143
|
+
if not is_new:
|
|
144
|
+
return {"ok": True} # already handled
|
|
145
|
+
`
|
|
146
|
+
|
|
147
|
+
For scripts/local workers there's also JSONFileIdempotencyStore("seen.json"). For production, use Redis or your database.
|
|
148
|
+
|
|
149
|
+
## Generic HMAC provider
|
|
150
|
+
|
|
151
|
+
For services that use a simple HMAC(secret, raw_body) header:
|
|
152
|
+
|
|
153
|
+
`python
|
|
154
|
+
from betyebo import GenericHMAC
|
|
155
|
+
|
|
156
|
+
sdk.register(GenericHMAC(
|
|
157
|
+
secret="s3cr3t",
|
|
158
|
+
name="acme",
|
|
159
|
+
signature_header="X-Acme-Signature",
|
|
160
|
+
prefix="sha256=",
|
|
161
|
+
))
|
|
162
|
+
`
|
|
163
|
+
|
|
164
|
+
## A few honest notes
|
|
165
|
+
|
|
166
|
+
- **Use the raw body.** If you parse and re-dump JSON before verifying, signatures will often fail.
|
|
167
|
+
- **“Valid signature” doesn’t mean “first time seeing this”.** Webhooks can be delivered twice. Use `event.id` (or the dedupe helper) so you don’t handle the same thing twice.
|
|
168
|
+
- This is an MVP. It covers the common cases well, but it’s not trying to support every webhook platform on day one.
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
betyebo/__init__.py,sha256=jZY5CB5x-vySM_vdI5mEVdZMLGL5zBFm7SzC1pvbY1A,914
|
|
2
|
+
betyebo/errors.py,sha256=nZJq_2plUonT9RbjbrNIBpIuzJJUMJ8UKTDrn0GZofo,936
|
|
3
|
+
betyebo/idempotency.py,sha256=NHLe3AdB77CjIRLCL2-iIhtOcCZHIbIku1Ct0dtqCo8,2984
|
|
4
|
+
betyebo/models.py,sha256=7nU0OB1Osxx7ut5rgOmUkQRrhBQxP6QmOCbNnKzj60A,1034
|
|
5
|
+
betyebo/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
6
|
+
betyebo/registry.py,sha256=L7v7OzMwcNwgP2qXra9ueu6fzXYdO355KsavbeLInig,3466
|
|
7
|
+
betyebo/providers/__init__.py,sha256=EJRdZYTnNGLh8eEvht0WZTQ5I75qHHbUCNM_5RAtiYw,251
|
|
8
|
+
betyebo/providers/base.py,sha256=t4htTFz7QSDQXvSx7P1iAZoyiSsCqMldD4FXKyvmJIM,3033
|
|
9
|
+
betyebo/providers/generic.py,sha256=Af3OZONLoHMCMr4VxuWDM2Rc7K_PAtCS5J42a88f4AI,2335
|
|
10
|
+
betyebo/providers/github.py,sha256=uLnhM76OxOSo-rn1H0Du_O8VaW8taDxhq4YN3sCqCSs,2210
|
|
11
|
+
betyebo/providers/shopify.py,sha256=U8lVlJc2qfKd4484SIQSNZZJcNPrLnBhfrHPaSaQh3U,2379
|
|
12
|
+
betyebo/providers/slack.py,sha256=rGw-4lO-ULAimyYsXnGRdbWdKxtUOpEKCk1rYAuqW2Y,2732
|
|
13
|
+
betyebo/providers/stripe.py,sha256=vLBXfMk9hA3SEjgf1ALdgnFsNFDn9gj85Sez7ec8VEA,3339
|
|
14
|
+
betyebo-0.1.0.dist-info/licenses/LICENSE,sha256=xqlhK2dYD4XQ0q8RVsRpcpTyqR5AMUzga2Ta0PJpTrU,1078
|
|
15
|
+
betyebo-0.1.0.dist-info/METADATA,sha256=TA9FdMPQTWllm2xN3VPle01ALR9yI5Puf9FALOY6klE,5347
|
|
16
|
+
betyebo-0.1.0.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
|
|
17
|
+
betyebo-0.1.0.dist-info/top_level.txt,sha256=E6FIjr22gw1gZn138iKPS2CwKnUmAevWXFSetXsKXKg,8
|
|
18
|
+
betyebo-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 REDX Contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
betyebo
|