@verdocs/js-sdk 6.1.1 → 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.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.
1701
- */
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.
1693
+ * Upload an attachment to an attachment field.
1729
1694
  */
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
@@ -1810,10 +1763,10 @@ const getEnvelopes = (endpoint, params) => endpoint.api //
1810
1763
  .then((r) => r.data);
1811
1764
 
1812
1765
  /**
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.
1766
+ * Create an initials block. In a typical signing workflow, the user is asked at the beginning of the process to
1767
+ * "adopt" an initials block to be used for all initials fields in the document. Thus, this is typically called
1768
+ * one time to create and store an initials block. Thereafter, the ID of the initials block may be re-used for each
1769
+ * initials field to be "stamped" by the user.
1817
1770
  *
1818
1771
  * Note: Both "guest" signers and authenticated users can create initials blocks. Guest signers
1819
1772
  * typically only ever have one, tied to that session. But authenticated users can create more than
@@ -1863,49 +1816,43 @@ const submitKbaChallengeResponse = (endpoint, envelope_id, role_name, responses)
1863
1816
  .then((r) => r.data);
1864
1817
 
1865
1818
  /**
1866
- * Update a recipient's status.
1819
+ * Agree to electronic signing dislosures.
1867
1820
  *
1868
1821
  * @group Recipients
1869
- * @api PUT /envelopes/:envelope_id/recipients/:role_name Update Recipient Status
1822
+ * @api POST /envelopes/:envelope_id/recipients/:role_name/agree Agree to e-Signing Disclosures
1870
1823
  * @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.
1824
+ * @apiParam string role_name The role to operate on.
1878
1825
  * @apiSuccess IRecipient . The updated Recipient.
1879
1826
  */
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
1827
  const envelopeRecipientAgree = (endpoint, envelopeId, roleName, disclosures) => endpoint.api //
1899
- .put(`/v2/envelopes/${envelopeId}/recipients/${encodeURIComponent(roleName)}`, { action: 'accept', disclosures })
1828
+ .post(`/v2/envelopes/${envelopeId}/recipients/${encodeURIComponent(roleName)}/agree`, { disclosures })
1900
1829
  .then((r) => r.data);
1901
1830
  /**
1902
- * Change a recipient's name.
1831
+ * Decline electronic signing dislosures. Note that if any recipient declines, the entire envelope
1832
+ * becomes non-viable and later recipients may no longer act. The creator will receive a notification
1833
+ * when this occurs.
1834
+ *
1835
+ * @group Recipients
1836
+ * @api POST /envelopes/:envelope_id/recipients/:role_name/decline Decline e-Signing Disclosures
1837
+ * @apiParam string(format:uuid) envelope_id The envelope to operate on.
1838
+ * @apiParam string role_name The role to adjust.
1839
+ * @apiSuccess IRecipient . The updated Recipient.
1903
1840
  */
1904
- const envelopeRecipientUpdateName = (endpoint, envelopeId, roleName, first_name, last_name) => updateRecipientStatus(endpoint, envelopeId, roleName, { action: 'update', first_name, last_name });
1841
+ const envelopeRecipientDecline = (endpoint, envelopeId, roleName) => endpoint.api //
1842
+ .post(`/v2/envelopes/${envelopeId}/recipients/${encodeURIComponent(roleName)}/decline`)
1843
+ .then((r) => r.data);
1905
1844
  /**
1906
- * Change a recipient's name.
1845
+ * Submit an envelope (signing is finished). Note that all fields must be valid/completed for this to succeed.
1846
+ *
1847
+ * @group Recipients
1848
+ * @api POST /envelopes/:envelope_id/recipients/:role_name/submit Submit envelope
1849
+ * @apiParam string(format:uuid) envelope_id The envelope to operate on.
1850
+ * @apiParam string role_name The role to submit.
1851
+ * @apiSuccess IRecipient . The updated Recipient.
1907
1852
  */
1908
- const envelopeRecipientPrepare = (endpoint, envelopeId, roleName, recipients) => updateRecipientStatus(endpoint, envelopeId, roleName, { action: 'prepare', recipients });
1853
+ const envelopeRecipientSubmit = (endpoint, envelopeId, roleName) => endpoint.api //
1854
+ .put(`/v2/envelopes/${envelopeId}/recipients/${roleName}/submit`)
1855
+ .then((r) => r.data);
1909
1856
  /**
1910
1857
  * Begin a signing session for an Envelope. This path requires an invite code, and should generally
1911
1858
  * be called with a NON-default Endpoint to avoid conflicting with any active user session the user
@@ -2099,7 +2046,7 @@ const recipientHasAction = (recipient) => !['submitted', 'canceled', 'declined']
2099
2046
  /**
2100
2047
  * Returns the recipients who still have a pending action. Note that not all of these recipients may be able to act (yet).
2101
2048
  */
2102
- const getRecipientsWithActions = (envelope) => (envelope?.recipients || []).filter(recipientHasAction);
2049
+ const getRecipientsWithActions = (envelope) => ['complete', 'declined', 'canceled'].includes(envelope.status) ? [] : (envelope?.recipients || []).filter(recipientHasAction);
2103
2050
  /**
2104
2051
  * Returns true if the recipient can act.
2105
2052
  */
@@ -2131,10 +2078,10 @@ const getNextRecipient = (envelope) => {
2131
2078
  };
2132
2079
 
2133
2080
  /**
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.
2081
+ * Create a signature block. In a typical signing workflow, the user is asked at the beginning of the process to
2082
+ * "adopt" a signature block to be used for all signature fields in the document. Thus, this is typically called one
2083
+ * time to create and store a signature block. Thereafter, the ID of the signature block may be re-used for each
2084
+ * signature field to be "stamped" by the user.
2138
2085
  *
2139
2086
  * Note: Both "guest" signers and authenticated users can create initials blocks. Guest signers
2140
2087
  * typically only ever have one, tied to that session. But authenticated users can create more than
@@ -2152,39 +2099,6 @@ const createSignature = (endpoint, name, signature) => {
2152
2099
  .post(`/v2/profiles/signatures`, data)
2153
2100
  .then((r) => r.data);
2154
2101
  };
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
2102
 
2189
2103
  /**
2190
2104
  * API keys are used to authenticate server-to-server calls. (API keys should **never** be used for client-to-server operations!)
@@ -3306,63 +3220,6 @@ const deleteTemplateRole = (endpoint, template_id, name) => endpoint.api //
3306
3220
  .delete(`/v2/roles/${template_id}/${encodeURIComponent(name)}`)
3307
3221
  .then((r) => r.data);
3308
3222
 
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
3223
  /**
3367
3224
  * A Template defines how a Verdocs signing flow will be performed, including attachments, signing fields, and
3368
3225
  * recipients.
@@ -3578,44 +3435,28 @@ const updateTemplate = (endpoint, templateId, params) => endpoint.api //
3578
3435
  const deleteTemplate = (endpoint, templateId) => endpoint.api //
3579
3436
  .delete(`/v2/templates/${templateId}`)
3580
3437
  .then((r) => r.data);
3581
-
3582
- /**
3583
- * A TemplateDocument represents a PDF or other attachment in a Template.
3584
- *
3585
- * @module
3586
- */
3587
3438
  /**
3588
- * Get all the Template Documents associated to a particular Template.
3439
+ * Toggle the template star for a template.
3589
3440
  *
3590
3441
  * ```typescript
3591
- * import {TemplateDocument} from '@verdocs/js-sdk/Templates';
3442
+ * import {toggleTemplateStar} from '@verdocs/js-sdk/Templates';
3592
3443
  *
3593
- * await TemplateDocument.geTemplateDocuments((VerdocsEndpoint.getDefault(), templateId);
3444
+ * await toggleTemplateStar((VerdocsEndpoint.getDefault(), '83da3d70-7857-4392-b876-c4592a304bc9');
3594
3445
  * ```
3595
3446
  *
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
3447
+ * @group Templates
3448
+ * @api POST /v2/templates/:template_id/star Star or unstar a template (toggle state)
3449
+ * @apiSuccess ITemplate . Success
3599
3450
  */
3600
- const getTemplateDocuments = (endpoint, templateId) => endpoint.api //
3601
- .get(`/templates/${templateId}/documents/`)
3451
+ const toggleTemplateStar = (endpoint, templateId) => endpoint.api //
3452
+ .post(`/v2/templates/${templateId}/stars/toggle`)
3602
3453
  .then((r) => r.data);
3454
+
3603
3455
  /**
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
- * ```
3456
+ * A TemplateDocument represents a PDF or other attachment in a Template.
3611
3457
  *
3612
- * @group Template Documents
3613
- * @api GET /v2/templates/:template_id/documents/:document_id Get an individual template document
3614
- * @apiSuccess ITemplateDocument . Template document
3458
+ * @module
3615
3459
  */
3616
- const getTemplateDocument = (endpoint, templateId, documentId) => endpoint.api //
3617
- .get(`/templates/${templateId}/documents/${documentId}`)
3618
- .then((r) => r.data);
3619
3460
  /**
3620
3461
  * Create a Document for a particular Template.
3621
3462
  *
@@ -3630,11 +3471,11 @@ const getTemplateDocument = (endpoint, templateId, documentId) => endpoint.api /
3630
3471
  * @apiBody string(format:binary) file Document file to attach. The file name will automatically be used as the document name.
3631
3472
  * @apiSuccess ITemplateDocument . Template document
3632
3473
  */
3633
- const createTemplateDocument = (endpoint, templateId, file, onUploadProgress) => {
3474
+ const createTemplateDocument = (endpoint, file, onUploadProgress) => {
3634
3475
  const formData = new FormData();
3635
3476
  formData.append('document', file, file.name);
3636
3477
  return endpoint.api //
3637
- .post(`/templates/${templateId}/documents`, formData, {
3478
+ .post(`/v2/template-documents`, formData, {
3638
3479
  timeout: 120000,
3639
3480
  onUploadProgress: (event) => {
3640
3481
  const total = event.total || 1;
@@ -3658,7 +3499,48 @@ const createTemplateDocument = (endpoint, templateId, file, onUploadProgress) =>
3658
3499
  * @apiSuccess string . Success
3659
3500
  */
3660
3501
  const deleteTemplateDocument = (endpoint, templateId, documentId) => endpoint.api //
3661
- .delete(`/templates/${templateId}/documents/${documentId}`)
3502
+ .delete(`/v2/templates/${templateId}/documents/${documentId}`)
3503
+ .then((r) => r.data);
3504
+ /**
3505
+ * Get all metadata for a template document. Note that when called by non-creators (e.g. Org Collaborators)
3506
+ * this will return only the **metadata** the caller is allowed to view.
3507
+ *
3508
+ * @group Template Documents
3509
+ * @api GET /v2/envelope-documents/:id Get envelope document
3510
+ * @apiParam string(format: 'uuid') document_id The ID of the document to retrieve.
3511
+ * @apiSuccess IEnvelopeDocument . The detailed metadata for the document requested
3512
+ */
3513
+ const getTemplateDocument = async (endpoint, documentId) => endpoint.api //
3514
+ .get(`/v2/template-documents/${documentId}`)
3515
+ .then((r) => r.data);
3516
+ /**
3517
+ * Download a document directly.
3518
+ */
3519
+ const downloadTemplateDocument = async (endpoint, documentId) => endpoint.api //
3520
+ .get(`/v2/template-documents/${documentId}?type=file`, { responseType: 'blob' })
3521
+ .then((r) => r.data);
3522
+ /**
3523
+ * Get an envelope document's metadata, or the document itself. If no "type" parameter is specified,
3524
+ * the document metadata is returned. If "type" is set to "file", the document binary content is
3525
+ * returned with Content-Type set to the MIME type of the file. If "type" is set to "download", a
3526
+ * string download link will be returned. If "type" is set to "preview" a string preview link will
3527
+ * be returned. This link expires quickly, so it should be accessed immediately and never shared.
3528
+ *
3529
+ * @group Template Documents
3530
+ * @api GET /v2/envelope-documents/:document_id Preview, Download, or Link to a Document
3531
+ * @apiParam string(format: 'uuid') document_id The ID of the document to retrieve.
3532
+ * @apiQuery string(enum:'file'|'download'|'preview') type? Download the file directly, generate a download link, or generate a preview link.
3533
+ * @apiSuccess string . The generated link.
3534
+ */
3535
+ const getTemplateDocumentDownloadLink = async (endpoint, _envelopeId, documentId) => endpoint.api //
3536
+ .get(`/v2/template-documents/${documentId}?type=download`)
3537
+ .then((r) => r.data);
3538
+ /**
3539
+ * Get a pre-signed preview link for an Envelope Document. This link expires quickly, so it should
3540
+ * be accessed immediately and never shared. Content-Disposition will be set to "inline".
3541
+ */
3542
+ const getTemplateDocumentPreviewLink = async (endpoint, _envelopeId, documentId) => endpoint.api //
3543
+ .get(`/v2/envelope-documents/${documentId}?type=preview`)
3662
3544
  .then((r) => r.data);
3663
3545
  /**
3664
3546
  * Get (binary download) a file attached to a Template. It is important to use this method
@@ -3666,7 +3548,7 @@ const deleteTemplateDocument = (endpoint, templateId, documentId) => endpoint.ap
3666
3548
  * request.
3667
3549
  */
3668
3550
  const getTemplateDocumentFile = async (endpoint, templateId, documentId) => endpoint.api //
3669
- .get(`/templates/${templateId}/documents/${documentId}?file=true`, { responseType: 'blob' })
3551
+ .get(`/v2/templates/${templateId}/documents/${documentId}?file=true`, { responseType: 'blob' })
3670
3552
  .then((r) => r.data);
3671
3553
  /**
3672
3554
  * Get (binary download) a file attached to a Template. It is important to use this method
@@ -3674,7 +3556,7 @@ const getTemplateDocumentFile = async (endpoint, templateId, documentId) => endp
3674
3556
  * request.
3675
3557
  */
3676
3558
  const getTemplateDocumentThumbnail = async (endpoint, templateId, documentId) => endpoint.api //
3677
- .get(`/templates/${templateId}/documents/${documentId}?thumbnail=true`, { responseType: 'blob' })
3559
+ .get(`/v2/templates/${templateId}/documents/${documentId}?thumbnail=true`, { responseType: 'blob' })
3678
3560
  .then((r) => r.data);
3679
3561
  /**
3680
3562
  * Get a display URI for a given page in a file attached to a template document. These pages are rendered server-side
@@ -3684,29 +3566,34 @@ const getTemplateDocumentThumbnail = async (endpoint, templateId, documentId) =>
3684
3566
  */
3685
3567
  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
3568
 
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
3569
  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
3570
  // @see https://www.regextester.com/1978
3705
3571
  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}))/;
3572
+ const URL_REGEX = /https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)/;
3573
+ const POSTAL_CODE_REGEX = /^[A-Za-z0-9-\s]{3,10}$/;
3574
+ const NUMBER_REGEX = /^\d+$/;
3575
+ const DATE_REGEX = /^(\d{4}[-\/]\d{2}[-\/]\d{2})|(\d{2}[-\/]\d{2}[-\/]\d{4})$/;
3576
+ const VALIDATORS = {
3577
+ email: { regex: EMAIL_REGEX, label: 'Email Address' },
3578
+ phone: { regex: PHONE_REGEX, label: 'Phone Number' },
3579
+ url: { regex: URL_REGEX, label: 'URL' },
3580
+ postal_code: { regex: POSTAL_CODE_REGEX, label: 'Zip/Postal Code' },
3581
+ number: { regex: NUMBER_REGEX, label: 'Number' },
3582
+ date: { regex: DATE_REGEX, label: 'Date' },
3583
+ };
3584
+ const isValidInput = (value, validator) => Object.keys(VALIDATORS).includes(validator) && VALIDATORS[validator].regex.test(value);
3585
+ /**
3586
+ * Get a list of available validators for field inputs. Note that validators always check strings,
3587
+ * because that is all a user can enter in an HTML input field. Numeric-format validators should
3588
+ * perform any necessary conversions internally. Validators never throw - they just return a boolean.
3589
+ * indicating whether the value is valid.
3590
+ */
3591
+ const getValidators = () => Object.keys(VALIDATORS);
3592
+ const isValidEmail = (email) => !!email && EMAIL_REGEX.test(email);
3706
3593
  const isValidPhone = (phone) => !!phone && PHONE_REGEX.test(phone);
3707
3594
  const isValidRoleName = (value, roles) => roles.findIndex((role) => role.name === value) !== -1;
3708
3595
  const TagRegEx = /^[a-zA-Z0-9-]{0,32}$/;
3709
3596
  const isValidTag = (value, tags) => TagRegEx.test(value) || tags.findIndex((tag) => tag === value) !== -1;
3710
3597
 
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 };
3598
+ 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, 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
3599
  //# sourceMappingURL=index.mjs.map