Selected work

Field operations software · Pre-launch

Jemparo

A client flags one repair on a three-item job. What should the contractor reopen, and which version of the receipt should the office keep? I built Jemparo’s field tools around handoffs like this.

TypeScriptNext.jsPostgreSQLStripe webhooks

One event crosses three boundaries

The billing package verifies the raw Stripe message, checks the event against the checkout binding, then records an entitlement decision. Retries and delayed messages complicate every step. A cancellation takes precedence over a grant with the same provider timestamp.

I wrote a standalone version of this problem using Node’s crypto APIs and SQLite. It commits the delivery record, access projection and downstream notification in one transaction. A failed transaction permits a safe retry. Its local tests also cover conflicting identities, two database connections and recovery after reopening the database.

Source explorer.

Follow the public implementation from integration logic to failure tests.

JavaScriptjemparo.mjs

Commit a delivery

Fingerprint the normalized event and record its projection, delivery outcome and notification inside one database transaction.

Lines 75–105
GitHub ↗
  receive(body, signature, options = {}) {    const event = normalize(openEnvelope(body, signature, this.secret, this.clock()), this.account);    // Hash normalized business fields. JSON whitespace, key order and unrelated    // envelope properties can change without changing the delivery's identity.    const digest = createHash('sha256').update(JSON.stringify(event)).digest('hex');    this.db.exec('BEGIN IMMEDIATE');    try {      const previous = this.db.prepare('SELECT fingerprint,result FROM inbox WHERE account=? AND event_id=?')        .get(event.account, event.id);      let response;      if (previous) {        response = previous.fingerprint === digest          ? {result:previous.result, replay:true}          : {result:'identity-conflict', replay:false};      } else {        const result = this.project(event);        // A binding can arrive after the subscription event. An ACK here would        // make a later redelivery useless, so leave this particular key unclaimed.        if (result !== 'retry-unbound') {          this.db.prepare('INSERT INTO inbox VALUES(?,?,?,?)').run(event.account, event.id, digest, result);        }        options.beforeCommit?.(); // test seam for a crash after the writes        response = {result, replay:false};      }      this.db.exec('COMMIT');      return response;    } catch (error) {      this.db.exec('ROLLBACK');      throw error;    }  }
Explore Dealer OS