Snippet with terminal
Language tabs, a copy button, numbered lines with one picked out, and the terminal output underneath. For an SDK quickstart.
import { Halden } from "@halden/sdk";
// Reads HALDEN_KEY from your environment
const halden = new Halden();
const job = await halden.jobs.get("JS-2207");
const invoice = await job.invoice();
await invoice.send({ to: job.client });
from halden import Halden
# Reads HALDEN_KEY from your environment
halden = Halden()
job = halden.jobs.get("JS-2207")
invoice = job.invoice()
invoice.send(to=job.client)
# The same call, straight to the API
curl api.halden.example/v2/invoices \
-H "Authorization: Bearer $HALDEN_KEY" \
-d job=JS-2207 \
-d send=true
$ npx tsx send-invoice.ts ✓ Drafted INV-0418 from 22.5 h and 3 receipts ✓ Sent to Reyes Framing · $2,140.00 $
The code
Plain HTML and CSS on your kit's variables. Put it next to tokens/variables.css from your kit's files and it draws in your look.
<div class="ukc-code-sdk-snippet">
<div class="cd">
<input class="r r-ts" type="radio" name="ukc-code-sdk-snippet-lang" id="ukc-code-sdk-snippet-ts" checked>
<input class="r r-py" type="radio" name="ukc-code-sdk-snippet-lang" id="ukc-code-sdk-snippet-py">
<input class="r r-sh" type="radio" name="ukc-code-sdk-snippet-lang" id="ukc-code-sdk-snippet-sh">
<div class="bar">
<div class="tabs"><label class="t-ts" for="ukc-code-sdk-snippet-ts">TypeScript</label><label class="t-py" for="ukc-code-sdk-snippet-py">Python</label><label class="t-sh" for="ukc-code-sdk-snippet-sh">cURL</label></div>
<button class="copy" type="button" aria-label="Copy code"><svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><rect x="8" y="8" width="12" height="12" rx="1"/><path d="M16 8V4H4v12h4"/></svg><span class="tx" aria-hidden="true">Copy</span></button>
</div>
<pre class="src p-ts"><code><span class="l"><span class="k">import</span> { Halden } <span class="k">from</span> <span class="s">"@halden/sdk"</span>;</span>
<span class="l"> </span>
<span class="l"><span class="c">// Reads HALDEN_KEY from your environment</span></span>
<span class="l"><span class="k">const</span> halden = <span class="k">new</span> <span class="f">Halden</span>();</span>
<span class="l"><span class="k">const</span> job = <span class="k">await</span> halden.jobs.<span class="f">get</span>(<span class="s">"JS-2207"</span>);</span>
<span class="l hl"><span class="k">const</span> invoice = <span class="k">await</span> job.<span class="f">invoice</span>();</span>
<span class="l"><span class="k">await</span> invoice.<span class="f">send</span>({ to: job.client });</span></code></pre>
<pre class="src p-py"><code><span class="l"><span class="k">from</span> halden <span class="k">import</span> Halden</span>
<span class="l"> </span>
<span class="l"><span class="c"># Reads HALDEN_KEY from your environment</span></span>
<span class="l">halden = <span class="f">Halden</span>()</span>
<span class="l">job = halden.jobs.<span class="f">get</span>(<span class="s">"JS-2207"</span>)</span>
<span class="l hl">invoice = job.<span class="f">invoice</span>()</span>
<span class="l">invoice.<span class="f">send</span>(to=job.client)</span></code></pre>
<pre class="src p-sh"><code><span class="l"><span class="c"># The same call, straight to the API</span></span>
<span class="l"><span class="k">curl</span> api.halden.example/v2/invoices \</span>
<span class="l"> -H <span class="s">"Authorization: Bearer $HALDEN_KEY"</span> \</span>
<span class="l hl"> -d job=JS-2207 \</span>
<span class="l"> -d send=true</span></code></pre>
<pre class="term"><samp><span class="l"><span class="pr">$</span> <kbd>npx tsx send-invoice.ts</kbd></span>
<span class="l"><span class="ok">✓</span> Drafted INV-0418 from 22.5 h and 3 receipts</span>
<span class="l"><span class="ok">✓</span> Sent to Reyes Framing · <b>$2,140.00</b></span>
<span class="l"><span class="pr">$</span> <span class="cur"></span></span></samp></pre>
</div>
</div>
.ukc-code-sdk-snippet { position: relative; font-family: var(--uk-font-body, system-ui, sans-serif); color: var(--uk-ink); font-size: 15px; line-height: 1.5;
--tint: color-mix(in srgb, var(--uk-accent) 12%, var(--uk-paper));
--tint-strong: color-mix(in srgb, var(--uk-accent) 22%, var(--uk-paper));
--accent-deep: color-mix(in srgb, var(--uk-accent) 72%, black);
--ink-soft: color-mix(in srgb, var(--uk-ink) 8%, var(--uk-paper));
--line-strong: color-mix(in srgb, var(--uk-ink) 32%, var(--uk-paper));
--danger-tint: color-mix(in srgb, var(--uk-danger) 12%, var(--uk-paper));
--high-tint: color-mix(in srgb, var(--uk-highlight) 28%, var(--uk-paper)); }
.ukc-code-sdk-snippet *, .ukc-code-sdk-snippet *::before, .ukc-code-sdk-snippet *::after { box-sizing: border-box; }
.ukc-code-sdk-snippet :where(h1, h2, h3, h4, p, ul, ol, dl, dd, figure, blockquote) { margin: 0; }
.ukc-code-sdk-snippet :where(ul, ol) { padding: 0; list-style: none; }
.ukc-code-sdk-snippet :where(button, input, select, textarea) { font: inherit; color: inherit; }
.ukc-code-sdk-snippet :where(a) { color: inherit; }
.ukc-code-sdk-snippet svg { flex: none; }
.ukc-code-sdk-snippet .r { position: absolute; opacity: 0; pointer-events: none; }
.ukc-code-sdk-snippet { container-type: inline-size; inline-size: 100%; }
.ukc-code-sdk-snippet .cd { position: relative; max-width: 560px; border: var(--uk-border-width) solid var(--uk-line); border-radius: var(--uk-radius-lg); overflow: hidden; background: var(--uk-surface); box-shadow: var(--uk-card-shadow); }
.ukc-code-sdk-snippet .bar { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 6px 8px 6px 6px; border-bottom: 1px solid var(--uk-line); }
.ukc-code-sdk-snippet .tabs { display: flex; gap: 2px; min-width: 0; overflow-x: auto; }
.ukc-code-sdk-snippet .tabs label { padding: 5px 10px; border-radius: var(--uk-radius-sm); color: var(--uk-muted); font: 500 12.5px/1.4 var(--uk-font-mono, ui-monospace, monospace); white-space: nowrap; cursor: pointer; transition: background-color var(--uk-motion-duration) var(--uk-motion-ease), color var(--uk-motion-duration) var(--uk-motion-ease); }
.ukc-code-sdk-snippet .tabs label:hover { color: var(--uk-ink); }
.ukc-code-sdk-snippet .r-ts:checked ~ .bar .t-ts, .ukc-code-sdk-snippet .r-py:checked ~ .bar .t-py, .ukc-code-sdk-snippet .r-sh:checked ~ .bar .t-sh { background: var(--ink-soft); color: var(--uk-ink); }
.ukc-code-sdk-snippet .r-ts:focus-visible ~ .bar .t-ts, .ukc-code-sdk-snippet .r-py:focus-visible ~ .bar .t-py, .ukc-code-sdk-snippet .r-sh:focus-visible ~ .bar .t-sh { outline: 2px solid var(--uk-accent); outline-offset: 1px; }
.ukc-code-sdk-snippet .copy { display: inline-flex; align-items: center; gap: 6px; flex: none; padding: 5px 10px; border: 1px solid var(--uk-line); border-radius: var(--uk-radius-sm); background: var(--uk-paper); color: var(--uk-ink); font-size: 12px; font-weight: 500; line-height: 1.4; cursor: pointer; transition: border-color var(--uk-motion-duration) var(--uk-motion-ease), background-color var(--uk-motion-duration) var(--uk-motion-ease); }
.ukc-code-sdk-snippet .copy:hover { border-color: var(--line-strong); }
.ukc-code-sdk-snippet .copy:focus-visible { outline: 2px solid var(--uk-accent); outline-offset: 2px; }
.ukc-code-sdk-snippet .src { margin: 0; overflow-x: auto; font: 12.5px/1.7 var(--uk-font-mono, ui-monospace, monospace); tab-size: 2; }
.ukc-code-sdk-snippet .src code { display: grid; width: max-content; min-width: 100%; font: inherit; }
.ukc-code-sdk-snippet .src .l { min-height: 1.7em; padding: 0 16px; white-space: pre; }
.ukc-code-sdk-snippet .src code { counter-reset: ln; }
.ukc-code-sdk-snippet .src .l { padding-left: 0; }
.ukc-code-sdk-snippet .src .l::before { counter-increment: ln; content: counter(ln); display: inline-block; width: 5ch; padding-right: 2ch; text-align: right; color: color-mix(in srgb, var(--uk-ink) 40%, var(--uk-surface)); user-select: none; }
.ukc-code-sdk-snippet .src { display: none; padding: 12px 0; }
.ukc-code-sdk-snippet .r-ts:checked ~ .p-ts, .ukc-code-sdk-snippet .r-py:checked ~ .p-py, .ukc-code-sdk-snippet .r-sh:checked ~ .p-sh { display: block; }
.ukc-code-sdk-snippet .src .hl { background: var(--high-tint); }
.ukc-code-sdk-snippet .src .hl::before { color: var(--uk-ink); }
.ukc-code-sdk-snippet .src .k { color: color-mix(in srgb, var(--uk-accent) 60%, var(--uk-ink)); }
.ukc-code-sdk-snippet .src .s { color: color-mix(in srgb, var(--accent-deep) 60%, var(--uk-ink)); background: var(--tint); }
.ukc-code-sdk-snippet .src .n { color: color-mix(in srgb, var(--accent-deep) 60%, var(--uk-ink)); }
.ukc-code-sdk-snippet .src .c { color: var(--uk-muted); font-style: italic; }
.ukc-code-sdk-snippet .src .f { font-weight: 600; }
.ukc-code-sdk-snippet .term { margin: 0; padding: 12px 16px; overflow-x: auto; background: color-mix(in srgb, var(--uk-ink) 12%, black); color: color-mix(in srgb, var(--uk-paper) 15%, white); font: 12.5px/1.7 var(--uk-font-mono, ui-monospace, monospace); }
.ukc-code-sdk-snippet .term samp { display: grid; font: inherit; }
.ukc-code-sdk-snippet .term .l { white-space: pre-wrap; }
.ukc-code-sdk-snippet .term kbd { font: inherit; }
.ukc-code-sdk-snippet .term b { color: white; font-weight: 600; }
.ukc-code-sdk-snippet .term .pr { color: color-mix(in srgb, white 50%, transparent); user-select: none; }
.ukc-code-sdk-snippet .term .ok { color: color-mix(in srgb, white 70%, transparent); }
.ukc-code-sdk-snippet .term .cur { display: inline-block; width: 0.6em; height: 1.15em; vertical-align: -0.2em; background: currentColor; animation: ukc-code-sdk-snippet-blink 1.1s steps(1) infinite; }
@keyframes ukc-code-sdk-snippet-blink { 50% { opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .ukc-code-sdk-snippet .term .cur { animation: none; } }
@container (max-width: 340px) { .ukc-code-sdk-snippet .copy { padding: 6px; } .ukc-code-sdk-snippet .copy .tx { display: none; } }
More code blocks
All 24- Install with
npm install @halden/sdkpnpm add @halden/sdkyarn add @halden/sdk - halden sync~/crews/reyes
$ halden sync --since monday Syncing 38 job sheets for Reyes Framing 31/38 ✓JS-2207Alder St refit22.5 h ✓JS-2211Garage roof, Pier Ln14.0 h !JS-2214Bathroom, Mill Lnno sign-off ✗JS-2216Back deck rebuildupload failed Uploading receipts, 4 of 9
src/totals.ts +4−1 @@ -12,3 +12,5 @@ function lineTotal export function lineTotal(l: Line) {− return l.qty * l.rate * (1 + TAX);+ const net = round(l.qty * l.rate); + const tax = round(net * l.taxRate); + return { net, tax, total: net + tax }; }@@ -24,2 +26,3 @@ export const round = (n: number) => + // To the cent, half away from zero Math.round(n * 100) / 100;- .halden.yml+4−3
Changes to .halden.yml. Version 3.1 on the left, version 3.2 on the right. v3.1 v3.2 1 invoices: 1 invoices: 2 prefix: INV 2 prefix: INV 3 − due_days: 14 3 + due_days: 30 4 rounding: line 4 rounding: line 5 − tax: 0.0825 5 + tax: 6 + rate: 0.0825 7 + labor: false 6 − legacy_pdf: true 7 reminders: on 8 reminders: on export default { crew: "reyes-framing", currency: "USD", rounding: "line", reminders: [7, 14, 30], // Sync offline sheets sync: { every: "15m" }, };TypeScriptLn 5, Col 25
- POST
/v2/invoicesCreate an invoice from a signed-off job sheet.Request
Authorization: Bearer $HALDEN_KEY Content-Type: application/json { "job": "JS-2207", "due_days": 30, "send": true }Response
{ "id": "inv_0418", "number": "INV-0418", "status": "sent", "total": 2140.00, "currency": "USD", "pdf": "/v2/invoices/inv_0418.pdf" }{ "error": "job_not_signed_off", "message": "JS-2207 has no sign-off yet", "field": "job" }201 Created · 184 ms422 Unprocessable · 61 ms