← Back to Pack Library
Sharedlibraryuncertifiedv2026.12.0

vendor

B2B vendor compliance library pack: IRS Form W-9 for U.S. vendors (26 U.S.C. 3406), Certificate of Insurance (COI) attestation with annual renewal, and annual security report attestation for vendors handling sensitive data.

Verify locally with CLI
Validate schema & rules
pnpm ir check packs/vendor/pack.json
Run pack scenarios
pnpm ir test packs/vendor/pack.json
3Requirements
7Concepts
6Scenarios

Requirements (3)

Compliance and operational rules declared in this pack's policies, with authority classification, legal citations, and due/renewal schedules.

Form W-9 — Taxpayer Identification Number and Certification

vendor_w9
statutedocumenttax
Duevendor_contact: vendor/start_date (on day)
Citations
  • 26 U.S.C. 3406
  • 26 CFR 31.3406(h)-3

Certificate of Insurance (COI) Attestation

vendor_coi
practicedocumentinsurance
Duevendor_contact: vendor/start_date (on day) · reviewer: vendor/start_date (on day)
Expires onvendor/coi_expires_on
Renew within30 days
Citations
  • Commercial vendor insurance risk management practice

Annual Security Report and Information Security Attestation

vendor_security_report
practicedocumentsecurity
Duevendor_contact: vendor/start_date (on day)
Expires onvendor/security_report_expires_on
Renew within30 days
Citations
  • Third-party vendor information security assurance practice

Concepts (7)

Typed domain facts introduced by this pack that policies evaluate against.

ConceptTypeChoices / Description
vendor/is_us_personboolean

Whether the vendor is a U.S. person or U.S. business entity subject to federal tax reporting

vendor/requires_insuranceboolean

Whether the vendor engagement requires a Certificate of Insurance (COI)

vendor/handles_sensitive_databoolean

Whether the vendor handles sensitive, confidential, or regulated data requiring an annual security report

vendor/start_datedate

Scheduled vendor engagement or first payment date (YYYY-MM-DD)

vendor/reviewerstring

Procurement or compliance reviewer responsible for verifying vendor insurance coverage

vendor/coi_expires_ondate

Expiration date printed on the vendor's Certificate of Insurance (YYYY-MM-DD)

vendor/security_report_expires_ondate

Expiration date of the vendor's current security report or attestation (YYYY-MM-DD)

Scenarios (6)

Executable compliance test cases verified against this pack by pnpm ir test.

us-vendor-all-requirements
as of 2026-12-01

U.S. vendor requiring insurance and handling sensitive data triggers Form W-9, COI attestation, and annual security report, all due by vendor/start_date.

Given facts
vendor/is_us_person=truevendor/requires_insurance=truevendor/handles_sensitive_data=truevendor/start_date=2026-12-10vendor/reviewer=usr_reviewer_01
Expected outcomes
+ vendor_w9+ vendor_coi+ vendor_security_reportvendor_w9: availablevendor_coi: availablevendor_security_report: availablewake_at: 2026-12-11
non-us-vendor-no-optional-requirements
as of 2026-12-01

Non-U.S. vendor that does not require insurance and does not handle sensitive data triggers none of the vendor compliance requirements.

Given facts
vendor/is_us_person=falsevendor/requires_insurance=falsevendor/handles_sensitive_data=falsevendor/start_date=2026-12-10vendor/reviewer=usr_reviewer_01
Expected outcomes
− vendor_w9− vendor_coi− vendor_security_report
us-vendor-w9-only
as of 2026-12-01

U.S. vendor without insurance or sensitive data obligations requires Form W-9 only.

Given facts
vendor/is_us_person=truevendor/requires_insurance=falsevendor/handles_sensitive_data=falsevendor/start_date=2026-12-10vendor/reviewer=usr_reviewer_01
Expected outcomes
+ vendor_w9− vendor_coi− vendor_security_reportvendor_w9: availablewake_at: 2026-12-11
missing-facts-tentative
as of 2026-12-011 step

When vendor eligibility flags are unknown, requirements are tentative and blocked on missing facts until supplied.

Given facts
vendor/start_date=2026-12-10vendor/reviewer=usr_reviewer_01
Expected outcomes
+ vendor_w9+ vendor_coi+ vendor_security_reportvendor_w9: blocked_on_factsvendor_coi: blocked_on_factsvendor_security_report: blocked_on_facts
due-date-and-overdue
as of 2026-12-012 steps

Missing vendor/start_date blocks due-date computation; supplying start_date unlocks requirements with wake_at one day after due date, and advancing past start_date marks them overdue.

Given facts
vendor/is_us_person=truevendor/requires_insurance=truevendor/handles_sensitive_data=truevendor/reviewer=usr_reviewer_01
Expected outcomes
+ vendor_w9+ vendor_coi+ vendor_security_reportvendor_w9: blocked_on_factsvendor_coi: blocked_on_factsvendor_security_report: blocked_on_facts
coi-and-security-annual-renewal-and-expiry
as of 2026-12-013 steps

Completed COI and security report open 30-day renewal items before their expires_on dates and transition to expired once as_of reaches or passes expiry, while Form W-9 remains complete.

Given facts
vendor/is_us_person=truevendor/requires_insurance=truevendor/handles_sensitive_data=truevendor/start_date=2026-12-10vendor/reviewer=usr_reviewer_01vendor/coi_expires_on=2027-06-30vendor/security_report_expires_on=2027-09-15
Expected outcomes
+ vendor_w9+ vendor_coi+ vendor_security_report− vendor_coi:renewal− vendor_security_report:renewalvendor_w9: completedvendor_coi: completedvendor_security_report: completedwake_at: 2027-05-31

Pack JSON

Show raw packs/vendor/pack.json
{
  "format": 1,
  "name": "vendor",
  "version": "2026.12.0",
  "kind": "library",
  "description": "B2B vendor compliance library pack: IRS Form W-9 for U.S. vendors (26 U.S.C. 3406), Certificate of Insurance (COI) attestation with annual renewal, and annual security report attestation for vendors handling sensitive data.",
  "concepts": [
    {
      "key": "vendor/is_us_person",
      "type": "boolean",
      "description": "Whether the vendor is a U.S. person or U.S. business entity subject to federal tax reporting"
    },
    {
      "key": "vendor/requires_insurance",
      "type": "boolean",
      "description": "Whether the vendor engagement requires a Certificate of Insurance (COI)"
    },
    {
      "key": "vendor/handles_sensitive_data",
      "type": "boolean",
      "description": "Whether the vendor handles sensitive, confidential, or regulated data requiring an annual security report"
    },
    {
      "key": "vendor/start_date",
      "type": "date",
      "description": "Scheduled vendor engagement or first payment date (YYYY-MM-DD)"
    },
    {
      "key": "vendor/reviewer",
      "type": "string",
      "description": "Procurement or compliance reviewer responsible for verifying vendor insurance coverage"
    },
    {
      "key": "vendor/coi_expires_on",
      "type": "date",
      "description": "Expiration date printed on the vendor's Certificate of Insurance (YYYY-MM-DD)"
    },
    {
      "key": "vendor/security_report_expires_on",
      "type": "date",
      "description": "Expiration date of the vendor's current security report or attestation (YYYY-MM-DD)"
    }
  ],
  "templates": [
    {
      "key": "vendor_w9",
      "version": "2026.1.0",
      "title": "Form W-9 — Request for Taxpayer Identification Number and Certification",
      "roles": [
        {
          "name": "vendor_contact",
          "kind": "person",
          "label": "Authorized Tax Signer"
        }
      ],
      "sections": [
        {
          "id": "taxpayer",
          "role": "vendor_contact",
          "title": "Taxpayer Identification",
          "fields": [
            {
              "id": "taxpayer_legal_name",
              "type": "text",
              "label": "Taxpayer Legal Name",
              "required": true
            },
            {
              "id": "entity_classification",
              "type": "choice",
              "label": "Federal Tax Classification",
              "options": [
                "individual_sole_proprietor",
                "c_corp",
                "s_corp",
                "partnership",
                "llc",
                "other"
              ],
              "required": true
            },
            {
              "id": "tin",
              "type": "text",
              "label": "Taxpayer Identification Number (EIN or SSN)",
              "required": true,
              "sensitive": true
            },
            {
              "id": "exempt_backup_withholding",
              "type": "boolean",
              "label": "Exempt from backup withholding",
              "required": true
            }
          ],
          "signature": {
            "id": "w9_signature",
            "attestation": "Under penalties of perjury, I certify that the Taxpayer Identification Number provided is correct.",
            "covers": [
              "taxpayer"
            ]
          }
        }
      ]
    },
    {
      "key": "vendor_coi",
      "version": "2026.1.0",
      "title": "Certificate of Insurance (COI) Attestation",
      "roles": [
        {
          "name": "vendor_contact",
          "kind": "person",
          "label": "Vendor Representative"
        },
        {
          "name": "reviewer",
          "kind": "user",
          "label": "Compliance Reviewer",
          "after": [
            "vendor_contact"
          ]
        }
      ],
      "sections": [
        {
          "id": "coverage",
          "role": "vendor_contact",
          "title": "Insurance Coverage Details",
          "fields": [
            {
              "id": "insurer_name",
              "type": "text",
              "label": "Insurance Carrier",
              "required": true
            },
            {
              "id": "policy_number",
              "type": "text",
              "label": "Policy Number",
              "required": true
            },
            {
              "id": "coverage_type",
              "type": "choice",
              "label": "Coverage Type",
              "options": [
                "general_liability",
                "cyber_liability",
                "general_and_cyber",
                "errors_and_omissions"
              ],
              "required": true
            },
            {
              "id": "expiration_date",
              "type": "date",
              "label": "Policy Expiration Date",
              "required": true
            }
          ],
          "signature": {
            "id": "vendor_coi_signature",
            "attestation": "I certify that the insurance coverage details provided above reflect an active policy.",
            "covers": [
              "coverage"
            ]
          }
        },
        {
          "id": "review",
          "role": "reviewer",
          "title": "Coverage Verification",
          "readable": [
            "coverage"
          ],
          "fields": [
            {
              "id": "verification_status",
              "type": "choice",
              "label": "Verification Status",
              "options": [
                "verified",
                "insufficient_coverage"
              ],
              "required": true
            }
          ]
        }
      ]
    },
    {
      "key": "vendor_security_report",
      "version": "2026.1.0",
      "title": "Annual Security Report and Information Security Attestation",
      "roles": [
        {
          "name": "vendor_contact",
          "kind": "person",
          "label": "Vendor Security Contact"
        }
      ],
      "sections": [
        {
          "id": "security",
          "role": "vendor_contact",
          "title": "Information Security Report",
          "fields": [
            {
              "id": "report_type",
              "type": "choice",
              "label": "Security Assurance Report Type",
              "options": [
                "soc2_type_ii",
                "iso_27001",
                "security_questionnaire"
              ],
              "required": true
            },
            {
              "id": "report_date",
              "type": "date",
              "label": "Most Recent Report Date",
              "required": true
            },
            {
              "id": "expiration_date",
              "type": "date",
              "label": "Report Expiration Date",
              "required": true
            }
          ],
          "signature": {
            "id": "security_report_signature",
            "attestation": "I attest that our information security controls match the disclosures provided above.",
            "covers": [
              "security"
            ]
          }
        }
      ]
    }
  ],
  "policies": [
    {
      "key": "vendor",
      "version": "2026.12.0",
      "facts": {
        "vendor/is_us_person": {
          "type": "boolean"
        },
        "vendor/requires_insurance": {
          "type": "boolean"
        },
        "vendor/handles_sensitive_data": {
          "type": "boolean"
        },
        "vendor/start_date": {
          "type": "date"
        },
        "vendor/reviewer": {
          "type": "string"
        },
        "vendor/coi_expires_on": {
          "type": "date"
        },
        "vendor/security_report_expires_on": {
          "type": "date"
        }
      },
      "stages": [
        {
          "id": "tax",
          "title": "Tax Identification"
        },
        {
          "id": "insurance",
          "title": "Insurance Coverage"
        },
        {
          "id": "security",
          "title": "Information Security"
        }
      ],
      "requirements": {
        "vendor_w9": {
          "title": "Form W-9 — Taxpayer Identification Number and Certification",
          "kind": "document",
          "template": "vendor_w9",
          "stage": "tax",
          "parties": {
            "vendor_contact": "subject"
          },
          "due": {
            "vendor_contact": {
              "relative_to": "vendor/start_date",
              "days": 0
            }
          },
          "on_unknown": "wait",
          "cites": [
            "26 U.S.C. 3406",
            "26 CFR 31.3406(h)-3"
          ],
          "authority": "statute"
        },
        "vendor_coi": {
          "title": "Certificate of Insurance (COI) Attestation",
          "kind": "document",
          "template": "vendor_coi",
          "stage": "insurance",
          "parties": {
            "vendor_contact": "subject",
            "reviewer": "vendor/reviewer"
          },
          "due": {
            "vendor_contact": {
              "relative_to": "vendor/start_date",
              "days": 0
            },
            "reviewer": {
              "relative_to": "vendor/start_date",
              "days": 0
            }
          },
          "expires_on": "vendor/coi_expires_on",
          "renew_within": {
            "days": 30
          },
          "on_unknown": "wait",
          "cites": [
            "Commercial vendor insurance risk management practice"
          ],
          "authority": "practice"
        },
        "vendor_security_report": {
          "title": "Annual Security Report and Information Security Attestation",
          "kind": "document",
          "template": "vendor_security_report",
          "stage": "security",
          "parties": {
            "vendor_contact": "subject"
          },
          "due": {
            "vendor_contact": {
              "relative_to": "vendor/start_date",
              "days": 0
            }
          },
          "expires_on": "vendor/security_report_expires_on",
          "renew_within": {
            "days": 30
          },
          "on_unknown": "wait",
          "cites": [
            "Third-party vendor information security assurance practice"
          ],
          "authority": "practice"
        }
      },
      "policies": [
        {
          "id": "vendor-us-w9",
          "title": "Form W-9 for U.S. vendors",
          "when": {
            "fact": "vendor/is_us_person",
            "operator": "equal",
            "value": true
          },
          "require": [
            "vendor_w9"
          ],
          "optional": false,
          "cites": [
            "26 U.S.C. 3406",
            "26 CFR 31.3406(h)-3"
          ]
        },
        {
          "id": "vendor-coi-required",
          "title": "Certificate of Insurance for engagements requiring insurance coverage",
          "when": {
            "fact": "vendor/requires_insurance",
            "operator": "equal",
            "value": true
          },
          "require": [
            "vendor_coi"
          ],
          "optional": false,
          "cites": [
            "Commercial vendor insurance risk management practice"
          ]
        },
        {
          "id": "vendor-security-report-sensitive-data",
          "title": "Annual security report for vendors handling sensitive data",
          "when": {
            "fact": "vendor/handles_sensitive_data",
            "operator": "equal",
            "value": true
          },
          "require": [
            "vendor_security_report"
          ],
          "optional": false,
          "cites": [
            "Third-party vendor information security assurance practice"
          ]
        }
      ]
    }
  ],
  "scenarios": [
    {
      "name": "us-vendor-all-requirements",
      "description": "U.S. vendor requiring insurance and handling sensitive data triggers Form W-9, COI attestation, and annual security report, all due by vendor/start_date.",
      "policy_set": "vendor",
      "as_of": "2026-12-01",
      "facts": {
        "vendor/is_us_person": true,
        "vendor/requires_insurance": true,
        "vendor/handles_sensitive_data": true,
        "vendor/start_date": "2026-12-10",
        "vendor/reviewer": "usr_reviewer_01"
      },
      "expect": {
        "required": [
          "vendor_w9",
          "vendor_coi",
          "vendor_security_report"
        ],
        "not_required": [],
        "states": {
          "vendor_w9": "available",
          "vendor_coi": "available",
          "vendor_security_report": "available"
        },
        "missing_facts": [],
        "wake_at": "2026-12-11"
      }
    },
    {
      "name": "non-us-vendor-no-optional-requirements",
      "description": "Non-U.S. vendor that does not require insurance and does not handle sensitive data triggers none of the vendor compliance requirements.",
      "policy_set": "vendor",
      "as_of": "2026-12-01",
      "facts": {
        "vendor/is_us_person": false,
        "vendor/requires_insurance": false,
        "vendor/handles_sensitive_data": false,
        "vendor/start_date": "2026-12-10",
        "vendor/reviewer": "usr_reviewer_01"
      },
      "expect": {
        "required": [],
        "not_required": [
          "vendor_w9",
          "vendor_coi",
          "vendor_security_report"
        ],
        "missing_facts": []
      }
    },
    {
      "name": "us-vendor-w9-only",
      "description": "U.S. vendor without insurance or sensitive data obligations requires Form W-9 only.",
      "policy_set": "vendor",
      "as_of": "2026-12-01",
      "facts": {
        "vendor/is_us_person": true,
        "vendor/requires_insurance": false,
        "vendor/handles_sensitive_data": false,
        "vendor/start_date": "2026-12-10",
        "vendor/reviewer": "usr_reviewer_01"
      },
      "expect": {
        "required": [
          "vendor_w9"
        ],
        "not_required": [
          "vendor_coi",
          "vendor_security_report"
        ],
        "states": {
          "vendor_w9": "available"
        },
        "missing_facts": [],
        "wake_at": "2026-12-11"
      }
    },
    {
      "name": "missing-facts-tentative",
      "description": "When vendor eligibility flags are unknown, requirements are tentative and blocked on missing facts until supplied.",
      "policy_set": "vendor",
      "as_of": "2026-12-01",
      "facts": {
        "vendor/start_date": "2026-12-10",
        "vendor/reviewer": "usr_reviewer_01"
      },
      "expect": {
        "required": [
          "vendor_w9",
          "vendor_coi",
          "vendor_security_report"
        ],
        "not_required": [],
        "states": {
          "vendor_w9": "blocked_on_facts",
          "vendor_coi": "blocked_on_facts",
          "vendor_security_report": "blocked_on_facts"
        },
        "missing_facts": [
          "vendor/handles_sensitive_data",
          "vendor/is_us_person",
          "vendor/requires_insurance"
        ]
      },
      "steps": [
        {
          "name": "supply-vendor-facts",
          "set_facts": {
            "vendor/is_us_person": true,
            "vendor/requires_insurance": false,
            "vendor/handles_sensitive_data": true
          },
          "expect": {
            "required": [
              "vendor_w9",
              "vendor_security_report"
            ],
            "not_required": [
              "vendor_coi"
            ],
            "states": {
              "vendor_w9": "available",
              "vendor_security_report": "available"
            },
            "missing_facts": [],
            "wake_at": "2026-12-11"
          }
        }
      ]
    },
    {
      "name": "due-date-and-overdue",
      "description": "Missing vendor/start_date blocks due-date computation; supplying start_date unlocks requirements with wake_at one day after due date, and advancing past start_date marks them overdue.",
      "policy_set": "vendor",
      "as_of": "2026-12-01",
      "facts": {
        "vendor/is_us_person": true,
        "vendor/requires_insurance": true,
        "vendor/handles_sensitive_data": true,
        "vendor/reviewer": "usr_reviewer_01"
      },
      "expect": {
        "required": [
          "vendor_w9",
          "vendor_coi",
          "vendor_security_report"
        ],
        "not_required": [],
        "states": {
          "vendor_w9": "blocked_on_facts",
          "vendor_coi": "blocked_on_facts",
          "vendor_security_report": "blocked_on_facts"
        },
        "missing_facts": [
          "vendor/start_date"
        ]
      },
      "steps": [
        {
          "name": "set-start-date",
          "set_facts": {
            "vendor/start_date": "2026-12-10"
          },
          "expect": {
            "required": [
              "vendor_w9",
              "vendor_coi",
              "vendor_security_report"
            ],
            "not_required": [],
            "states": {
              "vendor_w9": "available",
              "vendor_coi": "available",
              "vendor_security_report": "available"
            },
            "missing_facts": [],
            "wake_at": "2026-12-11"
          }
        },
        {
          "name": "advance-past-due-date",
          "as_of": "2026-12-11",
          "expect": {
            "required": [
              "vendor_w9",
              "vendor_coi",
              "vendor_security_report"
            ],
            "not_required": [],
            "states": {
              "vendor_w9": "overdue",
              "vendor_coi": "overdue",
              "vendor_security_report": "overdue"
            },
            "missing_facts": []
          }
        }
      ]
    },
    {
      "name": "coi-and-security-annual-renewal-and-expiry",
      "description": "Completed COI and security report open 30-day renewal items before their expires_on dates and transition to expired once as_of reaches or passes expiry, while Form W-9 remains complete.",
      "policy_set": "vendor",
      "as_of": "2026-12-01",
      "facts": {
        "vendor/is_us_person": true,
        "vendor/requires_insurance": true,
        "vendor/handles_sensitive_data": true,
        "vendor/start_date": "2026-12-10",
        "vendor/reviewer": "usr_reviewer_01",
        "vendor/coi_expires_on": "2027-06-30",
        "vendor/security_report_expires_on": "2027-09-15"
      },
      "progress": {
        "vendor_w9": {
          "status": "completed",
          "document": "doc_vendor_w9_01",
          "roles": {
            "vendor_contact": "completed"
          }
        },
        "vendor_coi": {
          "status": "completed",
          "document": "doc_vendor_coi_01",
          "roles": {
            "vendor_contact": "completed",
            "reviewer": "completed"
          }
        },
        "vendor_security_report": {
          "status": "completed",
          "document": "doc_vendor_sec_01",
          "roles": {
            "vendor_contact": "completed"
          }
        }
      },
      "expect": {
        "required": [
          "vendor_w9",
          "vendor_coi",
          "vendor_security_report"
        ],
        "not_required": [
          "vendor_coi:renewal",
          "vendor_security_report:renewal"
        ],
        "states": {
          "vendor_w9": "completed",
          "vendor_coi": "completed",
          "vendor_security_report": "completed"
        },
        "missing_facts": [],
        "wake_at": "2027-05-31"
      },
      "steps": [
        {
          "name": "enter-coi-renewal-window",
          "as_of": "2027-06-05",
          "expect": {
            "required": [
              "vendor_w9",
              "vendor_coi",
              "vendor_coi:renewal",
              "vendor_security_report"
            ],
            "not_required": [
              "vendor_security_report:renewal"
            ],
            "states": {
              "vendor_w9": "completed",
              "vendor_coi": "completed",
              "vendor_coi:renewal": "available",
              "vendor_security_report": "completed"
            },
            "missing_facts": [],
            "wake_at": "2027-06-30"
          }
        },
        {
          "name": "advance-past-coi-expiry",
          "as_of": "2027-07-01",
          "expect": {
            "required": [
              "vendor_w9",
              "vendor_coi",
              "vendor_security_report"
            ],
            "not_required": [
              "vendor_coi:renewal",
              "vendor_security_report:renewal"
            ],
            "states": {
              "vendor_w9": "completed",
              "vendor_coi": "expired",
              "vendor_security_report": "completed"
            },
            "missing_facts": [],
            "wake_at": "2027-08-16"
          }
        },
        {
          "name": "advance-past-security-report-expiry",
          "as_of": "2027-09-16",
          "expect": {
            "required": [
              "vendor_w9",
              "vendor_coi",
              "vendor_security_report"
            ],
            "not_required": [
              "vendor_coi:renewal",
              "vendor_security_report:renewal"
            ],
            "states": {
              "vendor_w9": "completed",
              "vendor_coi": "expired",
              "vendor_security_report": "expired"
            },
            "missing_facts": []
          }
        }
      ]
    }
  ]
}

Forma Lisp

Show Forma Lisp source vendor.forma
(pack vendor
  :format 1
  :version "2026.12.0"
  :kind "library"
  :description "B2B vendor compliance library pack: IRS Form W-9 for U.S. vendors (26 U.S.C. 3406), Certificate of Insurance (COI) attestation with annual renewal, and annual security report attestation for vendors handling sensitive data.")

;; ── Concepts ───────────────────────────────────────────────────────────────

(concept "vendor/is_us_person"
  :type "boolean"
  :description "Whether the vendor is a U.S. person or U.S. business entity subject to federal tax reporting")

(concept "vendor/requires_insurance"
  :type "boolean"
  :description "Whether the vendor engagement requires a Certificate of Insurance (COI)")

(concept "vendor/handles_sensitive_data"
  :type "boolean"
  :description "Whether the vendor handles sensitive, confidential, or regulated data requiring an annual security report")

(concept "vendor/start_date"
  :type "date"
  :description "Scheduled vendor engagement or first payment date (YYYY-MM-DD)")

(concept "vendor/reviewer"
  :type "string"
  :description "Procurement or compliance reviewer responsible for verifying vendor insurance coverage")

(concept "vendor/coi_expires_on"
  :type "date"
  :description "Expiration date printed on the vendor's Certificate of Insurance (YYYY-MM-DD)")

(concept "vendor/security_report_expires_on"
  :type "date"
  :description "Expiration date of the vendor's current security report or attestation (YYYY-MM-DD)")

;; ── Document Templates ─────────────────────────────────────────────────────

(template vendor_w9
  :version "2026.1.0"
  :title "Form W-9 — Request for Taxpayer Identification Number and Certification"
  :roles [{:name "vendor_contact" :kind "person" :label "Authorized Tax Signer"}]
  :sections
    [{:id "taxpayer"
       :role "vendor_contact"
       :title "Taxpayer Identification"
       :fields
        [{:id "taxpayer_legal_name"
           :type "text"
           :label "Taxpayer Legal Name"
           :required true}
         {:id "entity_classification"
           :type "choice"
           :label "Federal Tax Classification"
           :options ["individual_sole_proprietor" "c_corp" "s_corp" "partnership" "llc" "other"]
           :required true}
         {:id "tin"
           :type "text"
           :label "Taxpayer Identification Number (EIN or SSN)"
           :required true
           :sensitive true}
         {:id "exempt_backup_withholding"
           :type "boolean"
           :label "Exempt from backup withholding"
           :required true}]
       :signature
        {:id "w9_signature"
         :attestation "Under penalties of perjury, I certify that the Taxpayer Identification Number provided is correct."
         :covers ["taxpayer"]}}])

(template vendor_coi
  :version "2026.1.0"
  :title "Certificate of Insurance (COI) Attestation"
  :roles
    [{:name "vendor_contact" :kind "person" :label "Vendor Representative"}
     {:name "reviewer"
       :kind "user"
       :label "Compliance Reviewer"
       :after ["vendor_contact"]}]
  :sections
    [{:id "coverage"
       :role "vendor_contact"
       :title "Insurance Coverage Details"
       :fields
        [{:id "insurer_name" :type "text" :label "Insurance Carrier" :required true}
         {:id "policy_number" :type "text" :label "Policy Number" :required true}
         {:id "coverage_type"
           :type "choice"
           :label "Coverage Type"
           :options
            ["general_liability"
             "cyber_liability"
             "general_and_cyber"
             "errors_and_omissions"]
           :required true}
         {:id "expiration_date"
           :type "date"
           :label "Policy Expiration Date"
           :required true}]
       :signature
        {:id "vendor_coi_signature"
         :attestation "I certify that the insurance coverage details provided above reflect an active policy."
         :covers ["coverage"]}}
     {:id "review"
       :role "reviewer"
       :title "Coverage Verification"
       :readable ["coverage"]
       :fields
        [{:id "verification_status"
           :type "choice"
           :label "Verification Status"
           :options ["verified" "insufficient_coverage"]
           :required true}]}])

(template vendor_security_report
  :version "2026.1.0"
  :title "Annual Security Report and Information Security Attestation"
  :roles [{:name "vendor_contact" :kind "person" :label "Vendor Security Contact"}]
  :sections
    [{:id "security"
       :role "vendor_contact"
       :title "Information Security Report"
       :fields
        [{:id "report_type"
           :type "choice"
           :label "Security Assurance Report Type"
           :options ["soc2_type_ii" "iso_27001" "security_questionnaire"]
           :required true}
         {:id "report_date"
           :type "date"
           :label "Most Recent Report Date"
           :required true}
         {:id "expiration_date"
           :type "date"
           :label "Report Expiration Date"
           :required true}]
       :signature
        {:id "security_report_signature"
         :attestation "I attest that our information security controls match the disclosures provided above."
         :covers ["security"]}}])

;; ── Compliance Policy Sets ─────────────────────────────────────────────────

(policy-set vendor
  :version "2026.12.0"
  :facts
    {"vendor/is_us_person" {:type "boolean"}
     "vendor/requires_insurance" {:type "boolean"}
     "vendor/handles_sensitive_data" {:type "boolean"}
     "vendor/start_date" {:type "date"}
     "vendor/reviewer" {:type "string"}
     "vendor/coi_expires_on" {:type "date"}
     "vendor/security_report_expires_on" {:type "date"}}
  :stages
    [{:id "tax" :title "Tax Identification"}
     {:id "insurance" :title "Insurance Coverage"}
     {:id "security" :title "Information Security"}]
  :requirements
    {:vendor_w9
      {:title "Form W-9 — Taxpayer Identification Number and Certification"
       :kind "document"
       :template "vendor_w9"
       :stage "tax"
       :parties {:vendor_contact "subject"}
       :due {:vendor_contact {:relative_to "vendor/start_date" :days 0}}
       :on_unknown "wait"
       :cites ["26 U.S.C. 3406" "26 CFR 31.3406(h)-3"]
       :authority "statute"}
     :vendor_coi
      {:title "Certificate of Insurance (COI) Attestation"
       :kind "document"
       :template "vendor_coi"
       :stage "insurance"
       :parties {:vendor_contact "subject" :reviewer "vendor/reviewer"}
       :due
        {:vendor_contact {:relative_to "vendor/start_date" :days 0}
         :reviewer {:relative_to "vendor/start_date" :days 0}}
       :expires_on "vendor/coi_expires_on"
       :renew_within {:days 30}
       :on_unknown "wait"
       :cites ["Commercial vendor insurance risk management practice"]
       :authority "practice"}
     :vendor_security_report
      {:title "Annual Security Report and Information Security Attestation"
       :kind "document"
       :template "vendor_security_report"
       :stage "security"
       :parties {:vendor_contact "subject"}
       :due {:vendor_contact {:relative_to "vendor/start_date" :days 0}}
       :expires_on "vendor/security_report_expires_on"
       :renew_within {:days 30}
       :on_unknown "wait"
       :cites ["Third-party vendor information security assurance practice"]
       :authority "practice"}}
  :policies
    [{:id "vendor-us-w9"
       :title "Form W-9 for U.S. vendors"
       :when {:fact "vendor/is_us_person" :operator "equal" :value true}
       :require ["vendor_w9"]
       :optional false
       :cites ["26 U.S.C. 3406" "26 CFR 31.3406(h)-3"]}
     {:id "vendor-coi-required"
       :title "Certificate of Insurance for engagements requiring insurance coverage"
       :when {:fact "vendor/requires_insurance" :operator "equal" :value true}
       :require ["vendor_coi"]
       :optional false
       :cites ["Commercial vendor insurance risk management practice"]}
     {:id "vendor-security-report-sensitive-data"
       :title "Annual security report for vendors handling sensitive data"
       :when {:fact "vendor/handles_sensitive_data" :operator "equal" :value true}
       :require ["vendor_security_report"]
       :optional false
       :cites ["Third-party vendor information security assurance practice"]}])

;; ── Declarative Scenarios ──────────────────────────────────────────────────

(scenario us-vendor-all-requirements
  :description "U.S. vendor requiring insurance and handling sensitive data triggers Form W-9, COI attestation, and annual security report, all due by vendor/start_date."
  :policy-set "vendor"
  :as-of "2026-12-01"
  :facts
    {"vendor/is_us_person" true
     "vendor/requires_insurance" true
     "vendor/handles_sensitive_data" true
     "vendor/start_date" "2026-12-10"
     "vendor/reviewer" "usr_reviewer_01"}
  :expect
    {:required ["vendor_w9" "vendor_coi" "vendor_security_report"]
     :not_required []
     :states
      {:vendor_w9 "available"
       :vendor_coi "available"
       :vendor_security_report "available"}
     :missing_facts []
     :wake_at "2026-12-11"})

(scenario non-us-vendor-no-optional-requirements
  :description "Non-U.S. vendor that does not require insurance and does not handle sensitive data triggers none of the vendor compliance requirements."
  :policy-set "vendor"
  :as-of "2026-12-01"
  :facts
    {"vendor/is_us_person" false
     "vendor/requires_insurance" false
     "vendor/handles_sensitive_data" false
     "vendor/start_date" "2026-12-10"
     "vendor/reviewer" "usr_reviewer_01"}
  :expect
    {:required []
     :not_required ["vendor_w9" "vendor_coi" "vendor_security_report"]
     :missing_facts []})

(scenario us-vendor-w9-only
  :description "U.S. vendor without insurance or sensitive data obligations requires Form W-9 only."
  :policy-set "vendor"
  :as-of "2026-12-01"
  :facts
    {"vendor/is_us_person" true
     "vendor/requires_insurance" false
     "vendor/handles_sensitive_data" false
     "vendor/start_date" "2026-12-10"
     "vendor/reviewer" "usr_reviewer_01"}
  :expect
    {:required ["vendor_w9"]
     :not_required ["vendor_coi" "vendor_security_report"]
     :states {:vendor_w9 "available"}
     :missing_facts []
     :wake_at "2026-12-11"})

(scenario missing-facts-tentative
  :description "When vendor eligibility flags are unknown, requirements are tentative and blocked on missing facts until supplied."
  :policy-set "vendor"
  :as-of "2026-12-01"
  :facts {"vendor/start_date" "2026-12-10" "vendor/reviewer" "usr_reviewer_01"}
  :expect
    {:required ["vendor_w9" "vendor_coi" "vendor_security_report"]
     :not_required []
     :states
      {:vendor_w9 "blocked_on_facts"
       :vendor_coi "blocked_on_facts"
       :vendor_security_report "blocked_on_facts"}
     :missing_facts
      ["vendor/handles_sensitive_data"
       "vendor/is_us_person"
       "vendor/requires_insurance"]}
  :steps
    [{:name "supply-vendor-facts"
       :set_facts
        {"vendor/is_us_person" true
         "vendor/requires_insurance" false
         "vendor/handles_sensitive_data" true}
       :expect
        {:required ["vendor_w9" "vendor_security_report"]
         :not_required ["vendor_coi"]
         :states {:vendor_w9 "available" :vendor_security_report "available"}
         :missing_facts []
         :wake_at "2026-12-11"}}])

(scenario due-date-and-overdue
  :description "Missing vendor/start_date blocks due-date computation; supplying start_date unlocks requirements with wake_at one day after due date, and advancing past start_date marks them overdue."
  :policy-set "vendor"
  :as-of "2026-12-01"
  :facts
    {"vendor/is_us_person" true
     "vendor/requires_insurance" true
     "vendor/handles_sensitive_data" true
     "vendor/reviewer" "usr_reviewer_01"}
  :expect
    {:required ["vendor_w9" "vendor_coi" "vendor_security_report"]
     :not_required []
     :states
      {:vendor_w9 "blocked_on_facts"
       :vendor_coi "blocked_on_facts"
       :vendor_security_report "blocked_on_facts"}
     :missing_facts ["vendor/start_date"]}
  :steps
    [{:name "set-start-date"
       :set_facts {"vendor/start_date" "2026-12-10"}
       :expect
        {:required ["vendor_w9" "vendor_coi" "vendor_security_report"]
         :not_required []
         :states
          {:vendor_w9 "available"
           :vendor_coi "available"
           :vendor_security_report "available"}
         :missing_facts []
         :wake_at "2026-12-11"}}
     {:name "advance-past-due-date"
       :as_of "2026-12-11"
       :expect
        {:required ["vendor_w9" "vendor_coi" "vendor_security_report"]
         :not_required []
         :states {:vendor_w9 "overdue" :vendor_coi "overdue" :vendor_security_report "overdue"}
         :missing_facts []}}])

(scenario coi-and-security-annual-renewal-and-expiry
  :description "Completed COI and security report open 30-day renewal items before their expires_on dates and transition to expired once as_of reaches or passes expiry, while Form W-9 remains complete."
  :policy-set "vendor"
  :as-of "2026-12-01"
  :facts
    {"vendor/is_us_person" true
     "vendor/requires_insurance" true
     "vendor/handles_sensitive_data" true
     "vendor/start_date" "2026-12-10"
     "vendor/reviewer" "usr_reviewer_01"
     "vendor/coi_expires_on" "2027-06-30"
     "vendor/security_report_expires_on" "2027-09-15"}
  :progress
    {:vendor_w9
      {:status "completed"
       :document "doc_vendor_w9_01"
       :roles {:vendor_contact "completed"}}
     :vendor_coi
      {:status "completed"
       :document "doc_vendor_coi_01"
       :roles {:vendor_contact "completed" :reviewer "completed"}}
     :vendor_security_report
      {:status "completed"
       :document "doc_vendor_sec_01"
       :roles {:vendor_contact "completed"}}}
  :expect
    {:required ["vendor_w9" "vendor_coi" "vendor_security_report"]
     :not_required ["vendor_coi:renewal" "vendor_security_report:renewal"]
     :states
      {:vendor_w9 "completed"
       :vendor_coi "completed"
       :vendor_security_report "completed"}
     :missing_facts []
     :wake_at "2027-05-31"}
  :steps
    [{:name "enter-coi-renewal-window"
       :as_of "2027-06-05"
       :expect
        {:required ["vendor_w9" "vendor_coi" "vendor_coi:renewal" "vendor_security_report"]
         :not_required ["vendor_security_report:renewal"]
         :states
          {:vendor_w9 "completed"
           :vendor_coi "completed"
           "vendor_coi:renewal" "available"
           :vendor_security_report "completed"}
         :missing_facts []
         :wake_at "2027-06-30"}}
     {:name "advance-past-coi-expiry"
       :as_of "2027-07-01"
       :expect
        {:required ["vendor_w9" "vendor_coi" "vendor_security_report"]
         :not_required ["vendor_coi:renewal" "vendor_security_report:renewal"]
         :states
          {:vendor_w9 "completed"
           :vendor_coi "expired"
           :vendor_security_report "completed"}
         :missing_facts []
         :wake_at "2027-08-16"}}
     {:name "advance-past-security-report-expiry"
       :as_of "2027-09-16"
       :expect
        {:required ["vendor_w9" "vendor_coi" "vendor_security_report"]
         :not_required ["vendor_coi:renewal" "vendor_security_report:renewal"]
         :states
          {:vendor_w9 "completed"
           :vendor_coi "expired"
           :vendor_security_report "expired"}
         :missing_facts []}}])