@@ -26,8 +26,15 @@ const getTabGroups = async (args) => {
2626 const response = await axios . get ( url , { headers } ) ;
2727 const responseData = response . data ;
2828
29+ const filteredApps = responseData . filter ( app =>
30+ app . tabs ?. some ( tab =>
31+ ( tab . extensionData ?. actionContract ?. includes ( 'Verify' ) ) ||
32+ ( tab . tabLabel ?. includes ( 'connecteddata' ) )
33+ )
34+ ) ;
35+
2936 let uniqueApps = [ ] ;
30- if ( responseData && responseData . length > 0 ) {
37+ if ( filteredApps . length > 0 ) {
3138 uniqueApps = [ ...new Map ( responseData . map ( item => [ item . appId , item ] ) ) . values ( ) ] ;
3239 }
3340 //ds-snippet-end:ConnectedFields1Step3
@@ -70,31 +77,27 @@ const sendEnvelope = async (args) => {
7077/**
7178 * This function gets the verification data for selected extension app
7279 * @param {string } selectedAppId the GUID of selected extension app
73- * @param {array } apps the list of extension apps
80+ * @param {array } tab the extension tab
7481 * @returns {Object } Verification data
7582 */
7683//ds-snippet-start:ConnectedFields1Step4
77- const extractVerificationData = ( selectedAppId , apps ) => {
78- const selectedApp = apps . filter ( app => app . appId === selectedAppId ) [ 0 ] ;
84+ const extractVerificationData = ( selectedAppId , tab ) => {
85+ const extensionData = tab . extensionData ;
7986
8087 return {
81- appId : selectedApp . appId ,
82- extensionGroupId : selectedApp . tabs [ 0 ] . extensionData . extensionGroupId ,
83- publisherName : selectedApp . tabs [ 0 ] . extensionData . publisherName ,
84- applicationName : selectedApp . tabs [ 0 ] . extensionData . applicationName ,
85- actionName : selectedApp . tabs [ 0 ] . extensionData . actionName ,
86- actionInputKey : selectedApp . tabs [ 0 ] . extensionData . actionInputKey ,
87- actionContract : selectedApp . tabs [ 0 ] . extensionData . actionContract ,
88- extensionName : selectedApp . tabs [ 0 ] . extensionData . extensionName ,
89- extensionContract : selectedApp . tabs [ 0 ] . extensionData . extensionContract ,
90- requiredForExtension : selectedApp . tabs [ 0 ] . extensionData . requiredForExtension ,
91- tabLabel : selectedApp . tabs . map ( ( tab ) => tab . tabLabel ) . join ( ', ' ) ,
92- connectionKey : selectedApp . tabs [ 0 ] . extensionData . connectionInstances
93- ? selectedApp . tabs [ 0 ] . extensionData . connectionInstances [ 0 ] . connectionKey
94- : '' ,
95- connectionValue : selectedApp . tabs [ 0 ] . extensionData . connectionInstances
96- ? selectedApp . tabs [ 0 ] . extensionData . connectionInstances [ 0 ] . connectionValue
97- : '' ,
88+ appId : selectedAppId ,
89+ extensionGroupId : extensionData . extensionGroupId ,
90+ publisherName : extensionData . publisherName ,
91+ applicationName : extensionData . applicationName ,
92+ actionName : extensionData . actionName ,
93+ actionInputKey : extensionData . actionInputKey ,
94+ actionContract : extensionData . actionContract ,
95+ extensionName : extensionData . extensionName ,
96+ extensionContract : extensionData . extensionContract ,
97+ requiredForExtension : extensionData . requiredForExtension ,
98+ tabLabel : tab . tabLabel ,
99+ connectionKey : extensionData . connectionInstances ? extensionData . connectionInstances [ 0 ] . connectionKey : '' ,
100+ connectionValue : extensionData . connectionInstances ? extensionData . connectionInstances [ 0 ] . connectionValue : '' ,
98101 } ;
99102} ;
100103//ds-snippet-end:ConnectedFields1Step4
@@ -120,15 +123,14 @@ function makeEnvelope(args) {
120123 // The envelope has one recipients.
121124 // recipient 1 - signer
122125
123- let docPdfBytes ;
124- // read file from a local directory
125- // The read could raise an exception if the file is not available!
126- docPdfBytes = fs . readFileSync ( args . docFile ) ;
127-
128126 // create the envelope definition
129127 let env = new docusign . EnvelopeDefinition ( ) ;
130128 env . emailSubject = 'Please sign this document' ;
131129
130+ // read file from a local directory
131+ // The read could raise an exception if the file is not available!
132+ const docPdfBytes = fs . readFileSync ( args . docFile ) ;
133+
132134 // add the documents
133135 let doc = new docusign . Document ( ) ;
134136 let docb64 = Buffer . from ( docPdfBytes ) . toString ( 'base64' ) ;
@@ -141,77 +143,42 @@ function makeEnvelope(args) {
141143 env . documents = [ doc ] ;
142144
143145 // Create a signer recipient to sign the document, identified by name and email
144- let signer = docusign . Signer . constructFromObject ( {
145- email : args . signerEmail ,
146- name : args . signerName ,
147- recipientId : 1 ,
148- } ) ;
146+ let signer = new docusign . Signer ( ) ;
147+ signer . email = args . signerEmail ;
148+ signer . name = args . signerName ;
149+ signer . recipientId = '1' ;
150+ signer . routingOrder = '1' ;
149151
150152 // Create signHere fields (also known as tabs) on the documents,
151153 // We're using anchor (autoPlace) positioning
152154 //
153155 // The DocuSign platform seaches throughout your envelope's
154156 // documents for matching anchor strings.
155- let signHere = docusign . SignHere . constructFromObject ( {
156- anchorString : '/sn1/' ,
157- anchorYOffset : '10' ,
158- anchorUnits : 'pixels' ,
159- anchorXOffset : '20' ,
160- } ) ;
157+ let signHere = new docusign . SignHere ( ) ;
158+ signHere . anchorString = '/sn1/' ;
159+ signHere . anchorYOffset = '10' ;
160+ signHere . anchorUnits = 'pixels' ;
161+ signHere . anchorXOffset = '20' ;
162+
163+ let textTabs = [ ] ;
164+ for ( const tab of args . app . tabs . filter ( t => ! t . tabLabel . includes ( 'SuggestionInput' ) ) ) {
165+ const verificationData = extractVerificationData ( args . appId , tab ) ;
166+ const textTab = makeTextTab ( verificationData , textTabs . length ) ;
167+
168+ textTabs . push ( textTab ) ;
169+ }
161170
162- const extensionData = {
163- extensionGroupId : args . verificationData . extensionGroupId ,
164- publisherName : args . verificationData . publisherName ,
165- applicationId : args . verificationData . appId ,
166- applicationName : args . verificationData . applicationName ,
167- actionName : args . verificationData . actionName ,
168- actionContract : args . verificationData . actionContract ,
169- extensionName : args . verificationData . extensionName ,
170- extensionContract : args . verificationData . extensionContract ,
171- requiredForExtension : args . verificationData . requiredForExtension ,
172- actionInputKey : args . verificationData . actionInputKey ,
173- extensionPolicy : 'None' ,
174- connectionInstances : [
175- {
176- connectionKey : args . verificationData . connectionKey ,
177- connectionValue : args . verificationData . connectionValue ,
178- }
179- ]
180- } ;
181- let textTab = docusign . Text . constructFromObject ( {
182- requireInitialOnSharedChange : false ,
183- requireAll : false ,
184- name : args . verificationData . applicationName ,
185- required : true ,
186- locked : false ,
187- disableAutoSize : false ,
188- maxLength : 4000 ,
189- tabLabel : args . verificationData . tabLabel ,
190- font : 'lucidaconsole' ,
191- fontColor : 'black' ,
192- fontSize : 'size9' ,
193- documentId : '1' ,
194- recipientId : '1' ,
195- pageNumber : '1' ,
196- xPosition : '273' ,
197- yPosition : '191' ,
198- width : '84' ,
199- height : '22' ,
200- templateRequired : false ,
201- tabType : 'text' ,
202- } ) ;
203171 // Tabs are set per recipient / signer
204- let signerTabs = docusign . Tabs . constructFromObject ( {
205- signHereTabs : [ signHere ] ,
206- textTabs : [ textTab ]
207- } ) ;
172+ let signerTabs = new docusign . Tabs ( ) ;
173+ signerTabs . signHereTabs = [ signHere ] ;
174+ signerTabs . textTabs = textTabs ;
175+
208176 signer . tabs = signerTabs ;
209177
210178 // Add the recipient to the envelope object
211- let recipients = docusign . Recipients . constructFromObject ( {
212- signers : [ signer ] ,
213- } ) ;
214- recipients . signers [ 0 ] . tabs . textTabs [ 0 ] . extensionData = extensionData ;
179+ let recipients = new docusign . Recipients ( ) ;
180+ recipients . signers = [ signer ] ;
181+
215182 env . recipients = recipients ;
216183
217184 // Request that the envelope be sent by setting |status| to "sent".
@@ -220,6 +187,51 @@ function makeEnvelope(args) {
220187
221188 return env ;
222189}
190+
191+ const getExtensionData = ( verificationData ) => ( {
192+ extensionGroupId : verificationData . extensionGroupId ,
193+ publisherName : verificationData . publisherName ,
194+ applicationId : verificationData . appId ,
195+ applicationName : verificationData . applicationName ,
196+ actionName : verificationData . actionName ,
197+ actionContract : verificationData . actionContract ,
198+ extensionName : verificationData . extensionName ,
199+ extensionContract : verificationData . extensionContract ,
200+ requiredForExtension : verificationData . requiredForExtension ,
201+ actionInputKey : verificationData . actionInputKey ,
202+ extensionPolicy : 'MustVerifyToSign' ,
203+ connectionInstances : [
204+ {
205+ connectionKey : verificationData . connectionKey ,
206+ connectionValue : verificationData . connectionValue ,
207+ } ,
208+ ] ,
209+ } ) ;
210+
211+ const makeTextTab = ( verificationData , textTabsCount ) => ( {
212+ requireInitialOnSharedChange : false ,
213+ requireAll : false ,
214+ name : verificationData . applicationName ,
215+ required : true ,
216+ locked : false ,
217+ disableAutoSize : false ,
218+ maxLength : 4000 ,
219+ tabLabel : verificationData . tabLabel ,
220+ font : 'lucidaconsole' ,
221+ fontColor : 'black' ,
222+ fontSize : 'size9' ,
223+ documentId : '1' ,
224+ recipientId : '1' ,
225+ pageNumber : '1' ,
226+ xPosition : `${ 70 + 100 * Math . floor ( textTabsCount / 10 ) } ` ,
227+ yPosition : `${ 560 + 20 * ( textTabsCount % 10 ) } ` ,
228+ width : '84' ,
229+ height : '22' ,
230+ templateRequired : false ,
231+ tabType : 'text' ,
232+ tooltip : verificationData . actionInputKey ,
233+ extensionData : getExtensionData ( verificationData )
234+ } ) ;
223235//ds-snippet-end:ConnectedFields1Step5
224236
225237module . exports = { getTabGroups, sendEnvelope, extractVerificationData } ;
0 commit comments