@verdocs/js-sdk 1.4.0 → 2.0.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.
Files changed (72) hide show
  1. package/Documents/Documents.d.ts +26 -9
  2. package/Documents/Documents.js +42 -27
  3. package/Documents/Initials.d.ts +2 -1
  4. package/Documents/Initials.js +3 -4
  5. package/Documents/Recipients.d.ts +5 -1
  6. package/Documents/Recipients.js +6 -4
  7. package/Documents/Signatures.d.ts +14 -4
  8. package/Documents/Signatures.js +21 -13
  9. package/Documents/index.d.ts +0 -1
  10. package/Documents/index.js +0 -1
  11. package/Organizations/ApiKeys.d.ts +6 -5
  12. package/Organizations/ApiKeys.js +15 -16
  13. package/Organizations/Groups.d.ts +8 -7
  14. package/Organizations/Groups.js +21 -22
  15. package/Organizations/Invitations.d.ts +8 -7
  16. package/Organizations/Invitations.js +21 -22
  17. package/Organizations/Members.d.ts +6 -5
  18. package/Organizations/Members.js +15 -16
  19. package/Organizations/Organizations.d.ts +7 -6
  20. package/Organizations/Organizations.js +18 -19
  21. package/Organizations/Webhooks.d.ts +3 -2
  22. package/Organizations/Webhooks.js +6 -7
  23. package/Organizations/Whitelabel.d.ts +3 -2
  24. package/Organizations/Whitelabel.js +6 -7
  25. package/Search/Content.d.ts +4 -3
  26. package/Search/Content.js +9 -10
  27. package/Templates/Fields.d.ts +4 -3
  28. package/Templates/Fields.js +9 -10
  29. package/Templates/Pages.d.ts +5 -4
  30. package/Templates/Pages.js +12 -13
  31. package/Templates/Reminders.d.ts +5 -4
  32. package/Templates/Reminders.js +12 -13
  33. package/Templates/Roles.d.ts +8 -7
  34. package/Templates/Roles.js +21 -22
  35. package/Templates/Stars.d.ts +3 -2
  36. package/Templates/Stars.js +6 -7
  37. package/Templates/Tags.d.ts +7 -6
  38. package/Templates/Tags.js +18 -19
  39. package/Templates/TemplateDocuments.d.ts +5 -4
  40. package/Templates/TemplateDocuments.js +12 -13
  41. package/Templates/Templates.d.ts +7 -6
  42. package/Templates/Templates.js +18 -19
  43. package/Templates/Validators.d.ts +3 -2
  44. package/Templates/Validators.js +7 -10
  45. package/Users/Auth.d.ts +9 -27
  46. package/Users/Auth.js +18 -98
  47. package/Users/Billing.d.ts +1 -1
  48. package/Users/Billing.js +1 -1
  49. package/Users/Notifications.d.ts +2 -1
  50. package/Users/Notifications.js +3 -4
  51. package/Users/Profiles.d.ts +11 -10
  52. package/Users/Profiles.js +30 -31
  53. package/Users/Types.d.ts +1 -1
  54. package/Utils/Token.d.ts +1 -1
  55. package/Utils/Token.js +2 -2
  56. package/{HTTP → Utils}/globalThis.d.ts +0 -0
  57. package/{HTTP → Utils}/globalThis.js +0 -0
  58. package/VerdocsEndpoint.d.ts +193 -0
  59. package/VerdocsEndpoint.js +290 -0
  60. package/index.d.ts +1 -1
  61. package/index.js +1 -1
  62. package/package.json +1 -1
  63. package/Documents/Stars.d.ts +0 -2
  64. package/Documents/Stars.js +0 -40
  65. package/HTTP/Transport.d.ts +0 -34
  66. package/HTTP/Transport.js +0 -47
  67. package/HTTP/Types.d.ts +0 -1
  68. package/HTTP/Types.js +0 -1
  69. package/HTTP/VerdocsEndpoint.d.ts +0 -106
  70. package/HTTP/VerdocsEndpoint.js +0 -141
  71. package/HTTP/index.d.ts +0 -3
  72. package/HTTP/index.js +0 -3
package/Users/Auth.js CHANGED
@@ -1,5 +1,3 @@
1
- import { getEndpoint } from '../HTTP/Transport';
2
- import { decodeAccessTokenBody } from '../Utils/Token';
3
1
  /**
4
2
  * Authenticate to Verdocs via user/password authentication
5
3
  *
@@ -11,9 +9,9 @@ import { decodeAccessTokenBody } from '../Utils/Token';
11
9
  * Transport.setAuthToken(accessToken);
12
10
  * ```
13
11
  */
14
- export var authenticateUser = function (params) {
15
- return getEndpoint()
16
- .api.post('/authentication/login', params)
12
+ export var authenticateUser = function (endpoint, params) {
13
+ return endpoint.api //
14
+ .post('/authentication/login', params)
17
15
  .then(function (r) { return r.data; });
18
16
  };
19
17
  /**
@@ -31,9 +29,9 @@ export var authenticateUser = function (params) {
31
29
  * Transport.setAuthToken(accessToken);
32
30
  * ```
33
31
  */
34
- export var authenticateApp = function (params) {
35
- return getEndpoint()
36
- .api.post('/authentication/login_client', {}, { headers: params })
32
+ export var authenticateApp = function (endpoint, params) {
33
+ return endpoint.api //
34
+ .post('/authentication/login_client', {}, { headers: params })
37
35
  .then(function (r) { return r.data; });
38
36
  };
39
37
  /**
@@ -50,9 +48,9 @@ export var authenticateApp = function (params) {
50
48
  * }
51
49
  * ```
52
50
  */
53
- export var validateToken = function (params) {
54
- return getEndpoint()
55
- .api.post('/token/isValid', params)
51
+ export var validateToken = function (endpoint, params) {
52
+ return endpoint.api //
53
+ .post('/token/isValid', params)
56
54
  .then(function (r) { return r.data; });
57
55
  };
58
56
  /**
@@ -66,9 +64,9 @@ export var validateToken = function (params) {
66
64
  * Transport.setAuthToken(accessToken);
67
65
  * ```
68
66
  */
69
- export var refreshTokens = function () {
70
- return getEndpoint()
71
- .api.get('/token')
67
+ export var refreshTokens = function (endpoint) {
68
+ return endpoint.api //
69
+ .get('/token')
72
70
  .then(function (r) { return r.data; });
73
71
  };
74
72
  /**
@@ -83,9 +81,9 @@ export var refreshTokens = function () {
83
81
  * }
84
82
  * ```
85
83
  */
86
- export var updatePassword = function (params) {
87
- return getEndpoint()
88
- .api.put('/user/update_password', params)
84
+ export var updatePassword = function (endpoint, params) {
85
+ return endpoint.api //
86
+ .put('/user/update_password', params)
89
87
  .then(function (r) { return r.data; });
90
88
  };
91
89
  /**
@@ -97,86 +95,8 @@ export var updatePassword = function (params) {
97
95
  * const {profiles} = await Auth.updateEmail({ email: newEmail });
98
96
  * ```
99
97
  */
100
- export var updateEmail = function (params) {
101
- return getEndpoint()
102
- .api.put('/user/update_email', params)
98
+ export var updateEmail = function (endpoint, params) {
99
+ return endpoint.api //
100
+ .put('/user/update_email', params)
103
101
  .then(function (r) { return r.data; });
104
102
  };
105
- var clearSession = function (source, persist) {
106
- getEndpoint().setAuthorization(null);
107
- if (persist) {
108
- localStorage.removeItem(source);
109
- }
110
- notifySessionListeners(source, null);
111
- return null;
112
- };
113
- /**
114
- * Parses and sets the active session, optionally persisting (brower-only, persists to localStorage).
115
- */
116
- export var setSession = function (source, token, persist) {
117
- if (persist === void 0) { persist = false; }
118
- if (token === null) {
119
- return clearSession(source, persist);
120
- }
121
- var session = decodeAccessTokenBody(token || '');
122
- if (session === null || (session.exp && session.exp * 1000 < new Date().getTime())) {
123
- return clearSession(source, persist);
124
- }
125
- if (persist) {
126
- localStorage.setItem(source, token);
127
- }
128
- getEndpoint().setAuthorization(token);
129
- notifySessionListeners(source, session);
130
- return session;
131
- };
132
- /**
133
- * Load a session from localStorage
134
- */
135
- export var loadSession = function (source) {
136
- var token = localStorage.getItem(source);
137
- if (!token) {
138
- return null;
139
- }
140
- var session = decodeAccessTokenBody(token);
141
- if (!session) {
142
- return null;
143
- }
144
- if (session.exp && session.exp * 1000 < new Date().getTime()) {
145
- localStorage.removeItem(source);
146
- return null;
147
- }
148
- getEndpoint().setAuthorization(token);
149
- notifySessionListeners(source, session);
150
- return session;
151
- };
152
- /**
153
- * End the active session.
154
- */
155
- export var endSession = function (source, persist) {
156
- if (persist === void 0) { persist = false; }
157
- return clearSession(source, persist);
158
- };
159
- var sessionChangedListeners = new Map();
160
- var nextListenerId = 1;
161
- /**
162
- * Subscribe to session state change events.
163
- */
164
- export var onSessionChanged = function (listener) {
165
- // There's no value in randomizing this so we don't
166
- var listenerId = ++nextListenerId;
167
- var listenerSymbol = Symbol.for('' + listenerId);
168
- sessionChangedListeners.set(listenerSymbol, listener);
169
- return function () {
170
- sessionChangedListeners.delete(listenerSymbol);
171
- };
172
- };
173
- var notifySessionListeners = function (source, session) {
174
- sessionChangedListeners.forEach(function (listener) {
175
- try {
176
- listener(source, session);
177
- }
178
- catch (e) {
179
- // NOOP
180
- }
181
- });
182
- };
@@ -1 +1 @@
1
- export {};
1
+ export declare const billingPlaceholder: {};
package/Users/Billing.js CHANGED
@@ -1,2 +1,2 @@
1
- export {};
2
1
  // TODO
2
+ export var billingPlaceholder = {};
@@ -1 +1,2 @@
1
- export declare const getNotifications: () => Promise<any>;
1
+ import { VerdocsEndpoint } from '../VerdocsEndpoint';
2
+ export declare const getNotifications: (endpoint: VerdocsEndpoint) => Promise<any>;
@@ -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
- import { getEndpoint } from '../HTTP/Transport';
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*/, getEndpoint()
41
- .api.get('/notifications')
39
+ return [2 /*return*/, endpoint.api //
40
+ .get('/notifications')
42
41
  .then(function (r) { return r.data; })];
43
42
  });
44
43
  }); };
@@ -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 getEndpoint()
13
- .api.get('/profiles')
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 getEndpoint()
27
- .api.get('/roles')
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 getEndpoint()
41
- .api.get('/permissions')
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 getEndpoint()
55
- .api.post('/profiles', params)
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 getEndpoint()
70
- .api.get("/profiles/".concat(profileId))
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 getEndpoint()
84
- .api.get("/profiles/".concat(profileId, "/permissions"))
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 getEndpoint()
98
- .api.get("/profiles/".concat(profileId, "/groups"))
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 getEndpoint()
113
- .api.post("/profiles/".concat(profileId, "/switch"))
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 getEndpoint()
128
- .api.put("/profiles/".concat(profileId), params)
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 getEndpoint()
142
- .api.delete("/profiles/".concat(profileId))
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
@@ -1,5 +1,5 @@
1
1
  import { IGroup, IOrganization } from '../Organizations/Types';
2
- import { TRequestStatus } from '../HTTP/Types';
2
+ export declare type TRequestStatus = 'OK' | 'ERROR';
3
3
  /**
4
4
  * An operation within Verdocs the user may perform.
5
5
  */
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 decodeTokenBody: (token: string) => any;
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 decodeTokenBody = function (token) { return JSON.parse(AtoB((token || '').split('.')[1] || '')); };
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 = decodeTokenBody(token);
52
+ decoded = decodeJWTBody(token);
53
53
  if (decoded === null) {
54
54
  return null;
55
55
  }
File without changes
File without changes
@@ -0,0 +1,193 @@
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 token;
44
+ private nextListenerId;
45
+ private sessionListeners;
46
+ private requestLoggerId;
47
+ /**
48
+ * The current user session, or null if not authenticated. May be either a User or Signing session. If set, the
49
+ * presence of the `document_id` field can be used to differentiate the types. Only signing sessions are associated
50
+ * with Documents.
51
+ */
52
+ session: TSession;
53
+ api: AxiosInstance;
54
+ Documents: typeof Documents;
55
+ /**
56
+ * Create a new VerdocsEndpoint to call Verdocs platform services.
57
+ *
58
+ * ```typescript
59
+ * import {VerdocsEndpoint} from '@verdocs/js-sdk/HTTP';
60
+ * const endpoint = new VerdocsEndpoint();
61
+ * ```
62
+ */
63
+ constructor(options?: VerdocsEndpointOptions);
64
+ setDefault(): void;
65
+ static getDefault(): any;
66
+ /**
67
+ * Get the current environment.
68
+ */
69
+ getEnvironment(): TEnvironment;
70
+ /**
71
+ * Get the current session type.
72
+ */
73
+ getSessionType(): TSessionType;
74
+ /**
75
+ * Get the current base URL. This should rarely be anything other than 'https://api.verdocs.com'.
76
+ */
77
+ getBaseURL(): string;
78
+ /**
79
+ * Get the current client ID, if set.
80
+ */
81
+ getClientID(): string;
82
+ /**
83
+ * Get the current timeout.
84
+ */
85
+ getTimeout(): number;
86
+ /**
87
+ * Get the current session, if any.
88
+ */
89
+ getSession(): TSession;
90
+ /**
91
+ * Set the operating environment. This should rarely be anything other than 'verdocs'.
92
+ *
93
+ * ```typescript
94
+ * import {VerdocsEndpoint} from '@verdocs/js-sdk/HTTP';
95
+ *
96
+ * const endpoint = new VerdocsEndpoint();
97
+ * endpoint.setEnvironment('verdocs-stage');
98
+ * ```
99
+ */
100
+ setEnvironment(environment: TEnvironment): VerdocsEndpoint;
101
+ /**
102
+ * Set the session type. In general this should be done immediately when the endpoint is created. Changing the
103
+ * session type may be done at any time, but may have unintended consequences if the endpoint is shared between
104
+ * multiple widgets.
105
+ *
106
+ * Changing the session type will clear/reload the action session. This may trigger notifications to session state
107
+ * observers. Apps that use observers to trigger UI updates such as logging the user out should be prepared to
108
+ * handle this event.
109
+ *
110
+ * ```typescript
111
+ * import {VerdocsEndpoint} from '@verdocs/js-sdk/HTTP';
112
+ *
113
+ * const endpoint = new VerdocsEndpoint();
114
+ * endpoint.setEnvironment('verdocs-stage');
115
+ * ```
116
+ */
117
+ setSessionType(sessionType: TSessionType): VerdocsEndpoint;
118
+ /**
119
+ * Set the base URL for API calls. Should be called only upon direction from Verdocs Customer Solutions Engineering.
120
+ *
121
+ * ```typescript
122
+ * import {VerdocsEndpoint} from '@verdocs/js-sdk/HTTP';
123
+ *
124
+ * const endpoint = new VerdocsEndpoint();
125
+ * endpoint.setBaseURL('https://api.verdocs.com');
126
+ * ```
127
+ */
128
+ setBaseURL(url: string): VerdocsEndpoint;
129
+ /**
130
+ * Set the Client ID for Verdocs API calls.
131
+ *
132
+ * ```typescript
133
+ * import {VerdocsEndpoint} from '@verdocs/js-sdk/HTTP';
134
+ *
135
+ * const endpoint = new VerdocsEndpoint();
136
+ * endpoint.setClientID('1234);
137
+ * ```
138
+ */
139
+ setClientID(clientID: string): VerdocsEndpoint;
140
+ /**
141
+ * Set the timeout for API calls in milliseconds. 2000-4000ms is recommended for most purposes. 3000ms is the default.
142
+ *
143
+ * ```typescript
144
+ * import {VerdocsEndpoint} from '@verdocs/js-sdk/HTTP';
145
+ *
146
+ * const endpoint = new VerdocsEndpoint();
147
+ * endpoint.setTimeout(3000);
148
+ * ```
149
+ */
150
+ setTimeout(timeout: number): VerdocsEndpoint;
151
+ /**
152
+ * Enable or disable request logging. This may expose sensitive data in the console log, so it should only be used for debugging.
153
+ *
154
+ * ```typescript
155
+ * import {VerdocsEndpoint} from '@verdocs/js-sdk/HTTP';
156
+ *
157
+ * const endpoint = new VerdocsEndpoint();
158
+ * endpoint.logRequests(true);
159
+ * ```
160
+ */
161
+ logRequests(enable: boolean): VerdocsEndpoint;
162
+ /**
163
+ * Set the authorization token that will be used for Verdocs API calls. This will also set the session metadata
164
+ * and notify any listeners of the new data.
165
+ *
166
+ * If this Endpoint will be used for non-default purposes (e.g. signing, or in an alternate environment) those
167
+ * settings should be made before calling this. Sessions are persisted to localStorage, and the environment and
168
+ * type become part of the storage key.
169
+ *
170
+ * ```typescript
171
+ * import {VerdocsEndpoint} from '@verdocs/js-sdk/HTTP';
172
+ *
173
+ * const endpoint = new VerdocsEndpoint();
174
+ * endpoint.setToken(accessToken);
175
+ * ```
176
+ */
177
+ setToken(token: string | null): VerdocsEndpoint;
178
+ private sessionStorageKey;
179
+ /**
180
+ * Clear the active session.
181
+ */
182
+ clearSession(): this;
183
+ private notifySessionListeners;
184
+ /**
185
+ * Subscribe to session state change events.
186
+ */
187
+ onSessionChanged(listener: SessionChangedListener): () => void;
188
+ /**
189
+ * Load a persisted session from localStorage. Typically called once after the endpoint is configured when the app
190
+ * or component starts.
191
+ */
192
+ loadSession(): VerdocsEndpoint;
193
+ }