@verdocs/js-sdk 6.1.0 → 6.2.0-beta.1

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.
1703
- */
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.
1695
+ * Upload an attachment to an attachment field.
1731
1696
  */
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
@@ -1812,10 +1765,10 @@ const getEnvelopes = (endpoint, params) => endpoint.api //
1812
1765
  .then((r) => r.data);
1813
1766
 
1814
1767
  /**
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.
1768
+ * Create an initials block. In a typical signing workflow, the user is asked at the beginning of the process to
1769
+ * "adopt" an initials block to be used for all initials fields in the document. Thus, this is typically called
1770
+ * one time to create and store an initials block. Thereafter, the ID of the initials block may be re-used for each
1771
+ * initials field to be "stamped" by the user.
1819
1772
  *
1820
1773
  * Note: Both "guest" signers and authenticated users can create initials blocks. Guest signers
1821
1774
  * typically only ever have one, tied to that session. But authenticated users can create more than
@@ -1865,49 +1818,43 @@ const submitKbaChallengeResponse = (endpoint, envelope_id, role_name, responses)
1865
1818
  .then((r) => r.data);
1866
1819
 
1867
1820
  /**
1868
- * Update a recipient's status.
1821
+ * Agree to electronic signing dislosures.
1869
1822
  *
1870
1823
  * @group Recipients
1871
- * @api PUT /envelopes/:envelope_id/recipients/:role_name Update Recipient Status
1824
+ * @api POST /envelopes/:envelope_id/recipients/:role_name/agree Agree to e-Signing Disclosures
1872
1825
  * @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.
1826
+ * @apiParam string role_name The role to operate on.
1880
1827
  * @apiSuccess IRecipient . The updated Recipient.
1881
1828
  */
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
1829
  const envelopeRecipientAgree = (endpoint, envelopeId, roleName, disclosures) => endpoint.api //
1901
- .put(`/v2/envelopes/${envelopeId}/recipients/${encodeURIComponent(roleName)}`, { action: 'accept', disclosures })
1830
+ .post(`/v2/envelopes/${envelopeId}/recipients/${encodeURIComponent(roleName)}/agree`, { disclosures })
1902
1831
  .then((r) => r.data);
1903
1832
  /**
1904
- * Change a recipient's name.
1833
+ * Decline electronic signing dislosures. Note that if any recipient declines, the entire envelope
1834
+ * becomes non-viable and later recipients may no longer act. The creator will receive a notification
1835
+ * when this occurs.
1836
+ *
1837
+ * @group Recipients
1838
+ * @api POST /envelopes/:envelope_id/recipients/:role_name/decline Decline e-Signing Disclosures
1839
+ * @apiParam string(format:uuid) envelope_id The envelope to operate on.
1840
+ * @apiParam string role_name The role to adjust.
1841
+ * @apiSuccess IRecipient . The updated Recipient.
1905
1842
  */
1906
- const envelopeRecipientUpdateName = (endpoint, envelopeId, roleName, first_name, last_name) => updateRecipientStatus(endpoint, envelopeId, roleName, { action: 'update', first_name, last_name });
1843
+ const envelopeRecipientDecline = (endpoint, envelopeId, roleName) => endpoint.api //
1844
+ .post(`/v2/envelopes/${envelopeId}/recipients/${encodeURIComponent(roleName)}/decline`)
1845
+ .then((r) => r.data);
1907
1846
  /**
1908
- * Change a recipient's name.
1847
+ * Submit an envelope (signing is finished). Note that all fields must be valid/completed for this to succeed.
1848
+ *
1849
+ * @group Recipients
1850
+ * @api POST /envelopes/:envelope_id/recipients/:role_name/submit Submit envelope
1851
+ * @apiParam string(format:uuid) envelope_id The envelope to operate on.
1852
+ * @apiParam string role_name The role to submit.
1853
+ * @apiSuccess IRecipient . The updated Recipient.
1909
1854
  */
1910
- const envelopeRecipientPrepare = (endpoint, envelopeId, roleName, recipients) => updateRecipientStatus(endpoint, envelopeId, roleName, { action: 'prepare', recipients });
1855
+ const envelopeRecipientSubmit = (endpoint, envelopeId, roleName) => endpoint.api //
1856
+ .put(`/v2/envelopes/${envelopeId}/recipients/${roleName}/submit`)
1857
+ .then((r) => r.data);
1911
1858
  /**
1912
1859
  * Begin a signing session for an Envelope. This path requires an invite code, and should generally
1913
1860
  * be called with a NON-default Endpoint to avoid conflicting with any active user session the user
@@ -2101,7 +2048,7 @@ const recipientHasAction = (recipient) => !['submitted', 'canceled', 'declined']
2101
2048
  /**
2102
2049
  * Returns the recipients who still have a pending action. Note that not all of these recipients may be able to act (yet).
2103
2050
  */
2104
- const getRecipientsWithActions = (envelope) => (envelope?.recipients || []).filter(recipientHasAction);
2051
+ const getRecipientsWithActions = (envelope) => ['complete', 'declined', 'canceled'].includes(envelope.status) ? [] : (envelope?.recipients || []).filter(recipientHasAction);
2105
2052
  /**
2106
2053
  * Returns true if the recipient can act.
2107
2054
  */
@@ -2133,10 +2080,10 @@ const getNextRecipient = (envelope) => {
2133
2080
  };
2134
2081
 
2135
2082
  /**
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.
2083
+ * Create a signature block. In a typical signing workflow, the user is asked at the beginning of the process to
2084
+ * "adopt" a signature block to be used for all signature fields in the document. Thus, this is typically called one
2085
+ * time to create and store a signature block. Thereafter, the ID of the signature block may be re-used for each
2086
+ * signature field to be "stamped" by the user.
2140
2087
  *
2141
2088
  * Note: Both "guest" signers and authenticated users can create initials blocks. Guest signers
2142
2089
  * typically only ever have one, tied to that session. But authenticated users can create more than
@@ -2154,39 +2101,6 @@ const createSignature = (endpoint, name, signature) => {
2154
2101
  .post(`/v2/profiles/signatures`, data)
2155
2102
  .then((r) => r.data);
2156
2103
  };
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
2104
 
2191
2105
  /**
2192
2106
  * API keys are used to authenticate server-to-server calls. (API keys should **never** be used for client-to-server operations!)
@@ -3308,63 +3222,6 @@ const deleteTemplateRole = (endpoint, template_id, name) => endpoint.api //
3308
3222
  .delete(`/v2/roles/${template_id}/${encodeURIComponent(name)}`)
3309
3223
  .then((r) => r.data);
3310
3224
 
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
3225
  /**
3369
3226
  * A Template defines how a Verdocs signing flow will be performed, including attachments, signing fields, and
3370
3227
  * recipients.
@@ -3580,44 +3437,28 @@ const updateTemplate = (endpoint, templateId, params) => endpoint.api //
3580
3437
  const deleteTemplate = (endpoint, templateId) => endpoint.api //
3581
3438
  .delete(`/v2/templates/${templateId}`)
3582
3439
  .then((r) => r.data);
3583
-
3584
- /**
3585
- * A TemplateDocument represents a PDF or other attachment in a Template.
3586
- *
3587
- * @module
3588
- */
3589
3440
  /**
3590
- * Get all the Template Documents associated to a particular Template.
3441
+ * Toggle the template star for a template.
3591
3442
  *
3592
3443
  * ```typescript
3593
- * import {TemplateDocument} from '@verdocs/js-sdk/Templates';
3444
+ * import {toggleTemplateStar} from '@verdocs/js-sdk/Templates';
3594
3445
  *
3595
- * await TemplateDocument.geTemplateDocuments((VerdocsEndpoint.getDefault(), templateId);
3446
+ * await toggleTemplateStar((VerdocsEndpoint.getDefault(), '83da3d70-7857-4392-b876-c4592a304bc9');
3596
3447
  * ```
3597
3448
  *
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
3449
+ * @group Templates
3450
+ * @api POST /v2/templates/:template_id/star Star or unstar a template (toggle state)
3451
+ * @apiSuccess ITemplate . Success
3601
3452
  */
3602
- const getTemplateDocuments = (endpoint, templateId) => endpoint.api //
3603
- .get(`/templates/${templateId}/documents/`)
3453
+ const toggleTemplateStar = (endpoint, templateId) => endpoint.api //
3454
+ .post(`/v2/templates/${templateId}/stars/toggle`)
3604
3455
  .then((r) => r.data);
3456
+
3605
3457
  /**
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
- * ```
3458
+ * A TemplateDocument represents a PDF or other attachment in a Template.
3613
3459
  *
3614
- * @group Template Documents
3615
- * @api GET /v2/templates/:template_id/documents/:document_id Get an individual template document
3616
- * @apiSuccess ITemplateDocument . Template document
3460
+ * @module
3617
3461
  */
3618
- const getTemplateDocument = (endpoint, templateId, documentId) => endpoint.api //
3619
- .get(`/templates/${templateId}/documents/${documentId}`)
3620
- .then((r) => r.data);
3621
3462
  /**
3622
3463
  * Create a Document for a particular Template.
3623
3464
  *
@@ -3632,11 +3473,11 @@ const getTemplateDocument = (endpoint, templateId, documentId) => endpoint.api /
3632
3473
  * @apiBody string(format:binary) file Document file to attach. The file name will automatically be used as the document name.
3633
3474
  * @apiSuccess ITemplateDocument . Template document
3634
3475
  */
3635
- const createTemplateDocument = (endpoint, templateId, file, onUploadProgress) => {
3476
+ const createTemplateDocument = (endpoint, file, onUploadProgress) => {
3636
3477
  const formData = new FormData();
3637
3478
  formData.append('document', file, file.name);
3638
3479
  return endpoint.api //
3639
- .post(`/templates/${templateId}/documents`, formData, {
3480
+ .post(`/v2/template-documents`, formData, {
3640
3481
  timeout: 120000,
3641
3482
  onUploadProgress: (event) => {
3642
3483
  const total = event.total || 1;
@@ -3660,7 +3501,48 @@ const createTemplateDocument = (endpoint, templateId, file, onUploadProgress) =>
3660
3501
  * @apiSuccess string . Success
3661
3502
  */
3662
3503
  const deleteTemplateDocument = (endpoint, templateId, documentId) => endpoint.api //
3663
- .delete(`/templates/${templateId}/documents/${documentId}`)
3504
+ .delete(`/v2/templates/${templateId}/documents/${documentId}`)
3505
+ .then((r) => r.data);
3506
+ /**
3507
+ * Get all metadata for a template document. Note that when called by non-creators (e.g. Org Collaborators)
3508
+ * this will return only the **metadata** the caller is allowed to view.
3509
+ *
3510
+ * @group Template Documents
3511
+ * @api GET /v2/envelope-documents/:id Get envelope document
3512
+ * @apiParam string(format: 'uuid') document_id The ID of the document to retrieve.
3513
+ * @apiSuccess IEnvelopeDocument . The detailed metadata for the document requested
3514
+ */
3515
+ const getTemplateDocument = async (endpoint, documentId) => endpoint.api //
3516
+ .get(`/v2/template-documents/${documentId}`)
3517
+ .then((r) => r.data);
3518
+ /**
3519
+ * Download a document directly.
3520
+ */
3521
+ const downloadTemplateDocument = async (endpoint, documentId) => endpoint.api //
3522
+ .get(`/v2/template-documents/${documentId}?type=file`, { responseType: 'blob' })
3523
+ .then((r) => r.data);
3524
+ /**
3525
+ * Get an envelope document's metadata, or the document itself. If no "type" parameter is specified,
3526
+ * the document metadata is returned. If "type" is set to "file", the document binary content is
3527
+ * returned with Content-Type set to the MIME type of the file. If "type" is set to "download", a
3528
+ * string download link will be returned. If "type" is set to "preview" a string preview link will
3529
+ * be returned. This link expires quickly, so it should be accessed immediately and never shared.
3530
+ *
3531
+ * @group Template Documents
3532
+ * @api GET /v2/envelope-documents/:document_id Preview, Download, or Link to a Document
3533
+ * @apiParam string(format: 'uuid') document_id The ID of the document to retrieve.
3534
+ * @apiQuery string(enum:'file'|'download'|'preview') type? Download the file directly, generate a download link, or generate a preview link.
3535
+ * @apiSuccess string . The generated link.
3536
+ */
3537
+ const getTemplateDocumentDownloadLink = async (endpoint, _envelopeId, documentId) => endpoint.api //
3538
+ .get(`/v2/template-documents/${documentId}?type=download`)
3539
+ .then((r) => r.data);
3540
+ /**
3541
+ * Get a pre-signed preview link for an Envelope Document. This link expires quickly, so it should
3542
+ * be accessed immediately and never shared. Content-Disposition will be set to "inline".
3543
+ */
3544
+ const getTemplateDocumentPreviewLink = async (endpoint, _envelopeId, documentId) => endpoint.api //
3545
+ .get(`/v2/envelope-documents/${documentId}?type=preview`)
3664
3546
  .then((r) => r.data);
3665
3547
  /**
3666
3548
  * Get (binary download) a file attached to a Template. It is important to use this method
@@ -3668,7 +3550,7 @@ const deleteTemplateDocument = (endpoint, templateId, documentId) => endpoint.ap
3668
3550
  * request.
3669
3551
  */
3670
3552
  const getTemplateDocumentFile = async (endpoint, templateId, documentId) => endpoint.api //
3671
- .get(`/templates/${templateId}/documents/${documentId}?file=true`, { responseType: 'blob' })
3553
+ .get(`/v2/templates/${templateId}/documents/${documentId}?file=true`, { responseType: 'blob' })
3672
3554
  .then((r) => r.data);
3673
3555
  /**
3674
3556
  * Get (binary download) a file attached to a Template. It is important to use this method
@@ -3676,7 +3558,7 @@ const getTemplateDocumentFile = async (endpoint, templateId, documentId) => endp
3676
3558
  * request.
3677
3559
  */
3678
3560
  const getTemplateDocumentThumbnail = async (endpoint, templateId, documentId) => endpoint.api //
3679
- .get(`/templates/${templateId}/documents/${documentId}?thumbnail=true`, { responseType: 'blob' })
3561
+ .get(`/v2/templates/${templateId}/documents/${documentId}?thumbnail=true`, { responseType: 'blob' })
3680
3562
  .then((r) => r.data);
3681
3563
  /**
3682
3564
  * Get a display URI for a given page in a file attached to a template document. These pages are rendered server-side
@@ -3686,25 +3568,30 @@ const getTemplateDocumentThumbnail = async (endpoint, templateId, documentId) =>
3686
3568
  */
3687
3569
  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
3570
 
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
3571
  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
3572
  // @see https://www.regextester.com/1978
3707
3573
  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}))/;
3574
+ const URL_REGEX = /https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)/;
3575
+ const POSTAL_CODE_REGEX = /^[A-Za-z0-9-\s]{3,10}$/;
3576
+ const NUMBER_REGEX = /^\d+$/;
3577
+ const DATE_REGEX = /^(\d{4}[-\/]\d{2}[-\/]\d{2})|(\d{2}[-\/]\d{2}[-\/]\d{4})$/;
3578
+ const VALIDATORS = {
3579
+ email: { regex: EMAIL_REGEX, label: 'Email Address' },
3580
+ phone: { regex: PHONE_REGEX, label: 'Phone Number' },
3581
+ url: { regex: URL_REGEX, label: 'URL' },
3582
+ postal_code: { regex: POSTAL_CODE_REGEX, label: 'Zip/Postal Code' },
3583
+ number: { regex: NUMBER_REGEX, label: 'Number' },
3584
+ date: { regex: DATE_REGEX, label: 'Date' },
3585
+ };
3586
+ const isValidInput = (value, validator) => Object.keys(VALIDATORS).includes(validator) && VALIDATORS[validator].regex.test(value);
3587
+ /**
3588
+ * Get a list of available validators for field inputs. Note that validators always check strings,
3589
+ * because that is all a user can enter in an HTML input field. Numeric-format validators should
3590
+ * perform any necessary conversions internally. Validators never throw - they just return a boolean.
3591
+ * indicating whether the value is valid.
3592
+ */
3593
+ const getValidators = () => Object.keys(VALIDATORS);
3594
+ const isValidEmail = (email) => !!email && EMAIL_REGEX.test(email);
3708
3595
  const isValidPhone = (phone) => !!phone && PHONE_REGEX.test(phone);
3709
3596
  const isValidRoleName = (value, roles) => roles.findIndex((role) => role.name === value) !== -1;
3710
3597
  const TagRegEx = /^[a-zA-Z0-9-]{0,32}$/;
@@ -3721,7 +3608,6 @@ exports.VerdocsEndpoint = VerdocsEndpoint;
3721
3608
  exports.WEBHOOK_EVENTS = WEBHOOK_EVENTS;
3722
3609
  exports.acceptOrganizationInvitation = acceptOrganizationInvitation;
3723
3610
  exports.addGroupMember = addGroupMember;
3724
- exports.addTemplateTag = addTemplateTag;
3725
3611
  exports.authenticate = authenticate;
3726
3612
  exports.blobToBase64 = blobToBase64;
3727
3613
  exports.canAccessEnvelope = canAccessEnvelope;
@@ -3741,7 +3627,6 @@ exports.createOrganizationContact = createOrganizationContact;
3741
3627
  exports.createOrganizationInvitation = createOrganizationInvitation;
3742
3628
  exports.createProfile = createProfile;
3743
3629
  exports.createSignature = createSignature;
3744
- exports.createTag = createTag;
3745
3630
  exports.createTemplate = createTemplate;
3746
3631
  exports.createTemplateDocument = createTemplateDocument;
3747
3632
  exports.createTemplateFromSharepoint = createTemplateFromSharepoint;
@@ -3760,41 +3645,35 @@ exports.deleteOrganizationContact = deleteOrganizationContact;
3760
3645
  exports.deleteOrganizationInvitation = deleteOrganizationInvitation;
3761
3646
  exports.deleteOrganizationMember = deleteOrganizationMember;
3762
3647
  exports.deleteProfile = deleteProfile;
3763
- exports.deleteSignature = deleteSignature;
3764
3648
  exports.deleteTemplate = deleteTemplate;
3765
3649
  exports.deleteTemplateDocument = deleteTemplateDocument;
3766
3650
  exports.deleteTemplateRole = deleteTemplateRole;
3767
- exports.deleteTemplateTag = deleteTemplateTag;
3768
3651
  exports.downloadBlob = downloadBlob;
3769
- exports.downloadDocument = downloadDocument;
3652
+ exports.downloadEnvelopeDocument = downloadEnvelopeDocument;
3653
+ exports.downloadTemplateDocument = downloadTemplateDocument;
3770
3654
  exports.duplicateTemplate = duplicateTemplate;
3771
3655
  exports.envelopeIsActive = envelopeIsActive;
3772
3656
  exports.envelopeIsComplete = envelopeIsComplete;
3773
3657
  exports.envelopeRecipientAgree = envelopeRecipientAgree;
3774
- exports.envelopeRecipientChangeOwner = envelopeRecipientChangeOwner;
3775
3658
  exports.envelopeRecipientDecline = envelopeRecipientDecline;
3776
- exports.envelopeRecipientPrepare = envelopeRecipientPrepare;
3777
3659
  exports.envelopeRecipientSubmit = envelopeRecipientSubmit;
3778
- exports.envelopeRecipientUpdateName = envelopeRecipientUpdateName;
3779
3660
  exports.fileToDataUrl = fileToDataUrl;
3780
3661
  exports.formatFullName = formatFullName;
3781
3662
  exports.formatInitials = formatInitials;
3782
3663
  exports.formatShortTimeAgo = formatShortTimeAgo;
3783
3664
  exports.fullNameToInitials = fullNameToInitials;
3784
3665
  exports.getActiveEntitlements = getActiveEntitlements;
3785
- exports.getAllTags = getAllTags;
3786
3666
  exports.getApiKeys = getApiKeys;
3787
3667
  exports.getCountryByCode = getCountryByCode;
3788
3668
  exports.getCurrentProfile = getCurrentProfile;
3789
- exports.getDocumentDownloadLink = getDocumentDownloadLink;
3790
- exports.getDocumentPreviewLink = getDocumentPreviewLink;
3791
3669
  exports.getEntitlements = getEntitlements;
3792
3670
  exports.getEnvelope = getEnvelope;
3793
3671
  exports.getEnvelopeDocument = getEnvelopeDocument;
3672
+ exports.getEnvelopeDocumentDownloadLink = getEnvelopeDocumentDownloadLink;
3794
3673
  exports.getEnvelopeDocumentPageDisplayUri = getEnvelopeDocumentPageDisplayUri;
3674
+ exports.getEnvelopeDocumentPreviewLink = getEnvelopeDocumentPreviewLink;
3795
3675
  exports.getEnvelopeFile = getEnvelopeFile;
3796
3676
  exports.getEnvelopes = getEnvelopes;
3797
- exports.getFieldAttachment = getFieldAttachment;
3798
3677
  exports.getFieldsForRole = getFieldsForRole;
3799
3678
  exports.getGroup = getGroup;
3800
3679
  exports.getGroups = getGroups;
@@ -3820,19 +3699,14 @@ exports.getRTop = getRTop;
3820
3699
  exports.getRValue = getRValue;
3821
3700
  exports.getRecipientsWithActions = getRecipientsWithActions;
3822
3701
  exports.getRoleColor = getRoleColor;
3823
- exports.getSignature = getSignature;
3824
- exports.getSignatures = getSignatures;
3825
- exports.getStars = getStars;
3826
- exports.getTag = getTag;
3827
3702
  exports.getTemplate = getTemplate;
3828
3703
  exports.getTemplateDocument = getTemplateDocument;
3704
+ exports.getTemplateDocumentDownloadLink = getTemplateDocumentDownloadLink;
3829
3705
  exports.getTemplateDocumentFile = getTemplateDocumentFile;
3830
3706
  exports.getTemplateDocumentPageDisplayUri = getTemplateDocumentPageDisplayUri;
3707
+ exports.getTemplateDocumentPreviewLink = getTemplateDocumentPreviewLink;
3831
3708
  exports.getTemplateDocumentThumbnail = getTemplateDocumentThumbnail;
3832
- exports.getTemplateDocuments = getTemplateDocuments;
3833
- exports.getTemplateTags = getTemplateTags;
3834
3709
  exports.getTemplates = getTemplates;
3835
- exports.getValidator = getValidator;
3836
3710
  exports.getValidators = getValidators;
3837
3711
  exports.getWebhooks = getWebhooks;
3838
3712
  exports.hasRequiredPermissions = hasRequiredPermissions;
@@ -3848,6 +3722,7 @@ exports.isMartinique = isMartinique;
3848
3722
  exports.isMayotte = isMayotte;
3849
3723
  exports.isPuertoRico = isPuertoRico;
3850
3724
  exports.isValidEmail = isValidEmail;
3725
+ exports.isValidInput = isValidInput;
3851
3726
  exports.isValidPhone = isValidPhone;
3852
3727
  exports.isValidRoleName = isValidRoleName;
3853
3728
  exports.isValidTag = isValidTag;
@@ -3870,12 +3745,10 @@ exports.submitKbaChallengeResponse = submitKbaChallengeResponse;
3870
3745
  exports.submitKbaIdentity = submitKbaIdentity;
3871
3746
  exports.submitKbaPin = submitKbaPin;
3872
3747
  exports.switchProfile = switchProfile;
3873
- exports.toggleStar = toggleStar;
3748
+ exports.toggleTemplateStar = toggleTemplateStar;
3874
3749
  exports.updateApiKey = updateApiKey;
3875
3750
  exports.updateEnvelope = updateEnvelope;
3876
3751
  exports.updateEnvelopeField = updateEnvelopeField;
3877
- exports.updateEnvelopeFieldInitials = updateEnvelopeFieldInitials;
3878
- exports.updateEnvelopeFieldSignature = updateEnvelopeFieldSignature;
3879
3752
  exports.updateField = updateField;
3880
3753
  exports.updateGroup = updateGroup;
3881
3754
  exports.updateOrganization = updateOrganization;
@@ -3887,7 +3760,6 @@ exports.updateOrganizationThumbnail = updateOrganizationThumbnail;
3887
3760
  exports.updateProfile = updateProfile;
3888
3761
  exports.updateProfilePhoto = updateProfilePhoto;
3889
3762
  exports.updateRecipient = updateRecipient;
3890
- exports.updateRecipientStatus = updateRecipientStatus;
3891
3763
  exports.updateTemplate = updateTemplate;
3892
3764
  exports.updateTemplateRole = updateTemplateRole;
3893
3765
  exports.uploadEnvelopeFieldAttachment = uploadEnvelopeFieldAttachment;