askrobots / dbbasic-object-server
Public
Runs live, versioned Python application objects on one VM, with a suite of apps: projects, notes, tasks, files and more.
dbbasic-package.json · 11.3 KB · 84 lines
| 1 | { |
| 2 | "id": "app-disputes", |
| 3 | "name": "Disputes", |
| 4 | "version": "0.5.0", |
| 5 | "description": "A customer says something went wrong. This package is one small collection and one gate, and the gate is the whole point. Every shop already has disputes -- they live in an inbox, a notebook and somebody's memory -- and what they lack is not a place to write them down but an ENDING that can be checked: plan/fulfillment-logistics-spec.md asks for 'an outcome that is always a LINKED compensating record (refund, replacement shipment, credit), never an edit to history', and the difference between that sentence and a convention is hook_disputes. A dispute may not reach `resolved` unless it names a resolution, and for refund/replacement/credit the name has to RESOLVE -- the right collection for the kind, and a row that actually exists. `no_action` is a legitimate ending, because plenty of claims are genuinely not ours to compensate, but it carries a reason or it is not a decision, it is a queue somebody cleared. The failure all of that prevents is exactly one sentence long: a customer told 'it's sorted' when nothing happened, which is invisible from the inside forever -- the row looks finished, the badge goes down, and the only person who knows is the one still waiting. kind (shipment | delivery | payment | product | other) is five words that each route to different people and different evidence: a carrier argument, a signature-and-photo argument, a processor argument with a chargeback clock on it, an argument for whoever buys the stock, and an honest bucket so nobody has to lie. All three references -- order, shipment, payment -- are OPTIONAL, because the moment a dispute most needs recording is the moment somebody emails about 'my order' before anybody has worked out which parcel or which payment they mean. action_resolve_dispute is the ONE door where a dispute and its compensating record are written together, the same argument app-returns' action_disposition_return makes about returns and refunds: separating them is how a shop ends up with a resolved queue and no refunds against it. It defers the refund ceiling to app-payments' hook_refunds and surfaces that gate's refusal verbatim, so a customer is quoted the same number whichever door their claim arrived through, and it defers the resolution rule to hook_disputes by asking the hook in process rather than restating it. A credit is a wallet entry and wallets are app-billing's, which is deliberately NOT a dependency: a shop that does not sell credit should not have to install a billing engine to record an argument, so the action refuses honestly and names the missing app rather than closing a dispute as though credit had been issued. A replacement is a real sale order, raised CONFIRMED (a draft is not a commitment, and a resolution pointing at a document that promises nothing is the failure this package exists to prevent) with its lines copied at zero price, because the customer already paid on the order being argued about. Resolving twice refunds once: the terminal status is the primary guard and a provenance marker on the refund, the replacement order and the wallet entry is the belt behind it. What is deliberately NOT here, named so it reads as a decision rather than an omission: a carrier claim workflow (a connector boundary, like labels), chargeback representment, a customer-facing dispute form (it needs the same tokened door site_return_form got, and the door is the interesting half -- a later slice), and a REVIEW FREEZE. A disputed order's review window ought to be frozen while the argument is open, and this collection is where that read would come from; there is no reviews system on this server, so the field would be a column of blanks and the doctrine is written into the schema description instead of guessed at in code. Declares an attention count (collection + where, counted per viewer) for disputes at `open` -- claims nobody has picked up -- and a bench at /disputes showing the whole ladder, because the person standing at it needs to see what is in flight as well as what is untouched. The count deliberately excludes `investigating`: a badge that also counts work in progress can never reach zero, which is how a number stops meaning anything. Severity is `warning` rather than `urgent`: a waiting customer is the most human queue on this box, but tests/test_package_attention.py holds a calibration this package does not get to overrule -- `urgent` is reserved for the server reporting that it has stopped doing its own work, and a scale everything claims the top of is not a scale. 0.3.1: a row a registered user writes could point at anybody's record, because the rules asked only that the new row be the writer's own. Every pointer a non-admin can write now declares relation.requires (disputes.order_id update, disputes.shipment_id update, disputes.payment_id update), so over the API a row points only at a record its writer may see, or, where it moves money, stock or state of what it points at, may update; a record they may not see is answered like a missing one (docs/permissions-model.md, 'Pointing at a record you may not act on'). 0.3.2: action_resolve_dispute asks object_access for update on the order and on every payment it compensates from. Being allowed to update the dispute was the only check, so a dispute of one's own naming somebody else's payment refunded it, or credited the resolver's own wallet up to what that payment was, and a replacement copied somebody else's order (customer, address, lines) at no charge. 0.4.0: staff roles read the shop's records. role:cashier, role:shift_lead, role:manager and role:owner read every sale, not only rows they own: checkout files a guest sale under the shop's account, so staff saw nothing and signed in as the owner. Read only; changes go through app-counter's actions. 0.4.1: a credit lands only in the customer's own wallet. action_resolve_dispute took a body wallet_id and credited whatever wallet it named, with no owner, kind or active check, so whoever resolved a real complaint could send the customer's credit to their own wallet, a friend's or a gift card, and an unknown id answered differently (no_such_wallet), which said which wallet ids exist. The customer is now the order's customer (the dispute's customer_email, which is editable text, only when the dispute names no order); a wallet is theirs when its owner is that email or the one active user with that email, it is a balance or store_credit wallet, and it is active. wallet_id only picks among those; any other id gets the no_wallet_for_customer answer and writes nothing. Only an admin may name another wallet. A dispute naming an order the resolver may not act on credits nobody. 0.4.2: the action is the grant, so it checks its own scope. action_resolve_dispute used to leave who may resolve to an execute rule that is asked only with enforcement on, plus an owner check on the dispute, so a customer could resolve their own dispute and credit their own wallet. It now refuses (403) a caller who holds none of the roles its execute rules name and is not an admin (object_corrections.staff_refusal); the package's rule now grants execute to cashier, shift_lead, manager and owner instead of every registered user. 0.4.3: a credit is issued in the dispute's own currency. wallet_entries.amount_minor is in the wallet's denomination, so crediting an order's cents into a wallet of another denomination (or an order in another currency into a blank, i.e. USD, wallet) was a different amount of money; action_resolve_dispute now refuses with 409 currency_mismatch when they differ, or when the wallet's denomination cannot be read, and issues nothing. There is no rate here to convert at. 0.4.4: the help text of disputes.customer_email no longer says it is stamped from the order (nothing does: it is typed by whoever opens the dispute, and the resolve action reads the customer from the order instead). No behaviour change. 0.4.5: the execute rules' reason text no longer credits hook_refunds caps as the bound on a payout; the bound is the resolver's own update rights on the order and its payments (which the payments package gives to managers), so a cashier can close a dispute as no_action or withdrawn but cannot refund or credit. Text only; no rule changed. 0.5.0: a manager settles any dispute, and staff open one about a shop sale, without a right to edit orders. Under 0.4.5 nobody but an admin could pay out a dispute about a shop order: updating a dispute was owner-row only and the resolve action also asked for update on the order, which no shipped role holds. role:manager and role:owner now may update every dispute, and that is the payout grant: a refund, replacement or credit needs a role that may update every dispute (object_corrections.role_grants, which does not count owning the row), so a cashier or shift lead can still close a dispute of their own as no_action but not pay one out (403 payout_needs_manager). action_resolve_dispute no longer borrows the caller's update rights on the order and payments: it reads the order as the caller and checks under its own authority that the order's bill and payments are the order's own account's and that a payment the dispute names is on the order (409 order_mismatch), caps a credit at what was paid and never above the order's total, less refunds and other disputes' credits, and owns a refund by the payment's account and a replacement by the order's. New action_open_dispute (execute: cashier, shift_lead, manager, owner): the record API lets a dispute point only at an order its writer may update, so staff got 403 opening one about a shop order; the action checks the role itself, reads the order and payment as the caller, takes a shipment only as that order's own, and writes an open dispute owned by the caller. No grant on orders, invoices, payments or shipments was added. Reinstall the package after upgrading.", |
| 6 | "compatibility": { |
| 7 | "dbbasic_object_server": ">=0.1.0" |
| 8 | }, |
| 9 | "dependencies": [ |
| 10 | "app-orders", |
| 11 | "app-payments", |
| 12 | "app-shipping", |
| 13 | "app-views" |
| 14 | ], |
| 15 | "objects": [ |
| 16 | { |
| 17 | "id": "hook_disputes", |
| 18 | "path": "objects/hook/disputes.py" |
| 19 | }, |
| 20 | { |
| 21 | "id": "action_resolve_dispute", |
| 22 | "path": "objects/action/resolve_dispute.py" |
| 23 | }, |
| 24 | { |
| 25 | "id": "action_open_dispute", |
| 26 | "path": "objects/action/open_dispute.py" |
| 27 | } |
| 28 | ], |
| 29 | "schemas": [ |
| 30 | { |
| 31 | "collection": "disputes", |
| 32 | "path": "schemas/disputes.json" |
| 33 | } |
| 34 | ], |
| 35 | "permissions": [ |
| 36 | { |
| 37 | "path": "permissions/rules.json" |
| 38 | } |
| 39 | ], |
| 40 | "seed": [ |
| 41 | { |
| 42 | "collection": "disputes", |
| 43 | "path": "seed/disputes.tsv" |
| 44 | }, |
| 45 | { |
| 46 | "collection": "site_routes", |
| 47 | "path": "seed/site_routes.tsv" |
| 48 | }, |
| 49 | { |
| 50 | "collection": "views", |
| 51 | "path": "seed/views.tsv" |
| 52 | } |
| 53 | ], |
| 54 | "migrations": [], |
| 55 | "nav": [ |
| 56 | { |
| 57 | "id": "disputes", |
| 58 | "label": "Disputes", |
| 59 | "path": "/disputes", |
| 60 | "blurb": "Claims customers have made, and what we actually did about each one", |
| 61 | "surface": "operator", |
| 62 | "group": "Commerce", |
| 63 | "order": 430 |
| 64 | } |
| 65 | ], |
| 66 | "attention": [ |
| 67 | { |
| 68 | "id": "disputes_open", |
| 69 | "collection": "disputes", |
| 70 | "where": { |
| 71 | "status": "open" |
| 72 | }, |
| 73 | "detail": { |
| 74 | "op": "max_age_days", |
| 75 | "field": "created_at", |
| 76 | "text": "oldest waiting {value} days" |
| 77 | }, |
| 78 | "label": "Disputes to answer", |
| 79 | "path": "/disputes", |
| 80 | "group": "Commerce", |
| 81 | "severity": "warning" |
| 82 | } |
| 83 | ] |
| 84 | } |