@verdocs/js-sdk 4.1.14 → 4.1.15
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.d.mts +76 -45
- package/dist/index.d.ts +76 -45
- package/dist/index.js +89 -57
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +89 -57
- package/dist/index.mjs.map +1 -1
- package/dist/package.json +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1503,11 +1503,11 @@ const deleteEnvelopeReminder = (endpoint, envelopeId, reminderId) => endpoint.ap
|
|
|
1503
1503
|
/**
|
|
1504
1504
|
* Check to see if the user owns the envelope.
|
|
1505
1505
|
*/
|
|
1506
|
-
const userIsEnvelopeOwner = (
|
|
1506
|
+
const userIsEnvelopeOwner = (profile, envelope) => envelope.profile_id === profile?.id;
|
|
1507
1507
|
/**
|
|
1508
1508
|
* Check to see if the user owns the envelope.
|
|
1509
1509
|
*/
|
|
1510
|
-
const userIsEnvelopeRecipient = (
|
|
1510
|
+
const userIsEnvelopeRecipient = (profile, envelope) => envelope.profile_id === profile?.id;
|
|
1511
1511
|
/**
|
|
1512
1512
|
* Check to see if the envelope has pending actions.
|
|
1513
1513
|
*/
|
|
@@ -1519,14 +1519,14 @@ const envelopeIsComplete = (envelope) => envelope.status !== 'complete';
|
|
|
1519
1519
|
/**
|
|
1520
1520
|
* Check to see if the user owns the envelope.
|
|
1521
1521
|
*/
|
|
1522
|
-
const userCanCancelEnvelope = (
|
|
1522
|
+
const userCanCancelEnvelope = (profile, envelope) => userIsEnvelopeOwner(profile, envelope) &&
|
|
1523
1523
|
envelope.status !== 'complete' &&
|
|
1524
1524
|
envelope.status !== 'declined' &&
|
|
1525
1525
|
envelope.status !== 'canceled';
|
|
1526
1526
|
/**
|
|
1527
1527
|
* Check to see if the user owns the envelope.
|
|
1528
1528
|
*/
|
|
1529
|
-
const userCanFinishEnvelope = (
|
|
1529
|
+
const userCanFinishEnvelope = (profile, envelope) => userIsEnvelopeOwner(profile, envelope) &&
|
|
1530
1530
|
envelope.status !== 'complete' &&
|
|
1531
1531
|
envelope.status !== 'declined' &&
|
|
1532
1532
|
envelope.status !== 'canceled';
|
|
@@ -1552,15 +1552,15 @@ const userCanAct = (email, recipientsWithActions) => {
|
|
|
1552
1552
|
/**
|
|
1553
1553
|
* Returns true if the user can act.
|
|
1554
1554
|
*/
|
|
1555
|
-
const userCanSignNow = (
|
|
1556
|
-
if (!
|
|
1555
|
+
const userCanSignNow = (profile, envelope) => {
|
|
1556
|
+
if (!profile) {
|
|
1557
1557
|
return false;
|
|
1558
1558
|
}
|
|
1559
1559
|
const recipientsWithActions = getRecipientsWithActions(envelope);
|
|
1560
|
-
const myRecipient = recipientsWithActions.find((r) => r.profile_id ===
|
|
1560
|
+
const myRecipient = recipientsWithActions.find((r) => r.profile_id === profile?.id || r.email === profile?.email);
|
|
1561
1561
|
return (myRecipient &&
|
|
1562
1562
|
envelopeIsActive(envelope) &&
|
|
1563
|
-
userIsEnvelopeRecipient(
|
|
1563
|
+
userIsEnvelopeRecipient(profile, envelope) &&
|
|
1564
1564
|
recipientCanAct(myRecipient, recipientsWithActions));
|
|
1565
1565
|
};
|
|
1566
1566
|
const getNextRecipient = (envelope) => {
|
|
@@ -1616,9 +1616,9 @@ const deleteSignature = (endpoint, signatureId) => endpoint.api //
|
|
|
1616
1616
|
* Get a list of keys for a given organization. The caller must have admin access to the organization.
|
|
1617
1617
|
*
|
|
1618
1618
|
* ```typescript
|
|
1619
|
-
* import {
|
|
1619
|
+
* import {getApiKeys} from '@verdocs/js-sdk';
|
|
1620
1620
|
*
|
|
1621
|
-
* const keys = await
|
|
1621
|
+
* const keys = await getApiKeys(ORGID);
|
|
1622
1622
|
* ```
|
|
1623
1623
|
*/
|
|
1624
1624
|
const getApiKeys = (endpoint) => endpoint.api //
|
|
@@ -1628,9 +1628,9 @@ const getApiKeys = (endpoint) => endpoint.api //
|
|
|
1628
1628
|
* Create an API key.
|
|
1629
1629
|
*
|
|
1630
1630
|
* ```typescript
|
|
1631
|
-
* import {
|
|
1631
|
+
* import {createApiKey} from '@verdocs/js-sdk';
|
|
1632
1632
|
*
|
|
1633
|
-
* await
|
|
1633
|
+
* await createApiKey(ORGID, {name: NEWNAME});
|
|
1634
1634
|
* ```
|
|
1635
1635
|
*/
|
|
1636
1636
|
const createApiKey = (endpoint, params) => endpoint.api //
|
|
@@ -1640,9 +1640,9 @@ const createApiKey = (endpoint, params) => endpoint.api //
|
|
|
1640
1640
|
* Rotate the secret for an API key. The caller must have admin access to the organization.
|
|
1641
1641
|
*
|
|
1642
1642
|
* ```typescript
|
|
1643
|
-
* import {
|
|
1643
|
+
* import {rotateApiKey} from '@verdocs/js-sdk';
|
|
1644
1644
|
*
|
|
1645
|
-
* const {client_secret: newSecret} = await
|
|
1645
|
+
* const {client_secret: newSecret} = await rotateApiKey(ORGID, CLIENTID);
|
|
1646
1646
|
* ```
|
|
1647
1647
|
*/
|
|
1648
1648
|
const rotateApiKey = (endpoint, clientId) => endpoint.api //
|
|
@@ -1652,9 +1652,9 @@ const rotateApiKey = (endpoint, clientId) => endpoint.api //
|
|
|
1652
1652
|
* Update an API key to change its assigned Profile ID or Name.
|
|
1653
1653
|
*
|
|
1654
1654
|
* ```typescript
|
|
1655
|
-
* import {
|
|
1655
|
+
* import {updateApiKey} from '@verdocs/js-sdk';
|
|
1656
1656
|
*
|
|
1657
|
-
* await
|
|
1657
|
+
* await updateApiKey(ORGID, CLIENTID, {name: NEWNAME});
|
|
1658
1658
|
* ```
|
|
1659
1659
|
*/
|
|
1660
1660
|
const updateApiKey = (endpoint, clientId, params) => endpoint.api //
|
|
@@ -1664,9 +1664,9 @@ const updateApiKey = (endpoint, clientId, params) => endpoint.api //
|
|
|
1664
1664
|
* Delete an API key.
|
|
1665
1665
|
*
|
|
1666
1666
|
* ```typescript
|
|
1667
|
-
* import {
|
|
1667
|
+
* import {deleteApiKey} from '@verdocs/js-sdk';
|
|
1668
1668
|
*
|
|
1669
|
-
* await
|
|
1669
|
+
* await deleteApiKey(ORGID, CLIENTID);
|
|
1670
1670
|
* ```
|
|
1671
1671
|
*/
|
|
1672
1672
|
const deleteApiKey = (endpoint, clientId) => endpoint.api //
|
|
@@ -1790,19 +1790,37 @@ const declineOrganizationInvitation = (endpoint, email, token) => endpoint.api /
|
|
|
1790
1790
|
*/
|
|
1791
1791
|
/**
|
|
1792
1792
|
* Get a list of the members in the caller's organization.
|
|
1793
|
+
*
|
|
1794
|
+
* ```typescript
|
|
1795
|
+
* import {getOrganizationMembers} from '@verdocs/js-sdk';
|
|
1796
|
+
*
|
|
1797
|
+
* const members = await deleteOrganizationMember(VerdocsEndpoint.getDefault()});
|
|
1798
|
+
* ```
|
|
1793
1799
|
*/
|
|
1794
1800
|
const getOrganizationMembers = (endpoint) => endpoint.api //
|
|
1795
1801
|
.get(`/v2/organization-members`)
|
|
1796
1802
|
.then((r) => r.data);
|
|
1797
1803
|
/**
|
|
1798
1804
|
* Delete a member from the caller's organization. Note that the caller must be an admin or owner,
|
|
1799
|
-
* may not delete him/herself
|
|
1805
|
+
* may not delete him/herself.
|
|
1806
|
+
*
|
|
1807
|
+
* ```typescript
|
|
1808
|
+
* import {deleteOrganizationMember} from '@verdocs/js-sdk';
|
|
1809
|
+
*
|
|
1810
|
+
* await deleteOrganizationMember(VerdocsEndpoint.getDefault(), 'PROFILEID'});
|
|
1811
|
+
* ```
|
|
1800
1812
|
*/
|
|
1801
1813
|
const deleteOrganizationMember = (endpoint, profileId) => endpoint.api //
|
|
1802
1814
|
.delete(`/v2/organization-members/${profileId}`)
|
|
1803
1815
|
.then((r) => r.data);
|
|
1804
1816
|
/**
|
|
1805
1817
|
* Update a member.
|
|
1818
|
+
*
|
|
1819
|
+
* ```typescript
|
|
1820
|
+
* import {updateOrganizationMember} from '@verdocs/js-sdk';
|
|
1821
|
+
*
|
|
1822
|
+
* const result = await updateOrganizationMember(VerdocsEndpoint.getDefault(), 'PROFILEID', {roles:['member']});
|
|
1823
|
+
* ```
|
|
1806
1824
|
*/
|
|
1807
1825
|
const updateOrganizationMember = (endpoint, profileId, params) => endpoint.api //
|
|
1808
1826
|
.patch(`/v2/organization-members/${profileId}`, params)
|
|
@@ -1900,13 +1918,27 @@ const updateOrganizationThumbnail = (endpoint, organizationId, file, onUploadPro
|
|
|
1900
1918
|
* @module
|
|
1901
1919
|
*/
|
|
1902
1920
|
/**
|
|
1903
|
-
* Get the registered
|
|
1921
|
+
* Get the registered Webhook configuration for the caller's organization.
|
|
1922
|
+
*
|
|
1923
|
+
* ```typescript
|
|
1924
|
+
* import {getWebhooks} from '@verdocs/js-sdk';
|
|
1925
|
+
*
|
|
1926
|
+
* await getWebhooks(ORGID, params);
|
|
1927
|
+
* ```
|
|
1904
1928
|
*/
|
|
1905
1929
|
const getWebhooks = (endpoint) => endpoint.api //
|
|
1906
1930
|
.get(`/v2/webhooks/organization`)
|
|
1907
1931
|
.then((r) => r.data);
|
|
1908
1932
|
/**
|
|
1909
|
-
* Update the registered
|
|
1933
|
+
* Update the registered Webhook configuration for the caller's organization. Note that
|
|
1934
|
+
* Webhooks cannot currently be deleted, but may be easily disabled by setting `active`
|
|
1935
|
+
* to `false` and/or setting the `url` to an empty string.
|
|
1936
|
+
*
|
|
1937
|
+
* ```typescript
|
|
1938
|
+
* import {setWebhooks} from '@verdocs/js-sdk';
|
|
1939
|
+
*
|
|
1940
|
+
* await setWebhooks(ORGID, params);
|
|
1941
|
+
* ```
|
|
1910
1942
|
*/
|
|
1911
1943
|
const setWebhooks = (endpoint, params) => endpoint.api //
|
|
1912
1944
|
.patch(`/v2/webhooks/organization`, params)
|
|
@@ -1915,16 +1947,16 @@ const setWebhooks = (endpoint, params) => endpoint.api //
|
|
|
1915
1947
|
/**
|
|
1916
1948
|
* Confirm whether the user has all of the specified permissions.
|
|
1917
1949
|
*/
|
|
1918
|
-
const userHasPermissions = (
|
|
1950
|
+
const userHasPermissions = (profile, permissions) => permissions.every((perm) => (profile?.permissions || []).includes(perm));
|
|
1919
1951
|
|
|
1920
|
-
const canPerformTemplateAction = (
|
|
1952
|
+
const canPerformTemplateAction = (profile, action, template) => {
|
|
1921
1953
|
if (!template && !action.includes('create')) {
|
|
1922
1954
|
return { canPerform: false, message: 'Missing required template object' };
|
|
1923
1955
|
}
|
|
1924
1956
|
// We use BOGUS here to force the option-chain in things like template?.profile_id to NOT match profile?.profile_id because if both
|
|
1925
1957
|
// were undefined, they would actually match.
|
|
1926
|
-
const profile_id =
|
|
1927
|
-
const organization_id =
|
|
1958
|
+
const profile_id = profile?.id || 'BOGUS';
|
|
1959
|
+
const organization_id = profile?.organization_id || 'BOGUS';
|
|
1928
1960
|
if (!profile_id) {
|
|
1929
1961
|
return { canPerform: false, message: 'Active session required' };
|
|
1930
1962
|
}
|
|
@@ -1992,12 +2024,12 @@ const canPerformTemplateAction = (session, action, template) => {
|
|
|
1992
2024
|
default:
|
|
1993
2025
|
return { canPerform: false, message: 'Action is not defined' };
|
|
1994
2026
|
}
|
|
1995
|
-
if (hasRequiredPermissions(
|
|
2027
|
+
if (hasRequiredPermissions(profile, permissionsRequired)) {
|
|
1996
2028
|
return { canPerform: true, message: '' };
|
|
1997
2029
|
}
|
|
1998
2030
|
return { canPerform: false, message: `Insufficient access to perform '${action}'. Needed permissions: ${permissionsRequired.toString()}` };
|
|
1999
2031
|
};
|
|
2000
|
-
const hasRequiredPermissions = (
|
|
2032
|
+
const hasRequiredPermissions = (profile, permissions) => permissions.every((perm) => (profile?.permissions || []).includes(perm));
|
|
2001
2033
|
|
|
2002
2034
|
/**
|
|
2003
2035
|
* Add a field to a template.
|
|
@@ -2026,72 +2058,72 @@ const deleteField = (endpoint, templateId, fieldName) => endpoint.api //
|
|
|
2026
2058
|
/**
|
|
2027
2059
|
* Check to see if the user created the template.
|
|
2028
2060
|
*/
|
|
2029
|
-
const userIsTemplateCreator = (
|
|
2061
|
+
const userIsTemplateCreator = (profile, template) => profile && template && profile.id === template.profile_id;
|
|
2030
2062
|
/**
|
|
2031
2063
|
* Check to see if a template is "shared" with the user.
|
|
2032
2064
|
*/
|
|
2033
|
-
const userHasSharedTemplate = (
|
|
2065
|
+
const userHasSharedTemplate = (profile, template) => profile && template && !template.is_personal && profile.organization_id === template.organization_id;
|
|
2034
2066
|
/**
|
|
2035
2067
|
* Check to see if the user can create a personal/private template.
|
|
2036
2068
|
*/
|
|
2037
|
-
const userCanCreatePersonalTemplate = (
|
|
2069
|
+
const userCanCreatePersonalTemplate = (profile) => userHasPermissions(profile, ['template:creator:create:personal']);
|
|
2038
2070
|
/**
|
|
2039
2071
|
* Check to see if the user can create an org-shared template.
|
|
2040
2072
|
*/
|
|
2041
|
-
const userCanCreateOrgTemplate = (
|
|
2073
|
+
const userCanCreateOrgTemplate = (profile) => userHasPermissions(profile, ['template:creator:create:org']);
|
|
2042
2074
|
/**
|
|
2043
2075
|
* Check to see if the user can create a public template.
|
|
2044
2076
|
*/
|
|
2045
|
-
const userCanCreatePublicTemplate = (
|
|
2077
|
+
const userCanCreatePublicTemplate = (profile) => userHasPermissions(profile, ['template:creator:create:public']);
|
|
2046
2078
|
/**
|
|
2047
2079
|
* Check to see if the user can read/view a template.
|
|
2048
2080
|
*/
|
|
2049
|
-
const userCanReadTemplate = (
|
|
2050
|
-
userIsTemplateCreator(
|
|
2051
|
-
(userHasSharedTemplate(
|
|
2081
|
+
const userCanReadTemplate = (profile, template) => template.is_public ||
|
|
2082
|
+
userIsTemplateCreator(profile, template) ||
|
|
2083
|
+
(userHasSharedTemplate(profile, template) && userHasPermissions(profile, ['template:member:read']));
|
|
2052
2084
|
/**
|
|
2053
2085
|
* Check to see if the user can update a tempate.
|
|
2054
2086
|
*/
|
|
2055
|
-
const userCanUpdateTemplate = (
|
|
2056
|
-
(userHasSharedTemplate(
|
|
2087
|
+
const userCanUpdateTemplate = (profile, template) => userIsTemplateCreator(profile, template) ||
|
|
2088
|
+
(userHasSharedTemplate(profile, template) && userHasPermissions(profile, ['template:member:read', 'template:member:write']));
|
|
2057
2089
|
/**
|
|
2058
2090
|
* Check to see if the user can change whether a template is personal vs org-shared.
|
|
2059
2091
|
*/
|
|
2060
|
-
const userCanMakeTemplatePrivate = (
|
|
2061
|
-
? userHasPermissions(
|
|
2062
|
-
: userHasPermissions(
|
|
2092
|
+
const userCanMakeTemplatePrivate = (profile, template) => userIsTemplateCreator(profile, template)
|
|
2093
|
+
? userHasPermissions(profile, ['template:creator:create:personal'])
|
|
2094
|
+
: userHasPermissions(profile, ['template:member:visibility']);
|
|
2063
2095
|
/**
|
|
2064
2096
|
* Check to see if the user can change whether a template is personal vs org-shared.
|
|
2065
2097
|
*/
|
|
2066
|
-
const userCanMakeTemplateShared = (
|
|
2067
|
-
? userHasPermissions(
|
|
2068
|
-
: userHasPermissions(
|
|
2098
|
+
const userCanMakeTemplateShared = (profile, template) => userIsTemplateCreator(profile, template)
|
|
2099
|
+
? userHasPermissions(profile, ['template:creator:create:org'])
|
|
2100
|
+
: userHasPermissions(profile, ['template:member:visibility']);
|
|
2069
2101
|
/**
|
|
2070
2102
|
* Check to see if the user can change whether a template is personal vs org-shared.
|
|
2071
2103
|
*/
|
|
2072
|
-
const userCanMakeTemplatePublic = (
|
|
2073
|
-
? userHasPermissions(
|
|
2074
|
-
: userHasPermissions(
|
|
2104
|
+
const userCanMakeTemplatePublic = (profile, template) => userIsTemplateCreator(profile, template)
|
|
2105
|
+
? userHasPermissions(profile, ['template:creator:create:public'])
|
|
2106
|
+
: userHasPermissions(profile, ['template:member:visibility']);
|
|
2075
2107
|
/**
|
|
2076
2108
|
* Check to see if the user can change whether a template is personal vs org-shared.
|
|
2077
2109
|
*/
|
|
2078
|
-
const userCanChangeOrgVisibility = (
|
|
2110
|
+
const userCanChangeOrgVisibility = (profile, template) => userIsTemplateCreator(profile, template) && userHasPermissions(profile, ['template:creator:create:personal']);
|
|
2079
2111
|
/**
|
|
2080
2112
|
* Check to see if the user can change whether a template is personal vs org-shared.
|
|
2081
2113
|
*/
|
|
2082
|
-
const userCanDeleteTemplate = (
|
|
2083
|
-
? userHasPermissions(
|
|
2084
|
-
: userHasPermissions(
|
|
2114
|
+
const userCanDeleteTemplate = (profile, template) => userIsTemplateCreator(profile, template)
|
|
2115
|
+
? userHasPermissions(profile, ['template:creator:delete'])
|
|
2116
|
+
: userHasPermissions(profile, ['template:member:delete']);
|
|
2085
2117
|
/**
|
|
2086
2118
|
* Confirm whether the user can create an envelope using the specified template.
|
|
2087
2119
|
*/
|
|
2088
|
-
const userCanSendTemplate = (
|
|
2120
|
+
const userCanSendTemplate = (profile, template) => {
|
|
2089
2121
|
switch (template.sender) {
|
|
2090
2122
|
case 'creator':
|
|
2091
|
-
return userIsTemplateCreator(
|
|
2123
|
+
return userIsTemplateCreator(profile, template);
|
|
2092
2124
|
case 'organization_member':
|
|
2093
2125
|
case 'organization_member_as_creator':
|
|
2094
|
-
return userIsTemplateCreator(
|
|
2126
|
+
return userIsTemplateCreator(profile, template) || template.organization_id === profile?.organization_id;
|
|
2095
2127
|
default:
|
|
2096
2128
|
return true;
|
|
2097
2129
|
}
|
|
@@ -2099,19 +2131,19 @@ const userCanSendTemplate = (session, template) => {
|
|
|
2099
2131
|
/**
|
|
2100
2132
|
* Confirm whether the user can create a new template.
|
|
2101
2133
|
*/
|
|
2102
|
-
const userCanCreateTemplate = (
|
|
2134
|
+
const userCanCreateTemplate = (profile) => userCanCreatePersonalTemplate(profile) || userCanCreateOrgTemplate(profile) || userCanCreatePublicTemplate(profile);
|
|
2103
2135
|
/**
|
|
2104
2136
|
* Check to see if the user can "build" the template (use the field builder). The user must have write access to the
|
|
2105
2137
|
* template, and the template must have at least one signer role.
|
|
2106
2138
|
*/
|
|
2107
|
-
const userCanBuildTemplate = (
|
|
2139
|
+
const userCanBuildTemplate = (profile, template) => userCanUpdateTemplate(profile, template) && (template.roles || []).filter((role) => role.type === 'signer').length > 0;
|
|
2108
2140
|
const getFieldsForRole = (template, role_name) => (template.fields || []).filter((field) => field.role_name === role_name);
|
|
2109
2141
|
/**
|
|
2110
2142
|
* Check to see if the user can preview the template. The user must have read access to the template, the template must
|
|
2111
2143
|
* have at least one signer, and every signer must have at least one field.
|
|
2112
2144
|
*/
|
|
2113
|
-
const userCanPreviewTemplate = (
|
|
2114
|
-
const hasPermission = userCanReadTemplate(
|
|
2145
|
+
const userCanPreviewTemplate = (profile, template) => {
|
|
2146
|
+
const hasPermission = userCanReadTemplate(profile, template);
|
|
2115
2147
|
const signers = (template.roles || []).filter((role) => role.type === 'signer');
|
|
2116
2148
|
return hasPermission && signers.length > 0 && signers.every((signer) => getFieldsForRole(template, signer.name).length > 0);
|
|
2117
2149
|
};
|