-
Notifications
You must be signed in to change notification settings - Fork 448
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
Open
likithdt
wants to merge
17
commits into
corsairdev:main
Choose a base branch
from
likithdt:feat/docusign-plugin
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,083
−0
Open
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
8c4da68
feat(docusign): implement eSignature client, envelope/template endpoi…
likithdt b6885a1
test(docusign): verify plugin registration and client in demo server
likithdt fc3556f
fix(docusign): remove polynomial regex to resolve codeql redos warning
likithdt e7543f3
style(docusign): format and clean up package with biome
likithdt 7bdeb16
chore: revert demo/testing to keep PR strictly scoped to plugin
likithdt 96444b2
chore: sync pnpm-lock.yaml after reverting demo/testing
likithdt ef2809a
chore: trigger PR gate check
likithdt 6ca4695
chore: trigger PR gate check
likithdt 0e70ada
fix(docusign): export endpoint schemas and satisfy RequiredPluginEndp…
likithdt c2fc142
fix(docusign): export DocusignSchema from schema folder and pass tests
likithdt 7ec3fea
fix(docusign): update endpoint risk levels to read and write
likithdt ee4fdde
style(docusign): apply biome formatting
likithdt be59088
fix(docusign): structure webhook export with match and handler
likithdt 36c0a69
fix(docusign): implement rateLimit and auth errorHandlers on plugin
likithdt 7cbb3f3
fix(docusign): update webhook handler signature to (context, request)
likithdt f9e85a1
fix(docusign): resolve context client binding and schemas
likithdt 592c0b7
fix(docusign): update endpoint context typing
likithdt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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>; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| import { DocusignClient } from '../client'; | ||
| import type { | ||
| CreateEnvelopeParams, | ||
| CreateRecipientViewUrlParams, | ||
| DocusignExecutionContext, | ||
| GetEnvelopeParams, | ||
| SendEnvelopeParams, | ||
| } from './types'; | ||
|
|
||
| function resolveClient( | ||
| contextOrClient: DocusignExecutionContext | unknown, | ||
| ): DocusignClient { | ||
| if (contextOrClient instanceof DocusignClient) { | ||
| return contextOrClient; | ||
| } | ||
| if ( | ||
| contextOrClient && | ||
| typeof contextOrClient === 'object' && | ||
| 'client' in contextOrClient && | ||
| (contextOrClient as { client: unknown }).client | ||
| ) { | ||
| const candidate = (contextOrClient as { client: unknown }).client; | ||
| if ( | ||
| candidate instanceof DocusignClient || | ||
| typeof (candidate as { request?: unknown }).request === 'function' | ||
| ) { | ||
| return candidate as DocusignClient; | ||
| } | ||
| } | ||
| if ( | ||
| contextOrClient && | ||
| typeof (contextOrClient as { request?: unknown }).request === 'function' | ||
| ) { | ||
| return contextOrClient as DocusignClient; | ||
| } | ||
| throw new Error( | ||
| 'Invalid execution context: DocuSign client is not initialized or accessible.', | ||
| ); | ||
| } | ||
|
|
||
| export const createEnvelope = async ( | ||
| ctxOrClient: DocusignExecutionContext, | ||
| params: CreateEnvelopeParams, | ||
| ) => { | ||
| const client = resolveClient(ctxOrClient); | ||
| return client.request('/envelopes', { | ||
| method: 'POST', | ||
| body: JSON.stringify(params), | ||
| }); | ||
| }; | ||
|
|
||
| export const getEnvelope = async ( | ||
| ctxOrClient: DocusignExecutionContext, | ||
| params: GetEnvelopeParams, | ||
| ) => { | ||
| const client = resolveClient(ctxOrClient); | ||
| return client.request(`/envelopes/${params.envelopeId}`); | ||
| }; | ||
|
|
||
| export const sendEnvelope = async ( | ||
| ctxOrClient: DocusignExecutionContext, | ||
| params: SendEnvelopeParams, | ||
| ) => { | ||
| const client = resolveClient(ctxOrClient); | ||
| return client.request(`/envelopes/${params.envelopeId}`, { | ||
| method: 'PUT', | ||
| body: JSON.stringify({ status: 'sent' }), | ||
| }); | ||
| }; | ||
|
|
||
| export const createRecipientViewUrl = async ( | ||
| ctxOrClient: DocusignExecutionContext, | ||
| params: CreateRecipientViewUrlParams, | ||
| ) => { | ||
| const client = resolveClient(ctxOrClient); | ||
| const { | ||
| envelopeId, | ||
| authenticationMethod = 'none', | ||
| recipientId = '1', | ||
| ...rest | ||
| } = params; | ||
|
|
||
| return client.request(`/envelopes/${envelopeId}/views/recipient`, { | ||
| method: 'POST', | ||
| body: JSON.stringify({ | ||
| authenticationMethod, | ||
| recipientId, | ||
| ...rest, | ||
| }), | ||
| }); | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| import { DocusignClient } from '../client'; | ||
| import type { | ||
| DocusignExecutionContext, | ||
| GetTemplateParams, | ||
| ListTemplatesParams, | ||
| } from './types'; | ||
|
|
||
| function resolveClient( | ||
| contextOrClient: DocusignExecutionContext | unknown, | ||
| ): DocusignClient { | ||
| if (contextOrClient instanceof DocusignClient) { | ||
| return contextOrClient; | ||
| } | ||
| if ( | ||
| contextOrClient && | ||
| typeof contextOrClient === 'object' && | ||
| 'client' in contextOrClient && | ||
| (contextOrClient as { client: unknown }).client | ||
| ) { | ||
| const candidate = (contextOrClient as { client: unknown }).client; | ||
| if ( | ||
| candidate instanceof DocusignClient || | ||
| typeof (candidate as { request?: unknown }).request === 'function' | ||
| ) { | ||
| return candidate as DocusignClient; | ||
| } | ||
| } | ||
| if ( | ||
| contextOrClient && | ||
| typeof (contextOrClient as { request?: unknown }).request === 'function' | ||
| ) { | ||
| return contextOrClient as DocusignClient; | ||
| } | ||
| throw new Error( | ||
| 'Invalid execution context: DocuSign client is not initialized or accessible.', | ||
| ); | ||
| } | ||
|
|
||
| export const listTemplates = async ( | ||
| ctxOrClient: DocusignExecutionContext, | ||
| params?: ListTemplatesParams, | ||
| ) => { | ||
| const client = resolveClient(ctxOrClient); | ||
| 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 ( | ||
| ctxOrClient: DocusignExecutionContext, | ||
| params: GetTemplateParams, | ||
| ) => { | ||
| const client = resolveClient(ctxOrClient); | ||
| return client.request(`/templates/${params.templateId}`); | ||
| }; | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.