@signature-kit/documenso
v0.5.0
Published
Alchemy v2 remote-signature provider for Documenso envelope creation, lookup, listing, cancellation, deletion, and completed-document download.
Readme
@signature-kit/documenso
Alchemy v2 remote-signature provider for Documenso envelope creation, lookup, listing, cancellation, deletion, and completed-document download.
Install
bun add @signature-kit/documenso @signature-kit/http effect alchemyeffect and alchemy are direct runtime dependencies. Provide
signatureHttpClientLive at the stack boundary; providers(options) supplies
only Documenso credentials and resource providers. Provider options are stored as
a cached credential Effect, so retained list hooks and read calls without
cached output do not decode credentials.
Public surface
@signature-kit/documenso— Documenso envelope/document/recipient schemas,DocumensoSignatureRequest,providers,getDocumensoSignatureRequest,listDocumensoSignatureRequests,cancelDocumensoSignatureRequest,deleteDocumensoSignatureRequest, anddownloadDocumensoSignedDocument.
Capability matrix:
| Capability | Supported | | -------------------------------- | ------------------------------------------------------------------------- | | Create retained Alchemy envelope | Yes | | Get envelope | Yes | | List envelopes | Yes | | Cancel envelope | Yes | | Delete envelope | Yes | | Download signed document | Yes, after the envelope is completed and an envelope item id is available |
Retained-resource semantics: Alchemy reconcile creates once and returns cached output on subsequent plans; provider list returns []; nuke is skipped. Multi-step create rollback deletes remote state only after unambiguous pre-effect 4xx failures, excluding 408, 409, 429, 5xx, timeouts, and response-shape failures.
Example
import * as Alchemy from "alchemy";
import {
DocumensoSignatureRequest,
downloadDocumensoSignedDocument,
providers as documensoProviders,
type DocumensoProviderOptions,
} from "@signature-kit/documenso";
import { signatureHttpClientLive } from "@signature-kit/http";
import { Effect, Layer, Redacted } from "effect";
declare const pdfBase64: string;
declare const apiKey: string;
const options: DocumensoProviderOptions = {
apiKey: Redacted.make(apiKey),
};
export default class Contracts extends Alchemy.Stack<Contracts>()(
"Contracts",
{
providers: Layer.merge(documensoProviders(options), signatureHttpClientLive),
state: Alchemy.inMemoryState(),
},
Effect.gen(function* () {
return yield* DocumensoSignatureRequest("service-agreement", {
title: "Service agreement",
documents: [
{ fileName: "contract.pdf", mimeType: "application/pdf", contentBase64: pdfBase64 },
],
recipients: [{ name: "Ada Lovelace", email: "[email protected]", role: "signer" }],
send: true,
});
}),
) {}
export const downloadSigned = (envelopeId: string) =>
downloadDocumensoSignedDocument(options, envelopeId).pipe(
Effect.provide(signatureHttpClientLive),
);Wait for a final state
waitForDocumensoSignatureRequest(options, id, pollInterval) reads immediately and polls while the request is draft or sent. It returns the provider's final state, including cancellation, rejection, deletion, or expiry; inspect state before downloading. The interval must be positive and finite. Read failures propagate immediately without automatic retry. Interruption cancels the active read and stops future polls. The caller owns the deadline:
import { waitForDocumensoSignatureRequest } from "@signature-kit/documenso";
import { signatureHttpClientLive } from "@signature-kit/http";
import { Duration, Effect } from "effect";
import type { DocumensoProviderOptions } from "@signature-kit/documenso";
declare const options: DocumensoProviderOptions;
declare const requestId: string;
const program = waitForDocumensoSignatureRequest(options, requestId, Duration.seconds(2)).pipe(
Effect.timeout(Duration.minutes(5)),
Effect.provide(signatureHttpClientLive),
);Errors and i18n
Invalid inputs, remote HTTP failures, unsupported operations, and invalid response shapes fail as SignatureKitError from @signature-kit/signatures. Applications can render localized copy through errorMessage from @signature-kit/i18n with the signatureKitErrorMessages catalog from @signature-kit/signatures.
Docs: https://signaturekit.dev/en-US/docs/providers/documenso.
License
MIT. See LICENSE.
