Order approval with a shared library

A purchasing system asks if a user can place an order. The bundle has a shared library of roles, money and strings, and the decision uses only a few of its rules. Tree shaking removes the other rules, the unused library module, the tests and the data that the decision does not read.

Bundle orders, revision 2026-12-03, decision data.orders.approval.decision

Examples

Input: not-a-buyer

{
  "order": {
    "amount": 300,
    "department": "finance"
  },
  "user": {
    "department": "finance",
    "name": "carol",
    "roles": [
      "auditor"
    ]
  }
}

Ask the decision serverOpen in the debugger

Files

Show tree shaking for the decision

1package lib.money
2
3# True if the amount is not over the limit.
4within_limit(amount, limit) if amount <= limit
5
6# The amount with the tax of the region, in cents.
7with_tax(amount, region) := round((amount * (1 + data.orders.tax[region])) * 100)
8
9# The amount in cents.
10cents(amount) := round(amount * 100)
11
12# True if the company accepts the currency.
13accepted_currency(code) if code in {"EUR", "GBP", "USD"}
14