unslopkit

Components / Code blocks

File tree and editor

A dark editor with folders that open and close, the active and modified files marked, tabs, and a status line. Stacks when the column is narrow.

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

TypeScriptLn 5, Col 25

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-file-tree">
<div class="ide">
  <nav class="tree" aria-label="Project files">
    <p class="proj">halden-app</p>
    <ul>
      <li><details open><summary><svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M9 6l6 6-6 6"/></svg>src</summary><ul>
        <li><details open><summary><svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M9 6l6 6-6 6"/></svg>jobs</summary><ul>
          <li><a href="#">sheet.ts</a></li>
          <li><a href="#" class="mod">sync.ts<span class="sr"> (modified)</span></a></li>
        </ul></details></li>
        <li><a href="#">invoices.ts</a></li>
      </ul></details></li>
      <li><details><summary><svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M9 6l6 6-6 6"/></svg>tests</summary><ul><li><a href="#">totals.test.ts</a></li></ul></details></li>
      <li><a href="#" class="on" aria-current="page">halden.config.ts</a></li>
      <li><a href="#">package.json</a></li>
    </ul>
  </nav>
  <div class="ed">
    <div class="tabs"><a class="tab on" href="#" aria-current="page">halden.config.ts</a><a class="tab" href="#">sync.ts<span class="dot"></span><span class="sr"> (unsaved)</span></a></div>
    <pre class="src"><code><span class="l"><span class="k">export default</span> {</span>
<span class="l">  crew: <span class="s">"reyes-framing"</span>,</span>
<span class="l">  currency: <span class="s">"USD"</span>,</span>
<span class="l">  rounding: <span class="s">"line"</span>,</span>
<span class="l cur">  reminders: [<span class="n">7</span>, <span class="n">14</span>, <span class="n">30</span>]<span class="caret" aria-hidden="true"></span>,</span>
<span class="l">  <span class="c">// Sync offline sheets</span></span>
<span class="l">  sync: { every: <span class="s">"15m"</span> },</span>
<span class="l">};</span></code></pre>
    <p class="status"><span>TypeScript</span><span>Ln 5, Col 25</span></p>
  </div>
</div>
</div>

More code blocks

All 24
  • 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

  • UnhandledPOST /v2/invoicesstaging

    TypeError: Cannot read properties of undefined (reading 'rate')

    1. lineTotalsrc/totals.ts:15:23
      export function lineTotal(l: Line) {
        const price = PRICES[l.sku];
        return l.qty * price.rate;
                       ^^^^^ price is undefined
      }
    2. buildInvoicesrc/invoices.ts:42:18
        for (const line of sheet.lines) {
          totals.push(lineTotal(line));
        }
    3. POSTapp/api/invoices/route.ts:18:9
        const sheet = await getSheet(body.job);
        const draft = buildInvoice(sheet);
    4. 3 frames in node_modules
      • handle @halden/sdk/dist/http.js:88:11
      • dispatch router-lite/index.js:41:7
      • run router-lite/index.js:12:3
    Seen 3 times in the last hour

    Error with stack trace

  • .env.local4 of 5 set
    1. # Halden, test mode
    2. HALDEN_API_KEY=hidden, ends in 4f9chld_test_8Kq2Vn5x4f9c
    3. HALDEN_ENV=test
    4. DB_PASSWORD=hiddenlocal-dev-only
    5. # Webhooks
    6. HALDEN_WEBHOOK_SECRET=

      Empty Webhook checks fail until this is set. Copy it from Settings, then Webhooks.

    Env file with reveal