@verdocs/js-sdk 1.4.1 → 2.0.0
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/Documents/Documents.d.ts +26 -9
- package/Documents/Documents.js +42 -27
- package/Documents/Initials.d.ts +2 -1
- package/Documents/Initials.js +3 -4
- package/Documents/Recipients.d.ts +5 -1
- package/Documents/Recipients.js +6 -4
- package/Documents/Signatures.d.ts +14 -4
- package/Documents/Signatures.js +21 -13
- package/Documents/index.d.ts +0 -1
- package/Documents/index.js +0 -1
- package/Organizations/ApiKeys.d.ts +6 -5
- package/Organizations/ApiKeys.js +15 -16
- package/Organizations/Groups.d.ts +8 -7
- package/Organizations/Groups.js +21 -22
- package/Organizations/Invitations.d.ts +8 -7
- package/Organizations/Invitations.js +21 -22
- package/Organizations/Members.d.ts +6 -5
- package/Organizations/Members.js +15 -16
- package/Organizations/Organizations.d.ts +7 -6
- package/Organizations/Organizations.js +18 -19
- package/Organizations/Webhooks.d.ts +3 -2
- package/Organizations/Webhooks.js +6 -7
- package/Organizations/Whitelabel.d.ts +3 -2
- package/Organizations/Whitelabel.js +6 -7
- package/Search/Content.d.ts +4 -3
- package/Search/Content.js +9 -10
- package/Templates/Fields.d.ts +4 -3
- package/Templates/Fields.js +9 -10
- package/Templates/Pages.d.ts +5 -4
- package/Templates/Pages.js +12 -13
- package/Templates/Reminders.d.ts +5 -4
- package/Templates/Reminders.js +12 -13
- package/Templates/Roles.d.ts +8 -7
- package/Templates/Roles.js +21 -22
- package/Templates/Stars.d.ts +3 -2
- package/Templates/Stars.js +6 -7
- package/Templates/Tags.d.ts +7 -6
- package/Templates/Tags.js +18 -19
- package/Templates/TemplateDocuments.d.ts +5 -4
- package/Templates/TemplateDocuments.js +12 -13
- package/Templates/Templates.d.ts +7 -6
- package/Templates/Templates.js +18 -19
- package/Templates/Validators.d.ts +3 -2
- package/Templates/Validators.js +7 -10
- package/Users/Auth.d.ts +9 -27
- package/Users/Auth.js +18 -105
- package/Users/Billing.d.ts +1 -1
- package/Users/Billing.js +1 -1
- package/Users/Notifications.d.ts +2 -1
- package/Users/Notifications.js +3 -4
- package/Users/Profiles.d.ts +11 -10
- package/Users/Profiles.js +30 -31
- package/Users/Types.d.ts +1 -1
- package/Utils/Token.d.ts +1 -1
- package/Utils/Token.js +2 -2
- package/{HTTP → Utils}/globalThis.d.ts +0 -0
- package/{HTTP → Utils}/globalThis.js +0 -0
- package/VerdocsEndpoint.d.ts +188 -0
- package/VerdocsEndpoint.js +285 -0
- package/index.d.ts +1 -1
- package/index.js +1 -1
- package/package.json +1 -1
- package/Documents/Stars.d.ts +0 -2
- package/Documents/Stars.js +0 -40
- package/HTTP/Transport.d.ts +0 -34
- package/HTTP/Transport.js +0 -47
- package/HTTP/Types.d.ts +0 -1
- package/HTTP/Types.js +0 -1
- package/HTTP/VerdocsEndpoint.d.ts +0 -106
- package/HTTP/VerdocsEndpoint.js +0 -141
- package/HTTP/index.d.ts +0 -3
- package/HTTP/index.js +0 -3
package/Users/Auth.js
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
import { getEndpoint } from '../HTTP/Transport';
|
|
2
|
-
import { decodeAccessTokenBody } from '../Utils/Token';
|
|
3
|
-
import globalThis from '../HTTP/globalThis';
|
|
4
1
|
/**
|
|
5
2
|
* Authenticate to Verdocs via user/password authentication
|
|
6
3
|
*
|
|
@@ -12,9 +9,9 @@ import globalThis from '../HTTP/globalThis';
|
|
|
12
9
|
* Transport.setAuthToken(accessToken);
|
|
13
10
|
* ```
|
|
14
11
|
*/
|
|
15
|
-
export var authenticateUser = function (params) {
|
|
16
|
-
return
|
|
17
|
-
.
|
|
12
|
+
export var authenticateUser = function (endpoint, params) {
|
|
13
|
+
return endpoint.api //
|
|
14
|
+
.post('/authentication/login', params)
|
|
18
15
|
.then(function (r) { return r.data; });
|
|
19
16
|
};
|
|
20
17
|
/**
|
|
@@ -32,9 +29,9 @@ export var authenticateUser = function (params) {
|
|
|
32
29
|
* Transport.setAuthToken(accessToken);
|
|
33
30
|
* ```
|
|
34
31
|
*/
|
|
35
|
-
export var authenticateApp = function (params) {
|
|
36
|
-
return
|
|
37
|
-
.
|
|
32
|
+
export var authenticateApp = function (endpoint, params) {
|
|
33
|
+
return endpoint.api //
|
|
34
|
+
.post('/authentication/login_client', {}, { headers: params })
|
|
38
35
|
.then(function (r) { return r.data; });
|
|
39
36
|
};
|
|
40
37
|
/**
|
|
@@ -51,9 +48,9 @@ export var authenticateApp = function (params) {
|
|
|
51
48
|
* }
|
|
52
49
|
* ```
|
|
53
50
|
*/
|
|
54
|
-
export var validateToken = function (params) {
|
|
55
|
-
return
|
|
56
|
-
.
|
|
51
|
+
export var validateToken = function (endpoint, params) {
|
|
52
|
+
return endpoint.api //
|
|
53
|
+
.post('/token/isValid', params)
|
|
57
54
|
.then(function (r) { return r.data; });
|
|
58
55
|
};
|
|
59
56
|
/**
|
|
@@ -67,9 +64,9 @@ export var validateToken = function (params) {
|
|
|
67
64
|
* Transport.setAuthToken(accessToken);
|
|
68
65
|
* ```
|
|
69
66
|
*/
|
|
70
|
-
export var refreshTokens = function () {
|
|
71
|
-
return
|
|
72
|
-
.
|
|
67
|
+
export var refreshTokens = function (endpoint) {
|
|
68
|
+
return endpoint.api //
|
|
69
|
+
.get('/token')
|
|
73
70
|
.then(function (r) { return r.data; });
|
|
74
71
|
};
|
|
75
72
|
/**
|
|
@@ -84,9 +81,9 @@ export var refreshTokens = function () {
|
|
|
84
81
|
* }
|
|
85
82
|
* ```
|
|
86
83
|
*/
|
|
87
|
-
export var updatePassword = function (params) {
|
|
88
|
-
return
|
|
89
|
-
.
|
|
84
|
+
export var updatePassword = function (endpoint, params) {
|
|
85
|
+
return endpoint.api //
|
|
86
|
+
.put('/user/update_password', params)
|
|
90
87
|
.then(function (r) { return r.data; });
|
|
91
88
|
};
|
|
92
89
|
/**
|
|
@@ -98,92 +95,8 @@ export var updatePassword = function (params) {
|
|
|
98
95
|
* const {profiles} = await Auth.updateEmail({ email: newEmail });
|
|
99
96
|
* ```
|
|
100
97
|
*/
|
|
101
|
-
export var updateEmail = function (params) {
|
|
102
|
-
return
|
|
103
|
-
.
|
|
98
|
+
export var updateEmail = function (endpoint, params) {
|
|
99
|
+
return endpoint.api //
|
|
100
|
+
.put('/user/update_email', params)
|
|
104
101
|
.then(function (r) { return r.data; });
|
|
105
102
|
};
|
|
106
|
-
var clearSession = function (source, persist) {
|
|
107
|
-
getEndpoint().setAuthorization(null);
|
|
108
|
-
if (persist) {
|
|
109
|
-
localStorage.removeItem(source);
|
|
110
|
-
}
|
|
111
|
-
notifySessionListeners(source, null);
|
|
112
|
-
return null;
|
|
113
|
-
};
|
|
114
|
-
/**
|
|
115
|
-
* Parses and sets the active session, optionally persisting (brower-only, persists to localStorage).
|
|
116
|
-
*/
|
|
117
|
-
export var setSession = function (source, token, persist) {
|
|
118
|
-
if (persist === void 0) { persist = false; }
|
|
119
|
-
if (token === null) {
|
|
120
|
-
return clearSession(source, persist);
|
|
121
|
-
}
|
|
122
|
-
var session = decodeAccessTokenBody(token || '');
|
|
123
|
-
if (session === null || (session.exp && session.exp * 1000 < new Date().getTime())) {
|
|
124
|
-
return clearSession(source, persist);
|
|
125
|
-
}
|
|
126
|
-
if (persist) {
|
|
127
|
-
localStorage.setItem(source, token);
|
|
128
|
-
}
|
|
129
|
-
getEndpoint().setAuthorization(token);
|
|
130
|
-
notifySessionListeners(source, session);
|
|
131
|
-
return session;
|
|
132
|
-
};
|
|
133
|
-
/**
|
|
134
|
-
* Load a session from localStorage
|
|
135
|
-
*/
|
|
136
|
-
export var loadSession = function (source) {
|
|
137
|
-
var token = localStorage.getItem(source);
|
|
138
|
-
if (!token) {
|
|
139
|
-
return null;
|
|
140
|
-
}
|
|
141
|
-
var session = decodeAccessTokenBody(token);
|
|
142
|
-
if (!session) {
|
|
143
|
-
return null;
|
|
144
|
-
}
|
|
145
|
-
if (session.exp && session.exp * 1000 < new Date().getTime()) {
|
|
146
|
-
localStorage.removeItem(source);
|
|
147
|
-
return null;
|
|
148
|
-
}
|
|
149
|
-
getEndpoint().setAuthorization(token);
|
|
150
|
-
notifySessionListeners(source, session);
|
|
151
|
-
return session;
|
|
152
|
-
};
|
|
153
|
-
/**
|
|
154
|
-
* End the active session.
|
|
155
|
-
*/
|
|
156
|
-
export var endSession = function (source, persist) {
|
|
157
|
-
if (persist === void 0) { persist = false; }
|
|
158
|
-
return clearSession(source, persist);
|
|
159
|
-
};
|
|
160
|
-
var SESSION_LISTENERS_KEY = Symbol.for('verdocs-session-listeners');
|
|
161
|
-
if (!globalThis[SESSION_LISTENERS_KEY]) {
|
|
162
|
-
globalThis[SESSION_LISTENERS_KEY] = new Map();
|
|
163
|
-
}
|
|
164
|
-
var LISTENER_ID_KEY = Symbol.for('verdocs-session-listener-id');
|
|
165
|
-
if (!globalThis[LISTENER_ID_KEY]) {
|
|
166
|
-
globalThis[LISTENER_ID_KEY] = 0;
|
|
167
|
-
}
|
|
168
|
-
/**
|
|
169
|
-
* Subscribe to session state change events.
|
|
170
|
-
*/
|
|
171
|
-
export var onSessionChanged = function (listener) {
|
|
172
|
-
globalThis[LISTENER_ID_KEY]++;
|
|
173
|
-
// There's no value in randomizing this so we don't
|
|
174
|
-
var listenerSymbol = Symbol.for('' + globalThis[LISTENER_ID_KEY]);
|
|
175
|
-
globalThis[SESSION_LISTENERS_KEY].set(listenerSymbol, listener);
|
|
176
|
-
return function () {
|
|
177
|
-
globalThis[SESSION_LISTENERS_KEY].delete(listenerSymbol);
|
|
178
|
-
};
|
|
179
|
-
};
|
|
180
|
-
var notifySessionListeners = function (source, session) {
|
|
181
|
-
globalThis[SESSION_LISTENERS_KEY].forEach(function (listener) {
|
|
182
|
-
try {
|
|
183
|
-
listener(source, session);
|
|
184
|
-
}
|
|
185
|
-
catch (e) {
|
|
186
|
-
// NOOP
|
|
187
|
-
}
|
|
188
|
-
});
|
|
189
|
-
};
|
package/Users/Billing.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export {};
|
|
1
|
+
export declare const billingPlaceholder: {};
|
package/Users/Billing.js
CHANGED
package/Users/Notifications.d.ts
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import { VerdocsEndpoint } from '../VerdocsEndpoint';
|
|
2
|
+
export declare const getNotifications: (endpoint: VerdocsEndpoint) => Promise<any>;
|
package/Users/Notifications.js
CHANGED
|
@@ -34,11 +34,10 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
34
34
|
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
35
35
|
}
|
|
36
36
|
};
|
|
37
|
-
|
|
38
|
-
export var getNotifications = function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
37
|
+
export var getNotifications = function (endpoint) { return __awaiter(void 0, void 0, void 0, function () {
|
|
39
38
|
return __generator(this, function (_a) {
|
|
40
|
-
return [2 /*return*/,
|
|
41
|
-
.
|
|
39
|
+
return [2 /*return*/, endpoint.api //
|
|
40
|
+
.get('/notifications')
|
|
42
41
|
.then(function (r) { return r.data; })];
|
|
43
42
|
});
|
|
44
43
|
}); };
|
package/Users/Profiles.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ICreateProfileRequest, IUpdateProfileRequest } from './Types';
|
|
2
|
+
import { VerdocsEndpoint } from '../VerdocsEndpoint';
|
|
2
3
|
/**
|
|
3
4
|
* Get the user's available profiles. The current profile will be marked with `current: true`.
|
|
4
5
|
*
|
|
@@ -8,7 +9,7 @@ import { ICreateProfileRequest, IUpdateProfileRequest } from './Types';
|
|
|
8
9
|
* const profiles = await Profiles.getProfiles()
|
|
9
10
|
* ```
|
|
10
11
|
*/
|
|
11
|
-
export declare const getProfiles: () => Promise<any>;
|
|
12
|
+
export declare const getProfiles: (endpoint: VerdocsEndpoint) => Promise<any>;
|
|
12
13
|
/**
|
|
13
14
|
* Get a list of system roles.
|
|
14
15
|
*
|
|
@@ -18,7 +19,7 @@ export declare const getProfiles: () => Promise<any>;
|
|
|
18
19
|
* const roles = await Profiles.getRoles();
|
|
19
20
|
* ```
|
|
20
21
|
*/
|
|
21
|
-
export declare const getRoles: () => Promise<any>;
|
|
22
|
+
export declare const getRoles: (endpoint: VerdocsEndpoint) => Promise<any>;
|
|
22
23
|
/**
|
|
23
24
|
* Get a list of system roles.
|
|
24
25
|
*
|
|
@@ -28,7 +29,7 @@ export declare const getRoles: () => Promise<any>;
|
|
|
28
29
|
* const permissions = await Profiles.getPermissions();
|
|
29
30
|
* ```
|
|
30
31
|
*/
|
|
31
|
-
export declare const getPermissions: () => Promise<any>;
|
|
32
|
+
export declare const getPermissions: (endpoint: VerdocsEndpoint) => Promise<any>;
|
|
32
33
|
/**
|
|
33
34
|
* Create a profile. If the caller does not have a "current" profile set, the new profile will be made current.
|
|
34
35
|
*
|
|
@@ -38,7 +39,7 @@ export declare const getPermissions: () => Promise<any>;
|
|
|
38
39
|
* const newProfile = await Profiles.createProfile({ first_name: 'FIRST', last_name: 'LAST', email: 'EMAIL' });
|
|
39
40
|
* ```
|
|
40
41
|
*/
|
|
41
|
-
export declare const createProfile: (params: ICreateProfileRequest) => Promise<any>;
|
|
42
|
+
export declare const createProfile: (endpoint: VerdocsEndpoint, params: ICreateProfileRequest) => Promise<any>;
|
|
42
43
|
/**
|
|
43
44
|
* Get a profile. The caller must have admin access to the given profile.
|
|
44
45
|
* TODO: Add a "public" profile endpoint for public pages
|
|
@@ -49,7 +50,7 @@ export declare const createProfile: (params: ICreateProfileRequest) => Promise<a
|
|
|
49
50
|
* const profile = await Profiles.getProfile('PROFILEID');
|
|
50
51
|
* ```
|
|
51
52
|
*/
|
|
52
|
-
export declare const getProfile: (profileId: string) => Promise<any>;
|
|
53
|
+
export declare const getProfile: (endpoint: VerdocsEndpoint, profileId: string) => Promise<any>;
|
|
53
54
|
/**
|
|
54
55
|
* Get a profile's permissions. The caller must have admin access to the given profile.
|
|
55
56
|
*
|
|
@@ -59,7 +60,7 @@ export declare const getProfile: (profileId: string) => Promise<any>;
|
|
|
59
60
|
* const permissions = await Profiles.getProfilePermissions('PROFILEID');
|
|
60
61
|
* ```
|
|
61
62
|
*/
|
|
62
|
-
export declare const getProfilePermissions: (profileId: string) => Promise<any>;
|
|
63
|
+
export declare const getProfilePermissions: (endpoint: VerdocsEndpoint, profileId: string) => Promise<any>;
|
|
63
64
|
/**
|
|
64
65
|
* Get a profile's groups.
|
|
65
66
|
*
|
|
@@ -69,7 +70,7 @@ export declare const getProfilePermissions: (profileId: string) => Promise<any>;
|
|
|
69
70
|
* const groups = await Profiles.getProfileGroups('PROFILEID');
|
|
70
71
|
* ```
|
|
71
72
|
*/
|
|
72
|
-
export declare const getProfileGroups: (profileId: string) => Promise<any>;
|
|
73
|
+
export declare const getProfileGroups: (endpoint: VerdocsEndpoint, profileId: string) => Promise<any>;
|
|
73
74
|
/**
|
|
74
75
|
* Switch the caller's "current" profile. The current profile is used for permissions checking and profile_id field settings
|
|
75
76
|
* for most operations in Verdocs. It is important to select the appropropriate profile before calling other API functions.
|
|
@@ -80,7 +81,7 @@ export declare const getProfileGroups: (profileId: string) => Promise<any>;
|
|
|
80
81
|
* const newProfile = await Profiles.switchProfile('PROFILEID');
|
|
81
82
|
* ```
|
|
82
83
|
*/
|
|
83
|
-
export declare const switchProfile: (profileId: string) => Promise<any>;
|
|
84
|
+
export declare const switchProfile: (endpoint: VerdocsEndpoint, profileId: string) => Promise<any>;
|
|
84
85
|
/**
|
|
85
86
|
* Update a profile. For future expansion, the profile ID to update is required, but currently this must also be the
|
|
86
87
|
* "current" profile for the caller.
|
|
@@ -91,7 +92,7 @@ export declare const switchProfile: (profileId: string) => Promise<any>;
|
|
|
91
92
|
* const newProfile = await Profiles.updateProfile('PROFILEID');
|
|
92
93
|
* ```
|
|
93
94
|
*/
|
|
94
|
-
export declare const updateProfile: (profileId: string, params: IUpdateProfileRequest) => Promise<any>;
|
|
95
|
+
export declare const updateProfile: (endpoint: VerdocsEndpoint, profileId: string, params: IUpdateProfileRequest) => Promise<any>;
|
|
95
96
|
/**
|
|
96
97
|
* Delete a profile. If the requested profile is the caller's curent profile, the next available profile will be selected.
|
|
97
98
|
*
|
|
@@ -101,4 +102,4 @@ export declare const updateProfile: (profileId: string, params: IUpdateProfileRe
|
|
|
101
102
|
* await Profiles.deleteProfile('PROFILEID');
|
|
102
103
|
* ```
|
|
103
104
|
*/
|
|
104
|
-
export declare const deleteProfile: (profileId: string) => Promise<any>;
|
|
105
|
+
export declare const deleteProfile: (endpoint: VerdocsEndpoint, profileId: string) => Promise<any>;
|
package/Users/Profiles.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { getEndpoint } from '../HTTP/Transport';
|
|
2
1
|
/**
|
|
3
2
|
* Get the user's available profiles. The current profile will be marked with `current: true`.
|
|
4
3
|
*
|
|
@@ -8,9 +7,9 @@ import { getEndpoint } from '../HTTP/Transport';
|
|
|
8
7
|
* const profiles = await Profiles.getProfiles()
|
|
9
8
|
* ```
|
|
10
9
|
*/
|
|
11
|
-
export var getProfiles = function () {
|
|
12
|
-
return
|
|
13
|
-
.
|
|
10
|
+
export var getProfiles = function (endpoint) {
|
|
11
|
+
return endpoint.api //
|
|
12
|
+
.get('/profiles')
|
|
14
13
|
.then(function (r) { return r.data; });
|
|
15
14
|
};
|
|
16
15
|
/**
|
|
@@ -22,9 +21,9 @@ export var getProfiles = function () {
|
|
|
22
21
|
* const roles = await Profiles.getRoles();
|
|
23
22
|
* ```
|
|
24
23
|
*/
|
|
25
|
-
export var getRoles = function () {
|
|
26
|
-
return
|
|
27
|
-
.
|
|
24
|
+
export var getRoles = function (endpoint) {
|
|
25
|
+
return endpoint.api //
|
|
26
|
+
.get('/roles')
|
|
28
27
|
.then(function (r) { return r.data; });
|
|
29
28
|
};
|
|
30
29
|
/**
|
|
@@ -36,9 +35,9 @@ export var getRoles = function () {
|
|
|
36
35
|
* const permissions = await Profiles.getPermissions();
|
|
37
36
|
* ```
|
|
38
37
|
*/
|
|
39
|
-
export var getPermissions = function () {
|
|
40
|
-
return
|
|
41
|
-
.
|
|
38
|
+
export var getPermissions = function (endpoint) {
|
|
39
|
+
return endpoint.api //
|
|
40
|
+
.get('/permissions')
|
|
42
41
|
.then(function (r) { return r.data; });
|
|
43
42
|
};
|
|
44
43
|
/**
|
|
@@ -50,9 +49,9 @@ export var getPermissions = function () {
|
|
|
50
49
|
* const newProfile = await Profiles.createProfile({ first_name: 'FIRST', last_name: 'LAST', email: 'EMAIL' });
|
|
51
50
|
* ```
|
|
52
51
|
*/
|
|
53
|
-
export var createProfile = function (params) {
|
|
54
|
-
return
|
|
55
|
-
.
|
|
52
|
+
export var createProfile = function (endpoint, params) {
|
|
53
|
+
return endpoint.api //
|
|
54
|
+
.post('/profiles', params)
|
|
56
55
|
.then(function (r) { return r.data; });
|
|
57
56
|
};
|
|
58
57
|
/**
|
|
@@ -65,9 +64,9 @@ export var createProfile = function (params) {
|
|
|
65
64
|
* const profile = await Profiles.getProfile('PROFILEID');
|
|
66
65
|
* ```
|
|
67
66
|
*/
|
|
68
|
-
export var getProfile = function (profileId) {
|
|
69
|
-
return
|
|
70
|
-
.
|
|
67
|
+
export var getProfile = function (endpoint, profileId) {
|
|
68
|
+
return endpoint.api //
|
|
69
|
+
.get("/profiles/".concat(profileId))
|
|
71
70
|
.then(function (r) { return r.data; });
|
|
72
71
|
};
|
|
73
72
|
/**
|
|
@@ -79,9 +78,9 @@ export var getProfile = function (profileId) {
|
|
|
79
78
|
* const permissions = await Profiles.getProfilePermissions('PROFILEID');
|
|
80
79
|
* ```
|
|
81
80
|
*/
|
|
82
|
-
export var getProfilePermissions = function (profileId) {
|
|
83
|
-
return
|
|
84
|
-
.
|
|
81
|
+
export var getProfilePermissions = function (endpoint, profileId) {
|
|
82
|
+
return endpoint.api //
|
|
83
|
+
.get("/profiles/".concat(profileId, "/permissions"))
|
|
85
84
|
.then(function (r) { return r.data; });
|
|
86
85
|
};
|
|
87
86
|
/**
|
|
@@ -93,9 +92,9 @@ export var getProfilePermissions = function (profileId) {
|
|
|
93
92
|
* const groups = await Profiles.getProfileGroups('PROFILEID');
|
|
94
93
|
* ```
|
|
95
94
|
*/
|
|
96
|
-
export var getProfileGroups = function (profileId) {
|
|
97
|
-
return
|
|
98
|
-
.
|
|
95
|
+
export var getProfileGroups = function (endpoint, profileId) {
|
|
96
|
+
return endpoint.api //
|
|
97
|
+
.get("/profiles/".concat(profileId, "/groups"))
|
|
99
98
|
.then(function (r) { return r.data; });
|
|
100
99
|
};
|
|
101
100
|
/**
|
|
@@ -108,9 +107,9 @@ export var getProfileGroups = function (profileId) {
|
|
|
108
107
|
* const newProfile = await Profiles.switchProfile('PROFILEID');
|
|
109
108
|
* ```
|
|
110
109
|
*/
|
|
111
|
-
export var switchProfile = function (profileId) {
|
|
112
|
-
return
|
|
113
|
-
.
|
|
110
|
+
export var switchProfile = function (endpoint, profileId) {
|
|
111
|
+
return endpoint.api //
|
|
112
|
+
.post("/profiles/".concat(profileId, "/switch"))
|
|
114
113
|
.then(function (r) { return r.data; });
|
|
115
114
|
};
|
|
116
115
|
/**
|
|
@@ -123,9 +122,9 @@ export var switchProfile = function (profileId) {
|
|
|
123
122
|
* const newProfile = await Profiles.updateProfile('PROFILEID');
|
|
124
123
|
* ```
|
|
125
124
|
*/
|
|
126
|
-
export var updateProfile = function (profileId, params) {
|
|
127
|
-
return
|
|
128
|
-
.
|
|
125
|
+
export var updateProfile = function (endpoint, profileId, params) {
|
|
126
|
+
return endpoint.api //
|
|
127
|
+
.put("/profiles/".concat(profileId), params)
|
|
129
128
|
.then(function (r) { return r.data; });
|
|
130
129
|
};
|
|
131
130
|
/**
|
|
@@ -137,8 +136,8 @@ export var updateProfile = function (profileId, params) {
|
|
|
137
136
|
* await Profiles.deleteProfile('PROFILEID');
|
|
138
137
|
* ```
|
|
139
138
|
*/
|
|
140
|
-
export var deleteProfile = function (profileId) {
|
|
141
|
-
return
|
|
142
|
-
.
|
|
139
|
+
export var deleteProfile = function (endpoint, profileId) {
|
|
140
|
+
return endpoint.api //
|
|
141
|
+
.delete("/profiles/".concat(profileId))
|
|
143
142
|
.then(function (r) { return r.data; });
|
|
144
143
|
};
|
package/Users/Types.d.ts
CHANGED
package/Utils/Token.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ export declare const AtoB: (str: string) => string;
|
|
|
9
9
|
* Decode the body of a JWT. This helper may allow front-end applications to avoid a dependency on `jsonwebtoken` in
|
|
10
10
|
* many cases. Note that this should only be used for true JWTs. Opaque tokens will cause this to throw.
|
|
11
11
|
*/
|
|
12
|
-
export declare const
|
|
12
|
+
export declare const decodeJWTBody: (token: string) => any;
|
|
13
13
|
/**
|
|
14
14
|
* Decode the body of an Verdocs access token. Note that raw tokens contain namespaced fields, e.g.
|
|
15
15
|
* `https://verdocs.com/profile_id`. To make these tokens easier to use in front-end code, this name-spacing
|
package/Utils/Token.js
CHANGED
|
@@ -38,7 +38,7 @@ export var AtoB = function (str) {
|
|
|
38
38
|
* Decode the body of a JWT. This helper may allow front-end applications to avoid a dependency on `jsonwebtoken` in
|
|
39
39
|
* many cases. Note that this should only be used for true JWTs. Opaque tokens will cause this to throw.
|
|
40
40
|
*/
|
|
41
|
-
export var
|
|
41
|
+
export var decodeJWTBody = function (token) { return JSON.parse(AtoB((token || '').split('.')[1] || '')); };
|
|
42
42
|
/**
|
|
43
43
|
* Decode the body of an Verdocs access token. Note that raw tokens contain namespaced fields, e.g.
|
|
44
44
|
* `https://verdocs.com/profile_id`. To make these tokens easier to use in front-end code, this name-spacing
|
|
@@ -49,7 +49,7 @@ export var decodeTokenBody = function (token) { return JSON.parse(AtoB((token ||
|
|
|
49
49
|
export var decodeAccessTokenBody = function (token) {
|
|
50
50
|
var decoded;
|
|
51
51
|
try {
|
|
52
|
-
decoded =
|
|
52
|
+
decoded = decodeJWTBody(token);
|
|
53
53
|
if (decoded === null) {
|
|
54
54
|
return null;
|
|
55
55
|
}
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
import { AxiosInstance } from 'axios';
|
|
2
|
+
import { ISigningSession } from './Documents/Types';
|
|
3
|
+
import { IActiveSession } from './Users/Types';
|
|
4
|
+
import * as Documents from './Documents';
|
|
5
|
+
export declare type TEnvironment = 'verdocs' | 'verdocs-stage';
|
|
6
|
+
export declare type TSessionType = 'user' | 'signing';
|
|
7
|
+
export declare type TSession = IActiveSession | ISigningSession | null;
|
|
8
|
+
export declare type SessionChangedListener = (endpoint: VerdocsEndpoint, session: IActiveSession | ISigningSession | null) => void;
|
|
9
|
+
export interface VerdocsEndpointOptions {
|
|
10
|
+
baseURL?: string;
|
|
11
|
+
timeout?: number;
|
|
12
|
+
environment?: TEnvironment;
|
|
13
|
+
sessionType?: TSessionType;
|
|
14
|
+
clientID?: string;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* VerdocsEndpoint is a class wrapper for a specific connection and authorization context for calling the Verdocs APIs.
|
|
18
|
+
* Endpoints can be used for isolated session tasks.
|
|
19
|
+
*
|
|
20
|
+
* For instance, ephemeral signing sessions may be created independently of a caller's status as an authenticated user.
|
|
21
|
+
* In that case, an Endpoint can be created and authenticated, used for calls related to signing operations, then
|
|
22
|
+
* discarded once signing is complete.
|
|
23
|
+
*
|
|
24
|
+
* Note that endpoint configuration functions return the instance, so they can be chained, e.g.
|
|
25
|
+
*
|
|
26
|
+
* ```typescript
|
|
27
|
+
* import {VerdocsEndpoint} from '@verdocs/js-sdk/HTTP';
|
|
28
|
+
*
|
|
29
|
+
* const endpoint = new VerdocsEndpoint();
|
|
30
|
+
* endpoint
|
|
31
|
+
* .setSessionType('signing')
|
|
32
|
+
* .logRequests(true)
|
|
33
|
+
* .setClientID('1234)
|
|
34
|
+
* .setTimeout(5000);
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
export declare class VerdocsEndpoint {
|
|
38
|
+
private environment;
|
|
39
|
+
private sessionType;
|
|
40
|
+
private baseURL;
|
|
41
|
+
private clientID;
|
|
42
|
+
private timeout;
|
|
43
|
+
private session;
|
|
44
|
+
private token;
|
|
45
|
+
private nextListenerId;
|
|
46
|
+
private sessionListeners;
|
|
47
|
+
private requestLoggerId;
|
|
48
|
+
api: AxiosInstance;
|
|
49
|
+
Documents: typeof Documents;
|
|
50
|
+
/**
|
|
51
|
+
* Create a new VerdocsEndpoint to call Verdocs platform services.
|
|
52
|
+
*
|
|
53
|
+
* ```typescript
|
|
54
|
+
* import {VerdocsEndpoint} from '@verdocs/js-sdk/HTTP';
|
|
55
|
+
* const endpoint = new VerdocsEndpoint();
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
constructor(options?: VerdocsEndpointOptions);
|
|
59
|
+
setDefault(): void;
|
|
60
|
+
static getDefault(): any;
|
|
61
|
+
/**
|
|
62
|
+
* Get the current environment.
|
|
63
|
+
*/
|
|
64
|
+
getEnvironment(): TEnvironment;
|
|
65
|
+
/**
|
|
66
|
+
* Get the current session type.
|
|
67
|
+
*/
|
|
68
|
+
getSessionType(): TSessionType;
|
|
69
|
+
/**
|
|
70
|
+
* Get the current base URL. This should rarely be anything other than 'https://api.verdocs.com'.
|
|
71
|
+
*/
|
|
72
|
+
getBaseURL(): string;
|
|
73
|
+
/**
|
|
74
|
+
* Get the current client ID, if set.
|
|
75
|
+
*/
|
|
76
|
+
getClientID(): string;
|
|
77
|
+
/**
|
|
78
|
+
* Get the current timeout.
|
|
79
|
+
*/
|
|
80
|
+
getTimeout(): number;
|
|
81
|
+
/**
|
|
82
|
+
* Get the current session, if any.
|
|
83
|
+
*/
|
|
84
|
+
getSession(): TSession;
|
|
85
|
+
/**
|
|
86
|
+
* Set the operating environment. This should rarely be anything other than 'verdocs'.
|
|
87
|
+
*
|
|
88
|
+
* ```typescript
|
|
89
|
+
* import {VerdocsEndpoint} from '@verdocs/js-sdk/HTTP';
|
|
90
|
+
*
|
|
91
|
+
* const endpoint = new VerdocsEndpoint();
|
|
92
|
+
* endpoint.setEnvironment('verdocs-stage');
|
|
93
|
+
* ```
|
|
94
|
+
*/
|
|
95
|
+
setEnvironment(environment: TEnvironment): VerdocsEndpoint;
|
|
96
|
+
/**
|
|
97
|
+
* Set the session type. In general this should be done immediately when the endpoint is created. Changing the
|
|
98
|
+
* session type may be done at any time, but may have unintended consequences if the endpoint is shared between
|
|
99
|
+
* multiple widgets.
|
|
100
|
+
*
|
|
101
|
+
* Changing the session type will clear/reload the action session. This may trigger notifications to session state
|
|
102
|
+
* observers. Apps that use observers to trigger UI updates such as logging the user out should be prepared to
|
|
103
|
+
* handle this event.
|
|
104
|
+
*
|
|
105
|
+
* ```typescript
|
|
106
|
+
* import {VerdocsEndpoint} from '@verdocs/js-sdk/HTTP';
|
|
107
|
+
*
|
|
108
|
+
* const endpoint = new VerdocsEndpoint();
|
|
109
|
+
* endpoint.setEnvironment('verdocs-stage');
|
|
110
|
+
* ```
|
|
111
|
+
*/
|
|
112
|
+
setSessionType(sessionType: TSessionType): VerdocsEndpoint;
|
|
113
|
+
/**
|
|
114
|
+
* Set the base URL for API calls. Should be called only upon direction from Verdocs Customer Solutions Engineering.
|
|
115
|
+
*
|
|
116
|
+
* ```typescript
|
|
117
|
+
* import {VerdocsEndpoint} from '@verdocs/js-sdk/HTTP';
|
|
118
|
+
*
|
|
119
|
+
* const endpoint = new VerdocsEndpoint();
|
|
120
|
+
* endpoint.setBaseURL('https://api.verdocs.com');
|
|
121
|
+
* ```
|
|
122
|
+
*/
|
|
123
|
+
setBaseURL(url: string): VerdocsEndpoint;
|
|
124
|
+
/**
|
|
125
|
+
* Set the Client ID for Verdocs API calls.
|
|
126
|
+
*
|
|
127
|
+
* ```typescript
|
|
128
|
+
* import {VerdocsEndpoint} from '@verdocs/js-sdk/HTTP';
|
|
129
|
+
*
|
|
130
|
+
* const endpoint = new VerdocsEndpoint();
|
|
131
|
+
* endpoint.setClientID('1234);
|
|
132
|
+
* ```
|
|
133
|
+
*/
|
|
134
|
+
setClientID(clientID: string): VerdocsEndpoint;
|
|
135
|
+
/**
|
|
136
|
+
* Set the timeout for API calls in milliseconds. 2000-4000ms is recommended for most purposes. 3000ms is the default.
|
|
137
|
+
*
|
|
138
|
+
* ```typescript
|
|
139
|
+
* import {VerdocsEndpoint} from '@verdocs/js-sdk/HTTP';
|
|
140
|
+
*
|
|
141
|
+
* const endpoint = new VerdocsEndpoint();
|
|
142
|
+
* endpoint.setTimeout(3000);
|
|
143
|
+
* ```
|
|
144
|
+
*/
|
|
145
|
+
setTimeout(timeout: number): VerdocsEndpoint;
|
|
146
|
+
/**
|
|
147
|
+
* Enable or disable request logging. This may expose sensitive data in the console log, so it should only be used for debugging.
|
|
148
|
+
*
|
|
149
|
+
* ```typescript
|
|
150
|
+
* import {VerdocsEndpoint} from '@verdocs/js-sdk/HTTP';
|
|
151
|
+
*
|
|
152
|
+
* const endpoint = new VerdocsEndpoint();
|
|
153
|
+
* endpoint.logRequests(true);
|
|
154
|
+
* ```
|
|
155
|
+
*/
|
|
156
|
+
logRequests(enable: boolean): VerdocsEndpoint;
|
|
157
|
+
/**
|
|
158
|
+
* Set the authorization token that will be used for Verdocs API calls. This will also set the session metadata
|
|
159
|
+
* and notify any listeners of the new data.
|
|
160
|
+
*
|
|
161
|
+
* If this Endpoint will be used for non-default purposes (e.g. signing, or in an alternate environment) those
|
|
162
|
+
* settings should be made before calling this. Sessions are persisted to localStorage, and the environment and
|
|
163
|
+
* type become part of the storage key.
|
|
164
|
+
*
|
|
165
|
+
* ```typescript
|
|
166
|
+
* import {VerdocsEndpoint} from '@verdocs/js-sdk/HTTP';
|
|
167
|
+
*
|
|
168
|
+
* const endpoint = new VerdocsEndpoint();
|
|
169
|
+
* endpoint.setToken(accessToken);
|
|
170
|
+
* ```
|
|
171
|
+
*/
|
|
172
|
+
setToken(token: string | null): VerdocsEndpoint;
|
|
173
|
+
private sessionStorageKey;
|
|
174
|
+
/**
|
|
175
|
+
* Clear the active session.
|
|
176
|
+
*/
|
|
177
|
+
clearSession(): this;
|
|
178
|
+
private notifySessionListeners;
|
|
179
|
+
/**
|
|
180
|
+
* Subscribe to session state change events.
|
|
181
|
+
*/
|
|
182
|
+
onSessionChanged(listener: SessionChangedListener): () => void;
|
|
183
|
+
/**
|
|
184
|
+
* Load a persisted session from localStorage. Typically called once after the endpoint is configured when the app
|
|
185
|
+
* or component starts.
|
|
186
|
+
*/
|
|
187
|
+
loadSession(source: string): VerdocsEndpoint;
|
|
188
|
+
}
|