@verdocs/js-sdk 6.4.2 → 6.4.4

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
@@ -268,34 +268,6 @@ function blobToBase64(image) {
268
268
  function rescale(r, n) {
269
269
  return r * n;
270
270
  }
271
- /**
272
- * Utility function to sort fields by page, then by Y coordinate, then by X coordinate.
273
- * NOTE: This function mutates the input array.
274
- */
275
- function sortFields(fields) {
276
- fields.sort((a, b) => {
277
- const aPage = a.page || 0;
278
- const bPage = b.page || 0;
279
- const aX = a.x || 0;
280
- const aY = (a.y || 0) + (a.height || 0);
281
- const bX = b.x || 0;
282
- const bY = (b.y || 0) + (b.height || 0);
283
- if (aPage !== bPage) {
284
- return aPage - bPage;
285
- }
286
- // NOTE: Logic looks a little strange X vs Y. It's because we go top down,
287
- // left to right. But Y coordinates are inverted in PDFs. The reason for
288
- // the division is because no human makes perfect templates and frequently
289
- // two fields on the "same line" will be slightly offset vertically.
290
- const divaY = Math.floor(aY / 5);
291
- const divbY = Math.floor(bY / 5);
292
- if (divaY !== divbY) {
293
- return divbY - divaY;
294
- }
295
- return aX - bX;
296
- });
297
- return fields;
298
- }
299
271
 
300
272
  /**
301
273
  * Given a File, extract the file's content as a base64 encoded data URL. The response will have a prefix that
@@ -1794,6 +1766,51 @@ const getEnvelopes = (endpoint, params) => endpoint.api //
1794
1766
  */
1795
1767
  const getEnvelopesZip = (endpoint, envelope_ids) => endpoint.api //
1796
1768
  .get(`/v2/envelopes/zip/${envelope_ids.join(',')}`, { responseType: 'blob', timeout: 120000 });
1769
+ /**
1770
+ * Utility function to sort fields by page, then by Y coordinate, then by X coordinate.
1771
+ * NOTE: This function mutates the input array.
1772
+ */
1773
+ function sortFields(fields) {
1774
+ fields.sort((a, b) => {
1775
+ const aPage = a.page || 0;
1776
+ const bPage = b.page || 0;
1777
+ const aX = a.x || 0;
1778
+ const aY = (a.y || 0) + (a.height || 0);
1779
+ const bX = b.x || 0;
1780
+ const bY = (b.y || 0) + (b.height || 0);
1781
+ if (aPage !== bPage) {
1782
+ return aPage - bPage;
1783
+ }
1784
+ // NOTE: Logic looks a little strange X vs Y. It's because we go top down,
1785
+ // left to right. But Y coordinates are inverted in PDFs. The reason for
1786
+ // the division is because no human makes perfect templates and frequently
1787
+ // two fields on the "same line" will be slightly offset vertically.
1788
+ const divaY = Math.floor(aY / 5);
1789
+ const divbY = Math.floor(bY / 5);
1790
+ if (divaY !== divbY) {
1791
+ return divbY - divaY;
1792
+ }
1793
+ return aX - bX;
1794
+ });
1795
+ return fields;
1796
+ }
1797
+ /**
1798
+ * Utility function to sort documents by their order, falling back to created_at.
1799
+ * NOTE: This function mutates the input array.
1800
+ */
1801
+ function sortDocuments(documents) {
1802
+ return documents.sort((a, b) =>
1803
+ // The Date conversion is unnecessary 90% of the time but is safer, and this isn't something
1804
+ // we do much of so in reality it has almmost no impact.
1805
+ a.order !== b.order ? a.order - b.order : new Date(a.created_at).getTime() - new Date(b.created_at).getTime());
1806
+ }
1807
+ /**
1808
+ * Utility function to sort documents by their order, falling back to created_at.
1809
+ * NOTE: This function mutates the input array.
1810
+ */
1811
+ function sortRecipients(recipients) {
1812
+ return recipients?.sort((a, b) => (a.sequence !== b.sequence ? b.sequence - a.sequence : b.order - a.order));
1813
+ }
1797
1814
 
1798
1815
  const canPerformTemplateAction = (profile, action, template) => {
1799
1816
  if (!template && !action.includes('create')) {
@@ -3746,5 +3763,5 @@ const rotateWebhookSecret = (endpoint) => endpoint.api //
3746
3763
  .put(`/v2/webhooks/rotate-secret`)
3747
3764
  .then((r) => r.data);
3748
3765
 
3749
- export { ALL_PERMISSIONS, AtoB, Countries, DEFAULT_DISCLOSURES, DEFAULT_FIELD_HEIGHTS, DEFAULT_FIELD_WIDTHS, FIELD_TYPES, RolePermissions, VerdocsEndpoint, WEBHOOK_EVENTS, acceptOrganizationInvitation, addGroupMember, askQuestion, 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, isFieldFilled, isFieldValid, isFrenchGuiana, isGuadeloupe, isMartinique, isMayotte, isPuertoRico, isValidEmail, isValidInput, isValidPhone, isValidRoleName, isValidTag, nameToRGBA, randomString, recipientCanAct, recipientHasAction, refreshToken, remindRecipient, rescale, resendOrganizationInvitation, resendVerification, resetPassword, resetRecipient, rotateApiKey, rotateWebhookSecret, 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 };
3766
+ export { ALL_PERMISSIONS, AtoB, Countries, DEFAULT_DISCLOSURES, DEFAULT_FIELD_HEIGHTS, DEFAULT_FIELD_WIDTHS, FIELD_TYPES, RolePermissions, VerdocsEndpoint, WEBHOOK_EVENTS, acceptOrganizationInvitation, addGroupMember, askQuestion, 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, isFieldFilled, isFieldValid, isFrenchGuiana, isGuadeloupe, isMartinique, isMayotte, isPuertoRico, isValidEmail, isValidInput, isValidPhone, isValidRoleName, isValidTag, nameToRGBA, randomString, recipientCanAct, recipientHasAction, refreshToken, remindRecipient, rescale, resendOrganizationInvitation, resendVerification, resetPassword, resetRecipient, rotateApiKey, rotateWebhookSecret, setWebhooks, sortDocuments, sortFields, sortRecipients, 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 };
3750
3767
  //# sourceMappingURL=index.mjs.map