Service Agreement
A minimal client contract, showing the contract payload’s list of parties and a structured-array param. Start from the Simple Contract starter template for a production-grade one.
/*javasculpt-params# A #639 STRUCTURED ARRAY param: each row is an object of scalar fields. Contrast# with the invoice example's plain `color` param — a structured value arrives as# JSON text and has to be decoded, where a scalar arrives as a plain string.- name: deliverables type: array caption: Deliverables description: Key deliverables or milestones, each with a target date. item: name: milestone type: object fields: - name: title type: text caption: Deliverable - name: due_date type: date caption: Target date*/// ── Example: document-generation contract ──────────────────────────────────// A deliberately SMALL service agreement. Teaching material, not a template to// ship — for a production-grade contract start from the "Simple Contract"// starter template, which is copied into your own project and edited there.//// Read the invoice example first: it covers the data guard and how params reach// a doc-gen script. This one adds the two things a CONTRACT does differently:// 1. a different payload shape — client.names is a LIST of parties, and there// is no single client.name to read// 2. a structured-array param, which arrives as JSON rather than a string//// The payload:// business: { name, address, email, website, abn, colours, payment }// document: { id, issued, title?, currency, tax_inclusive }// client: { names: [string] } // one per named party; usually length 1// items: [{ index, description, note, quantity, unit_price, discount, tax, total }]// notes: { customer_facing: string | none }// custom: { <your frontmatter params> }
#let placeholder = ( business: (name: "Your Business", colours: (:)), document: (id: "SAMPLE-0001", issued: "", currency: "usd"), client: (names: ("Sample Client",)), items: (), custom: (:),)#let data = if "data" in sys.inputs { json(bytes(sys.inputs.data)) } else { placeholder }
// A STRUCTURED param needs decoding. On a plain editor Run it arrives as JSON// text on sys.inputs; on the generation path it is already a decoded value under// data.custom. Handling only one route leaves the control dead in the other.#let structured-param(name, default: ()) = if name in sys.inputs { json(bytes(sys.inputs.at(name)))} else { data.custom.at(name, default: default)}
#let accent = rgb("#4a5568")#let money(x) = str(calc.round(x, digits: 2)) + " " + upper(data.document.currency)
#set page(paper: "a4", margin: (x: 22mm, y: 20mm))#set text(size: 10.5pt, fill: luma(25))
#align(center)[ #text(size: 17pt, weight: "bold", fill: accent)[Service Agreement] #linebreak() #text(size: 9pt, fill: luma(100))[#data.document.id · #data.document.issued]]
#v(1.2em)
// The parties. `client.names` is a list — join it rather than reaching for a// single name, which a contract payload does not carry.#text(size: 8.5pt, fill: luma(100), weight: "medium")[BETWEEN]#linebreak()#text(weight: "bold")[#data.business.name]#linebreak()#text(size: 8.5pt, fill: luma(100), weight: "medium")[AND]#linebreak()#text(weight: "bold")[#data.client.names.join(", ")]
#v(1.2em)
#text(size: 8.5pt, fill: luma(100), weight: "medium")[COVERED WORK]#v(0.4em)#table( columns: (1fr, auto), align: (left, right), stroke: (bottom: 0.5pt + luma(200)), inset: (x: 6pt, y: 6pt), ..data.items.map(item => (item.description, money(item.total))).flatten(),)
// An unset array param is absent, so default to an empty list and render nothing.#let deliverables = structured-param("deliverables")#if deliverables.len() > 0 [ #v(1.2em) #text(size: 8.5pt, fill: luma(100), weight: "medium")[DELIVERABLES] #v(0.4em) #for row in deliverables [ · #row.at("title", default: "") #h(0.5em) #text(fill: luma(120))[#row.at("due_date", default: "")] #linebreak() ]]