-
Notifications
You must be signed in to change notification settings - Fork 475
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 11 commits
8c4da68
b6885a1
fc3556f
e7543f3
7bdeb16
96444b2
ef2809a
6ca4695
0e70ada
c2fc142
7ec3fea
ee4fdde
be59088
36c0a69
7cbb3f3
f9e85a1
592c0b7
88f600f
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}`); | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| }; | ||
|
|
||
| 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,141 @@ | ||
| import { z } from 'zod'; | ||
|
|
||
| export const CreateEnvelopeInputSchema = z.object({ | ||
| templateId: z.string().optional(), | ||
| emailSubject: z.string(), | ||
| status: z.enum(['sent', 'created']).default('sent'), | ||
| templateRoles: z | ||
| .array( | ||
| z.object({ | ||
| email: z.string(), | ||
| name: z.string(), | ||
| roleName: z.string(), | ||
| }), | ||
| ) | ||
| .optional(), | ||
| documents: z | ||
| .array( | ||
| z.object({ | ||
| documentId: z.string(), | ||
| name: z.string(), | ||
| fileExtension: z.string().optional(), | ||
| documentBase64: z.string().optional(), | ||
| }), | ||
| ) | ||
| .optional(), | ||
| recipients: z | ||
| .object({ | ||
| signers: z | ||
| .array( | ||
| z.object({ | ||
| email: z.string(), | ||
| name: z.string(), | ||
| recipientId: z.string(), | ||
| routingOrder: z.string().optional(), | ||
| }), | ||
| ) | ||
| .optional(), | ||
| }) | ||
| .optional(), | ||
| }); | ||
|
|
||
| export const GetEnvelopeInputSchema = z.object({ | ||
| envelopeId: z.string(), | ||
| }); | ||
|
|
||
| export const SendEnvelopeInputSchema = z.object({ | ||
| envelopeId: z.string(), | ||
| }); | ||
|
|
||
| export const ListTemplatesInputSchema = z | ||
| .object({ | ||
| count: z.number().optional(), | ||
| startPosition: z.number().optional(), | ||
| }) | ||
| .optional(); | ||
|
|
||
| export const GetTemplateInputSchema = z.object({ | ||
| templateId: z.string(), | ||
| }); | ||
|
|
||
| export const CreateEnvelopeOutputSchema = z | ||
| .object({ | ||
| envelopeId: z.string(), | ||
| status: z.string(), | ||
| statusDateTime: z.string().optional(), | ||
| uri: z.string().optional(), | ||
| }) | ||
| .passthrough(); | ||
|
|
||
| export const GetEnvelopeOutputSchema = z | ||
| .object({ | ||
| envelopeId: z.string().optional(), | ||
| status: z.string().optional(), | ||
| }) | ||
| .passthrough(); | ||
|
|
||
| export const SendEnvelopeOutputSchema = z | ||
| .object({ | ||
| envelopeId: z.string().optional(), | ||
| status: z.string().optional(), | ||
| }) | ||
| .passthrough(); | ||
|
|
||
| export const ListTemplatesOutputSchema = z | ||
| .object({ | ||
| envelopeTemplates: z.array(z.record(z.string(), z.unknown())).optional(), | ||
| }) | ||
| .passthrough(); | ||
|
|
||
| export const GetTemplateOutputSchema = z | ||
| .object({ | ||
| templateId: z.string().optional(), | ||
| name: z.string().optional(), | ||
| }) | ||
| .passthrough(); | ||
|
|
||
| export const EndpointInputSchemas = { | ||
| createEnvelope: CreateEnvelopeInputSchema, | ||
| getEnvelope: GetEnvelopeInputSchema, | ||
| sendEnvelope: SendEnvelopeInputSchema, | ||
| listTemplates: ListTemplatesInputSchema, | ||
| getTemplate: GetTemplateInputSchema, | ||
| }; | ||
|
|
||
| export const EndpointOutputSchemas = { | ||
| createEnvelope: CreateEnvelopeOutputSchema, | ||
| getEnvelope: GetEnvelopeOutputSchema, | ||
| sendEnvelope: SendEnvelopeOutputSchema, | ||
| listTemplates: ListTemplatesOutputSchema, | ||
| getTemplate: GetTemplateOutputSchema, | ||
| }; | ||
|
|
||
| export const docusignEndpointInputSchemas = EndpointInputSchemas; | ||
| export const docusignEndpointOutputSchemas = EndpointOutputSchemas; | ||
| export const DocusignEndpointInputSchemas = EndpointInputSchemas; | ||
| export const DocusignEndpointOutputSchemas = EndpointOutputSchemas; | ||
|
|
||
| export type CreateEnvelopeParams = z.infer<typeof CreateEnvelopeInputSchema>; | ||
| export type GetEnvelopeParams = z.infer<typeof GetEnvelopeInputSchema>; | ||
| export type ListTemplatesParams = NonNullable< | ||
| z.infer<typeof ListTemplatesInputSchema> | ||
| >; | ||
|
|
||
| export type DocusignEndpointInputs = { | ||
| createEnvelope: z.infer<typeof CreateEnvelopeInputSchema>; | ||
| getEnvelope: z.infer<typeof GetEnvelopeInputSchema>; | ||
| sendEnvelope: z.infer<typeof SendEnvelopeInputSchema>; | ||
| listTemplates: z.infer<typeof ListTemplatesInputSchema>; | ||
| getTemplate: z.infer<typeof GetTemplateInputSchema>; | ||
| }; | ||
|
|
||
| export type DocusignEndpointOutputs = { | ||
| createEnvelope: z.infer<typeof CreateEnvelopeOutputSchema>; | ||
| getEnvelope: z.infer<typeof GetEnvelopeOutputSchema>; | ||
| sendEnvelope: z.infer<typeof SendEnvelopeOutputSchema>; | ||
| listTemplates: z.infer<typeof ListTemplatesOutputSchema>; | ||
| getTemplate: z.infer<typeof GetTemplateOutputSchema>; | ||
| }; | ||
|
|
||
| export type EndpointInputs = DocusignEndpointInputs; | ||
| export type EndpointOutputs = DocusignEndpointOutputs; |
Uh oh!
There was an error while loading. Please reload this page.