@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.mjs CHANGED
@@ -1608,13 +1608,13 @@ const getEnvelope = async (endpoint, envelopeId) => endpoint.api //
1608
1608
  * @apiParam string(format: 'uuid') document_id The ID of the document to retrieve.
1609
1609
  * @apiSuccess IEnvelopeDocument . The detailed metadata for the document requested
1610
1610
  */
1611
- const getEnvelopeDocument = async (endpoint, _envelopeId, documentId) => endpoint.api //
1611
+ const getEnvelopeDocument = async (endpoint, documentId) => endpoint.api //
1612
1612
  .get(`/v2/envelope-documents/${documentId}`)
1613
1613
  .then((r) => r.data);
1614
1614
  /**
1615
1615
  * Download a document directly.
1616
1616
  */
1617
- const downloadDocument = async (endpoint, _envelopeId, documentId) => endpoint.api //
1617
+ const downloadEnvelopeDocument = async (endpoint, documentId) => endpoint.api //
1618
1618
  .get(`/v2/envelope-documents/${documentId}?type=file`, { responseType: 'blob' })
1619
1619
  .then((r) => r.data);
1620
1620
  /**
@@ -1630,14 +1630,14 @@ const downloadDocument = async (endpoint, _envelopeId, documentId) => endpoint.a
1630
1630
  * @apiQuery string(enum:'file'|'download'|'preview') type? Download the file directly, generate a download link, or generate a preview link.
1631
1631
  * @apiSuccess string . The generated link.
1632
1632
  */
1633
- const getDocumentDownloadLink = async (endpoint, _envelopeId, documentId) => endpoint.api //
1633
+ const getEnvelopeDocumentDownloadLink = async (endpoint, documentId) => endpoint.api //
1634
1634
  .get(`/v2/envelope-documents/${documentId}?type=download`)
1635
1635
  .then((r) => r.data);
1636
1636
  /**
1637
1637
  * Get a pre-signed preview link for an Envelope Document. This link expires quickly, so it should
1638
1638
  * be accessed immediately and never shared. Content-Disposition will be set to "inline".
1639
1639
  */
1640
- const getDocumentPreviewLink = async (endpoint, _envelopeId, documentId) => endpoint.api //
1640
+ const getEnvelopeDocumentPreviewLink = async (endpoint, documentId) => endpoint.api //
1641
1641
  .get(`/v2/envelope-documents/${documentId}?type=preview`)
1642
1642
  .then((r) => r.data);
1643
1643
  /**
@@ -1659,7 +1659,7 @@ const cancelEnvelope = async (endpoint, envelopeId) => endpoint.api //
1659
1659
  *
1660
1660
  * @deprecated Use getDocumentPreviewLink/getDocumentDownloadLink/downloadDocument instead.
1661
1661
  */
1662
- const getEnvelopeFile = async (endpoint, envelopeId, documentId) => endpoint.api //
1662
+ const getEnvelopeFile = async (endpoint, documentId) => endpoint.api //
1663
1663
  .get(`/v2/envelope-documents/${documentId}?type=file`, { responseType: 'blob' })
1664
1664
  .then((r) => r.data);
1665
1665
  /**
@@ -1678,60 +1678,25 @@ const updateEnvelope = async (endpoint, envelopeId, params) => endpoint.api //
1678
1678
  * Update a Document field. Typically called during the signing process as a Recipient fills in fields.
1679
1679
  *
1680
1680
  * @group Envelopes
1681
- * @api PUT /envelopes/:envelope_id/fields/:field_name Update Envelope Field
1681
+ * @api PUT /v2/envelopes/:envelope_id/fields/:field_name Update Envelope Field
1682
1682
  * @apiParam string(format: 'uuid') envelope_id The ID of the envelope to retrieve.
1683
+ * @apiParam string role_name The role to submit. Be sure to URL-encode the value.
1683
1684
  * @apiParam string field_name The name of the field to update. Be sure to URL-encode the value.
1684
- * @apiBody IEnvelopeFieldSettings . Set of properties to update. Leave undefined any properties that should not be changed.
1685
- * @apiSuccess IEnvelope . A copy of the newly-updated field.
1685
+ * @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.
1686
+ * @apiBody value . Value to set.
1687
+ * @apiSuccess IEnvelopeField . A copy of the newly-updated field.
1686
1688
  */
1687
- const updateEnvelopeField = async (endpoint, envelopeId, fieldName, value) => endpoint.api //
1688
- .put(`/envelopes/${envelopeId}/fields/${fieldName}`, value)
1689
+ const updateEnvelopeField = async (endpoint, envelopeId, roleName, fieldName, value) => endpoint.api //
1690
+ .put(`/v2/envelopes/${envelopeId}/recipients/${roleName}/fields/${fieldName}`, { value })
1689
1691
  .then((r) => r.data);
1690
1692
  /**
1691
- * Apply a signature to a signature field. Signature fields are ID-driven. Call `createSignature()`
1692
- * first to create a signature for a Recipient, then call `updateEnvelopeFieldSignature()` to
1693
- * attach it to a field.
1694
- *
1695
- * @group Envelopes
1696
- * @api PUT /envelopes/:envelope_id/fields/:field_name/signature/:signature_id Update Envelope
1697
- * @apiParam string(format: 'uuid') envelope_id The ID of the envelope to update.
1698
- * @apiParam string field_name The name of the field to update. Be sure to URL-encode the value.
1699
- * @apiParam string(format: 'uuid') signature_id The ID of the signature to attach.
1700
- * @apiSuccess IEnvelopeFieldSettings . A copy of the newly-updated field.
1693
+ * Upload an attachment to an attachment field.
1701
1694
  */
1702
- const updateEnvelopeFieldSignature = async (endpoint, envelopeId, fieldName, signatureId) => endpoint.api //
1703
- .put(`/envelopes/${envelopeId}/fields/${fieldName}/signature/${signatureId}`)
1704
- .then((r) => r.data);
1705
- /**
1706
- * Apply an initial to an initials field. Initial fields are ID-driven. Call `createInitial()`
1707
- * first to create an initial block for a Recipient, then call `supdateEnvelopeFieldInitials()` to
1708
- * attach it to a field.
1709
- *
1710
- * @group Envelopes
1711
- * @api PUT /envelopes/:envelope_id/fields/:field_name/initial/:initial_id Update Envelope
1712
- * @apiParam string(format: 'uuid') envelope_id The ID of the envelope to update.
1713
- * @apiParam string field_name The name of the field to update. Be sure to URL-encode the value.
1714
- * @apiParam string(format: 'uuid') initial_id The ID of the initial block to attach.
1715
- * @apiSuccess IEnvelopeFieldSettings . A copy of the newly-updated field.
1716
- */
1717
- const updateEnvelopeFieldInitials = async (endpoint, envelopeId, fieldName, initialId) => endpoint.api //
1718
- .put(`/envelopes/${envelopeId}/fields/${fieldName}/initial/${initialId}`)
1719
- .then((r) => r.data);
1720
- /**
1721
- * Upload an attachment to an attachment field
1722
- *
1723
- * @group Envelopes
1724
- * @api PUT /envelopes/:envelope_id/fields/:field_name Upload or Delete Attachment
1725
- * @apiParam string(format: 'uuid') envelope_id The ID of the envelope to update.
1726
- * @apiParam string field_name The name of the field to update. Be sure to URL-encode the value.
1727
- * @apiBody string document The file to attach. Must contain standard File object fields. If omitted, the attachment will be deleted instead.
1728
- * @apiSuccess IEnvelopeFieldSettings . A copy of the newly-updated field.
1729
- */
1730
- const uploadEnvelopeFieldAttachment = async (endpoint, envelopeId, fieldName, file, onUploadProgress) => {
1695
+ const uploadEnvelopeFieldAttachment = async (endpoint, envelopeId, roleName, fieldName, file, onUploadProgress) => {
1731
1696
  const formData = new FormData();
1732
1697
  formData.append('document', file, file.name);
1733
1698
  return endpoint.api //
1734
- .put(`/envelopes/${envelopeId}/fields/${fieldName}`, formData, {
1699
+ .put(`/v2/envelopes/${envelopeId}/recipients/${roleName}/fields/${fieldName}`, formData, {
1735
1700
  timeout: 120000,
1736
1701
  onUploadProgress: (event) => {
1737
1702
  const total = event.total || 1;
@@ -1746,25 +1711,13 @@ const uploadEnvelopeFieldAttachment = async (endpoint, envelopeId, fieldName, fi
1746
1711
  * being deleted. Instead, it is a similar operation to uploading a new attachment, but the
1747
1712
  * omission of the attachment signals the server to delete the current entry.
1748
1713
  */
1749
- const deleteEnvelopeFieldAttachment = async (endpoint, envelopeId, fieldName) => {
1714
+ const deleteEnvelopeFieldAttachment = async (endpoint, envelopeId, roleName, fieldName) => {
1750
1715
  const formData = new FormData();
1751
1716
  // Omitting file is the trigger here
1752
1717
  return endpoint.api //
1753
- .put(`/envelopes/${envelopeId}/fields/${fieldName}`, formData)
1718
+ .put(`/v2/envelopes/${envelopeId}/recipients/${roleName}/fields/${fieldName}`, formData)
1754
1719
  .then((r) => r.data);
1755
1720
  };
1756
- /**
1757
- * Get the attached file for an attachment field (if any).
1758
- *
1759
- * @group Envelopes
1760
- * @api GET /envelopes/:envelope_id/fields/:field_name/document Download attachment in binary format
1761
- * @apiParam string(format: 'uuid') envelope_id The ID of the envelope to retrieve.
1762
- * @apiParam string field_name The name of the field from which to download the attachment.
1763
- * @apiSuccess string . The file binary data.
1764
- */
1765
- const getFieldAttachment = async (endpoint, envelopeId, fieldName) => endpoint.api //
1766
- .get(`/envelopes/${envelopeId}/fields/${fieldName}/document`, { responseType: 'blob' })
1767
- .then((r) => r.data);
1768
1721
  /**
1769
1722
  * Get a display URI for a given page in a file attached to an envelope document. These pages are rendered server-side
1770
1723
  * into PNG resources suitable for display in IMG tags although they may be used elsewhere. Note that these are intended
@@ -1808,12 +1761,18 @@ const getEnvelopeDocumentPageDisplayUri = async (endpoint, documentId, page, var
1808
1761
  const getEnvelopes = (endpoint, params) => endpoint.api //
1809
1762
  .get('/v2/envelopes', { params })
1810
1763
  .then((r) => r.data);
1764
+ /**
1765
+ * Generate a ZIP file containing all data for the specified envelopes. The caller must be the
1766
+ * owner of each envelope. The returned ZIP file contains a folder for each envelope.
1767
+ */
1768
+ const getEnvelopesZip = (endpoint, envelope_ids) => endpoint.api //
1769
+ .get(`/v2/envelopes/zip/${envelope_ids.join(',')}`);
1811
1770
 
1812
1771
  /**
1813
- * Create an initials block. In a typical signing workflow, the user is asked at the beginning of the process to "adopt"
1814
- * an initials block to be used for all initials fields in the document. Thus, this is typically called one time to
1815
- * create and store an initials block. Thereafter, the ID of the initials block may be re-used for each initials field
1816
- * to be "stamped" by the user.
1772
+ * Create an initials block. In a typical signing workflow, the user is asked at the beginning of the process to
1773
+ * "adopt" an initials block to be used for all initials fields in the document. Thus, this is typically called
1774
+ * one time to create and store an initials block. Thereafter, the ID of the initials block may be re-used for each
1775
+ * initials field to be "stamped" by the user.
1817
1776
  *
1818
1777
  * Note: Both "guest" signers and authenticated users can create initials blocks. Guest signers
1819
1778
  * typically only ever have one, tied to that session. But authenticated users can create more than
@@ -1863,49 +1822,43 @@ const submitKbaChallengeResponse = (endpoint, envelope_id, role_name, responses)
1863
1822
  .then((r) => r.data);
1864
1823
 
1865
1824
  /**
1866
- * Update a recipient's status.
1825
+ * Agree to electronic signing dislosures.
1867
1826
  *
1868
1827
  * @group Recipients
1869
- * @api PUT /envelopes/:envelope_id/recipients/:role_name Update Recipient Status
1828
+ * @api POST /envelopes/:envelope_id/recipients/:role_name/agree Agree to e-Signing Disclosures
1870
1829
  * @apiParam string(format:uuid) envelope_id The envelope to operate on.
1871
- * @apiParam string role_name The role to adjust.
1872
- * @apiBody string(enum:'submit'|'decline'|'owner_update'|'update'|'prepare') action The action to take. Adjusts the status, and may also perform other operations.
1873
- * @apiBody string first_name? Ignored unless action is 'owner_update' or 'update'. The new owner's or recipient's first name.
1874
- * @apiBody string last_name? Ignored unless action is 'owner_update' or 'update'. The new owner's or recipient's last name.
1875
- * @apiBody string email? Ignored unless action is 'owner_update'. The new owner's email address.
1876
- * @apiBody boolean agreed? Ignored unless action is 'update'. Set to true to accept the e-signing disclosures.
1877
- * @apiBody array(items:IRecipient) recipients? Ignored unless action is 'prepare'. A list of recipients and their fields to set defaults for.
1830
+ * @apiParam string role_name The role to operate on.
1878
1831
  * @apiSuccess IRecipient . The updated Recipient.
1879
1832
  */
1880
- const updateRecipientStatus = async (endpoint, envelope_id, role_name, params) => endpoint.api //
1881
- .put(`/envelopes/${envelope_id}/recipients/${role_name}`, params)
1882
- .then((r) => r.data);
1883
- /**
1884
- * Submit an envelope (signing is finished). Note that all fields must be valid/completed for this to succeed.
1885
- */
1886
- const envelopeRecipientSubmit = (endpoint, envelopeId, roleName) => updateRecipientStatus(endpoint, envelopeId, roleName, { action: 'submit' });
1887
- /**
1888
- * Decline to complete an envelope (signing will not terminated).
1889
- */
1890
- const envelopeRecipientDecline = (endpoint, envelopeId, roleName) => updateRecipientStatus(endpoint, envelopeId, roleName, { action: 'decline' });
1891
- /**
1892
- * Claim / change ownership of an envelope. This is a special-case operation only available in certain workflows.
1893
- */
1894
- 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 });
1895
- /**
1896
- * Agree to electronic signing disclosures.
1897
- */
1898
1833
  const envelopeRecipientAgree = (endpoint, envelopeId, roleName, disclosures) => endpoint.api //
1899
- .put(`/v2/envelopes/${envelopeId}/recipients/${encodeURIComponent(roleName)}`, { action: 'accept', disclosures })
1834
+ .post(`/v2/envelopes/${envelopeId}/recipients/${encodeURIComponent(roleName)}/agree`, { disclosures })
1900
1835
  .then((r) => r.data);
1901
1836
  /**
1902
- * Change a recipient's name.
1837
+ * Decline electronic signing dislosures. Note that if any recipient declines, the entire envelope
1838
+ * becomes non-viable and later recipients may no longer act. The creator will receive a notification
1839
+ * when this occurs.
1840
+ *
1841
+ * @group Recipients
1842
+ * @api POST /envelopes/:envelope_id/recipients/:role_name/decline Decline e-Signing Disclosures
1843
+ * @apiParam string(format:uuid) envelope_id The envelope to operate on.
1844
+ * @apiParam string role_name The role to adjust.
1845
+ * @apiSuccess IRecipient . The updated Recipient.
1903
1846
  */
1904
- const envelopeRecipientUpdateName = (endpoint, envelopeId, roleName, first_name, last_name) => updateRecipientStatus(endpoint, envelopeId, roleName, { action: 'update', first_name, last_name });
1847
+ const envelopeRecipientDecline = (endpoint, envelopeId, roleName) => endpoint.api //
1848
+ .post(`/v2/envelopes/${envelopeId}/recipients/${encodeURIComponent(roleName)}/decline`)
1849
+ .then((r) => r.data);
1905
1850
  /**
1906
- * Change a recipient's name.
1851
+ * Submit an envelope (signing is finished). Note that all fields must be valid/completed for this to succeed.
1852
+ *
1853
+ * @group Recipients
1854
+ * @api POST /envelopes/:envelope_id/recipients/:role_name/submit Submit envelope
1855
+ * @apiParam string(format:uuid) envelope_id The envelope to operate on.
1856
+ * @apiParam string role_name The role to submit.
1857
+ * @apiSuccess IRecipient . The updated Recipient.
1907
1858
  */
1908
- const envelopeRecipientPrepare = (endpoint, envelopeId, roleName, recipients) => updateRecipientStatus(endpoint, envelopeId, roleName, { action: 'prepare', recipients });
1859
+ const envelopeRecipientSubmit = (endpoint, envelopeId, roleName) => endpoint.api //
1860
+ .put(`/v2/envelopes/${envelopeId}/recipients/${roleName}/submit`)
1861
+ .then((r) => r.data);
1909
1862
  /**
1910
1863
  * Begin a signing session for an Envelope. This path requires an invite code, and should generally
1911
1864
  * be called with a NON-default Endpoint to avoid conflicting with any active user session the user
@@ -2099,7 +2052,7 @@ const recipientHasAction = (recipient) => !['submitted', 'canceled', 'declined']
2099
2052
  /**
2100
2053
  * Returns the recipients who still have a pending action. Note that not all of these recipients may be able to act (yet).
2101
2054
  */
2102
- const getRecipientsWithActions = (envelope) => (envelope?.recipients || []).filter(recipientHasAction);
2055
+ const getRecipientsWithActions = (envelope) => ['complete', 'declined', 'canceled'].includes(envelope.status) ? [] : (envelope?.recipients || []).filter(recipientHasAction);
2103
2056
  /**
2104
2057
  * Returns true if the recipient can act.
2105
2058
  */
@@ -2131,10 +2084,10 @@ const getNextRecipient = (envelope) => {
2131
2084
  };
2132
2085
 
2133
2086
  /**
2134
- * Create a signature block. In a typical signing workflow, the user is asked at the beginning of the process to "adopt"
2135
- * a signature block to be used for all signature fields in the document. Thus, this is typically called one time to
2136
- * create and store a signature block. Thereafter, the ID of the signature block may be re-used for each signature field
2137
- * to be "stamped" by the user.
2087
+ * Create a signature block. In a typical signing workflow, the user is asked at the beginning of the process to
2088
+ * "adopt" a signature block to be used for all signature fields in the document. Thus, this is typically called one
2089
+ * time to create and store a signature block. Thereafter, the ID of the signature block may be re-used for each
2090
+ * signature field to be "stamped" by the user.
2138
2091
  *
2139
2092
  * Note: Both "guest" signers and authenticated users can create initials blocks. Guest signers
2140
2093
  * typically only ever have one, tied to that session. But authenticated users can create more than
@@ -2152,39 +2105,6 @@ const createSignature = (endpoint, name, signature) => {
2152
2105
  .post(`/v2/profiles/signatures`, data)
2153
2106
  .then((r) => r.data);
2154
2107
  };
2155
- /**
2156
- * Get the available signatures for a user.
2157
- *
2158
- * @group Signatures and Initials
2159
- * @api GET /signatures Create Signature Block
2160
- *
2161
- * @apiSuccess array(items:ISignature) . A list of signatures previously stored for the user.
2162
- */
2163
- const getSignatures = (endpoint) => endpoint.api //
2164
- .get('/signatures')
2165
- .then((r) => r.data);
2166
- /**
2167
- * Get a user's signature by ID.
2168
- *
2169
- * @group Signatures and Initials
2170
- * @api GET /signatures/:id Delete Signature Block
2171
- * @apiParam string(format: 'uuid') id The ID of the signature to delete.
2172
- * @apiSuccess ISignature . The signature metadata requested.
2173
- */
2174
- const getSignature = (endpoint, signatureId) => endpoint.api //
2175
- .get(`/signatures/${signatureId}`)
2176
- .then((r) => r.data);
2177
- /**
2178
- * Delete a user's signature.
2179
- *
2180
- * @group Signatures and Initials
2181
- * @api DELETE /signatures/:id Delete Signature Block
2182
- * @apiParam string(format: 'uuid') id The ID of the signature to delete.
2183
- * @apiSuccess string . OK
2184
- */
2185
- const deleteSignature = (endpoint, signatureId) => endpoint.api //
2186
- .delete(`/signatures/${signatureId}`)
2187
- .then((r) => r.data);
2188
2108
 
2189
2109
  /**
2190
2110
  * API keys are used to authenticate server-to-server calls. (API keys should **never** be used for client-to-server operations!)
@@ -3306,63 +3226,6 @@ const deleteTemplateRole = (endpoint, template_id, name) => endpoint.api //
3306
3226
  .delete(`/v2/roles/${template_id}/${encodeURIComponent(name)}`)
3307
3227
  .then((r) => r.data);
3308
3228
 
3309
- /**
3310
- * Get the template stars for a template.
3311
- */
3312
- const getStars = (endpoint, templateId) => endpoint.api //
3313
- .get(`/templates/${templateId}/stars`)
3314
- .then((r) => r.data);
3315
- /**
3316
- * Toggle the template star for a template.
3317
- */
3318
- const toggleStar = (endpoint, templateId) => endpoint.api //
3319
- .post(`/templates/${templateId}/stars/toggle`)
3320
- .then((r) => r.data);
3321
-
3322
- /**
3323
- * A Tag is a user-specified label applied to a template. Tags help users organize and find Templates.
3324
- * recipients. Every Organization has a set of tags "owned" by that Organization and only visible inside it.
3325
- * Verdocs also provides a set of system-wide "featured" tags available to all Organizations.
3326
- *
3327
- * @module
3328
- */
3329
- /**
3330
- * Apply a tag to a template.
3331
- */
3332
- const addTemplateTag = (endpoint, templateId, params) => endpoint.api //
3333
- .post(`/templates/${templateId}/tags/`, params)
3334
- .then((r) => r.data);
3335
- /**
3336
- * Get all tags for a template.
3337
- */
3338
- const getTemplateTags = (endpoint, templateId) => endpoint.api //
3339
- .get(`/templates/${templateId}/tags/`)
3340
- .then((r) => r.data);
3341
- /**
3342
- * Remove a tag from a template.
3343
- */
3344
- const deleteTemplateTag = (endpoint, templateId, tagName) => endpoint.api //
3345
- .post(`/templates/${templateId}/tags/${tagName}`)
3346
- .then((r) => r.data);
3347
- /**
3348
- * Create an Organization-wide tag.
3349
- */
3350
- const createTag = (endpoint, name) => endpoint.api //
3351
- .post('/tags', { tag_name: name })
3352
- .then((r) => r.data);
3353
- /**
3354
- * Get an Organization-wide tag.
3355
- */
3356
- const getTag = (endpoint, name) => endpoint.api //
3357
- .get(`/tags/${name}`)
3358
- .then((r) => r.data);
3359
- /**
3360
- * Get all tags available for use by an Organization.
3361
- */
3362
- const getAllTags = (endpoint) => endpoint.api //
3363
- .get('/tags')
3364
- .then((r) => r.data);
3365
-
3366
3229
  /**
3367
3230
  * A Template defines how a Verdocs signing flow will be performed, including attachments, signing fields, and
3368
3231
  * recipients.
@@ -3578,44 +3441,28 @@ const updateTemplate = (endpoint, templateId, params) => endpoint.api //
3578
3441
  const deleteTemplate = (endpoint, templateId) => endpoint.api //
3579
3442
  .delete(`/v2/templates/${templateId}`)
3580
3443
  .then((r) => r.data);
3581
-
3582
- /**
3583
- * A TemplateDocument represents a PDF or other attachment in a Template.
3584
- *
3585
- * @module
3586
- */
3587
3444
  /**
3588
- * Get all the Template Documents associated to a particular Template.
3445
+ * Toggle the template star for a template.
3589
3446
  *
3590
3447
  * ```typescript
3591
- * import {TemplateDocument} from '@verdocs/js-sdk/Templates';
3448
+ * import {toggleTemplateStar} from '@verdocs/js-sdk/Templates';
3592
3449
  *
3593
- * await TemplateDocument.geTemplateDocuments((VerdocsEndpoint.getDefault(), templateId);
3450
+ * await toggleTemplateStar((VerdocsEndpoint.getDefault(), '83da3d70-7857-4392-b876-c4592a304bc9');
3594
3451
  * ```
3595
3452
  *
3596
- * @group Template Documents
3597
- * @api GET /v2/templates/:template_id/documents List the documents assigned to a template
3598
- * @apiSuccess array(items: ITemplateDocument) . Template documents
3453
+ * @group Templates
3454
+ * @api POST /v2/templates/:template_id/star Star or unstar a template (toggle state)
3455
+ * @apiSuccess ITemplate . Success
3599
3456
  */
3600
- const getTemplateDocuments = (endpoint, templateId) => endpoint.api //
3601
- .get(`/templates/${templateId}/documents/`)
3457
+ const toggleTemplateStar = (endpoint, templateId) => endpoint.api //
3458
+ .post(`/v2/templates/${templateId}/stars/toggle`)
3602
3459
  .then((r) => r.data);
3460
+
3603
3461
  /**
3604
- * Get a specific Document.
3605
- *
3606
- * ```typescript
3607
- * import {TemplateDocument} from '@verdocs/js-sdk/Templates';
3608
- *
3609
- * await TemplateDocument.geTemplateDocument((VerdocsEndpoint.getDefault(), templateId,documentId);
3610
- * ```
3462
+ * A TemplateDocument represents a PDF or other attachment in a Template.
3611
3463
  *
3612
- * @group Template Documents
3613
- * @api GET /v2/templates/:template_id/documents/:document_id Get an individual template document
3614
- * @apiSuccess ITemplateDocument . Template document
3464
+ * @module
3615
3465
  */
3616
- const getTemplateDocument = (endpoint, templateId, documentId) => endpoint.api //
3617
- .get(`/templates/${templateId}/documents/${documentId}`)
3618
- .then((r) => r.data);
3619
3466
  /**
3620
3467
  * Create a Document for a particular Template.
3621
3468
  *
@@ -3630,11 +3477,11 @@ const getTemplateDocument = (endpoint, templateId, documentId) => endpoint.api /
3630
3477
  * @apiBody string(format:binary) file Document file to attach. The file name will automatically be used as the document name.
3631
3478
  * @apiSuccess ITemplateDocument . Template document
3632
3479
  */
3633
- const createTemplateDocument = (endpoint, templateId, file, onUploadProgress) => {
3480
+ const createTemplateDocument = (endpoint, file, onUploadProgress) => {
3634
3481
  const formData = new FormData();
3635
3482
  formData.append('document', file, file.name);
3636
3483
  return endpoint.api //
3637
- .post(`/templates/${templateId}/documents`, formData, {
3484
+ .post(`/v2/template-documents`, formData, {
3638
3485
  timeout: 120000,
3639
3486
  onUploadProgress: (event) => {
3640
3487
  const total = event.total || 1;
@@ -3658,7 +3505,48 @@ const createTemplateDocument = (endpoint, templateId, file, onUploadProgress) =>
3658
3505
  * @apiSuccess string . Success
3659
3506
  */
3660
3507
  const deleteTemplateDocument = (endpoint, templateId, documentId) => endpoint.api //
3661
- .delete(`/templates/${templateId}/documents/${documentId}`)
3508
+ .delete(`/v2/templates/${templateId}/documents/${documentId}`)
3509
+ .then((r) => r.data);
3510
+ /**
3511
+ * Get all metadata for a template document. Note that when called by non-creators (e.g. Org Collaborators)
3512
+ * this will return only the **metadata** the caller is allowed to view.
3513
+ *
3514
+ * @group Template Documents
3515
+ * @api GET /v2/envelope-documents/:id Get envelope document
3516
+ * @apiParam string(format: 'uuid') document_id The ID of the document to retrieve.
3517
+ * @apiSuccess IEnvelopeDocument . The detailed metadata for the document requested
3518
+ */
3519
+ const getTemplateDocument = async (endpoint, documentId) => endpoint.api //
3520
+ .get(`/v2/template-documents/${documentId}`)
3521
+ .then((r) => r.data);
3522
+ /**
3523
+ * Download a document directly.
3524
+ */
3525
+ const downloadTemplateDocument = async (endpoint, documentId) => endpoint.api //
3526
+ .get(`/v2/template-documents/${documentId}?type=file`, { responseType: 'blob' })
3527
+ .then((r) => r.data);
3528
+ /**
3529
+ * Get an envelope document's metadata, or the document itself. If no "type" parameter is specified,
3530
+ * the document metadata is returned. If "type" is set to "file", the document binary content is
3531
+ * returned with Content-Type set to the MIME type of the file. If "type" is set to "download", a
3532
+ * string download link will be returned. If "type" is set to "preview" a string preview link will
3533
+ * be returned. This link expires quickly, so it should be accessed immediately and never shared.
3534
+ *
3535
+ * @group Template Documents
3536
+ * @api GET /v2/envelope-documents/:document_id Preview, Download, or Link to a Document
3537
+ * @apiParam string(format: 'uuid') document_id The ID of the document to retrieve.
3538
+ * @apiQuery string(enum:'file'|'download'|'preview') type? Download the file directly, generate a download link, or generate a preview link.
3539
+ * @apiSuccess string . The generated link.
3540
+ */
3541
+ const getTemplateDocumentDownloadLink = async (endpoint, _envelopeId, documentId) => endpoint.api //
3542
+ .get(`/v2/template-documents/${documentId}?type=download`)
3543
+ .then((r) => r.data);
3544
+ /**
3545
+ * Get a pre-signed preview link for an Envelope Document. This link expires quickly, so it should
3546
+ * be accessed immediately and never shared. Content-Disposition will be set to "inline".
3547
+ */
3548
+ const getTemplateDocumentPreviewLink = async (endpoint, _envelopeId, documentId) => endpoint.api //
3549
+ .get(`/v2/envelope-documents/${documentId}?type=preview`)
3662
3550
  .then((r) => r.data);
3663
3551
  /**
3664
3552
  * Get (binary download) a file attached to a Template. It is important to use this method
@@ -3666,7 +3554,7 @@ const deleteTemplateDocument = (endpoint, templateId, documentId) => endpoint.ap
3666
3554
  * request.
3667
3555
  */
3668
3556
  const getTemplateDocumentFile = async (endpoint, templateId, documentId) => endpoint.api //
3669
- .get(`/templates/${templateId}/documents/${documentId}?file=true`, { responseType: 'blob' })
3557
+ .get(`/v2/templates/${templateId}/documents/${documentId}?file=true`, { responseType: 'blob' })
3670
3558
  .then((r) => r.data);
3671
3559
  /**
3672
3560
  * Get (binary download) a file attached to a Template. It is important to use this method
@@ -3674,7 +3562,7 @@ const getTemplateDocumentFile = async (endpoint, templateId, documentId) => endp
3674
3562
  * request.
3675
3563
  */
3676
3564
  const getTemplateDocumentThumbnail = async (endpoint, templateId, documentId) => endpoint.api //
3677
- .get(`/templates/${templateId}/documents/${documentId}?thumbnail=true`, { responseType: 'blob' })
3565
+ .get(`/v2/templates/${templateId}/documents/${documentId}?thumbnail=true`, { responseType: 'blob' })
3678
3566
  .then((r) => r.data);
3679
3567
  /**
3680
3568
  * Get a display URI for a given page in a file attached to a template document. These pages are rendered server-side
@@ -3684,29 +3572,34 @@ const getTemplateDocumentThumbnail = async (endpoint, templateId, documentId) =>
3684
3572
  */
3685
3573
  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);
3686
3574
 
3687
- /**
3688
- * Get all defined validators
3689
- *
3690
- * ```typescript
3691
- * import {Documents} from '@verdocs/js-sdk/Templates';
3692
- *
3693
- * await Documents.getDocuments(templateID);
3694
- * ```
3695
- */
3696
- const getValidators = (endpoint) => endpoint.api //
3697
- .get('/validators')
3698
- .then((r) => r.data);
3699
- const getValidator = (endpoint, validatorName) => endpoint.api //
3700
- .get(`/validators/${validatorName}`)
3701
- .then((r) => r.data);
3702
3575
  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,}))$/;
3703
- const isValidEmail = (email) => !!email && EMAIL_REGEX.test(email);
3704
3576
  // @see https://www.regextester.com/1978
3705
3577
  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}))/;
3578
+ const URL_REGEX = /https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)/;
3579
+ const POSTAL_CODE_REGEX = /^[A-Za-z0-9-\s]{3,10}$/;
3580
+ const NUMBER_REGEX = /^\d+$/;
3581
+ const DATE_REGEX = /^(\d{4}[-\/]\d{2}[-\/]\d{2})|(\d{2}[-\/]\d{2}[-\/]\d{4})$/;
3582
+ const VALIDATORS = {
3583
+ email: { regex: EMAIL_REGEX, label: 'Email Address' },
3584
+ phone: { regex: PHONE_REGEX, label: 'Phone Number' },
3585
+ url: { regex: URL_REGEX, label: 'URL' },
3586
+ postal_code: { regex: POSTAL_CODE_REGEX, label: 'Zip/Postal Code' },
3587
+ number: { regex: NUMBER_REGEX, label: 'Number' },
3588
+ date: { regex: DATE_REGEX, label: 'Date' },
3589
+ };
3590
+ const isValidInput = (value, validator) => Object.keys(VALIDATORS).includes(validator) && VALIDATORS[validator].regex.test(value);
3591
+ /**
3592
+ * Get a list of available validators for field inputs. Note that validators always check strings,
3593
+ * because that is all a user can enter in an HTML input field. Numeric-format validators should
3594
+ * perform any necessary conversions internally. Validators never throw - they just return a boolean.
3595
+ * indicating whether the value is valid.
3596
+ */
3597
+ const getValidators = () => Object.keys(VALIDATORS);
3598
+ const isValidEmail = (email) => !!email && EMAIL_REGEX.test(email);
3706
3599
  const isValidPhone = (phone) => !!phone && PHONE_REGEX.test(phone);
3707
3600
  const isValidRoleName = (value, roles) => roles.findIndex((role) => role.name === value) !== -1;
3708
3601
  const TagRegEx = /^[a-zA-Z0-9-]{0,32}$/;
3709
3602
  const isValidTag = (value, tags) => TagRegEx.test(value) || tags.findIndex((tag) => tag === value) !== -1;
3710
3603
 
3711
- export { ALL_PERMISSIONS, AtoB, Countries, DEFAULT_FIELD_HEIGHTS, DEFAULT_FIELD_WIDTHS, FIELD_TYPES, RolePermissions, VerdocsEndpoint, WEBHOOK_EVENTS, acceptOrganizationInvitation, addGroupMember, addTemplateTag, authenticate, blobToBase64, canAccessEnvelope, canPerformTemplateAction, cancelEnvelope, capitalize, changePassword, collapseEntitlements, convertToE164, createApiKey, createEnvelope, createField, createGroup, createInitials, createOrganization, createOrganizationContact, createOrganizationInvitation, createProfile, createSignature, createTag, createTemplate, createTemplateDocument, createTemplateFromSharepoint, createTemplateRole, declineOrganizationInvitation, decodeAccessTokenBody, decodeJWTBody, delegateRecipient, deleteApiKey, deleteEnvelopeFieldAttachment, deleteField, deleteGroup, deleteGroupMember, deleteOrganization, deleteOrganizationContact, deleteOrganizationInvitation, deleteOrganizationMember, deleteProfile, deleteSignature, deleteTemplate, deleteTemplateDocument, deleteTemplateRole, deleteTemplateTag, downloadBlob, downloadDocument, duplicateTemplate, envelopeIsActive, envelopeIsComplete, envelopeRecipientAgree, envelopeRecipientChangeOwner, envelopeRecipientDecline, envelopeRecipientPrepare, envelopeRecipientSubmit, envelopeRecipientUpdateName, fileToDataUrl, formatFullName, formatInitials, formatShortTimeAgo, fullNameToInitials, getActiveEntitlements, getAllTags, getApiKeys, getCountryByCode, getCurrentProfile, getDocumentDownloadLink, getDocumentPreviewLink, getEntitlements, getEnvelope, getEnvelopeDocument, getEnvelopeDocumentPageDisplayUri, getEnvelopeFile, getEnvelopes, getFieldAttachment, getFieldsForRole, getGroup, getGroups, getInPersonLink, getKbaStep, getMatchingCountry, getMyUser, getNextRecipient, getNotifications, getOrganization, getOrganizationChildren, getOrganizationContacts, getOrganizationInvitation, getOrganizationInvitations, getOrganizationMembers, getOrganizationUsage, getPlusOneCountry, getProfiles, getRGB, getRGBA, getRLeft, getRTop, getRValue, getRecipientsWithActions, getRoleColor, getSignature, getSignatures, getStars, getTag, getTemplate, getTemplateDocument, getTemplateDocumentFile, getTemplateDocumentPageDisplayUri, getTemplateDocumentThumbnail, getTemplateDocuments, getTemplateTags, getTemplates, getValidator, getValidators, getWebhooks, hasRequiredPermissions, integerSequence, isAmericanSamoa, isCanada, isDominicanRepublic, isEnvelopeOwner, isEnvelopeRecipient, isFrenchGuiana, isGuadeloupe, isMartinique, isMayotte, isPuertoRico, isValidEmail, isValidPhone, isValidRoleName, isValidTag, nameToRGBA, randomString, recipientCanAct, recipientHasAction, refreshToken, remindRecipient, rescale, resendOrganizationInvitation, resendVerification, resetPassword, resetRecipient, rotateApiKey, setWebhooks, sortFields, startSigningSession, submitKbaChallengeResponse, submitKbaIdentity, submitKbaPin, switchProfile, toggleStar, updateApiKey, updateEnvelope, updateEnvelopeField, updateEnvelopeFieldInitials, updateEnvelopeFieldSignature, updateField, updateGroup, updateOrganization, updateOrganizationContact, updateOrganizationInvitation, updateOrganizationLogo, updateOrganizationMember, updateOrganizationThumbnail, updateProfile, updateProfilePhoto, updateRecipient, updateRecipientStatus, updateTemplate, updateTemplateRole, uploadEnvelopeFieldAttachment, useCanAccessEnvelope, userCanAct, userCanBuildTemplate, userCanCancelEnvelope, userCanChangeOrgVisibility, userCanCreateOrgTemplate, userCanCreatePersonalTemplate, userCanCreatePublicTemplate, userCanCreateTemplate, userCanDeleteTemplate, userCanFinishEnvelope, userCanMakeTemplatePrivate, userCanMakeTemplatePublic, userCanMakeTemplateShared, userCanPreviewTemplate, userCanReadTemplate, userCanSendTemplate, userCanSignNow, userCanUpdateTemplate, userHasPermissions, userHasSharedTemplate, userIsEnvelopeOwner, userIsEnvelopeRecipient, userIsTemplateCreator, verifyEmail, verifySigner };
3604
+ export { ALL_PERMISSIONS, AtoB, Countries, DEFAULT_FIELD_HEIGHTS, DEFAULT_FIELD_WIDTHS, FIELD_TYPES, RolePermissions, VerdocsEndpoint, WEBHOOK_EVENTS, acceptOrganizationInvitation, addGroupMember, authenticate, blobToBase64, canAccessEnvelope, canPerformTemplateAction, cancelEnvelope, capitalize, changePassword, collapseEntitlements, convertToE164, createApiKey, createEnvelope, createField, createGroup, createInitials, createOrganization, createOrganizationContact, createOrganizationInvitation, createProfile, createSignature, createTemplate, createTemplateDocument, createTemplateFromSharepoint, createTemplateRole, declineOrganizationInvitation, decodeAccessTokenBody, decodeJWTBody, delegateRecipient, deleteApiKey, deleteEnvelopeFieldAttachment, deleteField, deleteGroup, deleteGroupMember, deleteOrganization, deleteOrganizationContact, deleteOrganizationInvitation, deleteOrganizationMember, deleteProfile, deleteTemplate, deleteTemplateDocument, deleteTemplateRole, downloadBlob, downloadEnvelopeDocument, downloadTemplateDocument, duplicateTemplate, envelopeIsActive, envelopeIsComplete, envelopeRecipientAgree, envelopeRecipientDecline, envelopeRecipientSubmit, fileToDataUrl, formatFullName, formatInitials, formatShortTimeAgo, fullNameToInitials, getActiveEntitlements, getApiKeys, getCountryByCode, getCurrentProfile, getEntitlements, getEnvelope, getEnvelopeDocument, getEnvelopeDocumentDownloadLink, getEnvelopeDocumentPageDisplayUri, getEnvelopeDocumentPreviewLink, getEnvelopeFile, getEnvelopes, getEnvelopesZip, getFieldsForRole, getGroup, getGroups, getInPersonLink, getKbaStep, getMatchingCountry, getMyUser, getNextRecipient, getNotifications, getOrganization, getOrganizationChildren, getOrganizationContacts, getOrganizationInvitation, getOrganizationInvitations, getOrganizationMembers, getOrganizationUsage, getPlusOneCountry, getProfiles, getRGB, getRGBA, getRLeft, getRTop, getRValue, getRecipientsWithActions, getRoleColor, getTemplate, getTemplateDocument, getTemplateDocumentDownloadLink, getTemplateDocumentFile, getTemplateDocumentPageDisplayUri, getTemplateDocumentPreviewLink, getTemplateDocumentThumbnail, getTemplates, getValidators, getWebhooks, hasRequiredPermissions, integerSequence, isAmericanSamoa, isCanada, isDominicanRepublic, isEnvelopeOwner, isEnvelopeRecipient, isFrenchGuiana, isGuadeloupe, isMartinique, isMayotte, isPuertoRico, isValidEmail, isValidInput, isValidPhone, isValidRoleName, isValidTag, nameToRGBA, randomString, recipientCanAct, recipientHasAction, refreshToken, remindRecipient, rescale, resendOrganizationInvitation, resendVerification, resetPassword, resetRecipient, rotateApiKey, setWebhooks, sortFields, startSigningSession, submitKbaChallengeResponse, submitKbaIdentity, submitKbaPin, switchProfile, toggleTemplateStar, updateApiKey, updateEnvelope, updateEnvelopeField, updateField, updateGroup, updateOrganization, updateOrganizationContact, updateOrganizationInvitation, updateOrganizationLogo, updateOrganizationMember, updateOrganizationThumbnail, updateProfile, updateProfilePhoto, updateRecipient, updateTemplate, updateTemplateRole, uploadEnvelopeFieldAttachment, useCanAccessEnvelope, userCanAct, userCanBuildTemplate, userCanCancelEnvelope, userCanChangeOrgVisibility, userCanCreateOrgTemplate, userCanCreatePersonalTemplate, userCanCreatePublicTemplate, userCanCreateTemplate, userCanDeleteTemplate, userCanFinishEnvelope, userCanMakeTemplatePrivate, userCanMakeTemplatePublic, userCanMakeTemplateShared, userCanPreviewTemplate, userCanReadTemplate, userCanSendTemplate, userCanSignNow, userCanUpdateTemplate, userHasPermissions, userHasSharedTemplate, userIsEnvelopeOwner, userIsEnvelopeRecipient, userIsTemplateCreator, verifyEmail, verifySigner };
3712
3605
  //# sourceMappingURL=index.mjs.map