unslopkit

Components / Code blocks

Unified diff

One file's changes in a single column: old and new line numbers, plus and minus gutters, a changed word marked, and folded lines you can open.

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;
Drawn in your kit, Plain.Change the look

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-unified-diff">
<figure class="df" aria-label="Changes to src/totals.ts">
  <figcaption class="hd">
    <span class="fn"><svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M14 3H6v18h12V7z"/><path d="M14 3v4h4"/></svg><span><span class="dir">src/</span>totals.ts</span></span>
    <span class="stat"><span>+4</span><span class="minus">−1</span><span class="bars" aria-hidden="true"><span class="a"></span><span class="a"></span><span class="a"></span><span class="a"></span><span class="d"></span></span></span>
  </figcaption>
  <pre class="src"><code><span class="l hunk">@@ -12,3 +12,5 @@ function lineTotal</span>
<span class="l"><span class="g" data-n="12" aria-hidden="true"></span><span class="g" data-n="12" aria-hidden="true"></span><span class="sg"> </span><span class="k">export function</span> <span class="f">lineTotal</span>(l: Line) {</span>
<del class="l"><span class="g" data-n="13" aria-hidden="true"></span><span class="g" aria-hidden="true"></span><span class="sg">−</span>  <span class="k">return</span> l.qty * l.rate <span class="w">* (1 + TAX)</span>;</del>
<ins class="l"><span class="g" aria-hidden="true"></span><span class="g" data-n="13" aria-hidden="true"></span><span class="sg">+</span>  <span class="k">const</span> net = <span class="f">round</span>(l.qty * l.rate);</ins>
<ins class="l"><span class="g" aria-hidden="true"></span><span class="g" data-n="14" aria-hidden="true"></span><span class="sg">+</span>  <span class="k">const</span> tax = <span class="f">round</span>(net * l.taxRate);</ins>
<ins class="l"><span class="g" aria-hidden="true"></span><span class="g" data-n="15" aria-hidden="true"></span><span class="sg">+</span>  <span class="k">return</span> { net, tax, total: net + tax };</ins>
<span class="l"><span class="g" data-n="14" aria-hidden="true"></span><span class="g" data-n="16" aria-hidden="true"></span><span class="sg"> </span>}</span></code></pre>
  <button class="more" type="button"><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"><path d="M8 9l4-4 4 4M8 15l4 4 4-4"/></svg>Show 9 unchanged lines</button>
  <pre class="src"><code><span class="l hunk">@@ -24,2 +26,3 @@</span>
<span class="l"><span class="g" data-n="24" aria-hidden="true"></span><span class="g" data-n="26" aria-hidden="true"></span><span class="sg"> </span><span class="k">export const</span> <span class="f">round</span> = (n: number) =&gt;</span>
<ins class="l"><span class="g" aria-hidden="true"></span><span class="g" data-n="27" aria-hidden="true"></span><span class="sg">+</span>  <span class="c">// To the cent, half away from zero</span></ins>
<span class="l"><span class="g" data-n="25" aria-hidden="true"></span><span class="g" data-n="28" aria-hidden="true"></span><span class="sg"> </span>  Math.<span class="f">round</span>(n * 100) / 100;</span></code></pre>
</figure>
</div>

More code blocks

All 24
  • .halden.yml+4−3
    Changes to .halden.yml. Version 3.1 on the left, version 3.2 on the right.
    v3.1v3.2
    1invoices:1invoices:
    2 prefix: INV2 prefix: INV
    3− due_days: 143+ due_days: 30
    4 rounding: line4 rounding: line
    5− tax: 0.08255+ tax:
    6+ rate: 0.0825
    7+ labor: false
    6− legacy_pdf: true
    7 reminders: on8 reminders: on

    Side-by-side diff

  • export default {
      crew: "reyes-framing",
      currency: "USD",
      rounding: "line",
      reminders: [7, 14, 30],
      // Sync offline sheets
      sync: { every: "15m" },
    };

    TypeScriptLn 5, Col 25

    File tree and editor

  • 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

    Request and response

  • job-sheet.json1.2 kB
    { 7 keys }
    "id": "JS-2207",
    "site": "14 Alder St",
    "signed_off": true,
    "crew": [ 2 items ],
    "Ines Ortega",
    "Dana Whitfield"
    ],
    "hours": { 3 keys },
    "labor": 22.5,
    "travel": 1.5,
    "overtime": 0
    },
    "materials": [ 2 items ],
    { 3 keys },
    "sku": "OAK-WT-30",
    "qty": 1,
    "unit_cost": 41800
    },
    { 3 keys }
    "sku": "2x6-PT-12",
    "qty": 40,
    "unit_cost": 1145
    }
    ],
    "invoice": null
    }

    Path$.materials[1].qty

    Collapsible JSON

  • Step 3Handle the webhook

    export async function POST(req: Request) {
      const raw = await req.text();
      const event = verify(raw, req.headers); (note 1)
     
      if (event.type === "invoice.paid") { (note 2)
        await markPaid(event.invoice);
      }
      return new Response(null, { status: 204 }); (note 3)
    }
    1. Note 1: verify throws if the signature or timestamp is off, so a forged call never reaches your code.

    2. Note 2: Check the type first. New event types get added, so skip the ones you don't handle.

    3. Note 3: Answer within 10 seconds. Slow or failed deliveries are retried for three days.

    Annotated snippet

  • src/jobs/sheet.ts TS 21 lines · 418 B Raw
    export type JobSheet = {
      id: string;
      site: string;
      crew: string[];
      hours: Array<Hours>;
      materials: Array<Material>;
      signedOffBy?: string;
      status: "open" | "signed" | "invoiced";
    };
    Show 12 more linesShow fewer lines
     
    export type Hours = {
      who: string;
      day: string; // ISO date
      hours: number;
    };
     
    export type Material = {
      sku: string;
      qty: number;
      unitCost: number; // in cents
    };

    File with show more