-
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 14 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,74 @@ | ||
| export interface DocusignAuthOptions { | ||
| accessToken: string; | ||
| accountId: string; | ||
| baseUri?: string; | ||
| } | ||
|
|
||
| export class DocusignClient { | ||
| private accessToken: string; | ||
| private accountId: string; | ||
| private baseUri: string; | ||
|
|
||
| constructor(options: DocusignAuthOptions) { | ||
| this.accessToken = options.accessToken; | ||
| this.accountId = options.accountId; | ||
| this.baseUri = this.resolveAndValidateBaseUri(options.baseUri); | ||
| } | ||
|
|
||
| private resolveAndValidateBaseUri(baseUri?: string): string { | ||
| const raw = baseUri || 'https://demo.docusign.net/restapi/v2.1'; | ||
| const url = new URL(raw.startsWith('http') ? raw : `https://${raw}`); | ||
|
|
||
| if (url.protocol !== 'https:') { | ||
| throw new Error('DocuSign baseUri must use HTTPS.'); | ||
| } | ||
|
|
||
| const host = url.hostname.toLowerCase(); | ||
| const isAllowedHost = | ||
| host === 'docusign.com' || | ||
| host.endsWith('.docusign.com') || | ||
| host === 'docusign.net' || | ||
| host.endsWith('.docusign.net'); | ||
|
|
||
| if (!isAllowedHost) { | ||
| throw new Error( | ||
| `Untrusted DocuSign baseUri host: "${host}". Must be a valid *.docusign.com or *.docusign.net domain.`, | ||
| ); | ||
| } | ||
|
|
||
| let path = url.pathname.replace(/\/+$/, ''); | ||
| if (!path.includes('/restapi/v2.1')) { | ||
| path = `${path}/restapi/v2.1`; | ||
| } | ||
| if (!path.includes(`/accounts/${this.accountId}`)) { | ||
| path = `${path}/accounts/${this.accountId}`; | ||
| } | ||
|
|
||
| return `${url.origin}${path}`; | ||
| } | ||
|
|
||
| async request<T = unknown>( | ||
| endpoint: string, | ||
| options: RequestInit = {}, | ||
| ): Promise<T> { | ||
| const path = endpoint.startsWith('/') ? endpoint : `/${endpoint}`; | ||
| const url = `${this.baseUri}${path}`; | ||
|
|
||
| const response = await fetch(url, { | ||
| ...options, | ||
| headers: { | ||
| Authorization: `Bearer ${this.accessToken}`, | ||
| 'Content-Type': 'application/json', | ||
| Accept: 'application/json', | ||
| ...options.headers, | ||
| }, | ||
| }); | ||
|
|
||
| if (!response.ok) { | ||
| const errorBody = await response.text(); | ||
| throw new Error(`DocuSign API error (${response.status}): ${errorBody}`); | ||
| } | ||
|
|
||
| return response.json() as Promise<T>; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| import type { DocusignClient } from '../client'; | ||
| import type { | ||
| CreateEnvelopeParams, | ||
| CreateRecipientViewUrlParams, | ||
| GetEnvelopeParams, | ||
| SendEnvelopeParams, | ||
| } 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: SendEnvelopeParams, | ||
| ) => { | ||
| return client.request(`/envelopes/${params.envelopeId}`, { | ||
| method: 'PUT', | ||
| body: JSON.stringify({ status: 'sent' }), | ||
| }); | ||
| }; | ||
|
|
||
| export const createRecipientViewUrl = async ( | ||
| client: DocusignClient, | ||
| params: CreateRecipientViewUrlParams, | ||
| ) => { | ||
| const { | ||
| envelopeId, | ||
| authenticationMethod = 'none', | ||
| recipientId = '1', | ||
| ...rest | ||
| } = params; | ||
|
|
||
| return client.request(`/envelopes/${envelopeId}/views/recipient`, { | ||
| method: 'POST', | ||
| body: JSON.stringify({ | ||
| authenticationMethod, | ||
| recipientId, | ||
| ...rest, | ||
| }), | ||
| }); | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| import type { DocusignClient } from '../client'; | ||
| import type { | ||
| CreateEnvelopeParams, | ||
| CreateRecipientViewUrlParams, | ||
| GetEnvelopeParams, | ||
| GetTemplateParams, | ||
| ListTemplatesParams, | ||
| SendEnvelopeParams, | ||
| } 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: SendEnvelopeParams, | ||
| ) => { | ||
| return client.request(`/envelopes/${params.envelopeId}`, { | ||
| method: 'PUT', | ||
| body: JSON.stringify({ status: 'sent' }), | ||
| }); | ||
| }; | ||
|
|
||
| export const createRecipientViewUrl = async ( | ||
| client: DocusignClient, | ||
| params: CreateRecipientViewUrlParams, | ||
| ) => { | ||
| const { | ||
| envelopeId, | ||
| authenticationMethod = 'none', | ||
| recipientId = '1', | ||
| ...rest | ||
| } = params; | ||
|
|
||
| return client.request(`/envelopes/${envelopeId}/views/recipient`, { | ||
| method: 'POST', | ||
| body: JSON.stringify({ | ||
| authenticationMethod, | ||
| recipientId, | ||
| ...rest, | ||
| }), | ||
| }); | ||
| }; | ||
|
|
||
| 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: GetTemplateParams, | ||
| ) => { | ||
| 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 |
||
| }; | ||
Uh oh!
There was an error while loading. Please reload this page.