mirror of
https://github.com/FlipsideCrypto/DefinitelyTyped.git
synced 2026-02-06 10:56:53 +00:00
Added type definitions for docusign-esign nodejs client (#47040)
* Added type definitions for docusign-esign * Fixed pull request errors Co-authored-by: edwin.quimbo <equimbo@SCUNBCHQ02594.local>
This commit is contained in:
parent
3ac3e82778
commit
65a1cba56b
80
types/docusign-esign/docusign-esign-tests.ts
Normal file
80
types/docusign-esign/docusign-esign-tests.ts
Normal file
@ -0,0 +1,80 @@
|
||||
import * as docusign from 'docusign-esign';
|
||||
|
||||
const oAuth = docusign.ApiClient.OAuth;
|
||||
const scopes = [oAuth.Scope.SIGNATURE, oAuth.Scope.IMPERSONATION];
|
||||
|
||||
interface RequestParams {
|
||||
token: string;
|
||||
baseUrl: string;
|
||||
accountName: string;
|
||||
accountId: string;
|
||||
}
|
||||
|
||||
interface AccessToken {
|
||||
jwtToken: string;
|
||||
tokenType: string;
|
||||
expiresIn: number;
|
||||
}
|
||||
|
||||
const apiClient = () => {
|
||||
const basePath = 'base/path';
|
||||
const oAuthBasePath = 'oauth/path';
|
||||
return new docusign.ApiClient({ basePath, oAuthBasePath });
|
||||
};
|
||||
|
||||
const getEnvelope = async (envelopeId: string, options: { advancedUpdate?: string; include?: string }) => {
|
||||
const params = await getDsRequestParams();
|
||||
const client = await getClient(params.token);
|
||||
const envelopesApi = new docusign.EnvelopesApi(client);
|
||||
|
||||
const results = await envelopesApi.getEnvelope(params.accountId, envelopeId, options);
|
||||
return results;
|
||||
};
|
||||
|
||||
const getClient = async (token: string) => {
|
||||
const client = apiClient();
|
||||
client.addDefaultHeader('Authorization', `Bearer ${token}`);
|
||||
return client;
|
||||
};
|
||||
|
||||
const getDsRequestParams = async (): Promise<RequestParams> => {
|
||||
const authToken = await getAccessToken();
|
||||
const { jwtToken, tokenType, expiresIn } = authToken;
|
||||
const cacheExpiration = expiresIn - 300;
|
||||
const userInfo = await getUserInfo(jwtToken);
|
||||
const { accountId, baseUri, accountName } = userInfo;
|
||||
|
||||
return {
|
||||
token: jwtToken,
|
||||
baseUrl: baseUri,
|
||||
accountName,
|
||||
accountId,
|
||||
};
|
||||
};
|
||||
|
||||
const getAccessToken = async (): Promise<AccessToken> => {
|
||||
const privateKey: Buffer = Buffer.from('read private key file');
|
||||
const integratorKey = 'integrator key';
|
||||
const apiUserGuid = 'api user id';
|
||||
const client = apiClient();
|
||||
const results = await client.requestJWTUserToken(
|
||||
integratorKey,
|
||||
apiUserGuid,
|
||||
scopes,
|
||||
privateKey,
|
||||
3600,
|
||||
);
|
||||
|
||||
return {
|
||||
jwtToken: results.body.access_token,
|
||||
tokenType: results.body.token_type,
|
||||
expiresIn: results.body.expires_in,
|
||||
};
|
||||
};
|
||||
|
||||
const getUserInfo = async (token: string) => {
|
||||
const client = apiClient();
|
||||
client.setOAuthBasePath('set oauth base path');
|
||||
const results = await client.getUserInfo(token);
|
||||
return results.accounts.find((account: { isDefault: string }) => account.isDefault === 'true');
|
||||
};
|
||||
46483
types/docusign-esign/index.d.ts
vendored
Normal file
46483
types/docusign-esign/index.d.ts
vendored
Normal file
File diff suppressed because it is too large
Load Diff
24
types/docusign-esign/tsconfig.json
Normal file
24
types/docusign-esign/tsconfig.json
Normal file
@ -0,0 +1,24 @@
|
||||
{
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"docusign-esign-tests.ts"
|
||||
],
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6",
|
||||
"dom"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"strictFunctionTypes": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
}
|
||||
}
|
||||
3
types/docusign-esign/tslint.json
Normal file
3
types/docusign-esign/tslint.json
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"extends": "dtslint/dt.json"
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user