npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@nodii/document-cloud-client

v0.10.0

Published

Typed S2S gRPC client for Document Cloud uploads, downloads, metadata and context links.

Readme

@nodii/document-cloud-client

The standard Nodii S2S client for Document Cloud. It hashes content, requests and confirms presigned uploads, sends bytes directly to S3, and links business contexts without carrying document bytes over gRPC.

A caller says what a document is and whose it is, never where it goes. There is no bucket, key, path or folder parameter: Document Cloud derives the storage key and the location (DOC-OV-1.2, DOC-OV-1.4). Publish your service's closed list of kinds once with publishDocumentKinds; an unregistered kind is refused.

const docs = createDocumentCloudClient({
  address: process.env.DOCUMENT_CLOUD_GRPC!, tenantId, serviceName: "hr-service",
  getS2SToken: ({ audience, scopes }) => tokens.get({ audience, scopes }),
});
const payslip = await docs.uploadDocument({
  documentKind: "hr.payslip", owner: { contextKind: "hr.employee", ref: employeeId },
  retentionBucket: "statutory", dataClass: "hr_payslip", // what you answer for each file (DOC-OV-1.8)
  title: "October payslip", body: pdfBuffer,
  contentType: "application/pdf", idempotencyKey: `payslip:${employeeId}:2026-10`,
});
console.log(payslip.documentId);

The owner record is linked for you. For a browser upload, get the URL now and confirm once the browser has finished:

const url = await docs.requestUploadUrl({
  documentKind: "hr.id_proof", owner: { contextKind: "hr.employee", ref: employeeId },
  fileName, contentType, sizeBytes, checksumSha256, idempotencyKey,
});
// The browser PUTs to url.url with url.method and exactly url.headers.
await docs.confirmUpload({ uploadId: url.uploadId, title, idempotencyKey: confirmKey });

A one-off copy records where each old object went with recordLegacyKeys, and rewrites its references from resolveLegacyKeys.

Readable bodies are hashed during a first pass into a private temporary file, including when sizeBytes is supplied. The PUT then sends that file as a disk-backed Blob (Bun.file under Bun, fs.openAsBlob under Node), so it is replayable for retries without retaining the document in memory. Every PUT carries a real Content-Length and never uses chunked transfer encoding, which S3 rejects when content-length is a signed header. Pass an AbortSignal as signal; PUTs also have a 120-second size-scaled overall deadline and a 30-second socket-idle deadline by default. Configure these with uploadTimeoutMs, uploadMinBytesPerSecond, and uploadSocketIdleTimeoutMs. The runtime sends the body without progress events, so stalls are detected per phase. Sending the body and waiting for response headers is bounded by uploadSocketIdleTimeoutMs plus the time the body needs at uploadMinBytesPerSecond, so a link slower than that floor is cut off and retried. When that bound is shorter than the overall deadline, a peer that stops reading ends the attempt with a retryable UploadTimeoutError before the overall deadline. With the defaults this covers bodies up to about 22.5 MiB. For larger bodies the bound reaches the overall deadline, so a stall ends at the overall deadline with no retry; raise uploadTimeoutMs if that matters. The socket-idle deadline then applies while the response is read. Each attempt uses a fresh connection. If a spooled temp file disappears before a retry, the upload fails with UploadBodyUnavailableError (reason upload_body_unavailable), which is not retried.

The low-level putOnce / putWithRetry exports take a Blob. They still accept a Node Readable for compatibility, but buffer it entirely into memory before sending, so peak memory is at least the body size per attempt. Pass a Blob, or use uploadDocument / uploadNewVersion, which spool streams to disk instead.

body accepts Buffer, Uint8Array, or a Node Readable. PUT retries are limited to timeouts, network failures, and HTTP 5xx; aborts and HTTP 4xx responses are terminal.

The client defaults to TLS and requests only the scope required by each RPC through @nodii/grpc-auth (document read/write, kind publishing, the old key map, or context-link read/write). The caller-provided token function remains responsible for minting the service token. Local plaintext test peers must opt in with allowInsecure: true; call close() during graceful shutdown.

downloadStream callers must either consume the returned stream to completion or call destroy() when abandoning it; otherwise download resources remain until the deadline expires. Checksum mismatch is reported at EOF; use downloadBytes when bytes must be verified before use.