/** * DocuSign Integration for WORKWAY * * Unified client for DocuSign eSignature operations: Envelopes, Templates, Recipients. * Designed for document workflow automation - send contracts, track signatures, * and trigger follow-up actions on completion. * * Zuhandenheit: "Contracts that sign themselves" not "POST /envelopes endpoint" * * @example * ```typescript * import { DocuSign } from '@workwayco/integrations/docusign'; * * const docusign = new DocuSign({ * accessToken: tokens.docusign.access_token, * accountId: tokens.docusign.account_id, * basePath: tokens.docusign.base_uri, * }); * * // Send document for signature * const envelope = await docusign.sendEnvelope({ * emailSubject: 'Please sign: Service Agreement', * documents: [{ name: 'contract.pdf', content: pdfBase64 }], * recipients: [{ email: 'client@example.com', name: 'Client Name' }], * }); * * // Check envelope status * const status = await docusign.getEnvelope(envelope.data.envelopeId); * * // Use template for recurring documents * const fromTemplate = await docusign.sendFromTemplate({ * templateId: 'abc-123', * recipients: [{ email: 'client@example.com', name: 'Client Name', roleName: 'Signer' }], * }); * ``` */ import { ActionResult } from '@workwayco/sdk'; import { BaseAPIClient } from '../core/index.js'; /** * DocuSign integration configuration */ export interface DocuSignConfig { /** OAuth access token */ accessToken: string; /** DocuSign account ID */ accountId: string; /** Base path from /oauth/userinfo (e.g., https://na4.docusign.net) */ basePath: string; /** OAuth refresh token for automatic refresh */ refreshToken?: string; /** OAuth client ID (integration key) */ clientId?: string; /** OAuth client secret */ clientSecret?: string; /** Callback when token is refreshed */ onTokenRefreshed?: (accessToken: string, refreshToken?: string) => void | Promise; /** Request timeout in milliseconds (default: 30000) */ timeout?: number; } /** * DocuSign Envelope (document package) */ export interface DSEnvelope { envelopeId: string; status: DSEnvelopeStatus; emailSubject: string; emailBlurb?: string; createdDateTime: string; sentDateTime?: string; completedDateTime?: string; voidedDateTime?: string; voidedReason?: string; statusChangedDateTime: string; documentsUri?: string; recipientsUri?: string; envelopeUri?: string; purgeState?: string; } /** * DocuSign Envelope Status */ export type DSEnvelopeStatus = 'created' | 'sent' | 'delivered' | 'signed' | 'completed' | 'declined' | 'voided' | 'deleted'; /** * DocuSign Recipient */ export interface DSRecipient { recipientId: string; recipientIdGuid?: string; email: string; name: string; recipientType?: 'signer' | 'cc' | 'certifiedDelivery' | 'inPersonSigner' | 'editor' | 'agent'; routingOrder?: string; status?: 'created' | 'sent' | 'delivered' | 'signed' | 'completed' | 'declined' | 'autoresponded'; signedDateTime?: string; deliveredDateTime?: string; declinedDateTime?: string; declinedReason?: string; roleName?: string; clientUserId?: string; tabs?: DSTabs; } /** * DocuSign Tabs (signature fields) */ export interface DSTabs { signHereTabs?: DSTab[]; initialHereTabs?: DSTab[]; dateSignedTabs?: DSTab[]; textTabs?: DSTab[]; checkboxTabs?: DSTab[]; } /** * DocuSign Tab (field) */ export interface DSTab { tabId?: string; tabLabel?: string; documentId?: string; recipientId?: string; pageNumber?: string; xPosition?: string; yPosition?: string; anchorString?: string; anchorXOffset?: string; anchorYOffset?: string; value?: string; locked?: string; required?: string; } /** * DocuSign Document */ export interface DSDocument { documentId: string; name: string; fileExtension?: string; order?: string; pages?: string; uri?: string; } /** * DocuSign Template */ export interface DSTemplate { templateId: string; name: string; description?: string; shared?: string; created?: string; lastModified?: string; uri?: string; folderName?: string; folderId?: string; owner?: { userName: string; email: string; }; } /** * DocuSign Envelope Summary (for lists) */ export interface DSEnvelopeSummary { envelopeId: string; status: DSEnvelopeStatus; emailSubject: string; sentDateTime?: string; completedDateTime?: string; statusChangedDateTime: string; } /** * DocuSign User Info */ export interface DSUserInfo { sub: string; name: string; givenName: string; familyName: string; email: string; accounts: Array<{ accountId: string; accountName: string; baseUri: string; isDefault: boolean; }>; } export interface SendEnvelopeOptions { /** Email subject line */ emailSubject: string; /** Email body text */ emailBlurb?: string; /** Documents to include */ documents: Array<{ /** Document name with extension */ name: string; /** Base64-encoded document content */ content: string; /** File extension (inferred from name if not provided) */ fileExtension?: string; /** Document order (1-based) */ order?: number; }>; /** Recipients (signers) */ recipients: Array<{ email: string; name: string; /** Routing order (1 = first to sign) */ routingOrder?: number; /** Recipient type */ recipientType?: 'signer' | 'cc'; /** Embedded signing client user ID */ clientUserId?: string; /** Tabs/fields for this recipient */ tabs?: DSTabs; }>; /** Send immediately or save as draft */ status?: 'sent' | 'created'; } export interface SendFromTemplateOptions { /** Template ID */ templateId: string; /** Email subject (overrides template default) */ emailSubject?: string; /** Email body (overrides template default) */ emailBlurb?: string; /** Template role assignments */ recipients: Array<{ email: string; name: string; /** Role name from template */ roleName: string; /** Embedded signing client user ID */ clientUserId?: string; /** Tab values to pre-fill */ tabs?: DSTabs; }>; /** Send immediately or save as draft */ status?: 'sent' | 'created'; } export interface ListEnvelopesOptions { /** Filter by status */ status?: DSEnvelopeStatus | 'any'; /** From date (ISO string) */ fromDate?: string; /** To date (ISO string) */ toDate?: string; /** Search in subject/recipient email */ searchText?: string; /** Include recipients in response */ includeRecipients?: boolean; /** Maximum results (default: 100) */ count?: number; /** Start position for pagination */ startPosition?: number; } export interface GetSigningUrlOptions { /** Envelope ID */ envelopeId: string; /** Recipient email */ recipientEmail: string; /** Recipient name */ recipientName: string; /** Client user ID (must match what was set when creating envelope) */ clientUserId: string; /** Return URL after signing */ returnUrl: string; /** Authentication method */ authenticationMethod?: string; } export interface VoidEnvelopeOptions { /** Envelope ID */ envelopeId: string; /** Reason for voiding */ voidedReason: string; } /** * DocuSign eSignature Integration * * Weniger, aber besser: Unified e-signature client for document workflow automation. */ export declare class DocuSign extends BaseAPIClient { private readonly accountId; constructor(config: DocuSignConfig); /** * Get an envelope by ID */ getEnvelope(envelopeId: string): Promise>; /** * List envelopes with optional filters */ listEnvelopes(options?: ListEnvelopesOptions): Promise>; /** * Get pending envelopes (Zuhandenheit API) * * Outcome-focused: "Which contracts are waiting for signatures?" */ getPendingEnvelopes(): Promise>; /** * Get completed envelopes (Zuhandenheit API) * * Outcome-focused: "Which contracts were signed recently?" */ getCompletedEnvelopes(days?: number): Promise>; /** * Send an envelope with documents */ sendEnvelope(options: SendEnvelopeOptions): Promise>; /** * Send an envelope from a template */ sendFromTemplate(options: SendFromTemplateOptions): Promise>; /** * Void an envelope */ voidEnvelope(options: VoidEnvelopeOptions): Promise>; /** * Resend envelope notifications */ resendEnvelope(envelopeId: string): Promise>; /** * Get envelope recipients */ getRecipients(envelopeId: string): Promise>; /** * Get envelope documents list */ getDocuments(envelopeId: string): Promise>; /** * Download a document (returns base64) */ downloadDocument(envelopeId: string, documentId: string): Promise>; /** * Download combined documents (all in one PDF) */ downloadCombinedDocuments(envelopeId: string): Promise>; /** * Get embedded signing URL * * Used for in-app signing experiences */ getSigningUrl(options: GetSigningUrlOptions): Promise>; /** * List available templates */ listTemplates(options?: { count?: number; startPosition?: number; }): Promise>; /** * Get template details */ getTemplate(templateId: string): Promise>; /** * Verify DocuSign Connect webhook signature * * @param payload - Raw request body * @param signature - X-DocuSign-Signature-1 header * @param hmacKey - Your Connect HMAC key */ verifyWebhook(payload: string, signature: string, hmacKey: string): Promise>; /** * Get capabilities for DocuSign actions */ private getCapabilities; } export interface DSWebhookEvent { event: string; apiVersion: string; uri: string; retryCount: number; configurationId: string; generatedDateTime: string; data: { accountId: string; userId: string; envelopeId: string; envelopeSummary?: { status: DSEnvelopeStatus; emailSubject: string; sentDateTime?: string; completedDateTime?: string; recipients?: { signers?: DSRecipient[]; carbonCopies?: DSRecipient[]; }; }; }; } //# sourceMappingURL=index.d.ts.map