Verify that a user meets the minimum age requirement and is in an allowed region.
A **user** is permitted
if the __date_of_birth__ of the **user** is earlier than 2008-03-21
and the __region__ of the **user** is not in ["restricted_region_1", "restricted_region_2"]
and the __account_verified__ of the **user** is equal to true.
{
"properties": {
"user": {
"properties": {
"date_of_birth": {
"type": "string"
},
"region": {
"type": "string"
},
"account_verified": {
"type": "boolean"
}
},
"required": [
"date_of_birth",
"region",
"account_verified"
],
"type": "object"
}
},
"required": [
"user"
],
"title": "User Model",
"type": "object"
}Adult verified user
Expect pass{
"user": {
"date_of_birth": "1995-06-15",
"region": "eu_west",
"account_verified": true
}
}Underage user
Expect fail{
"user": {
"date_of_birth": "2012-03-10",
"region": "eu_west",
"account_verified": true
}
}Execute this policy from your app using one of the official SDKs.
import { ExecutionClient } from "@policies2/sdk";
const client = new ExecutionClient({
apiKey: process.env.POLICY_API_KEY!,
transport: { kind: "rest", baseUrl: "https://api.policy2.net" },
});
const result = await client.executePolicy({
id: "your-policy-id", // replace with your published policy ID
reference: "base",
data: {
"user": {
"date_of_birth": "1995-06-15",
"region": "eu_west",
"account_verified": true
}
},
});
if (result.result) {
console.log("policy matched");
} else {
console.log("policy did not match");
}Ready to try this policy?
Open in editor