SDK reference · Node SDK
prov.attest.riskPolicies.simulate
prov.attest.riskPolicies.simulate in Node SDK. A dry run of this domain's draft or active document against facts you supply (nothing is written).
Signature
prov.attest.riskPolicies.simulate(params: { facts: Record<string, string | number | boolean | null>; document?: unknown; order?: Record<string, unknown>; /** #129: what `field` conditions read, sent as written. */ request?: Record<string, unknown>; }): Promise<Record<string, unknown>>Parameters
params{ facts: Record<string, string | number | boolean | null>; document?: unknown; order?: Record<string, unknown>; /** #129: what `field` conditions read, sent as written. */ request?: Record<string, unknown>; }Required
Request fields
Idempotency-Keystringheader- Retry a create safely: the same key + request returns the stored response (24 h, per caller).
documentobject- Draft rules to test; omit to use your active rules.
factsobject- The facts the rules read:
checkout.covered,order.*,agent.*,merchant.*,network.*. orderobject- A cart (
order_id, integertotalin minor units,currency,items); itsorder.*facts joinfacts. requestobject- The request a
fieldcondition reads itspathfrom:order(the cart) andmetadata(the cart's metadata), as on an assessment. phaseenum- Which rules run: the assessment's (default) or the after-approval rules. One of
assess,after_approval.
Returns
Promise<Record<string, unknown>> The outcome the facts would get.
HTTP operation
POST /v1/authorize/policies/simulate: Simulate your checkout rules
Errors
- authentication_required
- invalid_json
- parameter_invalid
- policy_account_required
- policy_invalid
- rate_limit_exceeded
Example
const data = await (await fetch(`${process.env.PROVENANCE_API}/v1/authorize/policies/simulate`, {
method: "POST",
headers: { Authorization: "Bearer prv_test_ent_E7nT2vQ9bW4mK8sYd3cFjLh6gAe1pR5x", "Content-Type": "application/json" },
body: JSON.stringify({
"document": {
"rules": [
{
"id": "gift-cards",
"when": [
{
"fact": "merchant.gift_card_amount",
"op": "gt",
"value": 100
}
],
"require": {
"approval": true
}
},
{
"id": "small-orders",
"label": "No mandate or approval, under $25",
"when": [
{
"fact": "checkout.covered",
"op": "eq",
"value": "none"
},
{
"fact": "order.amount",
"op": "lt",
"value": 25
}
],
"require": {
"no_challenge": true
}
}
]
},
"facts": {
"checkout.covered": "none",
"order.amount": 20
}
}),
})).json();import os
import httpx
api = os.environ["PROVENANCE_API"]
data = httpx.post(f"{api}/v1/authorize/policies/simulate", headers={"Authorization": "Bearer prv_test_ent_E7nT2vQ9bW4mK8sYd3cFjLh6gAe1pR5x"}, json={
"document": {
"rules": [
{
"id": "gift-cards",
"when": [
{
"fact": "merchant.gift_card_amount",
"op": "gt",
"value": 100
}
],
"require": {
"approval": True
}
},
{
"id": "small-orders",
"label": "No mandate or approval, under $25",
"when": [
{
"fact": "checkout.covered",
"op": "eq",
"value": "none"
},
{
"fact": "order.amount",
"op": "lt",
"value": 25
}
],
"require": {
"no_challenge": True
}
}
]
},
"facts": {
"checkout.covered": "none",
"order.amount": 20
}
}).json()