Scan your whole stack
From OX Research Newsroom
Are you using @osdlc/ref-lease?
Find out what’s in your code.
Scan your apps free in minutes (opens in a new tab)Latest version: v0.3.8
@osdlc/ref-lease was last scanned on 24 Nov 2026 at version 0.3.8. Risk score 0 of 100. No malicious behavior was detected.
| Version | Published | Status |
|---|---|---|
| 0.3.8 LATEST | 24 Nov 2026 | No rules fired |
| 0.3.7 | 22 Nov 2026 | No rules fired |
| 0.3.4 | 21 Nov 2026 | No rules fired |
| 0.3.2 | 18 Nov 2026 | Not shown |
| 0.3.1 | 17 Nov 2026 | Not shown |
Findings for v0.3.8. The score is a capped sum of the weights of the rules that fired — not CVSS, not exploitability, and not a probability. It is not comparable across packages with different scan coverage.
The score describes 0.3.8; other versions have their own rules, not their own score.
The publisher’s own README, as collected from the registry.
A lock that lives in a git remote. Several workers (CI jobs, agents, cron hosts) that all push to one repository can use it to make sure only one of them does a job at a time, with no lock server and no database.
worker A: read refs/locks/deploy (commit C1) ── push C2 "only if still C1" ── ✔ A holds the lease
worker B: read refs/locks/deploy (commit C1) ── push C3 "only if still C1" ── ✘ CasFailed: A got there first
A lease is a git ref whose commit holds a JSON payload you choose, such as who holds it and
until when. Every change is a compare-and-swap: git push --force-with-lease=<ref>:<sha-you-read>.
The remote, the authority, accepts exactly one of two racing writers. The library builds the
commits, runs the pushes and fetches, and tells a lost race (CasFailed) apart from a broken push
(GitFailed).
Do not use it when:
refs/heads and refs/tags. Check your host's ref
rules first.npm install @osdlc/ref-lease
ESM only. Node.js 22.22.2 or later on the 22 line, 24.15.0 or later on the 24 line, or 26 and later.
Bun also works. It runs the git CLI, which must be on PATH.
From examples/lease-lifecycle.test.ts:
import {
buildLeaseCommit,
casCreate,
casDelete,
casReplace,
CasFailed,
fetchNamespace,
fetchRef,
RefNotFound,
} from '@osdlc/ref-lease'
interface CacheLease {
holder: string
expiresAt: string
}
const decode = (v: unknown): CacheLease => {
const o = v as Partial<CacheLease>
if (typeof o.holder !== 'string' || typeof o.expiresAt !== 'string') {
throw new TypeError('not a cache lease')
}
return { holder: o.holder, expiresAt: o.expiresAt }
}
/** Claim `ref` for `holder`, or return the current holder when someone else has it. */
function claim(authority: string, ref: string, holder: string, cwd: string): string {
const sha = buildLeaseCommit({ holder, expiresAt: '2026-11-07T12:00:00Z' }, { cwd })
try {
casCreate(authority, ref, sha, { cwd })
return holder
} catch (e) {
if (!(e instanceof CasFailed)) throw e
return fetchRef(authority, ref, { cwd, decode }).payload.holder
}
}
The same file renews a lease with casReplace, lists leases with fetchNamespace and releases one
with casDelete.
| Guide | Read it when |
|---|---|
| How it works, in pictures | You want the idea explained with diagrams, no git knowledge needed. |
| Getting started | You want to take a first lease, step by step. |
| Recipes | You need claim with expiry, renew, release, list, an update that retries, or a keyed store of records. |
| Errors and retries | A call threw and you want to know whether to try again. |
| Testing | You are testing code that takes leases. |
| Git mechanics | You want to know what git does underneath. |
Every code block in the README and the guides is a region of a file under examples/, which the
test suite runs; tests/docs-snippets.test.ts fails when they differ.
| Term | Meaning |
|---|---|
| Authority | A git remote name or URL. Its refs are the truth. |
| Lease ref | A ref under a namespace you choose, such as refs/locks/build-cache. |
| Lease commit | The commit a lease ref points at. Its tree holds the payload as canonical JSON (lease.json by default) and any extra files you add. |
| Local repository | The repository the calls run in (cwd). It holds the commits a push sends and the mirror refs a fetch writes. |
| Mirror | The local copy of a lease ref, at the same name. Each write updates it, so a local reader sees the write without a fetch. If another process had moved it, the write leaves it alone, and the next fetch of that ref corrects it. |
| Operation | git | Fails with |
|---|---|---|
casCreate(authority, ref, newSha) |
push --force-with-lease=<ref>: |
CasFailed when the ref exists |
casReplace(authority, ref, expectedSha, newSha) |
push --force-with-lease=<ref>:<expected> |
CasFailed when the ref moved |
casDelete(authority, ref, expectedSha) |
push --delete --force-with-lease=<ref>:<expected> <ref> |
CasFailed when the ref moved or is gone |
fetchRef(authority, ref) |
fetch +<ref>:<ref>, then read the payload |
RefNotFound, PayloadUnreadable |
fetchNamespace(authority, prefix) |
fetch --prune +<prefix>/*:<prefix>/* |
GitFailed |
Any other git failure, such as an unreachable authority or a declined hook, is a GitFailed.
CasFailed, read the ref again and decide whether to retry.buildLeaseCommit writes the commit with git plumbing. It touches no index, work tree or branch.
Pass parentSha to chain each write to the one before, so git log <ref> is the lease's history.canonicalJson), so they give equal blobs on every host.checkNamespaceConflict(authority, 'refs/locks') once before the first write. A literal ref
at the namespace path itself blocks every ref under it, and git's own error for that is hard to
read.Every item has TSDoc in the source. The entry point is @osdlc/ref-lease.
| Item | What it is |
|---|---|
casCreate, casReplace, casDelete |
The three compare-and-swap writes. Options: cwd, env and onMirrorSkip. |
fetchRef<T> |
Read one lease. Options: payloadFile, and decode to turn the JSON into your type. |
fetchNamespace |
Every lease ref under a prefix, mapped to its sha. |
buildLeaseCommit |
Write a lease commit. Options: parentSha, extraParentShas, payloadFile, files, identity, commitDate, message. |
DEFAULT_PAYLOAD_FILE, DEFAULT_IDENTITY, DETERMINISTIC_EPOCH |
The defaults, and a fixed date for tests that need stable shas. |
checkNamespaceConflict |
Fail early when a literal ref blocks the namespace. |
canonicalJson |
The payload encoding. |
RefLeaseError and CasFailed, RefNotFound, NamespaceConflict, GitFailed, PayloadUnreadable |
The errors. Each has a kind string. |
Every option object takes cwd, the local repository (default process.cwd()), and env, merged
over the process environment for each git call, for settings such as GIT_SSH_COMMAND.
Refs and namespaces must be paths under refs/ outside refs/heads, refs/tags and
refs/remotes, and shas full object ids; anything else throws a TypeError before git runs. A
fetch force-updates your local copy of the refs it reads, and fetchNamespace deletes local refs
under the prefix that the authority no longer has, so a lease namespace must be one of its own.
| Class | kind |
When |
|---|---|---|
CasFailed |
cas-failed |
A write lost: the ref was not at the expected sha, or a create found it existing. |
RefNotFound |
ref-not-found |
The authority has no such ref. |
PayloadUnreadable |
payload-unreadable |
The lease commit has no payload file, or it is not JSON. |
NamespaceConflict |
namespace-conflict |
A literal ref sits at the namespace path. |
GitFailed |
git-failed |
Any other git failure. It carries op, exitCode and stderr. |
RefLeaseError |
other |
The base class. Your own lease errors may extend it. |
Which ones to retry, with an example handler:
Errors and retries. A decode function's own error is not
wrapped: it propagates as thrown. buildLeaseCommit throws a TypeError for a payload JSON cannot
hold or a bad file name, and a GitFailed when the local repository cannot write objects. A
GitFailed keeps the underlying git failure as its cause.
git runs in the C locale for every push and fetch, so its messages are read the same way whatever language the user's git speaks.
0.x: a minor release may break the API. No item is experimental; every export is stable within a
minor line. Experimental items, when there are any, are listed here as - \name`lines, andtests/tiers.test.tschecks this list against the@experimental` tags in the source.
Linux and macOS, where the tests run. Windows runs them in the tier-2 workflow, which reports and
never blocks. The library itself has no platform branches. It needs git 2.29 or later, for fetch --no-write-fetch-head.
packages/conformance/ref-lease/suite.json holds the protocol's cases as data: what each push
result (git's status for the ref and its rejection kind, as @osdlc/typed-git reads it) and each
failed fetch means, and the canonical JSON of each value. This package is the reference. The
ref-lease Rust crate runs the same cases; it holds the protocol half only
(no push or fetch yet).
| Library | Why not |
|---|---|
A lock file, proper-lockfile |
One machine only. |
| Git LFS file locking | A server API on the LFS host, for files, not a general lease. |
| Redis, etcd, a database row | Another service to run and secure. |
| Leases in the issue tracker of a git host | Tied to one host's API, and rate limited. |
@osdlc/typed-git's push with forceWithLease |
One guarded push. This library is built on it and adds the protocol: create, replace and delete semantics, the payload commit, the fetches and the error kinds. |
This library needs nothing but a git remote every participant can push to.
docs/planning/ records why the package has the shape it has, one decision per topic.
MIT OR Apache-2.0: dual-licensed under MIT or Apache-2.0, at
your option.
Find threats in your stack.
OX Radar can check high-priority threats, like critical package CVEs, against your context.
Each incident is marked Detected or Not Detected with a remediation plan and proof all tracked in the Response Center.
The probe returned only these fields for this server — auth requirement, protocol and tool list weren’t observed, so they’re not shown (never guessed).
The publisher’s own links, as the registry reports them. These are not sources for the assessment on this page.