sendclap 0.3.0__tar.gz → 0.4.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.
- {sendclap-0.3.0 → sendclap-0.4.0}/PKG-INFO +4 -3
- {sendclap-0.3.0 → sendclap-0.4.0}/README.md +3 -2
- {sendclap-0.3.0 → sendclap-0.4.0}/pyproject.toml +1 -1
- {sendclap-0.3.0 → sendclap-0.4.0}/src/sendclap/__init__.py +19 -5
- {sendclap-0.3.0 → sendclap-0.4.0}/tests/test_sendclap.py +16 -2
- {sendclap-0.3.0 → sendclap-0.4.0}/.gitignore +0 -0
- {sendclap-0.3.0 → sendclap-0.4.0}/src/sendclap/py.typed +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: sendclap
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.4.0
|
|
4
4
|
Summary: Official Sendclap client: license key checks for your app and the creator REST API
|
|
5
5
|
Project-URL: Homepage, https://sendclap.com
|
|
6
6
|
Project-URL: Documentation, https://sendclap.com/docs
|
|
@@ -32,7 +32,7 @@ def licensed(key: str, cache: dict) -> bool:
|
|
|
32
32
|
return time.time() - cache.get("validated_at", 0) < 7 * 86400
|
|
33
33
|
if r.valid:
|
|
34
34
|
cache["validated_at"] = time.time() # persist cache to disk yourself
|
|
35
|
-
return r.valid # status "not_found", "disabled" or "not_activated": lock the app
|
|
35
|
+
return r.valid # status "not_found", "disabled", "expired" or "not_activated": lock the app
|
|
36
36
|
```
|
|
37
37
|
|
|
38
38
|
On first run, activate the device and remember the instance id:
|
|
@@ -46,7 +46,7 @@ except DisabledLicenseError: ... # the payment was refunded or disputed
|
|
|
46
46
|
except ActivationLimitError as e: print(f"Used on {e.license.activations}/{e.license.max_activations} devices")
|
|
47
47
|
```
|
|
48
48
|
|
|
49
|
-
`deactivate(key, instance_id)` frees the device again, and raises `InstanceNotFoundError` if it wasn't activated. `validate` never raises for a bad key; it returns `status` `"active"`, `"not_activated"`, `"disabled"` (refunded or disputed) or `"not_found"` (unknown key), and raises `NetworkError` only when it could not reach Sendclap, so you can tell "offline" from "not found" and show "this license was refunded" for `"disabled"`.
|
|
49
|
+
`deactivate(key, instance_id)` frees the device again, and raises `InstanceNotFoundError` if it wasn't activated. `validate` never raises for a bad key; it returns `status` `"active"`, `"not_activated"`, `"expired"` (subscription over, see `license.expires_at`), `"disabled"` (refunded or disputed) or `"not_found"` (unknown key), and raises `NetworkError` only when it could not reach Sendclap, so you can tell "offline" from "not found" and show "this license was refunded" for `"disabled"`.
|
|
50
50
|
|
|
51
51
|
**Instance name:** `instance_name()` is the machine's hostname. It is sent to Sendclap and shown to the creator, and two machines with the same hostname share one activation. If that matters, pass your own stable id instead (for example a `uuid4()` saved on first run). The instance id Sendclap returns is the name you send.
|
|
52
52
|
|
|
@@ -82,6 +82,7 @@ Every exception is a `SendclapError` with `.status`, `.code` (the server's machi
|
|
|
82
82
|
|---|---|---|
|
|
83
83
|
| `InvalidLicenseError` | `license_not_found` | 404: the key doesn't exist |
|
|
84
84
|
| `DisabledLicenseError` | `license_disabled` | 403: disabled after a refund or dispute |
|
|
85
|
+
| `ExpiredLicenseError` | `license_expired` | 403: the subscription key expired; `.license.expires_at` says when |
|
|
85
86
|
| `InstanceNotFoundError` | `instance_not_found` | 404: `deactivate` for an instance that isn't activated |
|
|
86
87
|
| `ActivationLimitError` | `activation_limit` | 409: every activation is used; `.license` and `.product` say how many |
|
|
87
88
|
| `NetworkError` | `network_error` | No response: offline, DNS, TLS, timeout (`.status == 0`) |
|
|
@@ -19,7 +19,7 @@ def licensed(key: str, cache: dict) -> bool:
|
|
|
19
19
|
return time.time() - cache.get("validated_at", 0) < 7 * 86400
|
|
20
20
|
if r.valid:
|
|
21
21
|
cache["validated_at"] = time.time() # persist cache to disk yourself
|
|
22
|
-
return r.valid # status "not_found", "disabled" or "not_activated": lock the app
|
|
22
|
+
return r.valid # status "not_found", "disabled", "expired" or "not_activated": lock the app
|
|
23
23
|
```
|
|
24
24
|
|
|
25
25
|
On first run, activate the device and remember the instance id:
|
|
@@ -33,7 +33,7 @@ except DisabledLicenseError: ... # the payment was refunded or disputed
|
|
|
33
33
|
except ActivationLimitError as e: print(f"Used on {e.license.activations}/{e.license.max_activations} devices")
|
|
34
34
|
```
|
|
35
35
|
|
|
36
|
-
`deactivate(key, instance_id)` frees the device again, and raises `InstanceNotFoundError` if it wasn't activated. `validate` never raises for a bad key; it returns `status` `"active"`, `"not_activated"`, `"disabled"` (refunded or disputed) or `"not_found"` (unknown key), and raises `NetworkError` only when it could not reach Sendclap, so you can tell "offline" from "not found" and show "this license was refunded" for `"disabled"`.
|
|
36
|
+
`deactivate(key, instance_id)` frees the device again, and raises `InstanceNotFoundError` if it wasn't activated. `validate` never raises for a bad key; it returns `status` `"active"`, `"not_activated"`, `"expired"` (subscription over, see `license.expires_at`), `"disabled"` (refunded or disputed) or `"not_found"` (unknown key), and raises `NetworkError` only when it could not reach Sendclap, so you can tell "offline" from "not found" and show "this license was refunded" for `"disabled"`.
|
|
37
37
|
|
|
38
38
|
**Instance name:** `instance_name()` is the machine's hostname. It is sent to Sendclap and shown to the creator, and two machines with the same hostname share one activation. If that matters, pass your own stable id instead (for example a `uuid4()` saved on first run). The instance id Sendclap returns is the name you send.
|
|
39
39
|
|
|
@@ -69,6 +69,7 @@ Every exception is a `SendclapError` with `.status`, `.code` (the server's machi
|
|
|
69
69
|
|---|---|---|
|
|
70
70
|
| `InvalidLicenseError` | `license_not_found` | 404: the key doesn't exist |
|
|
71
71
|
| `DisabledLicenseError` | `license_disabled` | 403: disabled after a refund or dispute |
|
|
72
|
+
| `ExpiredLicenseError` | `license_expired` | 403: the subscription key expired; `.license.expires_at` says when |
|
|
72
73
|
| `InstanceNotFoundError` | `instance_not_found` | 404: `deactivate` for an instance that isn't activated |
|
|
73
74
|
| `ActivationLimitError` | `activation_limit` | 409: every activation is used; `.license` and `.product` say how many |
|
|
74
75
|
| `NetworkError` | `network_error` | No response: offline, DNS, TLS, timeout (`.status == 0`) |
|
|
@@ -9,13 +9,13 @@ import urllib.request
|
|
|
9
9
|
from dataclasses import dataclass
|
|
10
10
|
from typing import Any, Callable, Dict, Generic, Iterator, List, Optional, TypedDict, TypeVar
|
|
11
11
|
|
|
12
|
-
__version__ = "0.
|
|
12
|
+
__version__ = "0.4.0"
|
|
13
13
|
DEFAULT_BASE_URL = "https://sendclap.com"
|
|
14
14
|
USER_AGENT = f"sendclap-python/{__version__}"
|
|
15
15
|
|
|
16
16
|
__all__ = [
|
|
17
17
|
"LicenseClient", "ApiClient", "instance_name",
|
|
18
|
-
"SendclapError", "InvalidLicenseError", "DisabledLicenseError", "InstanceNotFoundError",
|
|
18
|
+
"SendclapError", "InvalidLicenseError", "DisabledLicenseError", "ExpiredLicenseError", "InstanceNotFoundError",
|
|
19
19
|
"ActivationLimitError", "NetworkError",
|
|
20
20
|
"ActivateResult", "ValidateResult", "DeactivateResult", "LicenseInfo", "ProductRef",
|
|
21
21
|
"Page", "Checkout", "Totals", "Stats", "Payment", "PaymentDetail", "Member", "IssuedLicense",
|
|
@@ -48,6 +48,15 @@ class DisabledLicenseError(SendclapError):
|
|
|
48
48
|
"""The key exists but was disabled after a refund or dispute (license_disabled)."""
|
|
49
49
|
|
|
50
50
|
|
|
51
|
+
class ExpiredLicenseError(SendclapError):
|
|
52
|
+
"""The subscription license key has expired (license_expired); license.expires_at says when."""
|
|
53
|
+
|
|
54
|
+
def __init__(self, status: int, message: str, license: LicenseInfo, product: ProductRef) -> None:
|
|
55
|
+
super().__init__(status, message, "license_expired")
|
|
56
|
+
self.license = license
|
|
57
|
+
self.product = product
|
|
58
|
+
|
|
59
|
+
|
|
51
60
|
class InstanceNotFoundError(SendclapError):
|
|
52
61
|
"""Deactivate was called for an instance that isn't activated (instance_not_found)."""
|
|
53
62
|
|
|
@@ -75,6 +84,7 @@ class LicenseInfo:
|
|
|
75
84
|
key: str
|
|
76
85
|
activations: int
|
|
77
86
|
max_activations: int
|
|
87
|
+
expires_at: Optional[str] = None # ISO 8601 time a subscription key expires, None if bought outright
|
|
78
88
|
|
|
79
89
|
|
|
80
90
|
@dataclass(frozen=True)
|
|
@@ -93,7 +103,7 @@ class ActivateResult:
|
|
|
93
103
|
@dataclass(frozen=True)
|
|
94
104
|
class ValidateResult:
|
|
95
105
|
valid: bool
|
|
96
|
-
status: str # "active", "not_activated", "disabled" (refunded or disputed) or "not_found" (unknown key)
|
|
106
|
+
status: str # "active", "not_activated", "expired" (subscription over), "disabled" (refunded or disputed) or "not_found" (unknown key)
|
|
97
107
|
license: Optional[LicenseInfo] = None
|
|
98
108
|
product: Optional[ProductRef] = None
|
|
99
109
|
|
|
@@ -189,6 +199,7 @@ class IssuedLicense(TypedDict):
|
|
|
189
199
|
max_activations: int
|
|
190
200
|
disabled: bool
|
|
191
201
|
issued_at: str
|
|
202
|
+
expires_at: Optional[str]
|
|
192
203
|
|
|
193
204
|
|
|
194
205
|
class Dispute(TypedDict):
|
|
@@ -212,6 +223,7 @@ class Product(TypedDict):
|
|
|
212
223
|
issues_license_key: bool
|
|
213
224
|
page: str
|
|
214
225
|
x402: Optional[str]
|
|
226
|
+
license_product_id: Optional[int]
|
|
215
227
|
|
|
216
228
|
|
|
217
229
|
class Membership(TypedDict):
|
|
@@ -282,6 +294,8 @@ class _Http:
|
|
|
282
294
|
raise InvalidLicenseError(status, msg, code)
|
|
283
295
|
if code == "license_disabled":
|
|
284
296
|
raise DisabledLicenseError(status, msg, code)
|
|
297
|
+
if code == "license_expired":
|
|
298
|
+
raise ExpiredLicenseError(status, msg, _license(d), _product(d))
|
|
285
299
|
if code == "instance_not_found":
|
|
286
300
|
raise InstanceNotFoundError(status, msg, code)
|
|
287
301
|
if code == "activation_limit":
|
|
@@ -292,7 +306,7 @@ class _Http:
|
|
|
292
306
|
def _license(d: Dict[str, Any]) -> LicenseInfo:
|
|
293
307
|
lic = d.get("license") or {}
|
|
294
308
|
return LicenseInfo(key=lic.get("key", ""), activations=lic.get("activations", 0),
|
|
295
|
-
max_activations=lic.get("max_activations", 0))
|
|
309
|
+
max_activations=lic.get("max_activations", 0), expires_at=lic.get("expires_at"))
|
|
296
310
|
|
|
297
311
|
|
|
298
312
|
def _product(d: Dict[str, Any]) -> ProductRef:
|
|
@@ -326,7 +340,7 @@ class LicenseClient:
|
|
|
326
340
|
return ActivateResult(instance_id=d["instance_id"], license=_license(d), product=_product(d))
|
|
327
341
|
|
|
328
342
|
def validate(self, license_key: str, instance_id: Optional[str] = None) -> ValidateResult:
|
|
329
|
-
"""Never raises for a bad key: returns status "not_found" or "
|
|
343
|
+
"""Never raises for a bad key: returns status "not_found", "disabled" or "expired". Raises NetworkError when offline."""
|
|
330
344
|
d = self._post("validate", license_key, instance_id)
|
|
331
345
|
known = "license" in d
|
|
332
346
|
return ValidateResult(valid=d.get("valid") is True, status=d["status"],
|
|
@@ -10,12 +10,13 @@ sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..", "src"))
|
|
|
10
10
|
|
|
11
11
|
import sendclap # noqa: E402
|
|
12
12
|
from sendclap import ( # noqa: E402
|
|
13
|
-
ActivationLimitError, ApiClient, DisabledLicenseError, InstanceNotFoundError, InvalidLicenseError,
|
|
13
|
+
ActivationLimitError, ApiClient, DisabledLicenseError, ExpiredLicenseError, InstanceNotFoundError, InvalidLicenseError,
|
|
14
14
|
LicenseClient, NetworkError, SendclapError,
|
|
15
15
|
)
|
|
16
16
|
|
|
17
17
|
LICENSE = {"key": "GOOD", "activations": 1, "max_activations": 3}
|
|
18
18
|
PRODUCT = {"id": 1, "name": "Pro"}
|
|
19
|
+
LAPSED = {**LICENSE, "expires_at": "2026-01-01T00:00:00.000Z"}
|
|
19
20
|
CHECKOUT = {"id": "0xabc", "status": "pending", "type": "product", "amount": 29, "currency": "usd",
|
|
20
21
|
"method": "card", "email": "buyer@example.com", "url": "http://x/checkout/0xabc", "paid_at": None}
|
|
21
22
|
PAYMENTS = [{"id": 3, "status": "paid"}, {"id": 2, "status": "paid"}, {"id": 1, "status": "paid"}]
|
|
@@ -45,6 +46,8 @@ class Mock(BaseHTTPRequestHandler):
|
|
|
45
46
|
if action == "validate":
|
|
46
47
|
if key == "REFUNDED":
|
|
47
48
|
return self.reply(200, {"valid": False, "status": "disabled"})
|
|
49
|
+
if key == "LAPSED":
|
|
50
|
+
return self.reply(200, {"valid": False, "status": "expired", "license": LAPSED, "product": PRODUCT})
|
|
48
51
|
if key not in ("GOOD", "FULL"):
|
|
49
52
|
return self.reply(200, {"valid": False, "status": "not_found"})
|
|
50
53
|
ok = inst in (None, "dev-1")
|
|
@@ -52,6 +55,9 @@ class Mock(BaseHTTPRequestHandler):
|
|
|
52
55
|
"license": LICENSE, "product": PRODUCT})
|
|
53
56
|
if key == "REFUNDED":
|
|
54
57
|
return self.reply(403, {"error": "this license key is disabled", "code": "license_disabled"})
|
|
58
|
+
if key == "LAPSED":
|
|
59
|
+
return self.reply(403, {"error": "this license key has expired", "code": "license_expired",
|
|
60
|
+
"license": LAPSED, "product": PRODUCT})
|
|
55
61
|
if key not in ("GOOD", "FULL"):
|
|
56
62
|
return self.reply(404, {"error": "license key not found", "code": "license_not_found"})
|
|
57
63
|
if not inst:
|
|
@@ -118,7 +124,7 @@ class SendclapTest(unittest.TestCase):
|
|
|
118
124
|
method, path, headers, body = SEEN[-1]
|
|
119
125
|
self.assertEqual((method, path), ("POST", "/api/v1/licenses/activate"))
|
|
120
126
|
self.assertEqual(body, {"license_key": "GOOD", "instance_id": "dev-1"})
|
|
121
|
-
self.assertEqual(headers["User-Agent"], "sendclap-python/0.
|
|
127
|
+
self.assertEqual(headers["User-Agent"], "sendclap-python/0.4.0")
|
|
122
128
|
self.assertEqual(headers["Content-Type"], "application/json")
|
|
123
129
|
self.assertNotIn("Authorization", headers)
|
|
124
130
|
|
|
@@ -142,6 +148,14 @@ class SendclapTest(unittest.TestCase):
|
|
|
142
148
|
self.assertNotIsInstance(cm.exception, InvalidLicenseError)
|
|
143
149
|
self.assertEqual((cm.exception.status, cm.exception.code), (403, "license_disabled"))
|
|
144
150
|
|
|
151
|
+
def test_expired_key(self):
|
|
152
|
+
r = self.lic.validate("LAPSED", "dev-1")
|
|
153
|
+
self.assertEqual((r.valid, r.status, r.license.expires_at, r.product.name), (False, "expired", "2026-01-01T00:00:00.000Z", "Pro"))
|
|
154
|
+
with self.assertRaises(ExpiredLicenseError) as cm:
|
|
155
|
+
self.lic.activate("LAPSED", "dev-1")
|
|
156
|
+
self.assertEqual((cm.exception.status, cm.exception.code, cm.exception.license.expires_at),
|
|
157
|
+
(403, "license_expired", "2026-01-01T00:00:00.000Z"))
|
|
158
|
+
|
|
145
159
|
def test_activate_missing_instance(self):
|
|
146
160
|
with self.assertRaises(SendclapError) as cm:
|
|
147
161
|
self.lic.activate("GOOD", "")
|
|
File without changes
|
|
File without changes
|