-
Notifications
You must be signed in to change notification settings - Fork 439
feat(plugins): add DocuSign eSignature integration plugin #1146
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 5 commits
8c4da68
b6885a1
fc3556f
e7543f3
7bdeb16
96444b2
ef2809a
6ca4695
0e70ada
c2fc142
7ec3fea
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| export interface DocusignAuthOptions { | ||
| accessToken: string; | ||
| accountId: string; | ||
| baseUri?: string; | ||
| } | ||
|
|
||
| export class DocusignClient { | ||
| public baseUri: string; | ||
| public accountId: string; | ||
| private token: string; | ||
|
|
||
| constructor(options: DocusignAuthOptions) { | ||
| this.accountId = options.accountId; | ||
| this.token = options.accessToken; | ||
|
|
||
| let root = options.baseUri?.trim() || 'https://demo.docusign.net/restapi'; | ||
| while (root.endsWith('/')) { | ||
| root = root.slice(0, -1); | ||
| } | ||
|
|
||
| this.baseUri = `${root}/v2.1/accounts/${this.accountId}`; | ||
| } | ||
|
|
||
| async request<T = any>( | ||
| endpoint: string, | ||
| options: RequestInit = {}, | ||
| ): Promise<T> { | ||
| const cleanPath = endpoint.startsWith('/') ? endpoint : `/${endpoint}`; | ||
| const url = `${this.baseUri}${cleanPath}`; | ||
|
|
||
| const response = await fetch(url, { | ||
| ...options, | ||
| headers: { | ||
| Authorization: `Bearer ${this.token}`, | ||
| 'Content-Type': 'application/json', | ||
| Accept: 'application/json', | ||
| ...options.headers, | ||
| }, | ||
| }); | ||
|
|
||
| if (!response.ok) { | ||
| const errorText = await response.text(); | ||
| throw new Error(`DocuSign API Error (${response.status}): ${errorText}`); | ||
| } | ||
|
|
||
| return response.json() as Promise<T>; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| import type { DocusignClient } from '../client'; | ||
|
|
||
| export interface CreateEnvelopeParams { | ||
| templateId?: string; | ||
| emailSubject: string; | ||
| status: 'sent' | 'created'; | ||
| templateRoles?: Array<{ | ||
| email: string; | ||
| name: string; | ||
| roleName: string; | ||
| }>; | ||
| documents?: Array<{ | ||
| documentId: string; | ||
| name: string; | ||
| fileExtension?: string; | ||
| documentBase64?: string; | ||
| }>; | ||
| recipients?: { | ||
| signers?: Array<{ | ||
| email: string; | ||
| name: string; | ||
| recipientId: string; | ||
| routingOrder?: string; | ||
| }>; | ||
| }; | ||
| } | ||
|
|
||
| export const createEnvelope = async ( | ||
| client: DocusignClient, | ||
| params: CreateEnvelopeParams, | ||
| ) => { | ||
| return client.request('/envelopes', { | ||
| method: 'POST', | ||
| body: JSON.stringify(params), | ||
| }); | ||
| }; | ||
|
|
||
| export const getEnvelope = async ( | ||
| client: DocusignClient, | ||
| { envelopeId }: { envelopeId: string }, | ||
| ) => { | ||
| return client.request(`/envelopes/${envelopeId}`); | ||
| }; | ||
|
|
||
| export const sendEnvelope = async ( | ||
| client: DocusignClient, | ||
| { envelopeId }: { envelopeId: string }, | ||
| ) => { | ||
| return client.request(`/envelopes/${envelopeId}`, { | ||
| method: 'PUT', | ||
| body: JSON.stringify({ status: 'sent' }), | ||
| }); | ||
| }; | ||
|
|
||
| export const createRecipientViewUrl = async ( | ||
| client: DocusignClient, | ||
| { | ||
| envelopeId, | ||
| ...params | ||
| }: { | ||
| envelopeId: string; | ||
| userName: string; | ||
| email: string; | ||
| returnUrl: string; | ||
| authenticationMethod?: string; | ||
| recipientId?: string; | ||
| }, | ||
| ) => { | ||
| return client.request(`/envelopes/${envelopeId}/views/recipient`, { | ||
| method: 'POST', | ||
| body: JSON.stringify({ | ||
| authenticationMethod: 'none', | ||
| recipientId: '1', | ||
| ...params, | ||
| }), | ||
| }); | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| import type { DocusignClient } from '../client'; | ||
| import type { | ||
| CreateEnvelopeParams, | ||
| GetEnvelopeParams, | ||
| ListTemplatesParams, | ||
| } from './types'; | ||
|
|
||
| export const createEnvelope = async ( | ||
| client: DocusignClient, | ||
| params: CreateEnvelopeParams, | ||
| ) => { | ||
| return client.request('/envelopes', { | ||
| method: 'POST', | ||
| body: JSON.stringify(params), | ||
| }); | ||
| }; | ||
|
|
||
| export const getEnvelope = async ( | ||
| client: DocusignClient, | ||
| params: GetEnvelopeParams, | ||
| ) => { | ||
| return client.request(`/envelopes/${params.envelopeId}`); | ||
| }; | ||
|
|
||
| export const sendEnvelope = async ( | ||
| client: DocusignClient, | ||
| params: GetEnvelopeParams, | ||
| ) => { | ||
| return client.request(`/envelopes/${params.envelopeId}`, { | ||
| method: 'PUT', | ||
| body: JSON.stringify({ status: 'sent' }), | ||
| }); | ||
| }; | ||
|
|
||
| export const listTemplates = async ( | ||
| client: DocusignClient, | ||
| params?: ListTemplatesParams, | ||
| ) => { | ||
| const query = new URLSearchParams(); | ||
| if (params?.count) query.append('count', String(params.count)); | ||
| if (params?.startPosition) | ||
| query.append('start_position', String(params.startPosition)); | ||
| const qs = query.toString() ? `?${query.toString()}` : ''; | ||
| return client.request(`/templates${qs}`); | ||
| }; | ||
|
|
||
| export const getTemplate = async ( | ||
| client: DocusignClient, | ||
| params: { templateId: string }, | ||
| ) => { | ||
| return client.request(`/templates/${params.templateId}`); | ||
| }; | ||
|
|
||
| export * from './types'; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| import type { DocusignClient } from '../client'; | ||
|
|
||
| export const listTemplates = async ( | ||
| client: DocusignClient, | ||
| params?: { count?: number; startPosition?: number }, | ||
| ) => { | ||
| const query = new URLSearchParams(); | ||
| if (params?.count) query.append('count', String(params.count)); | ||
| if (params?.startPosition) | ||
| query.append('start_position', String(params.startPosition)); | ||
| const qs = query.toString() ? `?${query.toString()}` : ''; | ||
| return client.request(`/templates${qs}`); | ||
| }; | ||
|
|
||
| export const getTemplate = async ( | ||
| client: DocusignClient, | ||
| { templateId }: { templateId: string }, | ||
| ) => { | ||
| return client.request(`/templates/${templateId}`); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔒 Security & Privacy | 🟠 Major | ⚡ Quick win 🔎 Supported by static analysis🏁 Script executed: #!/bin/bash
set -eu
printf '%s\n' '--- relevant repository conventions ---'
find /tmp/coderabbit-repo-knowledge/corsairdev-corsair-3579a5cc -type f -path '*/\*.md' -print | sort | while read -r f; do
case "$f" in
*/learnings/*) continue ;;
esac
printf '%s\n' "--- $f"
sed -n '1,220p' "$f"
done
printf '%s\n' '--- target file ---'
cat -n packages/docusign/endpoints/templates.ts
printf '%s\n' '--- docusign package files ---'
git ls-files packages/docusign
printf '%s\n' '--- templateId bindings and client.request definitions ---'
rg -n -C 3 'templateId|client\.request|class .*Client|request\s*\(' packages/docusign packages/corsair packages/cli packages/mcp packages/studio packages/ui packages/app 2>/dev/null | head -300Repository: corsairdev/corsair Length of output: 18650 🏁 Script executed: #!/bin/bash
set -eu
printf '%s\n' '--- client implementation ---'
cat -n packages/docusign/client.ts
printf '%s\n' '--- package exports and schema ---'
cat -n packages/docusign/index.ts
cat -n packages/docusign/endpoints/index.ts
cat -n packages/docusign/schema/index.ts
cat -n packages/docusign/schema/database.ts
printf '%s\n' '--- package metadata ---'
cat -n packages/docusign/package.json
printf '%s\n' '--- focused getTemplate and client references ---'
rg -n -C 5 '\bgetTemplate\b|\bDocusignClient\b' packages/docusign --glob '!schema.test.ts'Repository: corsairdev/corsair Length of output: 18332 🏁 Script executed: #!/bin/bash
set -eu
printf '%s\n' '--- target reachability and diff metadata ---'
git diff --stat -- packages/docusign/endpoints/templates.ts
git diff -- packages/docusign/endpoints/templates.ts | sed -n '1,180p'
rg -n -C 3 "(from ['\"][^'\"]*templates['\"]|require\([^)]*templates|endpoints/templates|['\"]\.?/?templates['\"])" . --glob '!node_modules/**' --glob '!dist/**' | head -160
printf '%s\n' '--- applicable repository convention files ---'
find /tmp/coderabbit-repo-knowledge/corsairdev-corsair-3579a5cc -type f -name '*.md' -print | sort
printf '%s\n' '--- exact URL parsing probe ---'
node - <<'JS'
const baseUri = 'https://demo.docusign.net/restapi/v2.1/accounts/123';
const templateId = '../../999/templates/abc';
const endpoint = `/templates/${templateId}`;
const urlText = `${baseUri}${endpoint}`;
console.log(JSON.stringify({ endpoint, urlText, parsedPath: new URL(urlText).pathname }));
JSRepository: corsairdev/corsair Length of output: 11796 Encode
🤖 Prompt for AI Agents |
||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| export interface CreateEnvelopeParams { | ||
| templateId?: string; | ||
| emailSubject: string; | ||
| status: 'sent' | 'created'; | ||
| templateRoles?: Array<{ | ||
| email: string; | ||
| name: string; | ||
| roleName: string; | ||
| }>; | ||
| } | ||
|
|
||
| export interface GetEnvelopeParams { | ||
| envelopeId: string; | ||
| } | ||
|
|
||
| export interface ListTemplatesParams { | ||
| count?: number; | ||
| startPosition?: number; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| import type { CorsairErrorHandler } from 'corsair/core'; | ||
| import { ApiError } from 'corsair/http'; | ||
|
|
||
| export const errorHandlers = { | ||
| RATE_LIMIT_ERROR: { | ||
| match: (error: Error) => { | ||
| if (error instanceof ApiError && error.status === 429) return true; | ||
| const msg = error.message.toLowerCase(); | ||
| return msg.includes('rate_limited') || msg.includes('429'); | ||
| }, | ||
| handler: async (error: Error) => { | ||
| let retryAfterMs: number | undefined; | ||
| if (error instanceof ApiError && error.retryAfter !== undefined) { | ||
| retryAfterMs = error.retryAfter; | ||
| } | ||
| return { maxRetries: 5, headersRetryAfterMs: retryAfterMs }; | ||
| }, | ||
| }, | ||
| AUTH_ERROR: { | ||
| match: (error: Error) => { | ||
| if (error instanceof ApiError && error.status === 401) return true; | ||
| const msg = error.message.toLowerCase(); | ||
| return msg.includes('unauthorized') || msg.includes('invalid_auth'); | ||
| }, | ||
| handler: async () => ({ maxRetries: 0 }), | ||
| }, | ||
| DEFAULT: { | ||
| match: () => true, | ||
| handler: async () => ({ maxRetries: 0 }), | ||
| }, | ||
| } satisfies CorsairErrorHandler; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| import type { DocusignAuthOptions } from './client'; | ||
| import { DocusignClient } from './client'; | ||
| import * as endpoints from './endpoints'; | ||
| import * as schema from './schema'; | ||
| import * as webhooks from './webhooks'; | ||
|
|
||
| export * from './client'; | ||
| export * from './endpoints'; | ||
| export * from './schema'; | ||
| export * from './webhooks'; | ||
|
|
||
| export const docusignEndpointsNested = { | ||
| createEnvelope: endpoints.createEnvelope, | ||
| getEnvelope: endpoints.getEnvelope, | ||
| sendEnvelope: endpoints.sendEnvelope, | ||
| listTemplates: endpoints.listTemplates, | ||
| getTemplate: endpoints.getTemplate, | ||
| }; | ||
|
likithdt marked this conversation as resolved.
|
||
|
|
||
| export const docusignWebhooksNested = { | ||
| handleWebhook: webhooks.handleWebhook, | ||
| }; | ||
|
|
||
| export const docusignEndpointMeta = { | ||
| createEnvelope: { | ||
| description: | ||
| 'Creates a signing envelope from a pre-existing DocuSign template.', | ||
| }, | ||
| getEnvelope: { | ||
| description: | ||
| 'Gets the status and basic information about an envelope from DocuSign.', | ||
| }, | ||
| sendEnvelope: { | ||
| description: 'Sends a draft envelope by updating its status to sent.', | ||
| }, | ||
| listTemplates: { | ||
| description: 'Gets the definition of templates in the specified account.', | ||
| }, | ||
| getTemplate: { | ||
| description: 'Gets a template definition from the specified account.', | ||
| }, | ||
| }; | ||
|
|
||
| export const docusignPlugin = { | ||
| id: 'docusign', | ||
| name: 'DocuSign', | ||
| description: | ||
| 'DocuSign eSignature REST API integration for agreements, envelopes, and templates.', | ||
| auth: { | ||
| type: 'oauth2' as const, | ||
| fields: ['accessToken', 'accountId', 'baseUri'], | ||
| }, | ||
| createClient: (options: DocusignAuthOptions) => new DocusignClient(options), | ||
| endpoints: docusignEndpointsNested, | ||
| webhooks: docusignWebhooksNested, | ||
| endpointMeta: docusignEndpointMeta, | ||
| schema, | ||
| }; | ||
|
|
||
| // Plugin factory function for corsair.ts plugins list | ||
| export const docusign = (config?: any) => ({ | ||
| ...docusignPlugin, | ||
| ...(config && { config }), | ||
| }); | ||
|
|
||
| export default docusign; | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
Repository: corsairdev/corsair
Length of output: 13158
🏁 Script executed:
Repository: corsairdev/corsair
Length of output: 6765
Type the template endpoint responses.
DocusignClient.request<T = any>defaults toany. Both exported template helpers omitT, so they exposePromise<any>. Define and export the response types, then pass them torequest;endpoints/types.tscurrently contains only request-parameter types.🤖 Prompt for AI Agents