Клиент узла Docusign - невозможно прочитать свойство 'cdseMode' с нулевой ошибкой при создании конверта - PullRequest
0 голосов
/ 29 ноября 2018

Я использую последнюю версию 4.2.0-rc5.

createEnvelope метод throws TypeError: Cannot read property 'cdseMode' of null

Ниже приведен код, который я использую:

var docusign = require('docusign-esign');
var oAuth = docusign.ApiClient.OAuth;
var restApi = docusign.ApiClient.RestApi;
var path = require('path');

var integratorKey = '*****';                    // Integrator Key associated with your DocuSign Integration
var userId = '****';                  // API Username for your DocuSign Account (use the GUID not the email address)
var fullName = 'User';                   // Recipient's Full Name
var recipientEmail = 'user@user.com'; // Recipient's Email

var expiresIn = 3600; // Number of seconds until the JWT assertion is invalid
var basePath = restApi.BasePath.DEMO;
var oAuthBasePath = oAuth.BasePath.DEMO;
var privateKeyFilename = '../keys/private-key'; //path to the file storing the private key from the RSA Keypair associated to the Integrator Key

var apiClient = new docusign.ApiClient({
    basePath: basePath,
    oAuthBasePath: oAuthBasePath
});
var scopes = [
    oAuth.Scope.IMPERSONATION,
    oAuth.Scope.SIGNATURE
];


function initApiClient() {
 docusign.Configuration.default.setDefaultApiClient(apiClient);
 var fs = require('fs');
 var privateKeyFile = fs.readFileSync(path.resolve(__dirname, privateKeyFilename));

 return new Promise((resolve,reject) => {
  apiClient.requestJWTUserToken(integratorKey, userId, scopes, privateKeyFile, expiresIn, function (err, res) {
      var baseUri,
        accountDomain;
      if (err) {
        return next(err);
      }
      apiClient.addDefaultHeader('Authorization', 'Bearer ' + res.body.access_token);

      apiClient.getUserInfo(res.body.access_token, function (err, userInfo) {
        if (err) {
          return reject(err);
        }
        accountId = userInfo.accounts[0].accountId;
        baseUri = userInfo.accounts[0].baseUri;
        accountDomain = baseUri.split('/v2');
        apiClient.setBasePath(accountDomain[0] + '/restapi');
        console.log('LoginInformation: ' + JSON.stringify(userInfo));
        resolve(userInfo.accounts[0].accountId);
      });
  }) 
})
}

const createEnvelope = () => {
  const e = new docusign.EnvelopeDefinition();
  console.log(e);
  console.log('-----------------------------');
  e.subject = 'subject';
  const doc = new docusign.Document();
  const base64Doc = 'TWFuIGlzIGRpc3Rpbmd1aXNoZWQsIG5vdCBvbmx5IGJ5IGhpcyByZWFzb24sIGJ1dCBieSB0aGlzIHNpbmd1bGFyIHBhc3Npb24gZnJvbSBvdGhlciBhbmltYWxzLCB3aGljaCBpcyBhIGx1c3Qgb2YgdGhlIG1pbmQsIHRoYXQgYnkgYSBwZXJzZXZlcmFuY2Ugb2YgZGVsaWdodCBpbiB0aGUgY29udGludWVkIGFuZCBpbmRlZmF0aWdhYmxlIGdlbmVyYXRpb24gb2Yga25vd2xlZGdlLCBleGNlZWRzIHRoZSBzaG9ydCB2ZWhlbWVuY2Ugb2YgYW55IGNhcm5hbCBwbGVhc3VyZS4=';
  doc.documentBase64 = base64Doc;
  doc.name = 'doc.txt'; // can be different from actual file name
  doc.documentId = '1';
  const docs = [];
  docs.push(doc);
  e.docs = docs;

  const signer = new docusign.Signer();
  signer.email = 'narasimha@checkbox.ai';
  signer.name = 'Narasimha M';
  signer.recipientId = '1' ;
  const signHere = new docusign.SignHere();
  signHere.documentId = '1';
  signHere.pageNumber = '1';
  signHere.recipientId = '1';
  signHere.xPosition = '100';
  signHere.yPosition = '100';

  const signHereTabs = [];
  signHereTabs.push(signHere);
  const tabs = new docusign.Tabs();
  tabs.signHereTabs = signHereTabs;
  signer.tabs = tabs;

  e.recipients = new docusign.Recipients();
  e.recipients.signers = [];
  e.recipients.signers.push(signer);

  e.status ='sent';
};

const sendEnvelope = (accountId, e) => {
  const envelopesApi = new docusign.EnvelopesApi();
  return new Promise((resolve, reject) => {
    envelopesApi.createEnvelope(accountId, e, null, (err, envelopeSummary, response) => {
      if (err) {
        console.log('><> ><> inside send envelope, error:', err);
        reject({
          ok: false,
          error: err,
          hasTokenExpired: false
        });
        return;
      }
      resolve({
        ok: true,
        response,
      });
    });
  });
};

initApiClient()
.then((r)=>{
  return sendEnvelope(r,createEnvelope()) 
})
.then((r)=>{
 console.log(r)
})
.catch((err)=>{
 console.log(err);
});



TypeError: Cannot read property 'cdseMode' of null
    at exports.createEnvelope (/Users/nmcheckbox/docusign/standalone/node_modules/docusign-esign/src/api/EnvelopesApi.js:995:36)
    at Promise (/Users/nmcheckbox/docusign/standalone/index.js:96:18)
    at new Promise (<anonymous>)
    at sendEnvelope (/Users/nmcheckbox/docusign/standalone/index.js:95:10)
    at initApiClient.then (/Users/nmcheckbox/docusign/standalone/index.js:116:10)
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:188:7)

Обратите внимание, что я попытался передать пустой объект вместо нулевого параметра в createEnvelope: envelopesApi.createEnvelope(accountId, e, {}, (err, envelopeSummary, response) => {

Это приводит к неверному ответу на запрос: text: '{\r\n _"errorCode": "UNSPECIFIED_ERROR",\r\n "message": "Non-static method requires a target."\r\n}',_

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...