stapel-delivery 0.1.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.
- stapel_delivery-0.1.0/CONFIG.MD +26 -0
- stapel_delivery-0.1.0/LICENSE +21 -0
- stapel_delivery-0.1.0/PKG-INFO +186 -0
- stapel_delivery-0.1.0/README.md +151 -0
- stapel_delivery-0.1.0/__init__.py +31 -0
- stapel_delivery-0.1.0/_capabilities.py +36 -0
- stapel_delivery-0.1.0/_codegen.py +123 -0
- stapel_delivery-0.1.0/_codegen_settings.py +121 -0
- stapel_delivery-0.1.0/actions.py +68 -0
- stapel_delivery-0.1.0/admin.py +114 -0
- stapel_delivery-0.1.0/apps.py +23 -0
- stapel_delivery-0.1.0/beat.py +60 -0
- stapel_delivery-0.1.0/carriers.py +222 -0
- stapel_delivery-0.1.0/checks.py +137 -0
- stapel_delivery-0.1.0/codegen_urls.py +6 -0
- stapel_delivery-0.1.0/conf.py +51 -0
- stapel_delivery-0.1.0/conftest.py +109 -0
- stapel_delivery-0.1.0/docs/capabilities.json +188 -0
- stapel_delivery-0.1.0/docs/errors.json +499 -0
- stapel_delivery-0.1.0/docs/flows.json +274 -0
- stapel_delivery-0.1.0/docs/llms.txt +153 -0
- stapel_delivery-0.1.0/dto.py +181 -0
- stapel_delivery-0.1.0/errors.py +57 -0
- stapel_delivery-0.1.0/flows.py +51 -0
- stapel_delivery-0.1.0/fsm.py +55 -0
- stapel_delivery-0.1.0/functions.py +73 -0
- stapel_delivery-0.1.0/gdpr.py +108 -0
- stapel_delivery-0.1.0/management/__init__.py +0 -0
- stapel_delivery-0.1.0/management/commands/__init__.py +0 -0
- stapel_delivery-0.1.0/management/commands/delivery_housekeeping.py +13 -0
- stapel_delivery-0.1.0/migrations/0001_initial.py +193 -0
- stapel_delivery-0.1.0/migrations/0002_intent_release_reason.py +18 -0
- stapel_delivery-0.1.0/migrations/__init__.py +0 -0
- stapel_delivery-0.1.0/models.py +372 -0
- stapel_delivery-0.1.0/money.py +82 -0
- stapel_delivery-0.1.0/pagination.py +57 -0
- stapel_delivery-0.1.0/presenters.py +163 -0
- stapel_delivery-0.1.0/preset.py +46 -0
- stapel_delivery-0.1.0/py.typed +0 -0
- stapel_delivery-0.1.0/pyproject.toml +89 -0
- stapel_delivery-0.1.0/schemas/consumes/orders.order.placed.json +69 -0
- stapel_delivery-0.1.0/schemas/consumes/orders.order.status_changed.json +31 -0
- stapel_delivery-0.1.0/schemas/consumes/user.merged.json +19 -0
- stapel_delivery-0.1.0/schemas/emits/delivery.shipment.created.json +66 -0
- stapel_delivery-0.1.0/schemas/emits/delivery.shipment.status_changed.json +74 -0
- stapel_delivery-0.1.0/schemas/functions/delivery.commit.json +44 -0
- stapel_delivery-0.1.0/schemas/functions/delivery.options.json +108 -0
- stapel_delivery-0.1.0/schemas/functions/delivery.quote.json +153 -0
- stapel_delivery-0.1.0/schemas/functions/delivery.release.json +54 -0
- stapel_delivery-0.1.0/schemas/functions/delivery.reserve.json +160 -0
- stapel_delivery-0.1.0/schemas/functions/delivery.shipment.status.json +20 -0
- stapel_delivery-0.1.0/serializers.py +300 -0
- stapel_delivery-0.1.0/services/__init__.py +27 -0
- stapel_delivery-0.1.0/services/addresses.py +231 -0
- stapel_delivery-0.1.0/services/checkout.py +444 -0
- stapel_delivery-0.1.0/services/events.py +111 -0
- stapel_delivery-0.1.0/services/housekeeping.py +25 -0
- stapel_delivery-0.1.0/services/rates.py +178 -0
- stapel_delivery-0.1.0/services/shipments.py +329 -0
- stapel_delivery-0.1.0/setup.cfg +4 -0
- stapel_delivery-0.1.0/stapel_delivery.egg-info/PKG-INFO +186 -0
- stapel_delivery-0.1.0/stapel_delivery.egg-info/SOURCES.txt +156 -0
- stapel_delivery-0.1.0/stapel_delivery.egg-info/dependency_links.txt +1 -0
- stapel_delivery-0.1.0/stapel_delivery.egg-info/requires.txt +10 -0
- stapel_delivery-0.1.0/stapel_delivery.egg-info/top_level.txt +1 -0
- stapel_delivery-0.1.0/tests/test_actor.py +97 -0
- stapel_delivery-0.1.0/tests/test_addresses_api.py +120 -0
- stapel_delivery-0.1.0/tests/test_architecture.py +48 -0
- stapel_delivery-0.1.0/tests/test_beat.py +40 -0
- stapel_delivery-0.1.0/tests/test_carriers.py +96 -0
- stapel_delivery-0.1.0/tests/test_catalog_api.py +77 -0
- stapel_delivery-0.1.0/tests/test_checkout_hooks.py +222 -0
- stapel_delivery-0.1.0/tests/test_checks.py +96 -0
- stapel_delivery-0.1.0/tests/test_concurrency.py +96 -0
- stapel_delivery-0.1.0/tests/test_contract.py +126 -0
- stapel_delivery-0.1.0/tests/test_contract_profile2.py +84 -0
- stapel_delivery-0.1.0/tests/test_contract_wire.py +209 -0
- stapel_delivery-0.1.0/tests/test_error_i18n.py +77 -0
- stapel_delivery-0.1.0/tests/test_error_params.py +71 -0
- stapel_delivery-0.1.0/tests/test_fsm.py +63 -0
- stapel_delivery-0.1.0/tests/test_gdpr.py +48 -0
- stapel_delivery-0.1.0/tests/test_hook_order.py +18 -0
- stapel_delivery-0.1.0/tests/test_merge.py +39 -0
- stapel_delivery-0.1.0/tests/test_money_bounds.py +46 -0
- stapel_delivery-0.1.0/tests/test_orders_seam.py +27 -0
- stapel_delivery-0.1.0/tests/test_permissions.py +44 -0
- stapel_delivery-0.1.0/tests/test_preset.py +39 -0
- stapel_delivery-0.1.0/tests/test_public_api.py +46 -0
- stapel_delivery-0.1.0/tests/test_quote.py +195 -0
- stapel_delivery-0.1.0/tests/test_rates.py +114 -0
- stapel_delivery-0.1.0/tests/test_readme_wiring.py +77 -0
- stapel_delivery-0.1.0/tests/test_release_semantics.py +115 -0
- stapel_delivery-0.1.0/tests/test_shipments_api.py +133 -0
- stapel_delivery-0.1.0/translations/errors.es.json +14 -0
- stapel_delivery-0.1.0/translations/errors.ru.json +14 -0
- stapel_delivery-0.1.0/urls.py +14 -0
- stapel_delivery-0.1.0/urls_v1.py +53 -0
- stapel_delivery-0.1.0/views.py +386 -0
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# CONFIG.MD — stapel-delivery
|
|
2
|
+
|
|
3
|
+
Config registry for **stapel-delivery**. One row per configuration key the
|
|
4
|
+
module reads, its **source** (`env` = the process environment / the
|
|
5
|
+
`STAPEL_DELIVERY` settings dict), what it is for, whether it is required,
|
|
6
|
+
and its default.
|
|
7
|
+
|
|
8
|
+
Every key is read through `delivery_settings` (`stapel_delivery.conf`,
|
|
9
|
+
namespace `STAPEL_DELIVERY`). Resolution order per key:
|
|
10
|
+
`settings.STAPEL_DELIVERY` dict → a flat Django setting of the same name →
|
|
11
|
+
environment variable → the default below. `REQUIRE_METHOD` and
|
|
12
|
+
`DEFAULT_CARRIER` are CTO-facing config axes.
|
|
13
|
+
|
|
14
|
+
## stapel-delivery
|
|
15
|
+
|
|
16
|
+
| Key | Source | Purpose | Required | Default |
|
|
17
|
+
|-----|--------|---------|----------|---------|
|
|
18
|
+
| REQUIRE_METHOD | env | axis: a checkout without `context.delivery` is refused with `error.400.delivery_method_required` (a cart where nothing ships is exempt); false = no shipping line, no shipment. | no | true |
|
|
19
|
+
| DEFAULT_CARRIER | env | axis: carrier of methods without their own: `manual` (staff), `mock` (auto-advancing; prototype stage only, E002/W002) or a registered slug; a dotted path only from the settings module. | no | manual |
|
|
20
|
+
| CARRIERS | settings | carrier registry {slug: "dotted.path.Carrier" or None} merged over the built-ins manual and mock; None removes one. Malformed is E001. | no | {} |
|
|
21
|
+
| MOCK_STEP_MINUTES | env | the mock carrier advances one status per this many minutes (beat pass). | no | 2 |
|
|
22
|
+
| MAX_ADDRESSES | env | saved addresses per user; over is `error.409.too_many_addresses`. | no | 20 |
|
|
23
|
+
| GEOCODE_FUNCTION | env | comm Function with the geo.geocode contract that fills missing coordinates of a saved address after commit (best-effort); "" = off; unreachable is W004. | no | "" |
|
|
24
|
+
| NOTIFY | env | best-effort buyer notification delivery.shipment_status_changed. | no | true |
|
|
25
|
+
| SHIPMENT_URL_TEMPLATE | env | `{shipment_id}` / `{number}` / `{order_id}` template for notification links; empty = no link. | no | "" |
|
|
26
|
+
| INTENT_TTL_HOURS | env | reserved/released checkout intents older than this are purged by the beat; also the window in which an `orders.order.placed` without an attempt key is matched to an intent. | no | 72 |
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Stapel 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,186 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: stapel-delivery
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Delivery methods, rates, pickup points, address book and shipment tracking for the Stapel framework
|
|
5
|
+
License: MIT
|
|
6
|
+
Project-URL: Homepage, https://github.com/usestapel/stapel-delivery
|
|
7
|
+
Project-URL: Repository, https://github.com/usestapel/stapel-delivery
|
|
8
|
+
Project-URL: Documentation, https://github.com/usestapel/stapel-delivery#readme
|
|
9
|
+
Project-URL: Changelog, https://github.com/usestapel/stapel-delivery/blob/main/CHANGELOG.md
|
|
10
|
+
Project-URL: Issues, https://github.com/usestapel/stapel-delivery/issues
|
|
11
|
+
Keywords: django,stapel,delivery,shipping,shipments,tracking,addresses
|
|
12
|
+
Classifier: Development Status :: 3 - Alpha
|
|
13
|
+
Classifier: Framework :: Django
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
16
|
+
Classifier: Operating System :: OS Independent
|
|
17
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
22
|
+
Classifier: Typing :: Typed
|
|
23
|
+
Requires-Python: >=3.11
|
|
24
|
+
Description-Content-Type: text/markdown
|
|
25
|
+
License-File: LICENSE
|
|
26
|
+
Requires-Dist: stapel-core<1.0,>=0.99.3
|
|
27
|
+
Provides-Extra: all
|
|
28
|
+
Provides-Extra: test
|
|
29
|
+
Requires-Dist: pytest; extra == "test"
|
|
30
|
+
Requires-Dist: pytest-django; extra == "test"
|
|
31
|
+
Requires-Dist: pytest-cov; extra == "test"
|
|
32
|
+
Requires-Dist: stapel-tools<1,>=0.84.0; extra == "test"
|
|
33
|
+
Requires-Dist: jsonschema>=4; extra == "test"
|
|
34
|
+
Dynamic: license-file
|
|
35
|
+
|
|
36
|
+
<!-- Generated by stapel-readme from docs/readme.md + docs/*.json. Do not edit this file; edit docs/readme.md and re-run `make readme`. -->
|
|
37
|
+
|
|
38
|
+
# stapel-delivery
|
|
39
|
+
|
|
40
|
+
[](https://github.com/usestapel/stapel-delivery/actions/workflows/ci.yml?query=branch%3Amain)
|
|
41
|
+
[](https://app.codecov.io/gh/usestapel/stapel-delivery)
|
|
42
|
+
[](https://pypi.org/project/stapel-delivery/)
|
|
43
|
+
[](https://pepy.tech/project/stapel-delivery)
|
|
44
|
+
[](https://pypi.org/project/stapel-delivery/)
|
|
45
|
+
[](https://github.com/usestapel/stapel-delivery/blob/main/LICENSE)
|
|
46
|
+
[](https://github.com/usestapel/stapel-delivery/blob/main/docs/llms.txt)
|
|
47
|
+
|
|
48
|
+
> Delivery methods (courier, pickup point, digital), zones matched by country / region / postcode prefix, rates (flat, free above a subtotal, per kilogram when cart lines carry attrs.weight_grams), pickup points with hours and coordinates, a per-user address book with one default, and shipments with a table FSM (pending, packed, shipped, delivered, returned, cancelled), a timeline, tracking number and link. It is the stapel-orders shipping adjuster (delivery.quote, kind shipping, order 200; honours a promotion's meta.free_shipping marker) and a checkout hook (delivery.reserve keeps the validated choice and the address snapshot under the checkout attempt key; commit creates the order's shipment; release on cancel cancels it). Carriers are a strategy registry: manual by default, an auto-advancing mock for prototypes, a documented Carrier ABC for real ones.
|
|
49
|
+
|
|
50
|
+
Part of the [Stapel framework](https://github.com/usestapel) — composable Django apps that deploy as a monolith or as microservices without changing module code.
|
|
51
|
+
|
|
52
|
+
## Install
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
pip install stapel-delivery
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## At a glance
|
|
59
|
+
|
|
60
|
+
| Fact | Value |
|
|
61
|
+
|---|---|
|
|
62
|
+
| Version | `0.1.0` |
|
|
63
|
+
| Python | `>=3.11` (3.11, 3.12, 3.13, 3.14) |
|
|
64
|
+
| HTTP operations | 15 |
|
|
65
|
+
| Config axes | 2 |
|
|
66
|
+
| Usage surface | 9 |
|
|
67
|
+
| Extension points | 12 |
|
|
68
|
+
| Error codes | 55 |
|
|
69
|
+
| Documented flows | 4 |
|
|
70
|
+
| Fleet dependencies | [`stapel-auth`](https://github.com/usestapel/stapel-auth) (optional) · [`stapel-core`](https://github.com/usestapel/stapel-core) · [`stapel-geo`](https://github.com/usestapel/stapel-geo) (optional) · [`stapel-notifications`](https://github.com/usestapel/stapel-notifications) (optional) · [`stapel-orders`](https://github.com/usestapel/stapel-orders) (optional) · [`stapel-promotions`](https://github.com/usestapel/stapel-promotions) (optional) |
|
|
71
|
+
|
|
72
|
+
## Documentation
|
|
73
|
+
|
|
74
|
+
[OpenAPI](https://github.com/usestapel/stapel-delivery/blob/main/docs/schema.json) · [capabilities.json](https://github.com/usestapel/stapel-delivery/blob/main/docs/capabilities.json) · [llms.txt (for agents)](https://github.com/usestapel/stapel-delivery/blob/main/docs/llms.txt)
|
|
75
|
+
|
|
76
|
+
## What this is
|
|
77
|
+
|
|
78
|
+
Delivery for a Stapel shop: delivery methods (courier, pickup point,
|
|
79
|
+
digital), zones and rates, pickup points, a per-user address book, and
|
|
80
|
+
shipments with tracking. It plugs into **stapel-orders** without either
|
|
81
|
+
module importing the other: delivery is the orders shipping adjuster
|
|
82
|
+
(`delivery.quote`) and a checkout hook (`delivery.reserve` / `commit` /
|
|
83
|
+
`release`), and every placed order with a physical delivery gets a
|
|
84
|
+
shipment the buyer can track.
|
|
85
|
+
|
|
86
|
+
Without orders installed the catalog, the address book, the options
|
|
87
|
+
Function and the shipment API still work on their own.
|
|
88
|
+
|
|
89
|
+
## Quick start
|
|
90
|
+
|
|
91
|
+
```python
|
|
92
|
+
INSTALLED_APPS = [
|
|
93
|
+
# ...
|
|
94
|
+
"stapel_delivery",
|
|
95
|
+
]
|
|
96
|
+
|
|
97
|
+
# urls.py
|
|
98
|
+
path("delivery/api/", include("stapel_delivery.urls")) # -> /delivery/api/v1/...
|
|
99
|
+
|
|
100
|
+
# carrier polling + intent purge (Celery optional: manage.py delivery_housekeeping)
|
|
101
|
+
from stapel_delivery.beat import get_delivery_beat_schedule
|
|
102
|
+
CELERY_BEAT_SCHEDULE = {**get_delivery_beat_schedule()}
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
Wire it into the orders checkout. A scaffolded project already calls the
|
|
106
|
+
merge helper in `settings.py`: add this brick's preset to that list (the
|
|
107
|
+
helper merges two levels deep, so other presets and your own keys stay):
|
|
108
|
+
|
|
109
|
+
<!-- orders-wiring:scaffold -->
|
|
110
|
+
```python
|
|
111
|
+
_stapel_merge_preset_defaults(globals(), [
|
|
112
|
+
# ... the presets already listed (stapel_shop.preset, other companions),
|
|
113
|
+
"stapel_delivery.preset",
|
|
114
|
+
])
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
A hand-wired project merges per key instead — **never assign**
|
|
118
|
+
`STAPEL_ORDERS = {...}`: pasted after another fragment it would drop that
|
|
119
|
+
fragment and the host's `PURCHASABLE_TYPES`:
|
|
120
|
+
|
|
121
|
+
<!-- orders-wiring:hand -->
|
|
122
|
+
```python
|
|
123
|
+
from stapel_delivery.preset import SETTINGS_DEFAULTS as _DELIVERY
|
|
124
|
+
|
|
125
|
+
STAPEL_ORDERS = globals().get("STAPEL_ORDERS") or {}
|
|
126
|
+
STAPEL_ORDERS = {
|
|
127
|
+
**STAPEL_ORDERS,
|
|
128
|
+
"ADJUSTERS": {**_DELIVERY["STAPEL_ORDERS"]["ADJUSTERS"], **STAPEL_ORDERS.get("ADJUSTERS", {})},
|
|
129
|
+
"CHECKOUT_HOOKS": {**_DELIVERY["STAPEL_ORDERS"]["CHECKOUT_HOOKS"], **STAPEL_ORDERS.get("CHECKOUT_HOOKS", {})},
|
|
130
|
+
}
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
Methods, zones, rates and pickup points are configured in the Django admin.
|
|
134
|
+
At checkout the client sends its choice in the orders `context`:
|
|
135
|
+
|
|
136
|
+
```json
|
|
137
|
+
{"delivery": {"method": "courier", "address": {"name": "Ada", "phone": "+1 555 0100",
|
|
138
|
+
"line1": "1 Main St", "city": "Springfield", "postal_code": "62701", "country": "US"}}}
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
(`address_id` instead of `address` for a saved address; `pickup_point`
|
|
142
|
+
for a pickup method; nothing more for a digital one.)
|
|
143
|
+
|
|
144
|
+
**Delivery owns the delivery address.** `context.delivery` (`address` /
|
|
145
|
+
`address_id` / `pickup_point`) is the address the shipment is sent to. Orders still requires and stores its own `shipping_address`, which is never
|
|
146
|
+
compared with delivery's. The client sends the ship-to chosen in the delivery
|
|
147
|
+
widget as `shipping_address`, so the buyer types it once, and
|
|
148
|
+
`OrderResponse.address_from_delivery` is true when the order was placed with
|
|
149
|
+
`context.delivery`. The shipping adjustment's `code`
|
|
150
|
+
is the method code (e.g. `courier`), which orders records as the order's
|
|
151
|
+
shipping method.
|
|
152
|
+
|
|
153
|
+
## Concepts
|
|
154
|
+
|
|
155
|
+
- **Zone** — where a rate applies: lists of countries, regions and
|
|
156
|
+
postcode prefixes (empty list = any). The most specific matching zone
|
|
157
|
+
wins (longest postcode prefix, then region, then country); a rate with no
|
|
158
|
+
zone applies everywhere. No GIS.
|
|
159
|
+
- **Rate** — per method, zone and currency: a flat amount, free above a
|
|
160
|
+
cart subtotal, and an optional price per kilogram used when every
|
|
161
|
+
shippable line carries `attrs.weight_grams` (the purchasable resolver's
|
|
162
|
+
extra field); otherwise the flat amount. Never converted between
|
|
163
|
+
currencies.
|
|
164
|
+
- **Free shipping from a promotion** — an earlier adjuster's adjustment
|
|
165
|
+
with `meta.free_shipping: true` (optionally `meta.free_shipping_methods`)
|
|
166
|
+
makes shipping 0.00.
|
|
167
|
+
- **Address book** — per user, one default, at most `MAX_ADDRESSES`.
|
|
168
|
+
Checkout and shipments keep a **copy** of the address; editing or
|
|
169
|
+
deleting a saved address never changes a placed order. Guests type the
|
|
170
|
+
address inline.
|
|
171
|
+
- **Shipment** — one per order: `pending → packed → shipped → delivered`,
|
|
172
|
+
`returned`, `cancelled`, with a timeline, a tracking number and link. An
|
|
173
|
+
order cancelled before the parcel left cancels its shipment.
|
|
174
|
+
- **Carriers** — `manual` (staff type the tracking number) by default;
|
|
175
|
+
`mock` advances shipments by itself for demos (prototype posture only);
|
|
176
|
+
a real carrier is a small `Carrier` subclass registered by slug.
|
|
177
|
+
- **GDPR** — erasure deletes the address book and blanks the recipient on
|
|
178
|
+
shipments; money, status and city/country stay.
|
|
179
|
+
|
|
180
|
+
## License
|
|
181
|
+
|
|
182
|
+
MIT — see [LICENSE](https://github.com/usestapel/stapel-delivery/blob/main/LICENSE).
|
|
183
|
+
|
|
184
|
+
---
|
|
185
|
+
|
|
186
|
+
<sub>This page is assembled by `stapel-readme` from `docs/readme.md` plus the contract artifacts in `docs/`. Edit the prose in `docs/readme.md`; the badges, facts and links above and below it are generated — do not hand-edit `README.md`.</sub>
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
<!-- Generated by stapel-readme from docs/readme.md + docs/*.json. Do not edit this file; edit docs/readme.md and re-run `make readme`. -->
|
|
2
|
+
|
|
3
|
+
# stapel-delivery
|
|
4
|
+
|
|
5
|
+
[](https://github.com/usestapel/stapel-delivery/actions/workflows/ci.yml?query=branch%3Amain)
|
|
6
|
+
[](https://app.codecov.io/gh/usestapel/stapel-delivery)
|
|
7
|
+
[](https://pypi.org/project/stapel-delivery/)
|
|
8
|
+
[](https://pepy.tech/project/stapel-delivery)
|
|
9
|
+
[](https://pypi.org/project/stapel-delivery/)
|
|
10
|
+
[](https://github.com/usestapel/stapel-delivery/blob/main/LICENSE)
|
|
11
|
+
[](https://github.com/usestapel/stapel-delivery/blob/main/docs/llms.txt)
|
|
12
|
+
|
|
13
|
+
> Delivery methods (courier, pickup point, digital), zones matched by country / region / postcode prefix, rates (flat, free above a subtotal, per kilogram when cart lines carry attrs.weight_grams), pickup points with hours and coordinates, a per-user address book with one default, and shipments with a table FSM (pending, packed, shipped, delivered, returned, cancelled), a timeline, tracking number and link. It is the stapel-orders shipping adjuster (delivery.quote, kind shipping, order 200; honours a promotion's meta.free_shipping marker) and a checkout hook (delivery.reserve keeps the validated choice and the address snapshot under the checkout attempt key; commit creates the order's shipment; release on cancel cancels it). Carriers are a strategy registry: manual by default, an auto-advancing mock for prototypes, a documented Carrier ABC for real ones.
|
|
14
|
+
|
|
15
|
+
Part of the [Stapel framework](https://github.com/usestapel) — composable Django apps that deploy as a monolith or as microservices without changing module code.
|
|
16
|
+
|
|
17
|
+
## Install
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
pip install stapel-delivery
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## At a glance
|
|
24
|
+
|
|
25
|
+
| Fact | Value |
|
|
26
|
+
|---|---|
|
|
27
|
+
| Version | `0.1.0` |
|
|
28
|
+
| Python | `>=3.11` (3.11, 3.12, 3.13, 3.14) |
|
|
29
|
+
| HTTP operations | 15 |
|
|
30
|
+
| Config axes | 2 |
|
|
31
|
+
| Usage surface | 9 |
|
|
32
|
+
| Extension points | 12 |
|
|
33
|
+
| Error codes | 55 |
|
|
34
|
+
| Documented flows | 4 |
|
|
35
|
+
| Fleet dependencies | [`stapel-auth`](https://github.com/usestapel/stapel-auth) (optional) · [`stapel-core`](https://github.com/usestapel/stapel-core) · [`stapel-geo`](https://github.com/usestapel/stapel-geo) (optional) · [`stapel-notifications`](https://github.com/usestapel/stapel-notifications) (optional) · [`stapel-orders`](https://github.com/usestapel/stapel-orders) (optional) · [`stapel-promotions`](https://github.com/usestapel/stapel-promotions) (optional) |
|
|
36
|
+
|
|
37
|
+
## Documentation
|
|
38
|
+
|
|
39
|
+
[OpenAPI](https://github.com/usestapel/stapel-delivery/blob/main/docs/schema.json) · [capabilities.json](https://github.com/usestapel/stapel-delivery/blob/main/docs/capabilities.json) · [llms.txt (for agents)](https://github.com/usestapel/stapel-delivery/blob/main/docs/llms.txt)
|
|
40
|
+
|
|
41
|
+
## What this is
|
|
42
|
+
|
|
43
|
+
Delivery for a Stapel shop: delivery methods (courier, pickup point,
|
|
44
|
+
digital), zones and rates, pickup points, a per-user address book, and
|
|
45
|
+
shipments with tracking. It plugs into **stapel-orders** without either
|
|
46
|
+
module importing the other: delivery is the orders shipping adjuster
|
|
47
|
+
(`delivery.quote`) and a checkout hook (`delivery.reserve` / `commit` /
|
|
48
|
+
`release`), and every placed order with a physical delivery gets a
|
|
49
|
+
shipment the buyer can track.
|
|
50
|
+
|
|
51
|
+
Without orders installed the catalog, the address book, the options
|
|
52
|
+
Function and the shipment API still work on their own.
|
|
53
|
+
|
|
54
|
+
## Quick start
|
|
55
|
+
|
|
56
|
+
```python
|
|
57
|
+
INSTALLED_APPS = [
|
|
58
|
+
# ...
|
|
59
|
+
"stapel_delivery",
|
|
60
|
+
]
|
|
61
|
+
|
|
62
|
+
# urls.py
|
|
63
|
+
path("delivery/api/", include("stapel_delivery.urls")) # -> /delivery/api/v1/...
|
|
64
|
+
|
|
65
|
+
# carrier polling + intent purge (Celery optional: manage.py delivery_housekeeping)
|
|
66
|
+
from stapel_delivery.beat import get_delivery_beat_schedule
|
|
67
|
+
CELERY_BEAT_SCHEDULE = {**get_delivery_beat_schedule()}
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
Wire it into the orders checkout. A scaffolded project already calls the
|
|
71
|
+
merge helper in `settings.py`: add this brick's preset to that list (the
|
|
72
|
+
helper merges two levels deep, so other presets and your own keys stay):
|
|
73
|
+
|
|
74
|
+
<!-- orders-wiring:scaffold -->
|
|
75
|
+
```python
|
|
76
|
+
_stapel_merge_preset_defaults(globals(), [
|
|
77
|
+
# ... the presets already listed (stapel_shop.preset, other companions),
|
|
78
|
+
"stapel_delivery.preset",
|
|
79
|
+
])
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
A hand-wired project merges per key instead — **never assign**
|
|
83
|
+
`STAPEL_ORDERS = {...}`: pasted after another fragment it would drop that
|
|
84
|
+
fragment and the host's `PURCHASABLE_TYPES`:
|
|
85
|
+
|
|
86
|
+
<!-- orders-wiring:hand -->
|
|
87
|
+
```python
|
|
88
|
+
from stapel_delivery.preset import SETTINGS_DEFAULTS as _DELIVERY
|
|
89
|
+
|
|
90
|
+
STAPEL_ORDERS = globals().get("STAPEL_ORDERS") or {}
|
|
91
|
+
STAPEL_ORDERS = {
|
|
92
|
+
**STAPEL_ORDERS,
|
|
93
|
+
"ADJUSTERS": {**_DELIVERY["STAPEL_ORDERS"]["ADJUSTERS"], **STAPEL_ORDERS.get("ADJUSTERS", {})},
|
|
94
|
+
"CHECKOUT_HOOKS": {**_DELIVERY["STAPEL_ORDERS"]["CHECKOUT_HOOKS"], **STAPEL_ORDERS.get("CHECKOUT_HOOKS", {})},
|
|
95
|
+
}
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
Methods, zones, rates and pickup points are configured in the Django admin.
|
|
99
|
+
At checkout the client sends its choice in the orders `context`:
|
|
100
|
+
|
|
101
|
+
```json
|
|
102
|
+
{"delivery": {"method": "courier", "address": {"name": "Ada", "phone": "+1 555 0100",
|
|
103
|
+
"line1": "1 Main St", "city": "Springfield", "postal_code": "62701", "country": "US"}}}
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
(`address_id` instead of `address` for a saved address; `pickup_point`
|
|
107
|
+
for a pickup method; nothing more for a digital one.)
|
|
108
|
+
|
|
109
|
+
**Delivery owns the delivery address.** `context.delivery` (`address` /
|
|
110
|
+
`address_id` / `pickup_point`) is the address the shipment is sent to. Orders still requires and stores its own `shipping_address`, which is never
|
|
111
|
+
compared with delivery's. The client sends the ship-to chosen in the delivery
|
|
112
|
+
widget as `shipping_address`, so the buyer types it once, and
|
|
113
|
+
`OrderResponse.address_from_delivery` is true when the order was placed with
|
|
114
|
+
`context.delivery`. The shipping adjustment's `code`
|
|
115
|
+
is the method code (e.g. `courier`), which orders records as the order's
|
|
116
|
+
shipping method.
|
|
117
|
+
|
|
118
|
+
## Concepts
|
|
119
|
+
|
|
120
|
+
- **Zone** — where a rate applies: lists of countries, regions and
|
|
121
|
+
postcode prefixes (empty list = any). The most specific matching zone
|
|
122
|
+
wins (longest postcode prefix, then region, then country); a rate with no
|
|
123
|
+
zone applies everywhere. No GIS.
|
|
124
|
+
- **Rate** — per method, zone and currency: a flat amount, free above a
|
|
125
|
+
cart subtotal, and an optional price per kilogram used when every
|
|
126
|
+
shippable line carries `attrs.weight_grams` (the purchasable resolver's
|
|
127
|
+
extra field); otherwise the flat amount. Never converted between
|
|
128
|
+
currencies.
|
|
129
|
+
- **Free shipping from a promotion** — an earlier adjuster's adjustment
|
|
130
|
+
with `meta.free_shipping: true` (optionally `meta.free_shipping_methods`)
|
|
131
|
+
makes shipping 0.00.
|
|
132
|
+
- **Address book** — per user, one default, at most `MAX_ADDRESSES`.
|
|
133
|
+
Checkout and shipments keep a **copy** of the address; editing or
|
|
134
|
+
deleting a saved address never changes a placed order. Guests type the
|
|
135
|
+
address inline.
|
|
136
|
+
- **Shipment** — one per order: `pending → packed → shipped → delivered`,
|
|
137
|
+
`returned`, `cancelled`, with a timeline, a tracking number and link. An
|
|
138
|
+
order cancelled before the parcel left cancels its shipment.
|
|
139
|
+
- **Carriers** — `manual` (staff type the tracking number) by default;
|
|
140
|
+
`mock` advances shipments by itself for demos (prototype posture only);
|
|
141
|
+
a real carrier is a small `Carrier` subclass registered by slug.
|
|
142
|
+
- **GDPR** — erasure deletes the address book and blanks the recipient on
|
|
143
|
+
shipments; money, status and city/country stay.
|
|
144
|
+
|
|
145
|
+
## License
|
|
146
|
+
|
|
147
|
+
MIT — see [LICENSE](https://github.com/usestapel/stapel-delivery/blob/main/LICENSE).
|
|
148
|
+
|
|
149
|
+
---
|
|
150
|
+
|
|
151
|
+
<sub>This page is assembled by `stapel-readme` from `docs/readme.md` plus the contract artifacts in `docs/`. Edit the prose in `docs/readme.md`; the badges, facts and links above and below it are generated — do not hand-edit `README.md`.</sub>
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"""stapel-delivery — Delivery and shipments for the Stapel framework.
|
|
2
|
+
|
|
3
|
+
Public API (lazily exported, PEP 562 — importing this package never pulls
|
|
4
|
+
in Django or requires configured settings):
|
|
5
|
+
|
|
6
|
+
- ``delivery_settings`` — resolved app settings (``stapel_delivery.conf``).
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
__all__ = [
|
|
10
|
+
"delivery_settings",
|
|
11
|
+
]
|
|
12
|
+
|
|
13
|
+
# name -> submodule that defines it. Resolution is deferred until first
|
|
14
|
+
# attribute access so that `import stapel_delivery` stays Django-free.
|
|
15
|
+
_LAZY_EXPORTS = {
|
|
16
|
+
"delivery_settings": ".conf",
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def __getattr__(name):
|
|
21
|
+
if name in _LAZY_EXPORTS:
|
|
22
|
+
from importlib import import_module
|
|
23
|
+
|
|
24
|
+
value = getattr(import_module(_LAZY_EXPORTS[name], __name__), name)
|
|
25
|
+
globals()[name] = value # cache for subsequent lookups
|
|
26
|
+
return value
|
|
27
|
+
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def __dir__():
|
|
31
|
+
return sorted(set(globals()) | set(__all__))
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"""stapel-delivery capabilities.json emitter — thin shim over stapel_tools.capabilities."""
|
|
2
|
+
from pathlib import Path
|
|
3
|
+
|
|
4
|
+
from stapel_tools.capabilities import axis_group_rules, run_capabilities_cli
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def main(argv=None):
|
|
8
|
+
from stapel_delivery._codegen import _configure
|
|
9
|
+
|
|
10
|
+
_configure()
|
|
11
|
+
from stapel_delivery.conf import DEFAULTS
|
|
12
|
+
from stapel_delivery.urls import GATE_REGISTRY
|
|
13
|
+
|
|
14
|
+
# Two CTO-facing axes, both behavioural (no endpoint is unmounted):
|
|
15
|
+
# REQUIRE_METHOD (must the buyer choose a delivery) and DEFAULT_CARRIER
|
|
16
|
+
# (manual | mock | a registered carrier). CARRIERS is the extension seam.
|
|
17
|
+
axes = {"REQUIRE_METHOD", "DEFAULT_CARRIER"}
|
|
18
|
+
return run_capabilities_cli(
|
|
19
|
+
argv,
|
|
20
|
+
repo=Path(__file__).resolve().parent,
|
|
21
|
+
canonical_prefix="/delivery/api/v1",
|
|
22
|
+
defaults=DEFAULTS,
|
|
23
|
+
registry=GATE_REGISTRY,
|
|
24
|
+
is_axis=lambda k: k in axes,
|
|
25
|
+
axis_group=axis_group_rules(
|
|
26
|
+
exact={
|
|
27
|
+
"REQUIRE_METHOD": "delivery.checkout",
|
|
28
|
+
"DEFAULT_CARRIER": "delivery.carrier",
|
|
29
|
+
}
|
|
30
|
+
),
|
|
31
|
+
prog="stapel-delivery-capabilities",
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
if __name__ == "__main__":
|
|
36
|
+
raise SystemExit(main())
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
"""stapel-delivery contract-emission harness (contract-pipeline.md §2-3).
|
|
2
|
+
|
|
3
|
+
Emits the module's own contract triad into ``docs/`` from a single-module
|
|
4
|
+
``{delivery + core}`` Django instance mounted at the canonical
|
|
5
|
+
``delivery/api/v1/`` prefix:
|
|
6
|
+
|
|
7
|
+
docs/schema.json drf-spectacular OpenAPI, this module only, canonical prefix
|
|
8
|
+
docs/flows.json generate_flow_docs machine artifact ([] — no @flow_step here)
|
|
9
|
+
docs/errors.json generate_error_keys registry
|
|
10
|
+
|
|
11
|
+
The *mechanism* is stapel_tools.codegen (shared, unchanged); this file is the
|
|
12
|
+
thin per-module *config* that wires the module's settings + canonical mount.
|
|
13
|
+
|
|
14
|
+
Usage:
|
|
15
|
+
python -m stapel_delivery._codegen --out docs # `make contract`
|
|
16
|
+
"""
|
|
17
|
+
from __future__ import annotations
|
|
18
|
+
|
|
19
|
+
import argparse
|
|
20
|
+
import os
|
|
21
|
+
import sys
|
|
22
|
+
from pathlib import Path
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def _configure() -> None:
|
|
26
|
+
"""Configure + boot the single-module Django instance for emission."""
|
|
27
|
+
repo_root = os.path.dirname(os.path.abspath(__file__))
|
|
28
|
+
sys.path[:] = [p for p in sys.path if os.path.abspath(p or os.getcwd()) != repo_root]
|
|
29
|
+
|
|
30
|
+
from django.conf import settings
|
|
31
|
+
|
|
32
|
+
if not settings.configured:
|
|
33
|
+
from stapel_delivery._codegen_settings import settings_kwargs
|
|
34
|
+
|
|
35
|
+
settings.configure(
|
|
36
|
+
**settings_kwargs(root_urlconf="stapel_delivery.codegen_urls", contract=True)
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
import django
|
|
40
|
+
|
|
41
|
+
django.setup()
|
|
42
|
+
|
|
43
|
+
from drf_spectacular.settings import spectacular_settings
|
|
44
|
+
|
|
45
|
+
from stapel_delivery._codegen_settings import CODEGEN_SCHEMA_PATH_PREFIX
|
|
46
|
+
|
|
47
|
+
spectacular_settings.SCHEMA_PATH_PREFIX = CODEGEN_SCHEMA_PATH_PREFIX
|
|
48
|
+
|
|
49
|
+
# Stable enum component names (stapel-schema-lint SCH004).
|
|
50
|
+
from drf_spectacular.plumbing import _load_enum_name_overrides
|
|
51
|
+
|
|
52
|
+
from stapel_delivery._codegen_settings import enum_name_overrides
|
|
53
|
+
|
|
54
|
+
spectacular_settings.ENUM_NAME_OVERRIDES = enum_name_overrides()
|
|
55
|
+
_load_enum_name_overrides.cache_clear()
|
|
56
|
+
|
|
57
|
+
# Register drf-spectacular's JWT cookie-auth extension explicitly (a real
|
|
58
|
+
# host triggers this as a side effect of wiring its Swagger URLs). Without
|
|
59
|
+
# it, the protected endpoints
|
|
60
|
+
# would emit without their `security: [{"JWTCookieAuth": []}]` entry — a
|
|
61
|
+
# real contract gap. Applied per stapel-calendar's precedent.
|
|
62
|
+
from stapel_core.django.openapi.swagger import _register_jwt_auth_extension
|
|
63
|
+
|
|
64
|
+
_register_jwt_auth_extension()
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def _require_python_312() -> None:
|
|
68
|
+
"""Abort emission if not running the pinned 3.12 interpreter.
|
|
69
|
+
|
|
70
|
+
drf-spectacular's rendering of component descriptions (``Optional[X]`` vs
|
|
71
|
+
``X | None``) depends on the Python minor version — contracts emitted on
|
|
72
|
+
anything other than 3.12 (the CI/monolith pin) produce false diffs.
|
|
73
|
+
"""
|
|
74
|
+
if sys.version_info[:2] != (3, 12):
|
|
75
|
+
got = f"{sys.version_info.major}.{sys.version_info.minor}"
|
|
76
|
+
raise SystemExit(
|
|
77
|
+
f"stapel-delivery contract emission ABORTED: running Python {got}, "
|
|
78
|
+
"but contracts must be emitted on Python 3.12 (the CI/monolith "
|
|
79
|
+
"pin). drf-spectacular renders component descriptions (Optional[X] "
|
|
80
|
+
"vs X | None) differently across Python minor versions, so emitting "
|
|
81
|
+
"on any other minor produces false diffs against the committed "
|
|
82
|
+
"docs/*.json. Re-run under a 3.12 interpreter."
|
|
83
|
+
)
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
def main(argv: list[str] | None = None) -> int:
|
|
87
|
+
_require_python_312()
|
|
88
|
+
|
|
89
|
+
parser = argparse.ArgumentParser(
|
|
90
|
+
prog="stapel-delivery-contract",
|
|
91
|
+
description="Emit this module's contract triad (schema.json + flows.json "
|
|
92
|
+
"+ errors.json) into --out, canonical /delivery/api/v1/ prefix.",
|
|
93
|
+
)
|
|
94
|
+
parser.add_argument(
|
|
95
|
+
"--out",
|
|
96
|
+
default="docs",
|
|
97
|
+
help="Output directory for the triad (default: docs).",
|
|
98
|
+
)
|
|
99
|
+
args = parser.parse_args(argv)
|
|
100
|
+
|
|
101
|
+
_configure()
|
|
102
|
+
|
|
103
|
+
from stapel_tools.codegen import emit_errors, emit_flows, emit_schema
|
|
104
|
+
|
|
105
|
+
out = Path(args.out)
|
|
106
|
+
out.mkdir(parents=True, exist_ok=True)
|
|
107
|
+
paths = emit_schema(out / "schema.json")
|
|
108
|
+
# Profile 2 goes to its own file: docs/schema.json is what stapel-react's
|
|
109
|
+
# generators read, and stays profile 1.
|
|
110
|
+
emit_schema(out / "schema.v2.json", contract_profile=2)
|
|
111
|
+
flows = emit_flows(out / "flows.json")
|
|
112
|
+
errors = emit_errors(out / "errors.json")
|
|
113
|
+
|
|
114
|
+
print(
|
|
115
|
+
f"stapel-delivery contract: {paths} paths, {flows} flows, {errors} error keys "
|
|
116
|
+
f"→ {out}/",
|
|
117
|
+
file=sys.stderr,
|
|
118
|
+
)
|
|
119
|
+
return 0
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
if __name__ == "__main__":
|
|
123
|
+
raise SystemExit(main())
|