@verdocs/js-sdk 6.1.1 → 6.2.0-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1610,13 +1610,13 @@ const getEnvelope = async (endpoint, envelopeId) => endpoint.api //
1610
1610
  * @apiParam string(format: 'uuid') document_id The ID of the document to retrieve.
1611
1611
  * @apiSuccess IEnvelopeDocument . The detailed metadata for the document requested
1612
1612
  */
1613
- const getEnvelopeDocument = async (endpoint, _envelopeId, documentId) => endpoint.api //
1613
+ const getEnvelopeDocument = async (endpoint, documentId) => endpoint.api //
1614
1614
  .get(`/v2/envelope-documents/${documentId}`)
1615
1615
  .then((r) => r.data);
1616
1616
  /**
1617
1617
  * Download a document directly.
1618
1618
  */
1619
- const downloadDocument = async (endpoint, _envelopeId, documentId) => endpoint.api //
1619
+ const downloadEnvelopeDocument = async (endpoint, documentId) => endpoint.api //
1620
1620
  .get(`/v2/envelope-documents/${documentId}?type=file`, { responseType: 'blob' })
1621
1621
  .then((r) => r.data);
1622
1622
  /**
@@ -1632,14 +1632,14 @@ const downloadDocument = async (endpoint, _envelopeId, documentId) => endpoint.a
1632
1632
  * @apiQuery string(enum:'file'|'download'|'preview') type? Download the file directly, generate a download link, or generate a preview link.
1633
1633
  * @apiSuccess string . The generated link.
1634
1634
  */
1635
- const getDocumentDownloadLink = async (endpoint, _envelopeId, documentId) => endpoint.api //
1635
+ const getEnvelopeDocumentDownloadLink = async (endpoint, documentId) => endpoint.api //
1636
1636
  .get(`/v2/envelope-documents/${documentId}?type=download`)
1637
1637
  .then((r) => r.data);
1638
1638
  /**
1639
1639
  * Get a pre-signed preview link for an Envelope Document. This link expires quickly, so it should
1640
1640
  * be accessed immediately and never shared. Content-Disposition will be set to "inline".
1641
1641
  */
1642
- const getDocumentPreviewLink = async (endpoint, _envelopeId, documentId) => endpoint.api //
1642
+ const getEnvelopeDocumentPreviewLink = async (endpoint, documentId) => endpoint.api //
1643
1643
  .get(`/v2/envelope-documents/${documentId}?type=preview`)
1644
1644
  .then((r) => r.data);
1645
1645
  /**
@@ -1661,7 +1661,7 @@ const cancelEnvelope = async (endpoint, envelopeId) => endpoint.api //
1661
1661
  *
1662
1662
  * @deprecated Use getDocumentPreviewLink/getDocumentDownloadLink/downloadDocument instead.
1663
1663
  */
1664
- const getEnvelopeFile = async (endpoint, envelopeId, documentId) => endpoint.api //
1664
+ const getEnvelopeFile = async (endpoint, documentId) => endpoint.api //
1665
1665
  .get(`/v2/envelope-documents/${documentId}?type=file`, { responseType: 'blob' })
1666
1666
  .then((r) => r.data);
1667
1667
  /**
@@ -1680,60 +1680,25 @@ const updateEnvelope = async (endpoint, envelopeId, params) => endpoint.api //
1680
1680
  * Update a Document field. Typically called during the signing process as a Recipient fills in fields.
1681
1681
  *
1682
1682
  * @group Envelopes
1683
- * @api PUT /envelopes/:envelope_id/fields/:field_name Update Envelope Field
1683
+ * @api PUT /v2/envelopes/:envelope_id/fields/:field_name Update Envelope Field
1684
1684
  * @apiParam string(format: 'uuid') envelope_id The ID of the envelope to retrieve.
1685
+ * @apiParam string role_name The role to submit. Be sure to URL-encode the value.
1685
1686
  * @apiParam string field_name The name of the field to update. Be sure to URL-encode the value.
1686
- * @apiBody IEnvelopeFieldSettings . Set of properties to update. Leave undefined any properties that should not be changed.
1687
- * @apiSuccess IEnvelope . A copy of the newly-updated field.
1687
+ * @apiParam string value The value to set. For signature/initial fields, the UUID of the signature/initial block. For attachment fields, a file uploaded in a FORM-POST field named "document". For checkbox/radio buttons, a boolean. For all other fields, a string.
1688
+ * @apiBody value . Value to set.
1689
+ * @apiSuccess IEnvelopeField . A copy of the newly-updated field.
1688
1690
  */
1689
- const updateEnvelopeField = async (endpoint, envelopeId, fieldName, value) => endpoint.api //
1690
- .put(`/envelopes/${envelopeId}/fields/${fieldName}`, value)
1691
+ const updateEnvelopeField = async (endpoint, envelopeId, roleName, fieldName, value) => endpoint.api //
1692
+ .put(`/v2/envelopes/${envelopeId}/recipients/${roleName}/fields/${fieldName}`, { value })
1691
1693
  .then((r) => r.data);
1692
1694
  /**
1693
- * Apply a signature to a signature field. Signature fields are ID-driven. Call `createSignature()`
1694
- * first to create a signature for a Recipient, then call `updateEnvelopeFieldSignature()` to
1695
- * attach it to a field.
1696
- *
1697
- * @group Envelopes
1698
- * @api PUT /envelopes/:envelope_id/fields/:field_name/signature/:signature_id Update Envelope
1699
- * @apiParam string(format: 'uuid') envelope_id The ID of the envelope to update.
1700
- * @apiParam string field_name The name of the field to update. Be sure to URL-encode the value.
1701
- * @apiParam string(format: 'uuid') signature_id The ID of the signature to attach.
1702
- * @apiSuccess IEnvelopeFieldSettings . A copy of the newly-updated field.
1695
+ * Upload an attachment to an attachment field.
1703
1696
  */
1704
- const updateEnvelopeFieldSignature = async (endpoint, envelopeId, fieldName, signatureId) => endpoint.api //
1705
- .put(`/envelopes/${envelopeId}/fields/${fieldName}/signature/${signatureId}`)
1706
- .then((r) => r.data);
1707
- /**
1708
- * Apply an initial to an initials field. Initial fields are ID-driven. Call `createInitial()`
1709
- * first to create an initial block for a Recipient, then call `supdateEnvelopeFieldInitials()` to
1710
- * attach it to a field.
1711
- *
1712
- * @group Envelopes
1713
- * @api PUT /envelopes/:envelope_id/fields/:field_name/initial/:initial_id Update Envelope
1714
- * @apiParam string(format: 'uuid') envelope_id The ID of the envelope to update.
1715
- * @apiParam string field_name The name of the field to update. Be sure to URL-encode the value.
1716
- * @apiParam string(format: 'uuid') initial_id The ID of the initial block to attach.
1717
- * @apiSuccess IEnvelopeFieldSettings . A copy of the newly-updated field.
1718
- */
1719
- const updateEnvelopeFieldInitials = async (endpoint, envelopeId, fieldName, initialId) => endpoint.api //
1720
- .put(`/envelopes/${envelopeId}/fields/${fieldName}/initial/${initialId}`)
1721
- .then((r) => r.data);
1722
- /**
1723
- * Upload an attachment to an attachment field
1724
- *
1725
- * @group Envelopes
1726
- * @api PUT /envelopes/:envelope_id/fields/:field_name Upload or Delete Attachment
1727
- * @apiParam string(format: 'uuid') envelope_id The ID of the envelope to update.
1728
- * @apiParam string field_name The name of the field to update. Be sure to URL-encode the value.
1729
- * @apiBody string document The file to attach. Must contain standard File object fields. If omitted, the attachment will be deleted instead.
1730
- * @apiSuccess IEnvelopeFieldSettings . A copy of the newly-updated field.
1731
- */
1732
- const uploadEnvelopeFieldAttachment = async (endpoint, envelopeId, fieldName, file, onUploadProgress) => {
1697
+ const uploadEnvelopeFieldAttachment = async (endpoint, envelopeId, roleName, fieldName, file, onUploadProgress) => {
1733
1698
  const formData = new FormData();
1734
1699
  formData.append('document', file, file.name);
1735
1700
  return endpoint.api //
1736
- .put(`/envelopes/${envelopeId}/fields/${fieldName}`, formData, {
1701
+ .put(`/v2/envelopes/${envelopeId}/recipients/${roleName}/fields/${fieldName}`, formData, {
1737
1702
  timeout: 120000,
1738
1703
  onUploadProgress: (event) => {
1739
1704
  const total = event.total || 1;
@@ -1748,25 +1713,13 @@ const uploadEnvelopeFieldAttachment = async (endpoint, envelopeId, fieldName, fi
1748
1713
  * being deleted. Instead, it is a similar operation to uploading a new attachment, but the
1749
1714
  * omission of the attachment signals the server to delete the current entry.
1750
1715
  */
1751
- const deleteEnvelopeFieldAttachment = async (endpoint, envelopeId, fieldName) => {
1716
+ const deleteEnvelopeFieldAttachment = async (endpoint, envelopeId, roleName, fieldName) => {
1752
1717
  const formData = new FormData();
1753
1718
  // Omitting file is the trigger here
1754
1719
  return endpoint.api //
1755
- .put(`/envelopes/${envelopeId}/fields/${fieldName}`, formData)
1720
+ .put(`/v2/envelopes/${envelopeId}/recipients/${roleName}/fields/${fieldName}`, formData)
1756
1721
  .then((r) => r.data);
1757
1722
  };
1758
- /**
1759
- * Get the attached file for an attachment field (if any).
1760
- *
1761
- * @group Envelopes
1762
- * @api GET /envelopes/:envelope_id/fields/:field_name/document Download attachment in binary format
1763
- * @apiParam string(format: 'uuid') envelope_id The ID of the envelope to retrieve.
1764
- * @apiParam string field_name The name of the field from which to download the attachment.
1765
- * @apiSuccess string . The file binary data.
1766
- */
1767
- const getFieldAttachment = async (endpoint, envelopeId, fieldName) => endpoint.api //
1768
- .get(`/envelopes/${envelopeId}/fields/${fieldName}/document`, { responseType: 'blob' })
1769
- .then((r) => r.data);
1770
1723
  /**
1771
1724
  * Get a display URI for a given page in a file attached to an envelope document. These pages are rendered server-side
1772
1725
  * into PNG resources suitable for display in IMG tags although they may be used elsewhere. Note that these are intended
@@ -1810,12 +1763,18 @@ const getEnvelopeDocumentPageDisplayUri = async (endpoint, documentId, page, var
1810
1763
  const getEnvelopes = (endpoint, params) => endpoint.api //
1811
1764
  .get('/v2/envelopes', { params })
1812
1765
  .then((r) => r.data);
1766
+ /**
1767
+ * Generate a ZIP file containing all data for the specified envelopes. The caller must be the
1768
+ * owner of each envelope. The returned ZIP file contains a folder for each envelope.
1769
+ */
1770
+ const getEnvelopesZip = (endpoint, envelope_ids) => endpoint.api //
1771
+ .get(`/v2/envelopes/zip/${envelope_ids.join(',')}`);
1813
1772
 
1814
1773
  /**
1815
- * Create an initials block. In a typical signing workflow, the user is asked at the beginning of the process to "adopt"
1816
- * an initials block to be used for all initials fields in the document. Thus, this is typically called one time to
1817
- * create and store an initials block. Thereafter, the ID of the initials block may be re-used for each initials field
1818
- * to be "stamped" by the user.
1774
+ * Create an initials block. In a typical signing workflow, the user is asked at the beginning of the process to
1775
+ * "adopt" an initials block to be used for all initials fields in the document. Thus, this is typically called
1776
+ * one time to create and store an initials block. Thereafter, the ID of the initials block may be re-used for each
1777
+ * initials field to be "stamped" by the user.
1819
1778
  *
1820
1779
  * Note: Both "guest" signers and authenticated users can create initials blocks. Guest signers
1821
1780
  * typically only ever have one, tied to that session. But authenticated users can create more than
@@ -1865,49 +1824,43 @@ const submitKbaChallengeResponse = (endpoint, envelope_id, role_name, responses)
1865
1824
  .then((r) => r.data);
1866
1825
 
1867
1826
  /**
1868
- * Update a recipient's status.
1827
+ * Agree to electronic signing dislosures.
1869
1828
  *
1870
1829
  * @group Recipients
1871
- * @api PUT /envelopes/:envelope_id/recipients/:role_name Update Recipient Status
1830
+ * @api POST /envelopes/:envelope_id/recipients/:role_name/agree Agree to e-Signing Disclosures
1872
1831
  * @apiParam string(format:uuid) envelope_id The envelope to operate on.
1873
- * @apiParam string role_name The role to adjust.
1874
- * @apiBody string(enum:'submit'|'decline'|'owner_update'|'update'|'prepare') action The action to take. Adjusts the status, and may also perform other operations.
1875
- * @apiBody string first_name? Ignored unless action is 'owner_update' or 'update'. The new owner's or recipient's first name.
1876
- * @apiBody string last_name? Ignored unless action is 'owner_update' or 'update'. The new owner's or recipient's last name.
1877
- * @apiBody string email? Ignored unless action is 'owner_update'. The new owner's email address.
1878
- * @apiBody boolean agreed? Ignored unless action is 'update'. Set to true to accept the e-signing disclosures.
1879
- * @apiBody array(items:IRecipient) recipients? Ignored unless action is 'prepare'. A list of recipients and their fields to set defaults for.
1832
+ * @apiParam string role_name The role to operate on.
1880
1833
  * @apiSuccess IRecipient . The updated Recipient.
1881
1834
  */
1882
- const updateRecipientStatus = async (endpoint, envelope_id, role_name, params) => endpoint.api //
1883
- .put(`/envelopes/${envelope_id}/recipients/${role_name}`, params)
1884
- .then((r) => r.data);
1885
- /**
1886
- * Submit an envelope (signing is finished). Note that all fields must be valid/completed for this to succeed.
1887
- */
1888
- const envelopeRecipientSubmit = (endpoint, envelopeId, roleName) => updateRecipientStatus(endpoint, envelopeId, roleName, { action: 'submit' });
1889
- /**
1890
- * Decline to complete an envelope (signing will not terminated).
1891
- */
1892
- const envelopeRecipientDecline = (endpoint, envelopeId, roleName) => updateRecipientStatus(endpoint, envelopeId, roleName, { action: 'decline' });
1893
- /**
1894
- * Claim / change ownership of an envelope. This is a special-case operation only available in certain workflows.
1895
- */
1896
- const envelopeRecipientChangeOwner = (endpoint, envelope_id, role_name, email, first_name, last_name) => updateRecipientStatus(endpoint, envelope_id, role_name, { action: 'owner_update', email, first_name, last_name });
1897
- /**
1898
- * Agree to electronic signing disclosures.
1899
- */
1900
1835
  const envelopeRecipientAgree = (endpoint, envelopeId, roleName, disclosures) => endpoint.api //
1901
- .put(`/v2/envelopes/${envelopeId}/recipients/${encodeURIComponent(roleName)}`, { action: 'accept', disclosures })
1836
+ .post(`/v2/envelopes/${envelopeId}/recipients/${encodeURIComponent(roleName)}/agree`, { disclosures })
1902
1837
  .then((r) => r.data);
1903
1838
  /**
1904
- * Change a recipient's name.
1839
+ * Decline electronic signing dislosures. Note that if any recipient declines, the entire envelope
1840
+ * becomes non-viable and later recipients may no longer act. The creator will receive a notification
1841
+ * when this occurs.
1842
+ *
1843
+ * @group Recipients
1844
+ * @api POST /envelopes/:envelope_id/recipients/:role_name/decline Decline e-Signing Disclosures
1845
+ * @apiParam string(format:uuid) envelope_id The envelope to operate on.
1846
+ * @apiParam string role_name The role to adjust.
1847
+ * @apiSuccess IRecipient . The updated Recipient.
1905
1848
  */
1906
- const envelopeRecipientUpdateName = (endpoint, envelopeId, roleName, first_name, last_name) => updateRecipientStatus(endpoint, envelopeId, roleName, { action: 'update', first_name, last_name });
1849
+ const envelopeRecipientDecline = (endpoint, envelopeId, roleName) => endpoint.api //
1850
+ .post(`/v2/envelopes/${envelopeId}/recipients/${encodeURIComponent(roleName)}/decline`)
1851
+ .then((r) => r.data);
1907
1852
  /**
1908
- * Change a recipient's name.
1853
+ * Submit an envelope (signing is finished). Note that all fields must be valid/completed for this to succeed.
1854
+ *
1855
+ * @group Recipients
1856
+ * @api POST /envelopes/:envelope_id/recipients/:role_name/submit Submit envelope
1857
+ * @apiParam string(format:uuid) envelope_id The envelope to operate on.
1858
+ * @apiParam string role_name The role to submit.
1859
+ * @apiSuccess IRecipient . The updated Recipient.
1909
1860
  */
1910
- const envelopeRecipientPrepare = (endpoint, envelopeId, roleName, recipients) => updateRecipientStatus(endpoint, envelopeId, roleName, { action: 'prepare', recipients });
1861
+ const envelopeRecipientSubmit = (endpoint, envelopeId, roleName) => endpoint.api //
1862
+ .put(`/v2/envelopes/${envelopeId}/recipients/${roleName}/submit`)
1863
+ .then((r) => r.data);
1911
1864
  /**
1912
1865
  * Begin a signing session for an Envelope. This path requires an invite code, and should generally
1913
1866
  * be called with a NON-default Endpoint to avoid conflicting with any active user session the user
@@ -2101,7 +2054,7 @@ const recipientHasAction = (recipient) => !['submitted', 'canceled', 'declined']
2101
2054
  /**
2102
2055
  * Returns the recipients who still have a pending action. Note that not all of these recipients may be able to act (yet).
2103
2056
  */
2104
- const getRecipientsWithActions = (envelope) => (envelope?.recipients || []).filter(recipientHasAction);
2057
+ const getRecipientsWithActions = (envelope) => ['complete', 'declined', 'canceled'].includes(envelope.status) ? [] : (envelope?.recipients || []).filter(recipientHasAction);
2105
2058
  /**
2106
2059
  * Returns true if the recipient can act.
2107
2060
  */
@@ -2133,10 +2086,10 @@ const getNextRecipient = (envelope) => {
2133
2086
  };
2134
2087
 
2135
2088
  /**
2136
- * Create a signature block. In a typical signing workflow, the user is asked at the beginning of the process to "adopt"
2137
- * a signature block to be used for all signature fields in the document. Thus, this is typically called one time to
2138
- * create and store a signature block. Thereafter, the ID of the signature block may be re-used for each signature field
2139
- * to be "stamped" by the user.
2089
+ * Create a signature block. In a typical signing workflow, the user is asked at the beginning of the process to
2090
+ * "adopt" a signature block to be used for all signature fields in the document. Thus, this is typically called one
2091
+ * time to create and store a signature block. Thereafter, the ID of the signature block may be re-used for each
2092
+ * signature field to be "stamped" by the user.
2140
2093
  *
2141
2094
  * Note: Both "guest" signers and authenticated users can create initials blocks. Guest signers
2142
2095
  * typically only ever have one, tied to that session. But authenticated users can create more than
@@ -2154,39 +2107,6 @@ const createSignature = (endpoint, name, signature) => {
2154
2107
  .post(`/v2/profiles/signatures`, data)
2155
2108
  .then((r) => r.data);
2156
2109
  };
2157
- /**
2158
- * Get the available signatures for a user.
2159
- *
2160
- * @group Signatures and Initials
2161
- * @api GET /signatures Create Signature Block
2162
- *
2163
- * @apiSuccess array(items:ISignature) . A list of signatures previously stored for the user.
2164
- */
2165
- const getSignatures = (endpoint) => endpoint.api //
2166
- .get('/signatures')
2167
- .then((r) => r.data);
2168
- /**
2169
- * Get a user's signature by ID.
2170
- *
2171
- * @group Signatures and Initials
2172
- * @api GET /signatures/:id Delete Signature Block
2173
- * @apiParam string(format: 'uuid') id The ID of the signature to delete.
2174
- * @apiSuccess ISignature . The signature metadata requested.
2175
- */
2176
- const getSignature = (endpoint, signatureId) => endpoint.api //
2177
- .get(`/signatures/${signatureId}`)
2178
- .then((r) => r.data);
2179
- /**
2180
- * Delete a user's signature.
2181
- *
2182
- * @group Signatures and Initials
2183
- * @api DELETE /signatures/:id Delete Signature Block
2184
- * @apiParam string(format: 'uuid') id The ID of the signature to delete.
2185
- * @apiSuccess string . OK
2186
- */
2187
- const deleteSignature = (endpoint, signatureId) => endpoint.api //
2188
- .delete(`/signatures/${signatureId}`)
2189
- .then((r) => r.data);
2190
2110
 
2191
2111
  /**
2192
2112
  * API keys are used to authenticate server-to-server calls. (API keys should **never** be used for client-to-server operations!)
@@ -3308,63 +3228,6 @@ const deleteTemplateRole = (endpoint, template_id, name) => endpoint.api //
3308
3228
  .delete(`/v2/roles/${template_id}/${encodeURIComponent(name)}`)
3309
3229
  .then((r) => r.data);
3310
3230
 
3311
- /**
3312
- * Get the template stars for a template.
3313
- */
3314
- const getStars = (endpoint, templateId) => endpoint.api //
3315
- .get(`/templates/${templateId}/stars`)
3316
- .then((r) => r.data);
3317
- /**
3318
- * Toggle the template star for a template.
3319
- */
3320
- const toggleStar = (endpoint, templateId) => endpoint.api //
3321
- .post(`/templates/${templateId}/stars/toggle`)
3322
- .then((r) => r.data);
3323
-
3324
- /**
3325
- * A Tag is a user-specified label applied to a template. Tags help users organize and find Templates.
3326
- * recipients. Every Organization has a set of tags "owned" by that Organization and only visible inside it.
3327
- * Verdocs also provides a set of system-wide "featured" tags available to all Organizations.
3328
- *
3329
- * @module
3330
- */
3331
- /**
3332
- * Apply a tag to a template.
3333
- */
3334
- const addTemplateTag = (endpoint, templateId, params) => endpoint.api //
3335
- .post(`/templates/${templateId}/tags/`, params)
3336
- .then((r) => r.data);
3337
- /**
3338
- * Get all tags for a template.
3339
- */
3340
- const getTemplateTags = (endpoint, templateId) => endpoint.api //
3341
- .get(`/templates/${templateId}/tags/`)
3342
- .then((r) => r.data);
3343
- /**
3344
- * Remove a tag from a template.
3345
- */
3346
- const deleteTemplateTag = (endpoint, templateId, tagName) => endpoint.api //
3347
- .post(`/templates/${templateId}/tags/${tagName}`)
3348
- .then((r) => r.data);
3349
- /**
3350
- * Create an Organization-wide tag.
3351
- */
3352
- const createTag = (endpoint, name) => endpoint.api //
3353
- .post('/tags', { tag_name: name })
3354
- .then((r) => r.data);
3355
- /**
3356
- * Get an Organization-wide tag.
3357
- */
3358
- const getTag = (endpoint, name) => endpoint.api //
3359
- .get(`/tags/${name}`)
3360
- .then((r) => r.data);
3361
- /**
3362
- * Get all tags available for use by an Organization.
3363
- */
3364
- const getAllTags = (endpoint) => endpoint.api //
3365
- .get('/tags')
3366
- .then((r) => r.data);
3367
-
3368
3231
  /**
3369
3232
  * A Template defines how a Verdocs signing flow will be performed, including attachments, signing fields, and
3370
3233
  * recipients.
@@ -3580,44 +3443,28 @@ const updateTemplate = (endpoint, templateId, params) => endpoint.api //
3580
3443
  const deleteTemplate = (endpoint, templateId) => endpoint.api //
3581
3444
  .delete(`/v2/templates/${templateId}`)
3582
3445
  .then((r) => r.data);
3583
-
3584
- /**
3585
- * A TemplateDocument represents a PDF or other attachment in a Template.
3586
- *
3587
- * @module
3588
- */
3589
3446
  /**
3590
- * Get all the Template Documents associated to a particular Template.
3447
+ * Toggle the template star for a template.
3591
3448
  *
3592
3449
  * ```typescript
3593
- * import {TemplateDocument} from '@verdocs/js-sdk/Templates';
3450
+ * import {toggleTemplateStar} from '@verdocs/js-sdk/Templates';
3594
3451
  *
3595
- * await TemplateDocument.geTemplateDocuments((VerdocsEndpoint.getDefault(), templateId);
3452
+ * await toggleTemplateStar((VerdocsEndpoint.getDefault(), '83da3d70-7857-4392-b876-c4592a304bc9');
3596
3453
  * ```
3597
3454
  *
3598
- * @group Template Documents
3599
- * @api GET /v2/templates/:template_id/documents List the documents assigned to a template
3600
- * @apiSuccess array(items: ITemplateDocument) . Template documents
3455
+ * @group Templates
3456
+ * @api POST /v2/templates/:template_id/star Star or unstar a template (toggle state)
3457
+ * @apiSuccess ITemplate . Success
3601
3458
  */
3602
- const getTemplateDocuments = (endpoint, templateId) => endpoint.api //
3603
- .get(`/templates/${templateId}/documents/`)
3459
+ const toggleTemplateStar = (endpoint, templateId) => endpoint.api //
3460
+ .post(`/v2/templates/${templateId}/stars/toggle`)
3604
3461
  .then((r) => r.data);
3462
+
3605
3463
  /**
3606
- * Get a specific Document.
3607
- *
3608
- * ```typescript
3609
- * import {TemplateDocument} from '@verdocs/js-sdk/Templates';
3610
- *
3611
- * await TemplateDocument.geTemplateDocument((VerdocsEndpoint.getDefault(), templateId,documentId);
3612
- * ```
3464
+ * A TemplateDocument represents a PDF or other attachment in a Template.
3613
3465
  *
3614
- * @group Template Documents
3615
- * @api GET /v2/templates/:template_id/documents/:document_id Get an individual template document
3616
- * @apiSuccess ITemplateDocument . Template document
3466
+ * @module
3617
3467
  */
3618
- const getTemplateDocument = (endpoint, templateId, documentId) => endpoint.api //
3619
- .get(`/templates/${templateId}/documents/${documentId}`)
3620
- .then((r) => r.data);
3621
3468
  /**
3622
3469
  * Create a Document for a particular Template.
3623
3470
  *
@@ -3632,11 +3479,11 @@ const getTemplateDocument = (endpoint, templateId, documentId) => endpoint.api /
3632
3479
  * @apiBody string(format:binary) file Document file to attach. The file name will automatically be used as the document name.
3633
3480
  * @apiSuccess ITemplateDocument . Template document
3634
3481
  */
3635
- const createTemplateDocument = (endpoint, templateId, file, onUploadProgress) => {
3482
+ const createTemplateDocument = (endpoint, file, onUploadProgress) => {
3636
3483
  const formData = new FormData();
3637
3484
  formData.append('document', file, file.name);
3638
3485
  return endpoint.api //
3639
- .post(`/templates/${templateId}/documents`, formData, {
3486
+ .post(`/v2/template-documents`, formData, {
3640
3487
  timeout: 120000,
3641
3488
  onUploadProgress: (event) => {
3642
3489
  const total = event.total || 1;
@@ -3660,7 +3507,48 @@ const createTemplateDocument = (endpoint, templateId, file, onUploadProgress) =>
3660
3507
  * @apiSuccess string . Success
3661
3508
  */
3662
3509
  const deleteTemplateDocument = (endpoint, templateId, documentId) => endpoint.api //
3663
- .delete(`/templates/${templateId}/documents/${documentId}`)
3510
+ .delete(`/v2/templates/${templateId}/documents/${documentId}`)
3511
+ .then((r) => r.data);
3512
+ /**
3513
+ * Get all metadata for a template document. Note that when called by non-creators (e.g. Org Collaborators)
3514
+ * this will return only the **metadata** the caller is allowed to view.
3515
+ *
3516
+ * @group Template Documents
3517
+ * @api GET /v2/envelope-documents/:id Get envelope document
3518
+ * @apiParam string(format: 'uuid') document_id The ID of the document to retrieve.
3519
+ * @apiSuccess IEnvelopeDocument . The detailed metadata for the document requested
3520
+ */
3521
+ const getTemplateDocument = async (endpoint, documentId) => endpoint.api //
3522
+ .get(`/v2/template-documents/${documentId}`)
3523
+ .then((r) => r.data);
3524
+ /**
3525
+ * Download a document directly.
3526
+ */
3527
+ const downloadTemplateDocument = async (endpoint, documentId) => endpoint.api //
3528
+ .get(`/v2/template-documents/${documentId}?type=file`, { responseType: 'blob' })
3529
+ .then((r) => r.data);
3530
+ /**
3531
+ * Get an envelope document's metadata, or the document itself. If no "type" parameter is specified,
3532
+ * the document metadata is returned. If "type" is set to "file", the document binary content is
3533
+ * returned with Content-Type set to the MIME type of the file. If "type" is set to "download", a
3534
+ * string download link will be returned. If "type" is set to "preview" a string preview link will
3535
+ * be returned. This link expires quickly, so it should be accessed immediately and never shared.
3536
+ *
3537
+ * @group Template Documents
3538
+ * @api GET /v2/envelope-documents/:document_id Preview, Download, or Link to a Document
3539
+ * @apiParam string(format: 'uuid') document_id The ID of the document to retrieve.
3540
+ * @apiQuery string(enum:'file'|'download'|'preview') type? Download the file directly, generate a download link, or generate a preview link.
3541
+ * @apiSuccess string . The generated link.
3542
+ */
3543
+ const getTemplateDocumentDownloadLink = async (endpoint, _envelopeId, documentId) => endpoint.api //
3544
+ .get(`/v2/template-documents/${documentId}?type=download`)
3545
+ .then((r) => r.data);
3546
+ /**
3547
+ * Get a pre-signed preview link for an Envelope Document. This link expires quickly, so it should
3548
+ * be accessed immediately and never shared. Content-Disposition will be set to "inline".
3549
+ */
3550
+ const getTemplateDocumentPreviewLink = async (endpoint, _envelopeId, documentId) => endpoint.api //
3551
+ .get(`/v2/envelope-documents/${documentId}?type=preview`)
3664
3552
  .then((r) => r.data);
3665
3553
  /**
3666
3554
  * Get (binary download) a file attached to a Template. It is important to use this method
@@ -3668,7 +3556,7 @@ const deleteTemplateDocument = (endpoint, templateId, documentId) => endpoint.ap
3668
3556
  * request.
3669
3557
  */
3670
3558
  const getTemplateDocumentFile = async (endpoint, templateId, documentId) => endpoint.api //
3671
- .get(`/templates/${templateId}/documents/${documentId}?file=true`, { responseType: 'blob' })
3559
+ .get(`/v2/templates/${templateId}/documents/${documentId}?file=true`, { responseType: 'blob' })
3672
3560
  .then((r) => r.data);
3673
3561
  /**
3674
3562
  * Get (binary download) a file attached to a Template. It is important to use this method
@@ -3676,7 +3564,7 @@ const getTemplateDocumentFile = async (endpoint, templateId, documentId) => endp
3676
3564
  * request.
3677
3565
  */
3678
3566
  const getTemplateDocumentThumbnail = async (endpoint, templateId, documentId) => endpoint.api //
3679
- .get(`/templates/${templateId}/documents/${documentId}?thumbnail=true`, { responseType: 'blob' })
3567
+ .get(`/v2/templates/${templateId}/documents/${documentId}?thumbnail=true`, { responseType: 'blob' })
3680
3568
  .then((r) => r.data);
3681
3569
  /**
3682
3570
  * Get a display URI for a given page in a file attached to a template document. These pages are rendered server-side
@@ -3686,25 +3574,30 @@ const getTemplateDocumentThumbnail = async (endpoint, templateId, documentId) =>
3686
3574
  */
3687
3575
  const getTemplateDocumentPageDisplayUri = async (endpoint, documentId, page, variant = 'original') => endpoint.api.get(`/v2/template-documents/page-image/${documentId}/${variant}/${page}`, { timeout: 20000 }).then((r) => r.data);
3688
3576
 
3689
- /**
3690
- * Get all defined validators
3691
- *
3692
- * ```typescript
3693
- * import {Documents} from '@verdocs/js-sdk/Templates';
3694
- *
3695
- * await Documents.getDocuments(templateID);
3696
- * ```
3697
- */
3698
- const getValidators = (endpoint) => endpoint.api //
3699
- .get('/validators')
3700
- .then((r) => r.data);
3701
- const getValidator = (endpoint, validatorName) => endpoint.api //
3702
- .get(`/validators/${validatorName}`)
3703
- .then((r) => r.data);
3704
3577
  const EMAIL_REGEX = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
3705
- const isValidEmail = (email) => !!email && EMAIL_REGEX.test(email);
3706
3578
  // @see https://www.regextester.com/1978
3707
3579
  const PHONE_REGEX = /((?:\+|00)[17](?: |\-)?|(?:\+|00)[1-9]\d{0,2}(?: |\-)?|(?:\+|00)1\-\d{3}(?: |\-)?)?(0\d|\([0-9]{3}\)|[1-9]{0,3})(?:((?: |\-)[0-9]{2}){4}|((?:[0-9]{2}){4})|((?: |\-)[0-9]{3}(?: |\-)[0-9]{4})|([0-9]{7}))/;
3580
+ const URL_REGEX = /https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)/;
3581
+ const POSTAL_CODE_REGEX = /^[A-Za-z0-9-\s]{3,10}$/;
3582
+ const NUMBER_REGEX = /^\d+$/;
3583
+ const DATE_REGEX = /^(\d{4}[-\/]\d{2}[-\/]\d{2})|(\d{2}[-\/]\d{2}[-\/]\d{4})$/;
3584
+ const VALIDATORS = {
3585
+ email: { regex: EMAIL_REGEX, label: 'Email Address' },
3586
+ phone: { regex: PHONE_REGEX, label: 'Phone Number' },
3587
+ url: { regex: URL_REGEX, label: 'URL' },
3588
+ postal_code: { regex: POSTAL_CODE_REGEX, label: 'Zip/Postal Code' },
3589
+ number: { regex: NUMBER_REGEX, label: 'Number' },
3590
+ date: { regex: DATE_REGEX, label: 'Date' },
3591
+ };
3592
+ const isValidInput = (value, validator) => Object.keys(VALIDATORS).includes(validator) && VALIDATORS[validator].regex.test(value);
3593
+ /**
3594
+ * Get a list of available validators for field inputs. Note that validators always check strings,
3595
+ * because that is all a user can enter in an HTML input field. Numeric-format validators should
3596
+ * perform any necessary conversions internally. Validators never throw - they just return a boolean.
3597
+ * indicating whether the value is valid.
3598
+ */
3599
+ const getValidators = () => Object.keys(VALIDATORS);
3600
+ const isValidEmail = (email) => !!email && EMAIL_REGEX.test(email);
3708
3601
  const isValidPhone = (phone) => !!phone && PHONE_REGEX.test(phone);
3709
3602
  const isValidRoleName = (value, roles) => roles.findIndex((role) => role.name === value) !== -1;
3710
3603
  const TagRegEx = /^[a-zA-Z0-9-]{0,32}$/;
@@ -3721,7 +3614,6 @@ exports.VerdocsEndpoint = VerdocsEndpoint;
3721
3614
  exports.WEBHOOK_EVENTS = WEBHOOK_EVENTS;
3722
3615
  exports.acceptOrganizationInvitation = acceptOrganizationInvitation;
3723
3616
  exports.addGroupMember = addGroupMember;
3724
- exports.addTemplateTag = addTemplateTag;
3725
3617
  exports.authenticate = authenticate;
3726
3618
  exports.blobToBase64 = blobToBase64;
3727
3619
  exports.canAccessEnvelope = canAccessEnvelope;
@@ -3741,7 +3633,6 @@ exports.createOrganizationContact = createOrganizationContact;
3741
3633
  exports.createOrganizationInvitation = createOrganizationInvitation;
3742
3634
  exports.createProfile = createProfile;
3743
3635
  exports.createSignature = createSignature;
3744
- exports.createTag = createTag;
3745
3636
  exports.createTemplate = createTemplate;
3746
3637
  exports.createTemplateDocument = createTemplateDocument;
3747
3638
  exports.createTemplateFromSharepoint = createTemplateFromSharepoint;
@@ -3760,41 +3651,36 @@ exports.deleteOrganizationContact = deleteOrganizationContact;
3760
3651
  exports.deleteOrganizationInvitation = deleteOrganizationInvitation;
3761
3652
  exports.deleteOrganizationMember = deleteOrganizationMember;
3762
3653
  exports.deleteProfile = deleteProfile;
3763
- exports.deleteSignature = deleteSignature;
3764
3654
  exports.deleteTemplate = deleteTemplate;
3765
3655
  exports.deleteTemplateDocument = deleteTemplateDocument;
3766
3656
  exports.deleteTemplateRole = deleteTemplateRole;
3767
- exports.deleteTemplateTag = deleteTemplateTag;
3768
3657
  exports.downloadBlob = downloadBlob;
3769
- exports.downloadDocument = downloadDocument;
3658
+ exports.downloadEnvelopeDocument = downloadEnvelopeDocument;
3659
+ exports.downloadTemplateDocument = downloadTemplateDocument;
3770
3660
  exports.duplicateTemplate = duplicateTemplate;
3771
3661
  exports.envelopeIsActive = envelopeIsActive;
3772
3662
  exports.envelopeIsComplete = envelopeIsComplete;
3773
3663
  exports.envelopeRecipientAgree = envelopeRecipientAgree;
3774
- exports.envelopeRecipientChangeOwner = envelopeRecipientChangeOwner;
3775
3664
  exports.envelopeRecipientDecline = envelopeRecipientDecline;
3776
- exports.envelopeRecipientPrepare = envelopeRecipientPrepare;
3777
3665
  exports.envelopeRecipientSubmit = envelopeRecipientSubmit;
3778
- exports.envelopeRecipientUpdateName = envelopeRecipientUpdateName;
3779
3666
  exports.fileToDataUrl = fileToDataUrl;
3780
3667
  exports.formatFullName = formatFullName;
3781
3668
  exports.formatInitials = formatInitials;
3782
3669
  exports.formatShortTimeAgo = formatShortTimeAgo;
3783
3670
  exports.fullNameToInitials = fullNameToInitials;
3784
3671
  exports.getActiveEntitlements = getActiveEntitlements;
3785
- exports.getAllTags = getAllTags;
3786
3672
  exports.getApiKeys = getApiKeys;
3787
3673
  exports.getCountryByCode = getCountryByCode;
3788
3674
  exports.getCurrentProfile = getCurrentProfile;
3789
- exports.getDocumentDownloadLink = getDocumentDownloadLink;
3790
- exports.getDocumentPreviewLink = getDocumentPreviewLink;
3791
3675
  exports.getEntitlements = getEntitlements;
3792
3676
  exports.getEnvelope = getEnvelope;
3793
3677
  exports.getEnvelopeDocument = getEnvelopeDocument;
3678
+ exports.getEnvelopeDocumentDownloadLink = getEnvelopeDocumentDownloadLink;
3794
3679
  exports.getEnvelopeDocumentPageDisplayUri = getEnvelopeDocumentPageDisplayUri;
3680
+ exports.getEnvelopeDocumentPreviewLink = getEnvelopeDocumentPreviewLink;
3795
3681
  exports.getEnvelopeFile = getEnvelopeFile;
3796
3682
  exports.getEnvelopes = getEnvelopes;
3797
- exports.getFieldAttachment = getFieldAttachment;
3683
+ exports.getEnvelopesZip = getEnvelopesZip;
3798
3684
  exports.getFieldsForRole = getFieldsForRole;
3799
3685
  exports.getGroup = getGroup;
3800
3686
  exports.getGroups = getGroups;
@@ -3820,19 +3706,14 @@ exports.getRTop = getRTop;
3820
3706
  exports.getRValue = getRValue;
3821
3707
  exports.getRecipientsWithActions = getRecipientsWithActions;
3822
3708
  exports.getRoleColor = getRoleColor;
3823
- exports.getSignature = getSignature;
3824
- exports.getSignatures = getSignatures;
3825
- exports.getStars = getStars;
3826
- exports.getTag = getTag;
3827
3709
  exports.getTemplate = getTemplate;
3828
3710
  exports.getTemplateDocument = getTemplateDocument;
3711
+ exports.getTemplateDocumentDownloadLink = getTemplateDocumentDownloadLink;
3829
3712
  exports.getTemplateDocumentFile = getTemplateDocumentFile;
3830
3713
  exports.getTemplateDocumentPageDisplayUri = getTemplateDocumentPageDisplayUri;
3714
+ exports.getTemplateDocumentPreviewLink = getTemplateDocumentPreviewLink;
3831
3715
  exports.getTemplateDocumentThumbnail = getTemplateDocumentThumbnail;
3832
- exports.getTemplateDocuments = getTemplateDocuments;
3833
- exports.getTemplateTags = getTemplateTags;
3834
3716
  exports.getTemplates = getTemplates;
3835
- exports.getValidator = getValidator;
3836
3717
  exports.getValidators = getValidators;
3837
3718
  exports.getWebhooks = getWebhooks;
3838
3719
  exports.hasRequiredPermissions = hasRequiredPermissions;
@@ -3848,6 +3729,7 @@ exports.isMartinique = isMartinique;
3848
3729
  exports.isMayotte = isMayotte;
3849
3730
  exports.isPuertoRico = isPuertoRico;
3850
3731
  exports.isValidEmail = isValidEmail;
3732
+ exports.isValidInput = isValidInput;
3851
3733
  exports.isValidPhone = isValidPhone;
3852
3734
  exports.isValidRoleName = isValidRoleName;
3853
3735
  exports.isValidTag = isValidTag;
@@ -3870,12 +3752,10 @@ exports.submitKbaChallengeResponse = submitKbaChallengeResponse;
3870
3752
  exports.submitKbaIdentity = submitKbaIdentity;
3871
3753
  exports.submitKbaPin = submitKbaPin;
3872
3754
  exports.switchProfile = switchProfile;
3873
- exports.toggleStar = toggleStar;
3755
+ exports.toggleTemplateStar = toggleTemplateStar;
3874
3756
  exports.updateApiKey = updateApiKey;
3875
3757
  exports.updateEnvelope = updateEnvelope;
3876
3758
  exports.updateEnvelopeField = updateEnvelopeField;
3877
- exports.updateEnvelopeFieldInitials = updateEnvelopeFieldInitials;
3878
- exports.updateEnvelopeFieldSignature = updateEnvelopeFieldSignature;
3879
3759
  exports.updateField = updateField;
3880
3760
  exports.updateGroup = updateGroup;
3881
3761
  exports.updateOrganization = updateOrganization;
@@ -3887,7 +3767,6 @@ exports.updateOrganizationThumbnail = updateOrganizationThumbnail;
3887
3767
  exports.updateProfile = updateProfile;
3888
3768
  exports.updateProfilePhoto = updateProfilePhoto;
3889
3769
  exports.updateRecipient = updateRecipient;
3890
- exports.updateRecipientStatus = updateRecipientStatus;
3891
3770
  exports.updateTemplate = updateTemplate;
3892
3771
  exports.updateTemplateRole = updateTemplateRole;
3893
3772
  exports.uploadEnvelopeFieldAttachment = uploadEnvelopeFieldAttachment;