@verdocs/js-sdk 3.10.30 → 4.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.
Files changed (112) hide show
  1. package/dist/README.md +75 -0
  2. package/dist/index.d.mts +41294 -0
  3. package/dist/index.d.ts +41294 -0
  4. package/dist/index.js +3045 -0
  5. package/dist/index.js.map +1 -0
  6. package/dist/index.mjs +3036 -0
  7. package/dist/index.mjs.map +1 -0
  8. package/dist/package.json +85 -0
  9. package/dist/tsconfig.json +16 -0
  10. package/package.json +29 -12
  11. package/.github/workflows/generate-docs.yml +0 -41
  12. package/Envelopes/Envelopes.d.ts +0 -242
  13. package/Envelopes/Envelopes.js +0 -339
  14. package/Envelopes/Initials.d.ts +0 -15
  15. package/Envelopes/Initials.js +0 -13
  16. package/Envelopes/Permissions.d.ts +0 -52
  17. package/Envelopes/Permissions.js +0 -84
  18. package/Envelopes/Recipients.d.ts +0 -89
  19. package/Envelopes/Recipients.js +0 -112
  20. package/Envelopes/Reminders.d.ts +0 -23
  21. package/Envelopes/Reminders.js +0 -33
  22. package/Envelopes/Signatures.d.ts +0 -28
  23. package/Envelopes/Signatures.js +0 -37
  24. package/Envelopes/Types.d.ts +0 -390
  25. package/Envelopes/Types.js +0 -45
  26. package/Envelopes/index.d.ts +0 -7
  27. package/Envelopes/index.js +0 -7
  28. package/Organizations/ApiKeys.d.ts +0 -64
  29. package/Organizations/ApiKeys.js +0 -82
  30. package/Organizations/Groups.d.ts +0 -47
  31. package/Organizations/Groups.js +0 -76
  32. package/Organizations/Invitations.d.ts +0 -24
  33. package/Organizations/Invitations.js +0 -45
  34. package/Organizations/Members.d.ts +0 -12
  35. package/Organizations/Members.js +0 -30
  36. package/Organizations/Organizations.d.ts +0 -27
  37. package/Organizations/Organizations.js +0 -45
  38. package/Organizations/Types.d.ts +0 -104
  39. package/Organizations/Types.js +0 -1
  40. package/Organizations/Webhooks.d.ts +0 -34
  41. package/Organizations/Webhooks.js +0 -10
  42. package/Organizations/Whitelabel.d.ts +0 -31
  43. package/Organizations/Whitelabel.js +0 -38
  44. package/Organizations/index.d.ts +0 -16
  45. package/Organizations/index.js +0 -16
  46. package/Sessions/Types.d.ts +0 -54
  47. package/Sessions/Types.js +0 -1
  48. package/Sessions/index.d.ts +0 -6
  49. package/Sessions/index.js +0 -7
  50. package/Templates/Actions.d.ts +0 -26
  51. package/Templates/Actions.js +0 -104
  52. package/Templates/Fields.d.ts +0 -14
  53. package/Templates/Fields.js +0 -24
  54. package/Templates/Pages.d.ts +0 -30
  55. package/Templates/Pages.js +0 -41
  56. package/Templates/Permissions.d.ts +0 -73
  57. package/Templates/Permissions.js +0 -124
  58. package/Templates/Reminders.d.ts +0 -23
  59. package/Templates/Reminders.js +0 -33
  60. package/Templates/Roles.d.ts +0 -16
  61. package/Templates/Roles.js +0 -42
  62. package/Templates/Stars.d.ts +0 -10
  63. package/Templates/Stars.js +0 -16
  64. package/Templates/Tags.d.ts +0 -33
  65. package/Templates/Tags.js +0 -55
  66. package/Templates/TemplateDocuments.d.ts +0 -66
  67. package/Templates/TemplateDocuments.js +0 -139
  68. package/Templates/Templates.d.ts +0 -284
  69. package/Templates/Templates.js +0 -309
  70. package/Templates/Types.d.ts +0 -346
  71. package/Templates/Types.js +0 -29
  72. package/Templates/Validators.d.ts +0 -21
  73. package/Templates/Validators.js +0 -27
  74. package/Templates/index.d.ts +0 -11
  75. package/Templates/index.js +0 -11
  76. package/Users/Auth.d.ts +0 -123
  77. package/Users/Auth.js +0 -142
  78. package/Users/Billing.d.ts +0 -1
  79. package/Users/Billing.js +0 -2
  80. package/Users/Notifications.d.ts +0 -2
  81. package/Users/Notifications.js +0 -43
  82. package/Users/Profiles.d.ts +0 -151
  83. package/Users/Profiles.js +0 -179
  84. package/Users/Types.d.ts +0 -146
  85. package/Users/Types.js +0 -47
  86. package/Users/index.d.ts +0 -5
  87. package/Users/index.js +0 -5
  88. package/Utils/Colors.d.ts +0 -18
  89. package/Utils/Colors.js +0 -102
  90. package/Utils/DateTime.d.ts +0 -6
  91. package/Utils/DateTime.js +0 -79
  92. package/Utils/Fields.d.ts +0 -5
  93. package/Utils/Fields.js +0 -24
  94. package/Utils/Files.d.ts +0 -16
  95. package/Utils/Files.js +0 -42
  96. package/Utils/Locales.d.ts +0 -17
  97. package/Utils/Locales.js +0 -1358
  98. package/Utils/Primitives.d.ts +0 -18
  99. package/Utils/Primitives.js +0 -31
  100. package/Utils/Strings.d.ts +0 -9
  101. package/Utils/Strings.js +0 -28
  102. package/Utils/Token.d.ts +0 -19
  103. package/Utils/Token.js +0 -67
  104. package/Utils/globalThis.d.ts +0 -2
  105. package/Utils/globalThis.js +0 -52
  106. package/Utils/index.d.ts +0 -8
  107. package/Utils/index.js +0 -8
  108. package/VerdocsEndpoint.d.ts +0 -199
  109. package/VerdocsEndpoint.js +0 -319
  110. package/index.d.ts +0 -18
  111. package/index.js +0 -18
  112. package/tsconfig-typedoc.json +0 -26
package/dist/index.mjs ADDED
@@ -0,0 +1,3036 @@
1
+ import axios from 'axios';
2
+
3
+ var Models = /*#__PURE__*/Object.freeze({
4
+ __proto__: null
5
+ });
6
+
7
+ /* tslint:disable:no-bitwise */
8
+ const b64 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
9
+ // Regular expression to check formal correctness of base64 encoded strings
10
+ const b64re = /^(?:[A-Za-z\d+\/]{4})*?(?:[A-Za-z\d+\/]{2}(?:==)?|[A-Za-z\d+\/]{3}=?)?$/;
11
+ /**
12
+ * Simplified, Node/Browser-safe alternative to atob() for base64 decoding.
13
+ * Modified from https://github.com/MaxArt2501/base64-js/blob/master/base64.js
14
+ */
15
+ const AtoB = (str) => {
16
+ // atob can work with strings with whitespaces, even inside the encoded part,
17
+ // but only \t, \n, \f, \r and ' ', which can be stripped.
18
+ str = String(str).replace(/[\t\n\f\r ]+/g, '');
19
+ if (!b64re.test(str))
20
+ throw new TypeError("Failed to execute 'atob' on 'Window': The string to be decoded is not correctly encoded.");
21
+ // Adding the padding if missing, for semplicity
22
+ str += '=='.slice(2 - (str.length & 3));
23
+ let bitmap;
24
+ let result = '';
25
+ let r1;
26
+ let r2;
27
+ let i = 0;
28
+ for (; i < str.length;) {
29
+ bitmap =
30
+ (b64.indexOf(str.charAt(i++)) << 18) |
31
+ (b64.indexOf(str.charAt(i++)) << 12) |
32
+ ((r1 = b64.indexOf(str.charAt(i++))) << 6) |
33
+ (r2 = b64.indexOf(str.charAt(i++)));
34
+ result +=
35
+ r1 === 64
36
+ ? String.fromCharCode((bitmap >> 16) & 255)
37
+ : r2 === 64
38
+ ? String.fromCharCode((bitmap >> 16) & 255, (bitmap >> 8) & 255)
39
+ : String.fromCharCode((bitmap >> 16) & 255, (bitmap >> 8) & 255, bitmap & 255);
40
+ }
41
+ return result;
42
+ };
43
+ /**
44
+ * Decode the body of a JWT. This helper may allow front-end applications to avoid a dependency on `jsonwebtoken` in
45
+ * many cases. Note that this should only be used for true JWTs. Opaque tokens will cause this to throw.
46
+ */
47
+ const decodeJWTBody = (token) => JSON.parse(AtoB((token || '').split('.')[1] || ''));
48
+ /**
49
+ * Decode the body of an Verdocs access token. Note that raw tokens contain namespaced fields, e.g.
50
+ * `https://verdocs.com/profile_id`. To make these tokens easier to use in front-end code, this name-spacing
51
+ * will be removed. Note that user and signing sessions have different access token formats. The calling
52
+ * application should distinguish between the two based on the context of the authenticated session, or by
53
+ * the presence of the `document_id` field, which will only be present for signing sessions.
54
+ */
55
+ const decodeAccessTokenBody = (token) => {
56
+ let decoded;
57
+ try {
58
+ decoded = decodeJWTBody(token);
59
+ if (decoded === null) {
60
+ return null;
61
+ }
62
+ }
63
+ catch (e) {
64
+ return null;
65
+ }
66
+ Object.keys(decoded).forEach((key) => {
67
+ if (typeof key === 'string' && key.startsWith('https://verdocs.com/')) {
68
+ decoded[key.replace('https://verdocs.com/', '')] = decoded[key];
69
+ delete decoded[key];
70
+ }
71
+ });
72
+ return decoded;
73
+ };
74
+
75
+ var Token = /*#__PURE__*/Object.freeze({
76
+ __proto__: null,
77
+ AtoB: AtoB,
78
+ decodeAccessTokenBody: decodeAccessTokenBody,
79
+ decodeJWTBody: decodeJWTBody
80
+ });
81
+
82
+ /**
83
+ * Create an envelope
84
+ *
85
+ * ```typescript
86
+ * import {Envelopes, ICreateEnvelopeRole, ICreateEnvelopeRequest} from '@verdocs/js-sdk/Envelopes';
87
+ *
88
+ * const role1: ICreateEnvelopeRole = {
89
+ * type: 'signer',
90
+ * name: 'Seller',
91
+ * full_name: 'Paige Turner',
92
+ * email: 'paige.turner@nomail.com',
93
+ * phone: '',
94
+ * sequence: 1,
95
+ * delegator: false,
96
+ * message: '',
97
+ * };
98
+ *
99
+ * const role2: ICreateEnvelopeRole = {
100
+ * type: 'signer',
101
+ * name: 'Buyer',
102
+ * full_name: 'Will Power',
103
+ * email: 'will.power@nomail.com',
104
+ * phone: '',
105
+ * sequence: 2,
106
+ * delegator: false,
107
+ * message: '',
108
+ * };
109
+ *
110
+ * const request: ICreateEnvelopeRequest = {template_id: 'd2338742-f3a1-465b-8592-806587413cc1', name: 'Bill of Sale', roles: [role1, role2]};
111
+ * const {id, recipients} = await Envelopes.createEnvelope(VerdocsEndpoint.getDefault(), request);
112
+ * ```
113
+ */
114
+ const createEnvelope = async (endpoint, request) => endpoint.api //
115
+ .post('/envelopes', request)
116
+ .then((r) => r.data);
117
+ /**
118
+ * Get a summary of currently active envelopes.
119
+ *
120
+ * ```typescript
121
+ * import {Envelopes} from '@verdocs/js-sdk/Envelopes';
122
+ *
123
+ * const {action_required, completed, waiting_on_others} = await Envelopes.getSummary(VerdocsEndpoint.getDefault());
124
+ * ```
125
+ */
126
+ const getSummary$1 = async (endpoint, page) => endpoint.api //
127
+ .post('/envelopes/summary', { page })
128
+ .then((r) => r.data);
129
+ /**
130
+ * Search for envelopes matching various criteria.
131
+ *
132
+ * ```typescript
133
+ * import {Envelopes} from '@verdocs/js-sdk/Envelopes';
134
+ *
135
+ * const {result, page, total} = await Envelopes.search(VerdocsEndpoint.getDefault(), { ... });
136
+ * ```
137
+ */
138
+ const searchEnvelopes = async (endpoint, params) => endpoint.api //
139
+ .post('/envelopes/search', params)
140
+ .then((r) => r.data);
141
+ /**
142
+ * Get a signing session for an Envelope.
143
+ */
144
+ const getSigningSession = async (endpoint, params) => {
145
+ window.console.log('[JS_SDK] getSigningSession', params, endpoint.api);
146
+ return endpoint.api //
147
+ .get(`/envelopes/${params.envelopeId}/recipients/${encodeURIComponent(params.roleId)}/invitation/${params.inviteCode}`)
148
+ .then((r) => {
149
+ // Avoiding a jsonwebtoken dependency here - we don't actually need the whole library
150
+ const signerToken = r.headers?.signer_token || '';
151
+ const session = decodeAccessTokenBody(signerToken);
152
+ endpoint.setToken(signerToken);
153
+ return { recipient: r.data, session, signerToken };
154
+ });
155
+ };
156
+ /**
157
+ * Get the list of recipients for an Envelope.
158
+ */
159
+ const getEnvelopeRecipients = async (endpoint, envelopeId) => endpoint.api //
160
+ .get(`/envelopes/${envelopeId}/recipients`)
161
+ .then((r) => r.data);
162
+ /**
163
+ * Get all metadata for an Envelope.
164
+ */
165
+ const getEnvelope = async (endpoint, envelopeId) => endpoint.api //
166
+ .get(`/envelopes/${envelopeId}`)
167
+ .then((r) => r.data);
168
+ /**
169
+ * Get an Envelope Document
170
+ */
171
+ const getEnvelopeDocument = async (endpoint, envelopeId, documentId) => endpoint.api //
172
+ .get(`/envelopes/${envelopeId}/envelope_documents/${documentId}`)
173
+ .then((r) => r.data);
174
+ /**
175
+ * Get a pre-signed download link for an Envelope Document. This link expires quickly, so it should
176
+ * be accessed immediately and never shared. Content-Disposition will be set to "download".
177
+ */
178
+ const getDocumentDownloadLink = async (endpoint, envelopeId, documentId) => endpoint.api //
179
+ .get(`/envelopes/${envelopeId}/envelope_documents/${documentId}?download=true`)
180
+ .then((r) => r.data);
181
+ /**
182
+ * Get a pre-signed preview link for an Envelope Document. This link expires quickly, so it should
183
+ * be accessed immediately and never shared. Content-Disposition will be set to "inline".
184
+ */
185
+ const getDocumentPreviewLink = async (endpoint, envelopeId, documentId) => endpoint.api //
186
+ .get(`/envelopes/${envelopeId}/envelope_documents/${documentId}?preview=true`)
187
+ .then((r) => r.data);
188
+ /**
189
+ * Cancel an Envelope.
190
+ */
191
+ const cancelEnvelope = async (endpoint, envelopeId) => endpoint.api //
192
+ .put(`/envelopes/${envelopeId}`, { action: 'cancel' })
193
+ .then((r) => r.data);
194
+ /**
195
+ * Get (binary download) a file attached to an Envelope. It is important to use this method
196
+ * rather than a direct A HREF or similar link to set the authorization headers for the
197
+ * request.
198
+ */
199
+ const getEnvelopeFile = async (endpoint, envelopeId, documentId) => endpoint.api //
200
+ .get(`/envelopes/${envelopeId}/envelope_documents/${documentId}?file=true`, { responseType: 'blob' })
201
+ .then((r) => r.data);
202
+ /**
203
+ * Update a Document field. Typically called during the signing process as a Recipient fills in fields.
204
+ */
205
+ const updateEnvelopeField = async (endpoint, envelopeId, fieldName, value) => endpoint.api //
206
+ .put(`/envelopes/${envelopeId}/fields/${fieldName}`, value)
207
+ .then((r) => r.data);
208
+ /**
209
+ * Update a Document signature field. Signature fields are ID-driven. Call `Document.createSignature()` first to create a
210
+ * signature for a Recipient, then call `Documents.updateDocumentFieldSignature()` to attach it to a field.
211
+ */
212
+ const updateEnvelopeFieldSignature = async (endpoint, envelopeId, fieldName, signatureId) => endpoint.api //
213
+ .put(`/envelopes/${envelopeId}/fields/${fieldName}/signature/${signatureId}`)
214
+ .then((r) => r.data);
215
+ /**
216
+ * Update a Document signature field. Signature fields are ID-driven. Call `Document.createSignature()` first to create a
217
+ * signature for a Recipient, then call `Documents.updateDocumentFieldSignature()` to attach it to a field.
218
+ */
219
+ const updateEnvelopeFieldInitials = async (endpoint, envelopeId, fieldName, initialId) => endpoint.api //
220
+ .put(`/envelopes/${envelopeId}/fields/${fieldName}/initial/${initialId}`)
221
+ .then((r) => r.data);
222
+ /**
223
+ * Upload an attachment.
224
+ */
225
+ const uploadEnvelopeFieldAttachment = async (endpoint, envelopeId, fieldName, file, onUploadProgress) => {
226
+ const formData = new FormData();
227
+ formData.append('document', file, file.name);
228
+ return endpoint.api //
229
+ .put(`/envelopes/${envelopeId}/fields/${fieldName}`, formData, {
230
+ timeout: 120000,
231
+ onUploadProgress: (event) => {
232
+ const total = event.total || 1;
233
+ const loaded = event.loaded || 0;
234
+ onUploadProgress?.(Math.floor((loaded * 100) / (total || 1)), loaded, total || 1);
235
+ },
236
+ })
237
+ .then((r) => r.data);
238
+ };
239
+ /**
240
+ * Delete an attachment.
241
+ */
242
+ const deleteEnvelopeFieldAttachment = async (endpoint, envelopeId, fieldName, file, onUploadProgress) => {
243
+ const formData = new FormData();
244
+ // Omitting file is the trigger here
245
+ return endpoint.api //
246
+ .put(`/envelopes/${envelopeId}/fields/${fieldName}`, formData, {
247
+ timeout: 120000,
248
+ onUploadProgress: (event) => {
249
+ const total = event.total || 1;
250
+ const loaded = event.loaded || 0;
251
+ onUploadProgress?.(Math.floor((loaded * 100) / (total || 1)), loaded, total || 1);
252
+ },
253
+ })
254
+ .then((r) => r.data);
255
+ };
256
+ /**
257
+ * Get the attached file for an attachment field (if any)
258
+ */
259
+ const getFieldAttachment = async (endpoint, envelopeId, fieldName) => endpoint.api //
260
+ .get(`/envelopes/${envelopeId}/fields/${fieldName}/document`, { responseType: 'blob' })
261
+ .then((r) => r.data);
262
+ /**
263
+ * Get a display URI for a given page in a file attached to an envelope document. These pages are rendered server-side
264
+ * into PNG resources suitable for display in IMG tags although they may be used elsewhere. Note that these are intended
265
+ * for DISPLAY ONLY, are not legally binding documents, and do not contain any encoded metadata from participants.
266
+ */
267
+ const getEnvelopeDocumentPageDisplayUri = async (endpoint, envelopeId, documentId, page, type = 'original') => endpoint.api
268
+ .get(`/envelopes/${envelopeId}/envelope_documents/${documentId}/pages/${page}/image?type=${type}`, { timeout: 20000 })
269
+ .then((r) => r.data);
270
+ const cachedEnvelopes = {};
271
+ /**
272
+ * Wrapper for `getEnvelope()` that limits queries to one every 2 seconds per template ID.
273
+ * This is intended for use in component hierarchies that all rely on the same template
274
+ * to avoid unnecessary repeat server calls.
275
+ */
276
+ const throttledGetEnvelope = (endpoint, envelopeId) => {
277
+ if (cachedEnvelopes[envelopeId] && cachedEnvelopes[envelopeId].loaded + 2000 < new Date().getTime()) {
278
+ return cachedEnvelopes[envelopeId].envelope;
279
+ }
280
+ return getEnvelope(endpoint, envelopeId).then((envelope) => {
281
+ cachedEnvelopes[envelopeId] = { loaded: new Date().getTime(), envelope };
282
+ return envelope;
283
+ });
284
+ };
285
+ /**a
286
+ * Lists all envelopes accessible by the caller, with optional filters.
287
+ *
288
+ * ```typescript
289
+ * import {Envelopes} from '@verdocs/js-sdk/Envelopes';
290
+ *
291
+ * const {totals, envelopes} = await Envelopes.listEnvelopes((VerdocsEndpoint.getDefault(), { q: 'test', sort: 'created_at' });
292
+ * ```
293
+ */
294
+ const listEnvelopes = (endpoint, params) => endpoint.api //
295
+ .post('/envelopes/list', params)
296
+ .then((r) => r.data);
297
+
298
+ var Envelopes = /*#__PURE__*/Object.freeze({
299
+ __proto__: null,
300
+ cancelEnvelope: cancelEnvelope,
301
+ createEnvelope: createEnvelope,
302
+ deleteEnvelopeFieldAttachment: deleteEnvelopeFieldAttachment,
303
+ getDocumentDownloadLink: getDocumentDownloadLink,
304
+ getDocumentPreviewLink: getDocumentPreviewLink,
305
+ getEnvelope: getEnvelope,
306
+ getEnvelopeDocument: getEnvelopeDocument,
307
+ getEnvelopeDocumentPageDisplayUri: getEnvelopeDocumentPageDisplayUri,
308
+ getEnvelopeFile: getEnvelopeFile,
309
+ getEnvelopeRecipients: getEnvelopeRecipients,
310
+ getFieldAttachment: getFieldAttachment,
311
+ getSigningSession: getSigningSession,
312
+ getSummary: getSummary$1,
313
+ listEnvelopes: listEnvelopes,
314
+ searchEnvelopes: searchEnvelopes,
315
+ throttledGetEnvelope: throttledGetEnvelope,
316
+ updateEnvelopeField: updateEnvelopeField,
317
+ updateEnvelopeFieldInitials: updateEnvelopeFieldInitials,
318
+ updateEnvelopeFieldSignature: updateEnvelopeFieldSignature,
319
+ uploadEnvelopeFieldAttachment: uploadEnvelopeFieldAttachment
320
+ });
321
+
322
+ /**
323
+ * Various helpers to identify available operations for an envelope by a user.
324
+ *
325
+ * @module
326
+ */
327
+ /**
328
+ * Check to see if the user owns the envelope.
329
+ */
330
+ const userIsEnvelopeOwner = (session, envelope) => envelope.profile_id === session?.profile_id;
331
+ /**
332
+ * Check to see if the user owns the envelope.
333
+ */
334
+ const userIsEnvelopeRecipient = (session, envelope) => envelope.profile_id === session?.profile_id;
335
+ /**
336
+ * Check to see if the envelope has pending actions.
337
+ */
338
+ const envelopeIsActive = (envelope) => envelope.status !== 'complete' && envelope.status !== 'declined' && envelope.status !== 'canceled';
339
+ /**
340
+ * Check to see if the envelope has been completed.
341
+ */
342
+ const envelopeIsComplete = (envelope) => envelope.status !== 'complete';
343
+ /**
344
+ * Check to see if the user owns the envelope.
345
+ */
346
+ const userCanCancelEnvelope = (session, envelope) => userIsEnvelopeOwner(session, envelope) &&
347
+ envelope.status !== 'complete' &&
348
+ envelope.status !== 'declined' &&
349
+ envelope.status !== 'canceled';
350
+ /**
351
+ * Check to see if the user owns the envelope.
352
+ */
353
+ const userCanFinishEnvelope = (session, envelope) => userIsEnvelopeOwner(session, envelope) &&
354
+ envelope.status !== 'complete' &&
355
+ envelope.status !== 'declined' &&
356
+ envelope.status !== 'canceled';
357
+ /**
358
+ * Returns true if the recipient has a pending action. Note that this does not necessarily mean the recipient can act (yet).
359
+ */
360
+ const recipientHasAction = (recipient) => !['submitted', 'canceled', 'declined'].includes(recipient.status);
361
+ /**
362
+ * Returns the recipients who still have a pending action. Note that not all of these recipients may be able to act (yet).
363
+ */
364
+ const getRecipientsWithActions = (envelope) => (envelope?.recipients || []).filter(recipientHasAction);
365
+ /**
366
+ * Returns true if the recipient can act.
367
+ */
368
+ const recipientCanAct = (recipient, recipientsWithActions) => recipient.sequence === recipientsWithActions?.[0]?.sequence;
369
+ /**
370
+ * Returns true if the user can act.
371
+ */
372
+ const userCanAct = (email, recipientsWithActions) => {
373
+ const recipient = recipientsWithActions.find((r) => r.email === email);
374
+ return recipient && recipient.sequence === recipientsWithActions?.[0]?.sequence;
375
+ };
376
+ /**
377
+ * Returns true if the user can act.
378
+ */
379
+ const userCanSignNow = (session, envelope) => {
380
+ if (!session) {
381
+ return false;
382
+ }
383
+ const recipientsWithActions = getRecipientsWithActions(envelope);
384
+ const myRecipient = recipientsWithActions.find((r) => r.profile_id === session?.profile_id || r.email === session?.email);
385
+ return (myRecipient &&
386
+ envelopeIsActive(envelope) &&
387
+ userIsEnvelopeRecipient(session, envelope) &&
388
+ recipientCanAct(myRecipient, recipientsWithActions));
389
+ };
390
+ const getNextRecipient = (envelope) => {
391
+ const recipientsWithActions = getRecipientsWithActions(envelope);
392
+ return recipientsWithActions?.[0];
393
+ };
394
+
395
+ var Permissions = /*#__PURE__*/Object.freeze({
396
+ __proto__: null,
397
+ envelopeIsActive: envelopeIsActive,
398
+ envelopeIsComplete: envelopeIsComplete,
399
+ getNextRecipient: getNextRecipient,
400
+ getRecipientsWithActions: getRecipientsWithActions,
401
+ recipientCanAct: recipientCanAct,
402
+ recipientHasAction: recipientHasAction,
403
+ userCanAct: userCanAct,
404
+ userCanCancelEnvelope: userCanCancelEnvelope,
405
+ userCanFinishEnvelope: userCanFinishEnvelope,
406
+ userCanSignNow: userCanSignNow,
407
+ userIsEnvelopeOwner: userIsEnvelopeOwner,
408
+ userIsEnvelopeRecipient: userIsEnvelopeRecipient
409
+ });
410
+
411
+ /**
412
+ * Update a recipient's status block
413
+ */
414
+ const updateRecipient = async (endpoint, envelopeId, roleName, params) => endpoint.api //
415
+ .put(`/envelopes/${envelopeId}/recipients/${roleName}`, params)
416
+ .then((r) => r.data);
417
+ /**
418
+ * Submit an envelope (signing is finished). Note that all fields must be valid/completed for this to succeed.
419
+ */
420
+ const envelopeRecipientSubmit = (endpoint, envelopeId, roleName) => updateRecipient(endpoint, envelopeId, roleName, { action: 'submit' });
421
+ /**
422
+ * Decline to complete an envelope (signing will not terminated).
423
+ */
424
+ const envelopeRecipientDecline = (endpoint, envelopeId, roleName) => updateRecipient(endpoint, envelopeId, roleName, { action: 'decline' });
425
+ /**
426
+ * Claim / change ownership of an envelope. This is a special-case operation only available in certain workflows.
427
+ */
428
+ const envelopeRecipientChangeOwner = (endpoint, envelopeId, roleName, email, fullName) => updateRecipient(endpoint, envelopeId, roleName, { action: 'owner_update', email, full_name: fullName });
429
+ /**
430
+ * Agree to electronic signing.
431
+ */
432
+ const envelopeRecipientAgree = (endpoint, envelopeId, roleName, agreed) => updateRecipient(endpoint, envelopeId, roleName, { action: 'update', agreed });
433
+ /**
434
+ * Change a recipient's name.
435
+ */
436
+ const envelopeRecipientUpdateName = (endpoint, envelopeId, roleName, fullName) => updateRecipient(endpoint, envelopeId, roleName, { action: 'update', new_full_name: fullName });
437
+ /**
438
+ * Change a recipient's name.
439
+ */
440
+ const envelopeRecipientPrepare = (endpoint, envelopeId, roleName, recipients) => updateRecipient(endpoint, envelopeId, roleName, { action: 'prepare', recipients });
441
+ /**
442
+ * Get a signing token.
443
+ */
444
+ const getSignerToken = (endpoint, envelopeId, roleName) => endpoint.api //
445
+ .get(`/envelopes/${envelopeId}/recipients/${encodeURIComponent(roleName)}/signer-token`)
446
+ .then((r) => r.data);
447
+ /**
448
+ * Get an in-person signing link.
449
+ */
450
+ const getInPersonLink = (endpoint, envelopeId, roleName) => endpoint.api //
451
+ .get(`/envelopes/${envelopeId}/recipients/${encodeURIComponent(roleName)}?in_person_link=true`)
452
+ .then((r) => r.data);
453
+ /**
454
+ * Send a delegation request.
455
+ */
456
+ const sendDelegate = (endpoint, envelopeId, roleName) => endpoint.api //
457
+ .post(`/envelopes/${envelopeId}/recipients/${encodeURIComponent(roleName)}/delegate`)
458
+ .then((r) => r.data);
459
+ /**
460
+ * Resend a recipient's invitation.
461
+ */
462
+ const resendInvitation$1 = (endpoint, envelopeId, roleName) => endpoint.api //
463
+ .post(`/envelopes/${envelopeId}/recipients/${encodeURIComponent(roleName)}/resend_invitation`)
464
+ .then((r) => r.data);
465
+
466
+ var Recipients = /*#__PURE__*/Object.freeze({
467
+ __proto__: null,
468
+ envelopeRecipientAgree: envelopeRecipientAgree,
469
+ envelopeRecipientChangeOwner: envelopeRecipientChangeOwner,
470
+ envelopeRecipientDecline: envelopeRecipientDecline,
471
+ envelopeRecipientPrepare: envelopeRecipientPrepare,
472
+ envelopeRecipientSubmit: envelopeRecipientSubmit,
473
+ envelopeRecipientUpdateName: envelopeRecipientUpdateName,
474
+ getInPersonLink: getInPersonLink,
475
+ getSignerToken: getSignerToken,
476
+ resendInvitation: resendInvitation$1,
477
+ sendDelegate: sendDelegate,
478
+ updateRecipient: updateRecipient
479
+ });
480
+
481
+ /**
482
+ * Enable automatic reminders. setup_time is the number of days after the envelope is sent that the first reminder
483
+ * should be sent. interval_time is the number of days between reminders.
484
+ */
485
+ const createReminder$1 = (endpoint, envelopeId, params) => endpoint.api //
486
+ .post(`/envelopes/${envelopeId}/reminder/`, params)
487
+ .then((r) => r.data);
488
+ /**
489
+ * Get the reminder configuration for an envelope.
490
+ */
491
+ const getReminder$1 = (endpoint, envelopeId, reminderId) => endpoint.api //
492
+ .get(`/envelopes/${envelopeId}/reminder/${reminderId}`)
493
+ .then((r) => r.data);
494
+ /**
495
+ * Update the reminder configuration for an envelope.
496
+ */
497
+ const updateReminder$1 = (endpoint, envelopeId, reminderId, params) => endpoint.api //
498
+ .put(`/envelopes/${envelopeId}/reminder/${reminderId}`, params)
499
+ .then((r) => r.data);
500
+ /**
501
+ * Delete the reminder configuration for an envelope.
502
+ */
503
+ const deleteReminder$1 = (endpoint, envelopeId, reminderId) => endpoint.api //
504
+ .delete(`/envelopes/${envelopeId}/reminder/${reminderId}`)
505
+ .then((r) => r.data);
506
+
507
+ var Reminders$1 = /*#__PURE__*/Object.freeze({
508
+ __proto__: null,
509
+ createReminder: createReminder$1,
510
+ deleteReminder: deleteReminder$1,
511
+ getReminder: getReminder$1,
512
+ updateReminder: updateReminder$1
513
+ });
514
+
515
+ /**
516
+ * Create a signature block. In a typical signing workflow, the user is asked at the beginning of the process to "adopt"
517
+ * a signature block to be used for all signature fields in the document. Thus, this is typically called one time to
518
+ * create and store a signature block. Thereafter, the ID of the signature block may be re-used for each signature field
519
+ * to be "stamped" by the user.
520
+ */
521
+ const createSignature = (endpoint, name, signature) => {
522
+ const data = new FormData();
523
+ data.append('signature', signature, name);
524
+ return endpoint.api //
525
+ .post(`/signatures`, data)
526
+ .then((r) => r.data);
527
+ };
528
+ /**
529
+ * Get the availbable signatures for a user.
530
+ */
531
+ const getSignatures = (endpoint) => endpoint.api //
532
+ .get('/signatures')
533
+ .then((r) => r.data);
534
+ /**
535
+ * Get a user's signature by ID.
536
+ */
537
+ const getSignature = (endpoint, signatureId) => endpoint.api //
538
+ .get(`/signatures/${signatureId}`)
539
+ .then((r) => r.data);
540
+ /**
541
+ * Delete a user's signature.
542
+ */
543
+ const deleteSignature = (endpoint, signatureId) => endpoint.api //
544
+ .delete(`/signatures/${signatureId}`)
545
+ .then((r) => r.data);
546
+
547
+ var Signatures = /*#__PURE__*/Object.freeze({
548
+ __proto__: null,
549
+ createSignature: createSignature,
550
+ deleteSignature: deleteSignature,
551
+ getSignature: getSignature,
552
+ getSignatures: getSignatures
553
+ });
554
+
555
+ /**
556
+ * Create an initials block. In a typical signing workflow, the user is asked at the beginning of the process to "adopt"
557
+ * an initials block to be used for all initials fields in the document. Thus, this is typically called one time to
558
+ * create and store an initials block. Thereafter, the ID of the initials block may be re-used for each initials field
559
+ * to be "stamped" by the user.
560
+ */
561
+ const createInitials = (endpoint, name, initials) => {
562
+ const data = new FormData();
563
+ data.append('initial', initials, name);
564
+ return endpoint.api //
565
+ .post(`/initials`, data)
566
+ .then((r) => r.data);
567
+ };
568
+
569
+ var Initials = /*#__PURE__*/Object.freeze({
570
+ __proto__: null,
571
+ createInitials: createInitials
572
+ });
573
+
574
+ var Types$5 = /*#__PURE__*/Object.freeze({
575
+ __proto__: null
576
+ });
577
+
578
+ var index$5 = /*#__PURE__*/Object.freeze({
579
+ __proto__: null,
580
+ Envelopes: Envelopes,
581
+ Initials: Initials,
582
+ Permissions: Permissions,
583
+ Recipients: Recipients,
584
+ Reminders: Reminders$1,
585
+ Signatures: Signatures,
586
+ Types: Types$5
587
+ });
588
+
589
+ /**
590
+ * API keys are used to authenticate server-to-server calls. (API keys should **never** be used for client-to-server operations!)
591
+ * To generate a key, either use the Verdocs admin interface and make note of the client_id and client_secret generated, or call
592
+ * createKey as shown below. Then call {@link Users.Auth.authenticateApp} to obtain an access token using the provided ID and
593
+ * secret. Note that server-to-server authentication requests return shorter-lived tokens, so it is important to check the `exp`
594
+ * field and re-authenticate as needed for subsequent calls.
595
+ *
596
+ * API keys may be updated or rotated at any time. Regular rotation is recommended. Rotation will not expire or invalidate
597
+ * existing server-to-server sessions, so it may be done at any time without disrupting your application.
598
+ *
599
+ * @module
600
+ */
601
+ /**
602
+ * Get a list of keys for a given organization. The caller must have admin access to the organization.
603
+ *
604
+ * ```typescript
605
+ * import {ApiKeys} from '@verdocs/js-sdk/Organizations';
606
+ *
607
+ * const keys = await ApiKeys.getKeys(ORGID);
608
+ * ```
609
+ */
610
+ const getKeys = (endpoint, organizationId) => endpoint.api //
611
+ .get(`/organizations/${organizationId}/api_key`)
612
+ .then((r) => r.data);
613
+ /**
614
+ * Create an API key.
615
+ *
616
+ * ```typescript
617
+ * import {ApiKeys} from '@verdocs/js-sdk/Organizations';
618
+ *
619
+ * await ApiKeys.createKey(ORGID, {name: NEWNAME});
620
+ * ```
621
+ */
622
+ const createKey = (endpoint, organizationId, params) => endpoint.api //
623
+ .post(`/organizations/${organizationId}/api_key`, params)
624
+ .then((r) => r.data);
625
+ /**
626
+ * Rotate the secret for an API key. The caller must have admin access to the organization.
627
+ *
628
+ * ```typescript
629
+ * import {ApiKeys} from '@verdocs/js-sdk/Organizations';
630
+ *
631
+ * const {client_secret: newSecret} = await ApiKeys.rotateKey(ORGID, CLIENTID);
632
+ * ```
633
+ */
634
+ const rotateKey = (endpoint, organizationId, clientId) => endpoint.api //
635
+ .put(`/organizations/${organizationId}/api_key/${clientId}/rotate`)
636
+ .then((r) => r.data);
637
+ /**
638
+ * Update an API key to change its assigned Profile ID or Name.
639
+ *
640
+ * ```typescript
641
+ * import {ApiKeys} from '@verdocs/js-sdk/Organizations';
642
+ *
643
+ * await ApiKeys.updateKey(ORGID, CLIENTID, {name: NEWNAME});
644
+ * ```
645
+ */
646
+ const updateKey = (endpoint, organizationId, clientId, params) => endpoint.api //
647
+ .patch(`/organizations/${organizationId}/api_key/${clientId}`, params)
648
+ .then((r) => r.data);
649
+ /**
650
+ * Delete an API key.
651
+ *
652
+ * ```typescript
653
+ * import {ApiKeys} from '@verdocs/js-sdk/Organizations';
654
+ *
655
+ * await ApiKeys.deleteKey(ORGID, CLIENTID);
656
+ * ```
657
+ */
658
+ const deleteKey = (endpoint, organizationId, clientId) => endpoint.api //
659
+ .delete(`/organizations/${organizationId}/api_key/${clientId}`)
660
+ .then((r) => r.data);
661
+
662
+ var ApiKeys = /*#__PURE__*/Object.freeze({
663
+ __proto__: null,
664
+ createKey: createKey,
665
+ deleteKey: deleteKey,
666
+ getKeys: getKeys,
667
+ rotateKey: rotateKey,
668
+ updateKey: updateKey
669
+ });
670
+
671
+ /**
672
+ * Organizations may contain "Groups" of user profiles, called Members. Groups may have permissions assigned that
673
+ * apply to all Members, making it easy to configure role-based access control (RBAC) within an Organization. Note
674
+ * that permissions are **additive**. A user may be a member of more than one group, and may also have permissions
675
+ * assigned directly. In that case, the user will have the combined set of all permissions inherited from all
676
+ * sources.
677
+ *
678
+ * @module
679
+ */
680
+ /**
681
+ * Get a list of groups for a given organization. The caller must have admin access to the organization.
682
+ *
683
+ * ```typescript
684
+ * import {Groups} from '@verdocs/js-sdk/Organizations';
685
+ *
686
+ * const groups = await Groups.getGroups(ORGID);
687
+ * ```
688
+ */
689
+ const getGroups = (endpoint, organizationId) => endpoint.api //
690
+ .get(`/organizations/${organizationId}/groups`)
691
+ .then((r) => r.data);
692
+ /**
693
+ * Get a single group by name. Returns a detail record.
694
+ *
695
+ * ```typescript
696
+ * import {Groups} from '@verdocs/js-sdk/Organizations';
697
+ *
698
+ * const groups = await Groups.getGroups(ORGID);
699
+ * ```
700
+ */
701
+ const getGroupByName = (endpoint, organizationId, name) => endpoint.api //
702
+ .get(`/organizations/${organizationId}/groups`, { params: { name } })
703
+ .then((r) => r.data);
704
+ /**
705
+ * Get the details for a group.
706
+ *
707
+ * ```typescript
708
+ * import {Groups} from '@verdocs/js-sdk/Organizations';
709
+ *
710
+ * const groups = await Groups.getGroups(ORGID);
711
+ * ```
712
+ */
713
+ const getGroup = (endpoint, organizationId, groupId) => endpoint.api //
714
+ .get(`/organizations/${organizationId}/groups/${groupId}`)
715
+ .then((r) => r.data);
716
+ const getMembers$1 = (endpoint, organizationId, groupId) => endpoint.api //
717
+ .get(`/organizations/${organizationId}/groups/${groupId}/members`)
718
+ .then((r) => r.data);
719
+ const addMembers = (endpoint, organizationId, groupId, params) => endpoint.api //
720
+ .post(`/organizations/${organizationId}/groups/${groupId}/members`, params)
721
+ .then((r) => r.data);
722
+ const deleteMembers = (endpoint, organizationId, groupId, params) => endpoint.api //
723
+ .put(`/organizations/${organizationId}/groups/${groupId}/delete_members`, params)
724
+ .then((r) => r.data);
725
+ const addPermission = (endpoint, organizationId, groupId, permissionId) => endpoint.api //
726
+ .post(`/organizations/${organizationId}/groups/${groupId}/permissions/${permissionId}`, {})
727
+ .then((r) => r.data);
728
+ const deletePermission = (endpoint, organizationId, groupId, permissionId) => endpoint.api //
729
+ .delete(`/organizations/${organizationId}/groups/${groupId}/permissions/${permissionId}`)
730
+ .then((r) => r.data);
731
+
732
+ var Groups = /*#__PURE__*/Object.freeze({
733
+ __proto__: null,
734
+ addMembers: addMembers,
735
+ addPermission: addPermission,
736
+ deleteMembers: deleteMembers,
737
+ deletePermission: deletePermission,
738
+ getGroup: getGroup,
739
+ getGroupByName: getGroupByName,
740
+ getGroups: getGroups,
741
+ getMembers: getMembers$1
742
+ });
743
+
744
+ /**
745
+ * An invitation represents an opportunity for a Member to join an Organization.
746
+ *
747
+ * @module
748
+ */
749
+ const getInvitations = (endpoint, organizationId) => endpoint.api //
750
+ .get(`/organizations/${organizationId}/invitation`)
751
+ .then((r) => r.data);
752
+ const createInvitation = (endpoint, organizationId, params) => endpoint.api //
753
+ .post(`/organizations/${organizationId}/invitation`, params)
754
+ .then((r) => r.data);
755
+ const deleteInvitation = (endpoint, organizationId, email) => endpoint.api //
756
+ .delete(`/organizations/${organizationId}/invitation/${email}`)
757
+ .then((r) => r.data);
758
+ const updateInvitation = (endpoint, organizationId, email, params) => endpoint.api //
759
+ .patch(`/organizations/${organizationId}/invitation/${email}`, params)
760
+ .then((r) => r.data);
761
+ const resendInvitation = (endpoint, organizationId, email) => endpoint.api //
762
+ .post(`/organizations/${organizationId}/invitation/${email}/resend`)
763
+ .then((r) => r.data);
764
+ const getInvitation = (endpoint, organizationId, email, token) => endpoint.api //
765
+ .get(`/organizations/${organizationId}/invitation/${email}/accept/${token}`)
766
+ .then((r) => r.data);
767
+ const acceptInvitation = (endpoint, organizationId, email, token) => endpoint.api //
768
+ .post(`/organizations/${organizationId}/invitation/${email}/accept/${token}`)
769
+ .then((r) => r.data);
770
+ const declineInvitation = (endpoint, organizationId, email, token) => endpoint.api //
771
+ .post(`/organizations/${organizationId}/invitation/${email}/decline/${token}`)
772
+ .then((r) => r.data);
773
+ const claimNewUser = (endpoint, organizationId, email, token) => endpoint.api //
774
+ .put(`/organizations/${organizationId}/invitation/${email}/token/${token}/new_user`)
775
+ .then((r) => r.data);
776
+
777
+ var Invitations = /*#__PURE__*/Object.freeze({
778
+ __proto__: null,
779
+ acceptInvitation: acceptInvitation,
780
+ claimNewUser: claimNewUser,
781
+ createInvitation: createInvitation,
782
+ declineInvitation: declineInvitation,
783
+ deleteInvitation: deleteInvitation,
784
+ getInvitation: getInvitation,
785
+ getInvitations: getInvitations,
786
+ resendInvitation: resendInvitation,
787
+ updateInvitation: updateInvitation
788
+ });
789
+
790
+ /**
791
+ * An Organization Member (aka Profile) is an individual user with access to an organization.
792
+ *
793
+ * @module
794
+ */
795
+ const getMembers = (endpoint, organizationId) => endpoint.api //
796
+ .get(`/organizations/${organizationId}/profiles`)
797
+ .then((r) => r.data);
798
+ const deleteMember = (endpoint, organizationId, profileId) => endpoint.api //
799
+ .delete(`/organizations/${organizationId}/profiles/${profileId}`)
800
+ .then((r) => r.data);
801
+ const addMemberRole = (endpoint, organizationId, profileId, roleId) => endpoint.api //
802
+ .post(`/organizations/${organizationId}/profiles/${profileId}/role/${roleId}`)
803
+ .then((r) => r.data);
804
+ const deleteMemberRole = (endpoint, organizationId, profileId, roleId) => endpoint.api //
805
+ .delete(`/organizations/${organizationId}/profiles/${profileId}/role/${roleId}`)
806
+ .then((r) => r.data);
807
+ const getMemberPlans = (endpoint, organizationId, profileId) => endpoint.api //
808
+ .get(`/organizations/${organizationId}/profiles/${profileId}/plans`)
809
+ .then((r) => r.data);
810
+
811
+ var Members = /*#__PURE__*/Object.freeze({
812
+ __proto__: null,
813
+ addMemberRole: addMemberRole,
814
+ deleteMember: deleteMember,
815
+ deleteMemberRole: deleteMemberRole,
816
+ getMemberPlans: getMemberPlans,
817
+ getMembers: getMembers
818
+ });
819
+
820
+ /**
821
+ * An Organization is the top level object for ownership for Members, Documents, and Templates.
822
+ *
823
+ * @module
824
+ */
825
+ /**
826
+ * Get a list of organizations the user has access to.
827
+ */
828
+ const getOrganizations = (endpoint) => endpoint.api //
829
+ .get('/organizations')
830
+ .then((r) => r.data);
831
+ /**
832
+ * Create an organization.
833
+ */
834
+ const createOrganization = (endpoint) => endpoint.api //
835
+ .post('/organizations')
836
+ .then((r) => r.data);
837
+ /**
838
+ * Delete an organization.
839
+ */
840
+ const deleteOrganization = (endpoint, organizationId) => endpoint.api //
841
+ .delete(`/organizations/${organizationId}`)
842
+ .then((r) => r.data);
843
+ /**
844
+ * Get an organization by ID.
845
+ */
846
+ const getOrganization = (endpoint, organizationId) => endpoint.api //
847
+ .get(`/organizations/${organizationId}`)
848
+ .then((r) => r.data);
849
+ /**
850
+ * Update an organization.
851
+ */
852
+ const updateOrganization = (endpoint, organizationId, params) => endpoint.api //
853
+ .patch(`/organizations/${organizationId}`, params)
854
+ .then((r) => r.data);
855
+
856
+ var Organizations = /*#__PURE__*/Object.freeze({
857
+ __proto__: null,
858
+ createOrganization: createOrganization,
859
+ deleteOrganization: deleteOrganization,
860
+ getOrganization: getOrganization,
861
+ getOrganizations: getOrganizations,
862
+ updateOrganization: updateOrganization
863
+ });
864
+
865
+ var Types$4 = /*#__PURE__*/Object.freeze({
866
+ __proto__: null
867
+ });
868
+
869
+ const getWebhooks = (endpoint) => endpoint.api //
870
+ .get(`/v2/webhooks/organization`)
871
+ .then((r) => r.data);
872
+ const setWebhooks = (endpoint, params) => endpoint.api //
873
+ .post(`/v2/webhooks/organization`, params)
874
+ .then((r) => r.data);
875
+
876
+ var Webhooks = /*#__PURE__*/Object.freeze({
877
+ __proto__: null,
878
+ getWebhooks: getWebhooks,
879
+ setWebhooks: setWebhooks
880
+ });
881
+
882
+ /**
883
+ * An Organization is a high-level container within Verdocs that groups together Templates, Documents, Profiles, Billing, and
884
+ * other settings. A User may be a member of more than one Organization. Each membership is tracked by a Profile representing
885
+ * that user's settings within that organization. It is important to select the correct Profile before performing operations
886
+ * against the Verdocs API, as this also sets the Organization that will be operated on, and the user's permissions within it.
887
+ *
888
+ * @module
889
+ */
890
+
891
+ var index$4 = /*#__PURE__*/Object.freeze({
892
+ __proto__: null,
893
+ ApiKeys: ApiKeys,
894
+ Groups: Groups,
895
+ Invitations: Invitations,
896
+ Members: Members,
897
+ Organizations: Organizations,
898
+ Types: Types$4,
899
+ Webhooks: Webhooks
900
+ });
901
+
902
+ var Types$3 = /*#__PURE__*/Object.freeze({
903
+ __proto__: null
904
+ });
905
+
906
+ /**
907
+ * Confirm whether the user has all of the specified permissions.
908
+ */
909
+ const userHasPermissions = (session, permissions) => permissions.every((perm) => (session?.permissions || []).includes(perm));
910
+
911
+ var index$3 = /*#__PURE__*/Object.freeze({
912
+ __proto__: null,
913
+ Types: Types$3,
914
+ userHasPermissions: userHasPermissions
915
+ });
916
+
917
+ const canPerformTemplateAction = (session, action, template) => {
918
+ if (!template && !action.includes('create')) {
919
+ return { canPerform: false, message: 'Missing required template object' };
920
+ }
921
+ // We use BOGUS here to force the option-chain in things like template?.profile_id to NOT match profile?.profile_id because if both
922
+ // were undefined, they would actually match.
923
+ const profile_id = session?.profile_id || 'BOGUS';
924
+ const organization_id = session?.organization_id || 'BOGUS';
925
+ if (!profile_id) {
926
+ return { canPerform: false, message: 'Active session required' };
927
+ }
928
+ const isCreator = template?.profile_id === profile_id;
929
+ const isSameOrg = template?.organization_id === organization_id;
930
+ const isPersonal = template?.is_personal ?? false;
931
+ const isPublic = template?.is_public ?? false;
932
+ const permissionsRequired = [];
933
+ switch (action) {
934
+ case 'create_personal':
935
+ permissionsRequired.push('template:creator:create:personal');
936
+ break;
937
+ case 'create_org':
938
+ permissionsRequired.push('template:creator:create:org');
939
+ break;
940
+ case 'create_public':
941
+ permissionsRequired.push('template:creator:create:public');
942
+ break;
943
+ case 'read':
944
+ if (!isCreator) {
945
+ if ((!isPersonal && isSameOrg) || !isPublic) {
946
+ permissionsRequired.push('template:member:read');
947
+ }
948
+ }
949
+ break;
950
+ case 'write':
951
+ if (!isCreator) {
952
+ permissionsRequired.push('template:member:read');
953
+ permissionsRequired.push('template:member:write');
954
+ }
955
+ break;
956
+ case 'change_visibility_personal':
957
+ if (isCreator) {
958
+ permissionsRequired.push('template:creator:create:personal');
959
+ }
960
+ else {
961
+ permissionsRequired.push('template:member:visibility');
962
+ }
963
+ break;
964
+ case 'change_visibility_org':
965
+ if (isCreator) {
966
+ permissionsRequired.push('template:creator:create:org');
967
+ }
968
+ else {
969
+ permissionsRequired.push('template:member:visibility');
970
+ }
971
+ break;
972
+ case 'change_visibility_public':
973
+ if (isCreator) {
974
+ permissionsRequired.push('template:creator:create:public');
975
+ permissionsRequired.push('template:creator:visibility');
976
+ }
977
+ else {
978
+ permissionsRequired.push('template:member:visibility');
979
+ }
980
+ break;
981
+ case 'delete':
982
+ if (isCreator) {
983
+ permissionsRequired.push('template:creator:delete');
984
+ }
985
+ else {
986
+ permissionsRequired.push('template:member:delete');
987
+ }
988
+ break;
989
+ default:
990
+ return { canPerform: false, message: 'Action is not defined' };
991
+ }
992
+ if (hasRequiredPermissions(session, permissionsRequired)) {
993
+ return { canPerform: true, message: '' };
994
+ }
995
+ return { canPerform: false, message: `Insufficient access to perform '${action}'. Needed permissions: ${permissionsRequired.toString()}` };
996
+ };
997
+ const hasRequiredPermissions = (session, permissions) => permissions.every((perm) => (session?.permissions || []).includes(perm));
998
+
999
+ var Actions = /*#__PURE__*/Object.freeze({
1000
+ __proto__: null,
1001
+ canPerformTemplateAction: canPerformTemplateAction,
1002
+ hasRequiredPermissions: hasRequiredPermissions
1003
+ });
1004
+
1005
+ /**
1006
+ * Add a field to a template.
1007
+ */
1008
+ const createField = (endpoint, templateId, params) => endpoint.api //
1009
+ .post(`/templates/${templateId}/fields`, params)
1010
+ .then((r) => r.data);
1011
+ /**
1012
+ * Update a template field.
1013
+ */
1014
+ const updateField = (endpoint, templateId, fieldName, params) => endpoint.api //
1015
+ .put(`/templates/${templateId}/fields/${fieldName}`, params)
1016
+ .then((r) => r.data);
1017
+ /**
1018
+ * REmove a field from a template.
1019
+ */
1020
+ const deleteField = (endpoint, templateId, fieldName) => endpoint.api //
1021
+ .delete(`/templates/${templateId}/fields/${fieldName}`)
1022
+ .then((r) => r.data);
1023
+
1024
+ var Fields$1 = /*#__PURE__*/Object.freeze({
1025
+ __proto__: null,
1026
+ createField: createField,
1027
+ deleteField: deleteField,
1028
+ updateField: updateField
1029
+ });
1030
+
1031
+ /**
1032
+ * Enable automatic reminders. setup_time is the number of days after the envelope is sent that the first reminder
1033
+ * should be sent. interval_time is the number of days between reminders.
1034
+ */
1035
+ const createReminder = (endpoint, templateId, params) => endpoint.api //
1036
+ .post(`/templates/${templateId}/reminder/`, params)
1037
+ .then((r) => r.data);
1038
+ /**
1039
+ * Get the reminder configuration for a template.
1040
+ */
1041
+ const getReminder = (endpoint, templateId, reminderId) => endpoint.api //
1042
+ .get(`/templates/${templateId}/reminder/${reminderId}`)
1043
+ .then((r) => r.data);
1044
+ /**
1045
+ * Update the reminder configuration for a template.
1046
+ */
1047
+ const updateReminder = (endpoint, templateId, reminderId, params) => endpoint.api //
1048
+ .put(`/templates/${templateId}/reminder/${reminderId}`, params)
1049
+ .then((r) => r.data);
1050
+ /**
1051
+ * Delete the reminder configuration for a template.
1052
+ */
1053
+ const deleteReminder = (endpoint, templateId, reminderId) => endpoint.api //
1054
+ .delete(`/templates/${templateId}/reminder/${reminderId}`)
1055
+ .then((r) => r.data);
1056
+
1057
+ var Reminders = /*#__PURE__*/Object.freeze({
1058
+ __proto__: null,
1059
+ createReminder: createReminder,
1060
+ deleteReminder: deleteReminder,
1061
+ getReminder: getReminder,
1062
+ updateReminder: updateReminder
1063
+ });
1064
+
1065
+ /**
1066
+ * A "role" is an individual participant in a signing flow, such as a signer or CC contact. Roles are identified by
1067
+ * their names, which must be unique (e.g. 'Recipient 1'). Template fields are assigned to roles for signing operations,
1068
+ * so you may have 'Recipient 1 Signature 1' and so forth.
1069
+ *
1070
+ * @module
1071
+ */
1072
+ const createRole = (endpoint, templateId, params) => endpoint.api //
1073
+ .post(`/templates/${templateId}/roles`, params)
1074
+ .then((r) => r.data);
1075
+ const getRoles$1 = (endpoint, templateId) => endpoint.api //
1076
+ .get(`/templates/${templateId}/roles`)
1077
+ .then((r) => r.data);
1078
+ const getRole = (endpoint, templateId, roleName) => endpoint.api //
1079
+ .get(`/templates/${templateId}/roles/${roleName}`)
1080
+ .then((r) => r.data);
1081
+ const updateRole = (endpoint, templateId, roleName, params) => endpoint.api //
1082
+ .put(`/templates/${templateId}/roles/${roleName}`, params)
1083
+ .then((r) => r.data);
1084
+ const deleteRole = (endpoint, templateId, roleName) => endpoint.api //
1085
+ .delete(`/templates/${templateId}/roles/${roleName}`)
1086
+ .then((r) => r.data);
1087
+ const getRoleFields = (endpoint, templateId, roleName) => endpoint.api //
1088
+ .get(`/templates/${templateId}/roles/${roleName}/fields`)
1089
+ .then((r) => r.data);
1090
+ const deleteSequence = (endpoint, templateId) => endpoint.api //
1091
+ .delete(`/templates/${templateId}/roles`)
1092
+ .then((r) => r.data);
1093
+
1094
+ var Roles = /*#__PURE__*/Object.freeze({
1095
+ __proto__: null,
1096
+ createRole: createRole,
1097
+ deleteRole: deleteRole,
1098
+ deleteSequence: deleteSequence,
1099
+ getRole: getRole,
1100
+ getRoleFields: getRoleFields,
1101
+ getRoles: getRoles$1,
1102
+ updateRole: updateRole
1103
+ });
1104
+
1105
+ /**
1106
+ * Get the template stars for a template.
1107
+ */
1108
+ const getStars = (endpoint, templateId) => endpoint.api //
1109
+ .get(`/templates/${templateId}/stars`)
1110
+ .then((r) => r.data);
1111
+ /**
1112
+ * Toggle the template star for a template.
1113
+ */
1114
+ const toggleStar = (endpoint, templateId) => endpoint.api //
1115
+ .post(`/templates/${templateId}/stars/toggle`)
1116
+ .then((r) => r.data);
1117
+
1118
+ var Stars = /*#__PURE__*/Object.freeze({
1119
+ __proto__: null,
1120
+ getStars: getStars,
1121
+ toggleStar: toggleStar
1122
+ });
1123
+
1124
+ /**
1125
+ * A Tag is a user-specified label applied to a template. Tags help users organize and find Templates.
1126
+ * recipients. Every Organization has a set of tags "owned" by that Organization and only visible inside it.
1127
+ * Verdocs also provides a set of system-wide "featured" tags available to all Organizations.
1128
+ *
1129
+ * @module
1130
+ */
1131
+ /**
1132
+ * Apply a tag to a template.
1133
+ */
1134
+ const addTemplateTag = (endpoint, templateId, params) => endpoint.api //
1135
+ .post(`/templates/${templateId}/tags/`, params)
1136
+ .then((r) => r.data);
1137
+ /**
1138
+ * Get all tags for a template.
1139
+ */
1140
+ const getTemplateTags = (endpoint, templateId) => endpoint.api //
1141
+ .get(`/templates/${templateId}/tags/`)
1142
+ .then((r) => r.data);
1143
+ /**
1144
+ * Remove a tag from a template.
1145
+ */
1146
+ const deleteTemplateTag = (endpoint, templateId, tagName) => endpoint.api //
1147
+ .post(`/templates/${templateId}/tags/${tagName}`)
1148
+ .then((r) => r.data);
1149
+ /**
1150
+ * Create an Organization-wide tag.
1151
+ */
1152
+ const createTag = (endpoint, name) => endpoint.api //
1153
+ .post('/tags', { tag_name: name })
1154
+ .then((r) => r.data);
1155
+ /**
1156
+ * Get an Organization-wide tag.
1157
+ */
1158
+ const getTag = (endpoint, name) => endpoint.api //
1159
+ .get(`/tags/${name}`)
1160
+ .then((r) => r.data);
1161
+ /**
1162
+ * Get all tags available for use by an Organization.
1163
+ */
1164
+ const getAllTags = (endpoint) => endpoint.api //
1165
+ .get('/tags')
1166
+ .then((r) => r.data);
1167
+
1168
+ var Tags = /*#__PURE__*/Object.freeze({
1169
+ __proto__: null,
1170
+ addTemplateTag: addTemplateTag,
1171
+ createTag: createTag,
1172
+ deleteTemplateTag: deleteTemplateTag,
1173
+ getAllTags: getAllTags,
1174
+ getTag: getTag,
1175
+ getTemplateTags: getTemplateTags
1176
+ });
1177
+
1178
+ /**
1179
+ * A Template defines how a Verdocs signing flow will be performed, including attachments, signing fields, and
1180
+ * recipients.
1181
+ *
1182
+ * @module
1183
+ */
1184
+ /**
1185
+ * Get all templates accessible by the caller, with optional filters.
1186
+ *
1187
+ * ```typescript
1188
+ * import {Templates} from '@verdocs/js-sdk/Templates';
1189
+ *
1190
+ * await Templates.getTemplates((VerdocsEndpoint.getDefault());
1191
+ * await Templates.getTemplates((VerdocsEndpoint.getDefault(), { is_starred: true });
1192
+ * await Templates.getTemplates((VerdocsEndpoint.getDefault(), { is_creator: true });
1193
+ * await Templates.getTemplates((VerdocsEndpoint.getDefault(), { is_organization: true });
1194
+ * ```
1195
+ */
1196
+ const getTemplates = (endpoint, params) => endpoint.api //
1197
+ .post('/templates', { params })
1198
+ .then((r) => r.data);
1199
+ // export interface IListTemplatesParams {
1200
+ // name?: string;
1201
+ // sharing?: 'all' | 'personal' | 'shared' | 'public';
1202
+ // starred?: 'all' | 'starred' | 'unstarred';
1203
+ // sort?: 'name' | 'created_at' | 'updated_at' | 'last_used_at' | 'counter' | 'star_counter';
1204
+ // direction?: 'asc' | 'desc';
1205
+ // page?: number;
1206
+ // rows?: number;
1207
+ // }
1208
+ /**
1209
+ * Lists all templates accessible by the caller, with optional filters.
1210
+ *
1211
+ * ```typescript
1212
+ * import {Templates} from '@verdocs/js-sdk/Templates';
1213
+ *
1214
+ * await Templates.listTemplates((VerdocsEndpoint.getDefault(), { sharing: 'personal', sort: 'last_used_at' });
1215
+ * ```
1216
+ */
1217
+ // export const listTemplates = (endpoint: VerdocsEndpoint, params?: IListTemplatesParams) =>
1218
+ // endpoint.api //
1219
+ // .post<ITemplateSummaries>('/templates/list', params, {baseURL: endpoint.getBaseURLv2()})
1220
+ // .then((r) => r.data);
1221
+ /**
1222
+ * Get one template by its ID.
1223
+ *
1224
+ * ```typescript
1225
+ * import {Templates} from '@verdocs/js-sdk/Templates';
1226
+ *
1227
+ * const template = await Templates.getTemplate((VerdocsEndpoint.getDefault(), '83da3d70-7857-4392-b876-c4592a304bc9');
1228
+ * ```
1229
+ */
1230
+ const getTemplate = (endpoint, templateId) => endpoint.api //
1231
+ .get(`/templates/${templateId}`)
1232
+ .then((r) => r.data);
1233
+ /**
1234
+ * Get owner information for a template.
1235
+ *
1236
+ * ```typescript
1237
+ * import {Templates} from '@verdocs/js-sdk/Templates';
1238
+ *
1239
+ * const template = await Templates.getTemplateOwnerInfo((VerdocsEndpoint.getDefault(), '83da3d70-7857-4392-b876-c4592a304bc9');
1240
+ * ```
1241
+ */
1242
+ const getTemplateOwnerInfo = (endpoint, templateId) => endpoint.api //
1243
+ .get(`/templates/${templateId}`)
1244
+ .then((r) => r.data);
1245
+ const ALLOWED_CREATE_FIELDS = [
1246
+ 'name',
1247
+ 'is_personal',
1248
+ 'is_public',
1249
+ 'sender',
1250
+ 'description',
1251
+ 'roles',
1252
+ 'fields',
1253
+ ];
1254
+ /**
1255
+ * Create a template.
1256
+ *
1257
+ * ```typescript
1258
+ * import {Templates} from '@verdocs/js-sdk/Templates';
1259
+ *
1260
+ * const newTemplate = await Templates.createTemplate((VerdocsEndpoint.getDefault(), {...});
1261
+ * ```
1262
+ */
1263
+ const createTemplate = (endpoint, params, onUploadProgress) => {
1264
+ const options = {
1265
+ timeout: 120000,
1266
+ onUploadProgress: (event) => {
1267
+ const total = event.total || 1;
1268
+ const loaded = event.loaded || 0;
1269
+ onUploadProgress?.(Math.floor((loaded * 100) / (total || 1)), loaded, total || 1);
1270
+ },
1271
+ };
1272
+ if (params.documents && params.documents[0] instanceof File) {
1273
+ if (params.documents.length > 10) {
1274
+ throw new Error('createTemplate() has a maximum of 10 documents that can be attached.');
1275
+ }
1276
+ const formData = new FormData();
1277
+ ALLOWED_CREATE_FIELDS.forEach((allowedKey) => {
1278
+ if (params[allowedKey] !== undefined) {
1279
+ formData.append(allowedKey, params[allowedKey]);
1280
+ }
1281
+ });
1282
+ params.documents.forEach((file) => {
1283
+ formData.append('documents', file, file.name);
1284
+ });
1285
+ return endpoint.api.post('/templates', formData, options).then((r) => r.data);
1286
+ }
1287
+ else {
1288
+ return endpoint.api.post('/templates', params, options).then((r) => r.data);
1289
+ }
1290
+ };
1291
+ /**
1292
+ * Create a template.
1293
+ *
1294
+ * ```typescript
1295
+ * import {Templates} from '@verdocs/js-sdk/Templates';
1296
+ *
1297
+ * const newTemplate = await Templates.createTemplatev2((VerdocsEndpoint.getDefault(), {...});
1298
+ * ```
1299
+ */
1300
+ const createTemplatev2 = (endpoint, params, onUploadProgress) => {
1301
+ const options = {
1302
+ timeout: 120000,
1303
+ onUploadProgress: (event) => {
1304
+ const total = event.total || 1;
1305
+ const loaded = event.loaded || 0;
1306
+ onUploadProgress?.(Math.floor((loaded * 100) / (total || 1)), loaded, total || 1);
1307
+ },
1308
+ };
1309
+ if (params.documents && params.documents[0] instanceof File) {
1310
+ const formData = new FormData();
1311
+ ALLOWED_CREATE_FIELDS.forEach((allowedKey) => {
1312
+ if (params[allowedKey] !== undefined) {
1313
+ formData.append(allowedKey, params[allowedKey]);
1314
+ }
1315
+ });
1316
+ params.documents.forEach((file) => {
1317
+ formData.append('documents', file, file.name);
1318
+ });
1319
+ return endpoint.api.post('/v2/templates', formData, options).then((r) => r.data);
1320
+ }
1321
+ else {
1322
+ return endpoint.api.post('/v2/templates', params, options).then((r) => r.data);
1323
+ }
1324
+ };
1325
+ /**
1326
+ * Create a template from a Sharepoint asset.
1327
+ *
1328
+ * ```typescript
1329
+ * import {Templates} from '@verdocs/js-sdk/Templates';
1330
+ *
1331
+ * const newTemplate = await Templates.createTemplateFromSharepoint((VerdocsEndpoint.getDefault(), {...});
1332
+ * ```
1333
+ */
1334
+ const createTemplateFromSharepoint = (endpoint, params) => {
1335
+ const options = {
1336
+ timeout: 120000,
1337
+ };
1338
+ return endpoint.api.post('/templates/from-sharepoint', params, options).then((r) => r.data);
1339
+ };
1340
+ /**
1341
+ * Update a template.
1342
+ *
1343
+ * ```typescript
1344
+ * import {Templates} from '@verdocs/js-sdk/Templates';
1345
+ *
1346
+ * const updatedTemplate = await Templates.updateTemplate((VerdocsEndpoint.getDefault(), '83da3d70-7857-4392-b876-c4592a304bc9', { name: 'New Name' });
1347
+ * ```
1348
+ */
1349
+ const updateTemplate = (endpoint, templateId, params) => endpoint.api //
1350
+ .put(`/templates/${templateId}`, params)
1351
+ .then((r) => r.data);
1352
+ /**
1353
+ * Delete a template.
1354
+ *
1355
+ * ```typescript
1356
+ * import {Templates} from '@verdocs/js-sdk/Templates';
1357
+ *
1358
+ * await Templates.deleteTemplate((VerdocsEndpoint.getDefault(), '83da3d70-7857-4392-b876-c4592a304bc9');
1359
+ * ```
1360
+ */
1361
+ const deleteTemplate = (endpoint, templateId) => endpoint.api //
1362
+ .delete(`/templates/${templateId}`)
1363
+ .then((r) => r.data);
1364
+ /**
1365
+ * Search for templates matching various criteria.
1366
+ *
1367
+ * ```typescript
1368
+ * import {Templates} from '@verdocs/js-sdk/Templates';
1369
+ *
1370
+ * const {result, page, total} = await Templates.search((VerdocsEndpoint.getDefault(), { ... });
1371
+ * ```
1372
+ */
1373
+ const searchTemplates = async (endpoint, params) => endpoint.api //
1374
+ .post('/templates/search', params)
1375
+ .then((r) => r.data);
1376
+ /**
1377
+ * Get a summary of template data, typically used to populate admin panel dashboard pages.
1378
+ *
1379
+ * ```typescript
1380
+ * import {Templates} from '@verdocs/js-sdk/Templates';
1381
+ *
1382
+ * const summary = await Templates.getSummary((VerdocsEndpoint.getDefault(), 0);
1383
+ * ```
1384
+ */
1385
+ const getSummary = async (endpoint, params = {}) => endpoint.api //
1386
+ .post('/templates/summary', params)
1387
+ .then((r) => r.data);
1388
+ const cachedTemplates = {};
1389
+ /**
1390
+ * Wrapper for `getTemplate()` that limits queries to one every 2 seconds per template ID.
1391
+ * This is intended for use in component hierarchies that all rely on the same template
1392
+ * to avoid unnecessary repeat server calls.
1393
+ */
1394
+ const throttledGetTemplate = (endpoint, templateId) => {
1395
+ if (cachedTemplates[templateId] && cachedTemplates[templateId].loaded + 2000 < new Date().getTime()) {
1396
+ return cachedTemplates[templateId].template;
1397
+ }
1398
+ return getTemplate(endpoint, templateId).then((template) => {
1399
+ cachedTemplates[templateId] = { loaded: new Date().getTime(), template };
1400
+ return template;
1401
+ });
1402
+ };
1403
+ /**
1404
+ * List templates.
1405
+ *
1406
+ * ```typescript
1407
+ * import {Templates} from '@verdocs/js-sdk/Templates';
1408
+ *
1409
+ * const {totals, templates} = await Templates.listTemplates((VerdocsEndpoint.getDefault(), { q: 'test', sort: 'created_at' }); * ```
1410
+ */
1411
+ const listTemplates = async (endpoint, params = {}) => endpoint.api //
1412
+ .post('/templates/list', params)
1413
+ .then((r) => r.data);
1414
+
1415
+ var Templates = /*#__PURE__*/Object.freeze({
1416
+ __proto__: null,
1417
+ createTemplate: createTemplate,
1418
+ createTemplateFromSharepoint: createTemplateFromSharepoint,
1419
+ createTemplatev2: createTemplatev2,
1420
+ deleteTemplate: deleteTemplate,
1421
+ getSummary: getSummary,
1422
+ getTemplate: getTemplate,
1423
+ getTemplateOwnerInfo: getTemplateOwnerInfo,
1424
+ getTemplates: getTemplates,
1425
+ listTemplates: listTemplates,
1426
+ searchTemplates: searchTemplates,
1427
+ throttledGetTemplate: throttledGetTemplate,
1428
+ updateTemplate: updateTemplate
1429
+ });
1430
+
1431
+ /**
1432
+ * A TemplateDocument represents a PDF or other attachment in a Template.
1433
+ *
1434
+ * @module
1435
+ */
1436
+ /**
1437
+ * Get all the Template Documents associated to a particular Template.
1438
+ *
1439
+ * ```typescript
1440
+ * import {TemplateDocument} from '@verdocs/js-sdk/Templates';
1441
+ *
1442
+ * await TemplateDocument.geTemplateDocuments((VerdocsEndpoint.getDefault(), templateId);
1443
+ * ```
1444
+ */
1445
+ const getTemplateDocuments = (endpoint, templateId) => endpoint.api //
1446
+ .get(`/templates/${templateId}/documents/`)
1447
+ .then((r) => r.data);
1448
+ /**
1449
+ * Get a specific Document.
1450
+ *
1451
+ * ```typescript
1452
+ * import {TemplateDocument} from '@verdocs/js-sdk/Templates';
1453
+ *
1454
+ * await TemplateDocument.geTemplateDocument((VerdocsEndpoint.getDefault(), templateId,documentId);
1455
+ * ```
1456
+ */
1457
+ const getTemplateDocument = (endpoint, templateId, documentId) => endpoint.api //
1458
+ .get(`/templates/${templateId}/documents/${documentId}`)
1459
+ .then((r) => r.data);
1460
+ /**
1461
+ * Create a Document for a particular Template.
1462
+ *
1463
+ * ```typescript
1464
+ * import {TemplateDocument} from '@verdocs/js-sdk/Templates';
1465
+ *
1466
+ * await TemplateDocument.createDocument((VerdocsEndpoint.getDefault(), templateID, params);
1467
+ * ```
1468
+ */
1469
+ const createTemplateDocument = (endpoint, templateId, file, onUploadProgress) => {
1470
+ const formData = new FormData();
1471
+ formData.append('document', file, file.name);
1472
+ return endpoint.api //
1473
+ .post(`/templates/${templateId}/documents`, formData, {
1474
+ timeout: 120000,
1475
+ onUploadProgress: (event) => {
1476
+ const total = event.total || 1;
1477
+ const loaded = event.loaded || 0;
1478
+ onUploadProgress?.(Math.floor((loaded * 100) / (total || 1)), loaded, total || 1);
1479
+ },
1480
+ })
1481
+ .then((r) => r.data);
1482
+ };
1483
+ /**
1484
+ * Delete a specific Document.
1485
+ *
1486
+ * ```typescript
1487
+ * import {TemplateDocument} from '@verdocs/js-sdk/Templates';
1488
+ *
1489
+ * await TemplateDocument.deleteDocument((VerdocsEndpoint.getDefault(), templateID, documentID);
1490
+ * ```
1491
+ */
1492
+ const deleteTemplateDocument = (endpoint, templateId, documentId) => endpoint.api //
1493
+ .delete(`/templates/${templateId}/documents/${documentId}`)
1494
+ .then((r) => r.data);
1495
+ /**
1496
+ * Get (binary download) a file attached to a Template. It is important to use this method
1497
+ * rather than a direct A HREF or similar link to set the authorization headers for the
1498
+ * request.
1499
+ */
1500
+ const getTemplateDocumentFile = async (endpoint, templateId, documentId) => endpoint.api //
1501
+ .get(`/templates/${templateId}/documents/${documentId}?file=true`, { responseType: 'blob' })
1502
+ .then((r) => r.data);
1503
+ /**
1504
+ * Get (binary download) a file attached to a Template. It is important to use this method
1505
+ * rather than a direct A HREF or similar link to set the authorization headers for the
1506
+ * request.
1507
+ */
1508
+ const getTemplateDocumentThumbnail = async (endpoint, templateId, documentId) => endpoint.api //
1509
+ .get(`/templates/${templateId}/documents/${documentId}?thumbnail=true`, { responseType: 'blob' })
1510
+ .then((r) => r.data);
1511
+ /**
1512
+ * Get a display URI for a given page in a file attached to a template document. These pages are rendered server-side
1513
+ * into PNG resources suitable for display in IMG tags although they may be used elsewhere. Note that these are intended
1514
+ * for DISPLAY ONLY, are not legally binding documents, and do not contain any encoded metadata from participants. The
1515
+ * original asset may be obtained by calling `getTemplateDocumentFile()` or similar.
1516
+ */
1517
+ const getTemplateDocumentPageDisplayUri = async (endpoint, templateId, documentId, page) => endpoint.api.get(`/templates/${templateId}/documents/${documentId}/pages/${page}/image`).then((r) => r.data);
1518
+
1519
+ var TemplateDocuments = /*#__PURE__*/Object.freeze({
1520
+ __proto__: null,
1521
+ createTemplateDocument: createTemplateDocument,
1522
+ deleteTemplateDocument: deleteTemplateDocument,
1523
+ getTemplateDocument: getTemplateDocument,
1524
+ getTemplateDocumentFile: getTemplateDocumentFile,
1525
+ getTemplateDocumentPageDisplayUri: getTemplateDocumentPageDisplayUri,
1526
+ getTemplateDocumentThumbnail: getTemplateDocumentThumbnail,
1527
+ getTemplateDocuments: getTemplateDocuments
1528
+ });
1529
+
1530
+ var Types$2 = /*#__PURE__*/Object.freeze({
1531
+ __proto__: null
1532
+ });
1533
+
1534
+ /**
1535
+ * Get all defined validators
1536
+ *
1537
+ * ```typescript
1538
+ * import {Documents} from '@verdocs/js-sdk/Templates';
1539
+ *
1540
+ * await Documents.getDocuments(templateID);
1541
+ * ```
1542
+ */
1543
+ const getValidators = (endpoint) => endpoint.api //
1544
+ .get('/validators')
1545
+ .then((r) => r.data);
1546
+ const getValidator = (endpoint, validatorName) => endpoint.api //
1547
+ .get(`/validators/${validatorName}`)
1548
+ .then((r) => r.data);
1549
+ 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,}))$/;
1550
+ const isValidEmail = (email) => !!email && EMAIL_REGEX.test(email);
1551
+ // @see https://www.regextester.com/1978
1552
+ 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}))/;
1553
+ const isValidPhone = (phone) => !!phone && PHONE_REGEX.test(phone);
1554
+ const isValidRoleName = (value, roles) => roles.findIndex((role) => role.name === value) !== -1;
1555
+ const TagRegEx = /^[a-zA-Z0-9-]{0,32}$/;
1556
+ const isValidTag = (value, tags) => TagRegEx.test(value) || tags.findIndex((tag) => tag === value) !== -1;
1557
+
1558
+ var Validators = /*#__PURE__*/Object.freeze({
1559
+ __proto__: null,
1560
+ getValidator: getValidator,
1561
+ getValidators: getValidators,
1562
+ isValidEmail: isValidEmail,
1563
+ isValidPhone: isValidPhone,
1564
+ isValidRoleName: isValidRoleName,
1565
+ isValidTag: isValidTag
1566
+ });
1567
+
1568
+ var index$2 = /*#__PURE__*/Object.freeze({
1569
+ __proto__: null,
1570
+ Actions: Actions,
1571
+ Fields: Fields$1,
1572
+ Reminders: Reminders,
1573
+ Roles: Roles,
1574
+ Stars: Stars,
1575
+ Tags: Tags,
1576
+ TemplateDocuments: TemplateDocuments,
1577
+ Templates: Templates,
1578
+ Types: Types$2,
1579
+ Validators: Validators
1580
+ });
1581
+
1582
+ /**
1583
+ * Authenticate to Verdocs via user/password authentication
1584
+ *
1585
+ * ```typescript
1586
+ * import {Auth} from '@verdocs/js-sdk/Auth';
1587
+ * import {Transport} from '@verdocs/js-sdk/HTTP';
1588
+ *
1589
+ * const {accessToken} = await Auth.authenticateUser({ username: 'test@test.com', password: 'PASSWORD' });
1590
+ * Transport.setAuthToken(accessToken);
1591
+ * ```
1592
+ */
1593
+ const authenticateUser = (endpoint, params) => endpoint.api //
1594
+ .post('/authentication/login', params)
1595
+ .then((r) => r.data);
1596
+ /**
1597
+ * Authenticate to Verdocs via client ID / Secret authentication. **NOTE: This is only suitable for
1598
+ * NodeJS server-side applications. Never expose your Client Secret in a Web or Mobile app!** Also note
1599
+ * that access tokens may be cached by server-side apps (and this is recommended) but do expire after 2
1600
+ * hours. This expiration may change based on future security needs. Application developers are encouraged
1601
+ * to check the `exp` expiration field in the response accessToken and renew tokens after they expire.
1602
+ *
1603
+ * ```typescript
1604
+ * import {Auth} from '@verdocs/js-sdk/Auth';
1605
+ * import {Transport} from '@verdocs/js-sdk/HTTP';
1606
+ *
1607
+ * const {accessToken} = await Auth.authenticateApp({ client_id: 'CLIENTID', client_secret: 'SECRET' });
1608
+ * Transport.setAuthToken(accessToken);
1609
+ * ```
1610
+ */
1611
+ const authenticateApp = (endpoint, params) => endpoint.api //
1612
+ .post('/authentication/login_client', {}, { headers: params })
1613
+ .then((r) => r.data);
1614
+ /**
1615
+ * Validate a token. Only Verdocs tokens will be accepted. Most applications can decode tokens locally,
1616
+ * because tokens will be validated when API calls are made anyway. However, high-security applications
1617
+ * may use this endpoint to check if a token has been revoked.
1618
+ *
1619
+ * ```typescript
1620
+ * import {Auth} from '@verdocs/js-sdk/Auth';
1621
+ *
1622
+ * const {valid} = await Auth.validateToken({ token });
1623
+ * if (!valid) {
1624
+ * window.alert('Session invalid or expired. Please re-authenticate.');
1625
+ * }
1626
+ * ```
1627
+ */
1628
+ const validateToken = (endpoint, params) => endpoint.api //
1629
+ .post('/token/isValid', params)
1630
+ .then((r) => r.data);
1631
+ /**
1632
+ * If called before the session expires, this will refresh the caller's session and tokens.
1633
+ *
1634
+ * ```typescript
1635
+ * import {Auth} from '@verdocs/js-sdk/Auth';
1636
+ * import {Transport} from '@verdocs/js-sdk/HTTP';
1637
+ *
1638
+ * const {accessToken} = await Auth.refreshTokens();
1639
+ * Transport.setAuthToken(accessToken);
1640
+ * ```
1641
+ */
1642
+ const refreshTokens = (endpoint) => endpoint.api //
1643
+ .get('/token')
1644
+ .then((r) => r.data);
1645
+ /**
1646
+ * Update the caller's password. To help prevent CSRF attack vectors, the user's old password and email address are required.
1647
+ *
1648
+ * ```typescript
1649
+ * import {Auth} from '@verdocs/js-sdk/Auth';
1650
+ *
1651
+ * const {status, message} = await Auth.updatePassword({ email, oldPassword, newPassword });
1652
+ * if (status !== 'OK') {
1653
+ * window.alert(`Password reset error: ${message}`);
1654
+ * }
1655
+ * ```
1656
+ */
1657
+ const updatePassword = (endpoint, params) => endpoint.api //
1658
+ .put('/user/update_password', params)
1659
+ .then((r) => r.data);
1660
+ /**
1661
+ * Reset the caller's password.
1662
+ *
1663
+ * ```typescript
1664
+ * import {Auth} from '@verdocs/js-sdk/Auth';
1665
+ *
1666
+ * const {success} = await Auth.resetPassword({ email });
1667
+ * if (status !== 'OK') {
1668
+ * window.alert(`Please check your email for instructions on how to reset your password.`);
1669
+ * }
1670
+ * ```
1671
+ */
1672
+ const resetPassword = (endpoint, params) => endpoint.api //
1673
+ .post('/user/reset_password', params)
1674
+ .then((r) => r.data);
1675
+ /**
1676
+ * Update the caller's email address.
1677
+ *
1678
+ * ```typescript
1679
+ * import {Auth} from '@verdocs/js-sdk/Auth';
1680
+ *
1681
+ * const {profiles} = await Auth.updateEmail({ email: newEmail });
1682
+ * ```
1683
+ */
1684
+ const updateEmail = (endpoint, params) => endpoint.api //
1685
+ .put('/user/update_email', params)
1686
+ .then((r) => r.data);
1687
+ /**
1688
+ * Resend the email verification request. Note that to prevent certain forms of abuse, the email address is not
1689
+ * a parameter here. Instead, the caller must be authenticated as the (unverified) user. To simplify this process,
1690
+ * the access token to be used may be passed directly as a parameter here. This avoids the need to set it as the
1691
+ * active token on an endpoint, which may be inconvenient in workflows where it is preferable to keep the user in
1692
+ * "anonymous" mode while verification is being performed.
1693
+ *
1694
+ * ```typescript
1695
+ * import {Auth} from '@verdocs/js-sdk/Auth';
1696
+ *
1697
+ * const result = await Auth.resendVerification();
1698
+ * ```
1699
+ */
1700
+ const resendVerification = (endpoint, accessToken) => endpoint.api //
1701
+ .post('/user/email_verification', {}, accessToken ? { headers: { Authorization: `Bearer ${accessToken}` } } : {})
1702
+ .then((r) => r.data);
1703
+ const createUser = (endpoint, params) => endpoint.api //
1704
+ .post('/user', params)
1705
+ .then((r) => r.data);
1706
+
1707
+ var Auth = /*#__PURE__*/Object.freeze({
1708
+ __proto__: null,
1709
+ authenticateApp: authenticateApp,
1710
+ authenticateUser: authenticateUser,
1711
+ createUser: createUser,
1712
+ refreshTokens: refreshTokens,
1713
+ resendVerification: resendVerification,
1714
+ resetPassword: resetPassword,
1715
+ updateEmail: updateEmail,
1716
+ updatePassword: updatePassword,
1717
+ validateToken: validateToken
1718
+ });
1719
+
1720
+ // TODO
1721
+ const billingPlaceholder = {};
1722
+
1723
+ var Billing = /*#__PURE__*/Object.freeze({
1724
+ __proto__: null,
1725
+ billingPlaceholder: billingPlaceholder
1726
+ });
1727
+
1728
+ const getNotifications = async (endpoint) => endpoint.api //
1729
+ .get('/notifications')
1730
+ .then((r) => r.data);
1731
+
1732
+ var Notifications = /*#__PURE__*/Object.freeze({
1733
+ __proto__: null,
1734
+ getNotifications: getNotifications
1735
+ });
1736
+
1737
+ /**
1738
+ * Get the user's available profiles. The current profile will be marked with `current: true`.
1739
+ *
1740
+ * ```typescript
1741
+ * import {Profiles} from '@verdocs/js-sdk/Users';
1742
+ *
1743
+ * const profiles = await Profiles.getProfiles()
1744
+ * ```
1745
+ */
1746
+ const getProfiles = (endpoint) => endpoint.api //
1747
+ .get('/profiles')
1748
+ .then((r) => r.data);
1749
+ /**
1750
+ * Get the user's available profiles. The current profile will be marked with `current: true`.
1751
+ *
1752
+ * ```typescript
1753
+ * import {Profiles} from '@verdocs/js-sdk/Users';
1754
+ *
1755
+ * const profiles = await Profiles.getCurrentProfile()
1756
+ * ```
1757
+ */
1758
+ const getCurrentProfile = (endpoint) => endpoint.api //
1759
+ .get('/profiles')
1760
+ .then((r) => (r.data || []).find((profile) => profile.current));
1761
+ /**
1762
+ * Get a list of system roles.
1763
+ *
1764
+ * ```typescript
1765
+ * import {Profiles} from '@verdocs/js-sdk/Users';
1766
+ *
1767
+ * const roles = await Profiles.getRoles();
1768
+ * ```
1769
+ */
1770
+ const getRoles = (endpoint) => endpoint.api //
1771
+ .get('/roles')
1772
+ .then((r) => r.data);
1773
+ /**
1774
+ * Get a list of system roles.
1775
+ *
1776
+ * ```typescript
1777
+ * import {Profiles} from '@verdocs/js-sdk/Users';
1778
+ *
1779
+ * const permissions = await Profiles.getPermissions();
1780
+ * ```
1781
+ */
1782
+ const getPermissions = (endpoint) => endpoint.api //
1783
+ .get('/permissions')
1784
+ .then((r) => r.data);
1785
+ /**
1786
+ * Create a profile. If the caller does not have a "current" profile set, the new profile will be made current.
1787
+ *
1788
+ * ```typescript
1789
+ * import {Profiles} from '@verdocs/js-sdk/Users';
1790
+ *
1791
+ * const newProfile = await Profiles.createProfile({ first_name: 'FIRST', last_name: 'LAST', email: 'EMAIL' });
1792
+ * ```
1793
+ */
1794
+ const createProfile = (endpoint, params) => endpoint.api //
1795
+ .post('/profiles', params)
1796
+ .then((r) => r.data);
1797
+ /**
1798
+ * Get a profile. The caller must have admin access to the given profile.
1799
+ * TODO: Add a "public" profile endpoint for public pages
1800
+ *
1801
+ * ```typescript
1802
+ * import {Profiles} from '@verdocs/js-sdk/Users';
1803
+ *
1804
+ * const profile = await Profiles.getProfile('PROFILEID');
1805
+ * ```
1806
+ */
1807
+ const getProfile = (endpoint, profileId) => endpoint.api //
1808
+ .get(`/profiles/${profileId}`)
1809
+ .then((r) => r.data);
1810
+ /**
1811
+ * Get a profile's permissions. The caller must have admin access to the given profile.
1812
+ *
1813
+ * ```typescript
1814
+ * import {Profiles} from '@verdocs/js-sdk/Users';
1815
+ *
1816
+ * const permissions = await Profiles.getProfilePermissions('PROFILEID');
1817
+ * ```
1818
+ */
1819
+ const getProfilePermissions = (endpoint, profileId) => endpoint.api //
1820
+ .get(`/profiles/${profileId}/permissions`)
1821
+ .then((r) => r.data);
1822
+ /**
1823
+ * Get a profile's groups.
1824
+ *
1825
+ * ```typescript
1826
+ * import {Profiles} from '@verdocs/js-sdk/Users';
1827
+ *
1828
+ * const groups = await Profiles.getProfileGroups('PROFILEID');
1829
+ * ```
1830
+ */
1831
+ const getProfileGroups = (endpoint, profileId) => endpoint.api //
1832
+ .get(`/profiles/${profileId}/groups`)
1833
+ .then((r) => r.data);
1834
+ /**
1835
+ * Switch the caller's "current" profile. The current profile is used for permissions checking and profile_id field settings
1836
+ * for most operations in Verdocs. It is important to select the appropropriate profile before calling other API functions.
1837
+ *
1838
+ * ```typescript
1839
+ * import {Profiles} from '@verdocs/js-sdk/Users';
1840
+ *
1841
+ * const newProfile = await Profiles.switchProfile('PROFILEID');
1842
+ * ```
1843
+ */
1844
+ const switchProfile = (endpoint, profileId) => endpoint.api //
1845
+ .post(`/profiles/${profileId}/switch`)
1846
+ .then((r) => r.data);
1847
+ /**
1848
+ * Update a profile. For future expansion, the profile ID to update is required, but currently this must also be the
1849
+ * "current" profile for the caller.
1850
+ *
1851
+ * ```typescript
1852
+ * import {Profiles} from '@verdocs/js-sdk/Users';
1853
+ *
1854
+ * const newProfile = await Profiles.updateProfile('PROFILEID');
1855
+ * ```
1856
+ */
1857
+ const updateProfile = (endpoint, profileId, params) => endpoint.api //
1858
+ .put(`/profiles/${profileId}`, params)
1859
+ .then((r) => r.data);
1860
+ /**
1861
+ * Delete a profile. If the requested profile is the caller's curent profile, the next available profile will be selected.
1862
+ *
1863
+ * ```typescript
1864
+ * import {Profiles} from '@verdocs/js-sdk/Users';
1865
+ *
1866
+ * await Profiles.deleteProfile('PROFILEID');
1867
+ * ```
1868
+ */
1869
+ const deleteProfile = (endpoint, profileId) => endpoint.api //
1870
+ .delete(`/profiles/${profileId}`)
1871
+ .then((r) => r.data);
1872
+ /**
1873
+ * Create a user account and parent organization. This endpoint is for creating a new organization. Users joining an
1874
+ * existing organization should be invited, and follow their invitation links/instructions to create their accounts.
1875
+ *
1876
+ * ```typescript
1877
+ * import {Profiles} from '@verdocs/js-sdk/Users';
1878
+ *
1879
+ * const newAccount = await Profiles.createBusinessAccount({
1880
+ * orgName: 'ORG', email: 'a@b.com', password: '12345678', firstName: 'FIRST', lastName: 'LAST'
1881
+ * });
1882
+ * ```
1883
+ */
1884
+ const createBusinessAccount = (endpoint, params) => endpoint.api //
1885
+ .post('/user/business', params)
1886
+ .then((r) => r.data);
1887
+ const recordSignupSurvey = (endpoint, params) => endpoint.api //
1888
+ .post('/user/signup', params)
1889
+ .then((r) => r.data);
1890
+
1891
+ var Profiles = /*#__PURE__*/Object.freeze({
1892
+ __proto__: null,
1893
+ createBusinessAccount: createBusinessAccount,
1894
+ createProfile: createProfile,
1895
+ deleteProfile: deleteProfile,
1896
+ getCurrentProfile: getCurrentProfile,
1897
+ getPermissions: getPermissions,
1898
+ getProfile: getProfile,
1899
+ getProfileGroups: getProfileGroups,
1900
+ getProfilePermissions: getProfilePermissions,
1901
+ getProfiles: getProfiles,
1902
+ getRoles: getRoles,
1903
+ recordSignupSurvey: recordSignupSurvey,
1904
+ switchProfile: switchProfile,
1905
+ updateProfile: updateProfile
1906
+ });
1907
+
1908
+ var Types$1 = /*#__PURE__*/Object.freeze({
1909
+ __proto__: null
1910
+ });
1911
+
1912
+ var index$1 = /*#__PURE__*/Object.freeze({
1913
+ __proto__: null,
1914
+ Auth: Auth,
1915
+ Billing: Billing,
1916
+ Notifications: Notifications,
1917
+ Profiles: Profiles,
1918
+ Types: Types$1
1919
+ });
1920
+
1921
+ /* tslint:disable:no-bitwise */
1922
+ /**
1923
+ * Given a `rgba(r,g,b,a)` string value, returns the hex equivalent, dropping the alpha channel.
1924
+ */
1925
+ function getRGB(rgba) {
1926
+ const rgbNumbers = rgba.replace('rgba(', '').replace(')', '').split(',');
1927
+ const rgbObject = {
1928
+ red: +rgbNumbers[0],
1929
+ green: +rgbNumbers[1],
1930
+ blue: +rgbNumbers[2],
1931
+ alpha: +rgbNumbers[3],
1932
+ };
1933
+ const alpha = 1 - rgbObject.alpha;
1934
+ const red = Math.round((rgbObject.alpha * (rgbObject.red / 255) + alpha) * 255);
1935
+ const green = Math.round((rgbObject.alpha * (rgbObject.green / 255) + alpha) * 255);
1936
+ const blue = Math.round((rgbObject.alpha * (rgbObject.blue / 255) + alpha) * 255);
1937
+ return '#' + rgbToHex(red) + rgbToHex(green) + rgbToHex(blue);
1938
+ }
1939
+ /**
1940
+ * Given an RGB string value, returns the hex equivalent.
1941
+ */
1942
+ function rgbToHex(rgb) {
1943
+ const hex = rgb.toString(16);
1944
+ if (hex.length < 2) {
1945
+ return '0' + hex;
1946
+ }
1947
+ return hex;
1948
+ }
1949
+ /**
1950
+ * Given a signer role index, return the color code for that signer.
1951
+ */
1952
+ function getRGBA(roleIndex) {
1953
+ switch (roleIndex % 10) {
1954
+ case 0:
1955
+ return roleIndex === 0 ? 'rgba(255, 193, 7, 0.4)' : 'rgba(134, 134, 134, 0.3)'; // #FFE69C
1956
+ case 1:
1957
+ return 'rgba(156, 39, 176, .4)'; // '#E3C3E9'
1958
+ case 2:
1959
+ return 'rgba(33, 150, 243, .4)'; // '#C1E1FB'
1960
+ case 3:
1961
+ return 'rgba(220, 231, 117, 0.3)';
1962
+ case 4:
1963
+ return 'rgba(121, 134, 203, 0.3)';
1964
+ case 5:
1965
+ return 'rgba(77, 182, 172, 0.3)';
1966
+ case 6:
1967
+ return 'rgba(255, 202, 165, 0.3)';
1968
+ case 7:
1969
+ return 'rgba(2, 247, 190, 0.3)';
1970
+ case 8:
1971
+ return 'rgba(255, 138, 101, 0.3)';
1972
+ case 9:
1973
+ return 'rgba(82, 255, 79, 0.3)';
1974
+ default:
1975
+ return 'rgba(229, 115, 155, 0.3)';
1976
+ }
1977
+ }
1978
+ /**
1979
+ * Given a role name, return a color code for it. This works by computing a hash code so the specific color returned
1980
+ * is not specified explicitly, but will be the same for every call with the same input value.
1981
+ */
1982
+ function nameToRGBA(str) {
1983
+ if (!!str) {
1984
+ const validNum = parseInt(str.slice(-1), 10);
1985
+ if (!isNaN(validNum)) {
1986
+ str += (validNum * 99).toString();
1987
+ }
1988
+ let hash = 0;
1989
+ for (let i = 0; i < str.length; i++) {
1990
+ hash = str.charCodeAt(i) + ((hash << 5) - hash);
1991
+ }
1992
+ hash = Math.round(hash / 1.3);
1993
+ const c = (hash & 0x00ffff08).toString(16).toUpperCase();
1994
+ const hex = '#' + '00000'.substring(0, 6 - c.length) + c;
1995
+ const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
1996
+ const color = {
1997
+ r: parseInt(result[1], 16),
1998
+ g: parseInt(result[2], 16),
1999
+ b: parseInt(result[3], 16),
2000
+ };
2001
+ return `rgba(${color.r}, ${color.g}, ${color.b}, 0.2)`;
2002
+ }
2003
+ }
2004
+ /**
2005
+ * Helper function to obtain a color code given a role name given various possible inputs.
2006
+ */
2007
+ function getRoleColor(name, roles, index) {
2008
+ if (index) {
2009
+ return getRGBA(index);
2010
+ }
2011
+ else if (roles && roles.length > 0) {
2012
+ const roleIndex = roles.findIndex((role) => role === name);
2013
+ if (roleIndex > -1) {
2014
+ return getRGBA(roleIndex);
2015
+ }
2016
+ else {
2017
+ return nameToRGBA(name);
2018
+ }
2019
+ }
2020
+ else {
2021
+ return nameToRGBA(name);
2022
+ }
2023
+ }
2024
+
2025
+ var Colors = /*#__PURE__*/Object.freeze({
2026
+ __proto__: null,
2027
+ getRGB: getRGB,
2028
+ getRGBA: getRGBA,
2029
+ getRoleColor: getRoleColor,
2030
+ nameToRGBA: nameToRGBA
2031
+ });
2032
+
2033
+ const YEAR = 365 * 24 * 60 * 60;
2034
+ // const MONTH = 30 * 24 * 60 * 60;
2035
+ const WEEK = 7 * 24 * 60 * 60;
2036
+ const DAY = 24 * 60 * 60;
2037
+ const HOUR = 60 * 60;
2038
+ const MINUTE = 60;
2039
+ const formatShortTimeAgo = (val) => {
2040
+ if (val === undefined || val === null) {
2041
+ return '';
2042
+ }
2043
+ let dateInput;
2044
+ if (typeof val === 'string' || typeof val === 'number') {
2045
+ dateInput = new Date(val);
2046
+ }
2047
+ else if (typeof val === 'object') {
2048
+ dateInput = val;
2049
+ }
2050
+ else {
2051
+ return '';
2052
+ }
2053
+ const timeDiff = Math.floor((new Date().getTime() - dateInput.getTime()) / 1000);
2054
+ if (timeDiff >= YEAR) {
2055
+ return Math.floor(timeDiff / YEAR) + 'Y';
2056
+ }
2057
+ // if (timeDiff >= MONTH) {
2058
+ // return Math.floor(timeDiff / MONTH) + 'M';
2059
+ // }
2060
+ if (timeDiff >= WEEK) {
2061
+ return Math.floor(timeDiff / WEEK) + 'W';
2062
+ }
2063
+ if (timeDiff >= DAY) {
2064
+ return Math.floor(timeDiff / DAY) + 'D';
2065
+ }
2066
+ if (timeDiff >= HOUR) {
2067
+ return Math.floor(timeDiff / HOUR) + 'H';
2068
+ }
2069
+ if (timeDiff >= MINUTE) {
2070
+ return Math.floor(timeDiff / MINUTE) + 'M';
2071
+ }
2072
+ return `${timeDiff}S`;
2073
+ };
2074
+ function timePeriod(type) {
2075
+ let endDate = new Date().getTime();
2076
+ const today = new Date();
2077
+ const month = today.getMonth();
2078
+ const year = today.getFullYear();
2079
+ let startDate = null;
2080
+ switch (type) {
2081
+ case '30d':
2082
+ startDate = endDate - 60 * 60 * 24 * 30 * 1000;
2083
+ break;
2084
+ case '60d':
2085
+ startDate = endDate - 60 * 60 * 24 * 60 * 1000;
2086
+ break;
2087
+ case '6m':
2088
+ startDate = endDate - 60 * 60 * 24 * 30 * 6 * 1000;
2089
+ break;
2090
+ case 'this_month':
2091
+ startDate = new Date(year, month, 1).getTime();
2092
+ break;
2093
+ case 'last_month':
2094
+ startDate = new Date(year, month - 1, 1).getTime();
2095
+ endDate = new Date(year, month, 0).getTime();
2096
+ break;
2097
+ case 'this_year':
2098
+ startDate = new Date(year, 0, 1);
2099
+ break;
2100
+ case 'all_time':
2101
+ default:
2102
+ return null;
2103
+ }
2104
+ if (startDate === null && endDate === null) {
2105
+ return null;
2106
+ }
2107
+ return {
2108
+ start_time: new Date(startDate).toISOString(),
2109
+ end_time: new Date(endDate).toISOString(),
2110
+ };
2111
+ }
2112
+
2113
+ var DateTime = /*#__PURE__*/Object.freeze({
2114
+ __proto__: null,
2115
+ formatShortTimeAgo: formatShortTimeAgo,
2116
+ timePeriod: timePeriod
2117
+ });
2118
+
2119
+ function getRTop(y, fieldHeight, iTextHeight, yRatio) {
2120
+ return iTextHeight - (y + fieldHeight) * yRatio;
2121
+ }
2122
+ function getRLeft(x, ratio) {
2123
+ return x * ratio;
2124
+ }
2125
+ function getRValue(y, ratio) {
2126
+ return y * ratio;
2127
+ }
2128
+ function blobToBase64(image) {
2129
+ const fileReader = new FileReader();
2130
+ return new Promise((resolve, reject) => {
2131
+ fileReader.onerror = () => {
2132
+ reject(new DOMException('Problem reading blob.'));
2133
+ };
2134
+ fileReader.onload = () => {
2135
+ resolve(fileReader.result);
2136
+ };
2137
+ fileReader.readAsDataURL(image);
2138
+ });
2139
+ }
2140
+ function rescale(r, n) {
2141
+ return r * n;
2142
+ }
2143
+
2144
+ var Fields = /*#__PURE__*/Object.freeze({
2145
+ __proto__: null,
2146
+ blobToBase64: blobToBase64,
2147
+ getRLeft: getRLeft,
2148
+ getRTop: getRTop,
2149
+ getRValue: getRValue,
2150
+ rescale: rescale
2151
+ });
2152
+
2153
+ /**
2154
+ * Given a File, extract the file's content as a base64 encoded data URL. The response will have a prefix that
2155
+ * includes the MIME type of the file, e.g. "data:image/jpeg;base64,iVBORw0K......"
2156
+ */
2157
+ const fileToDataUrl = (file) => new Promise((resolve, reject) => {
2158
+ const reader = new FileReader();
2159
+ reader.onload = () => resolve({
2160
+ lastModified: file.lastModified,
2161
+ size: file.size,
2162
+ type: file.type,
2163
+ name: file.name,
2164
+ data: reader.result,
2165
+ });
2166
+ reader.onerror = reject;
2167
+ if (file) {
2168
+ reader.readAsDataURL(file);
2169
+ }
2170
+ else {
2171
+ reject(new Error('Invalid file'));
2172
+ }
2173
+ });
2174
+ /**
2175
+ * Trigger a download dialog to save a blob as a file on disk.
2176
+ */
2177
+ const downloadBlob = (blob, name = 'file.pdf') => {
2178
+ const blobUrl = URL.createObjectURL(blob);
2179
+ const link = document.createElement('a');
2180
+ link.href = blobUrl;
2181
+ link.download = name;
2182
+ document.body.appendChild(link);
2183
+ link.dispatchEvent(new MouseEvent('click', {
2184
+ bubbles: true,
2185
+ cancelable: true,
2186
+ view: window,
2187
+ }));
2188
+ document.body.removeChild(link);
2189
+ };
2190
+
2191
+ var Files = /*#__PURE__*/Object.freeze({
2192
+ __proto__: null,
2193
+ downloadBlob: downloadBlob,
2194
+ fileToDataUrl: fileToDataUrl
2195
+ });
2196
+
2197
+ const Countries = [
2198
+ { code: '+7 840', name: 'Abkhazia', value: '+7' },
2199
+ { code: '+93', name: 'Afghanistan', value: '+93' },
2200
+ { code: '+355', name: 'Albania', value: '+355' },
2201
+ { code: '+213', name: 'Algeria', value: '+213' },
2202
+ { code: '+1', name: 'American Samoa', value: '+1' },
2203
+ { code: '+376', name: 'Andorra', value: '+376' },
2204
+ { code: '+244', name: 'Angola', value: '+244' },
2205
+ { code: '+1', name: 'Anguilla', value: '+1' },
2206
+ { code: '+1', name: 'Antigua and Barbuda', value: '+1' },
2207
+ { code: '+54', name: 'Argentina', value: '+54' },
2208
+ { code: '+374', name: 'Armenia', value: '+374' },
2209
+ { code: '+297', name: 'Aruba', value: '+297' },
2210
+ { code: '+247', name: 'Ascension', value: '+247' },
2211
+ { code: '+61', name: 'Australia', value: '+61' },
2212
+ { code: '+672', name: 'Australian External Territories', value: '+672' },
2213
+ { code: '+43', name: 'Austria', value: '+43' },
2214
+ { code: '+994', name: 'Azerbaijan', value: '+994' },
2215
+ { code: '+1', name: 'Bahamas', value: '+1' },
2216
+ { code: '+973', name: 'Bahrain', value: '+973' },
2217
+ { code: '+880', name: 'Bangladesh', value: '+880' },
2218
+ { code: '+1', name: 'Barbados', value: '+1' },
2219
+ { code: '+1', name: 'Barbuda', value: '+1' },
2220
+ { code: '+375', name: 'Belarus', value: '+375' },
2221
+ { code: '+32', name: 'Belgium', value: '+32' },
2222
+ { code: '+501', name: 'Belize', value: '+501' },
2223
+ { code: '+229', name: 'Benin', value: '+229' },
2224
+ { code: '+1', name: 'Bermuda', value: '+1' },
2225
+ { code: '+975', name: 'Bhutan', value: '+975' },
2226
+ { code: '+591', name: 'Bolivia', value: '+591' },
2227
+ { code: '+387', name: 'Bosnia and Herzegovina', value: '+387' },
2228
+ { code: '+267', name: 'Botswana', value: '+267' },
2229
+ { code: '+55', name: 'Brazil', value: '+55' },
2230
+ { code: '+246', name: 'British Indian Ocean Territory', value: '+246' },
2231
+ { code: '+1', name: 'British Virgin Islands', value: '+1' },
2232
+ { code: '+673', name: 'Brunei', value: '+673' },
2233
+ { code: '+359', name: 'Bulgaria', value: '+359' },
2234
+ { code: '+226', name: 'Burkina Faso', value: '+226' },
2235
+ { code: '+257', name: 'Burundi', value: '+257' },
2236
+ { code: '+855', name: 'Cambodia', value: '+855' },
2237
+ { code: '+237', name: 'Cameroon', value: '+237' },
2238
+ { code: '+1', name: 'Canada', value: '+1' },
2239
+ { code: '+238', name: 'Cape Verde', value: '+238' },
2240
+ { code: '+1', name: 'Cayman Islands', value: '+1' },
2241
+ { code: '+236', name: 'Central African Republic', value: '+236' },
2242
+ { code: '+235', name: 'Chad', value: '+235' },
2243
+ { code: '+56', name: 'Chile', value: '+56' },
2244
+ { code: '+86', name: 'China', value: '+86' },
2245
+ { code: '+61', name: 'Christmas Island', value: '+61' },
2246
+ { code: '+61', name: 'Cocos-Keeling Islands', value: '+61' },
2247
+ { code: '+57', name: 'Colombia', value: '+57' },
2248
+ { code: '+269', name: 'Comoros', value: '+269' },
2249
+ { code: '+242', name: 'Congo', value: '+242' },
2250
+ { code: '+243', name: 'Congo, Dem. Rep. of (Zaire)', value: '+243' },
2251
+ { code: '+682', name: 'Cook Islands', value: '+682' },
2252
+ { code: '+506', name: 'Costa Rica', value: '+506' },
2253
+ { code: '+385', name: 'Croatia', value: '+385' },
2254
+ { code: '+53', name: 'Cuba', value: '+53' },
2255
+ { code: '+599', name: 'Curacao', value: '+599' },
2256
+ { code: '+537', name: 'Cyprus', value: '+537' },
2257
+ { code: '+420', name: 'Czech Republic', value: '+420' },
2258
+ { code: '+45', name: 'Denmark', value: '+45' },
2259
+ { code: '+246', name: 'Diego Garcia', value: '+246' },
2260
+ { code: '+253', name: 'Djibouti', value: '+253' },
2261
+ { code: '+1', name: 'Dominica', value: '+1' },
2262
+ { code: '+1', name: 'Dominican Republic', value: '+1' },
2263
+ { code: '+670', name: 'East Timor', value: '+670' },
2264
+ { code: '+56', name: 'Easter Island', value: '+56' },
2265
+ { code: '+593', name: 'Ecuador', value: '+593' },
2266
+ { code: '+20', name: 'Egypt', value: '+20' },
2267
+ { code: '+503', name: 'El Salvador', value: '+503' },
2268
+ { code: '+240', name: 'Equatorial Guinea', value: '+240' },
2269
+ { code: '+291', name: 'Eritrea', value: '+291' },
2270
+ { code: '+372', name: 'Estonia', value: '+372' },
2271
+ { code: '+251', name: 'Ethiopia', value: '+251' },
2272
+ { code: '+500', name: 'Falkland Islands', value: '+500' },
2273
+ { code: '+298', name: 'Faroe Islands', value: '+298' },
2274
+ { code: '+679', name: 'Fiji', value: '+679' },
2275
+ { code: '+358', name: 'Finland', value: '+358' },
2276
+ { code: '+33', name: 'France', value: '+33' },
2277
+ { code: '+596', name: 'Martinique', value: '+596' },
2278
+ { code: '+594', name: 'French Guiana', value: '+594' },
2279
+ { code: '+689', name: 'French Polynesia', value: '+689' },
2280
+ { code: '+241', name: 'Gabon', value: '+241' },
2281
+ { code: '+220', name: 'Gambia', value: '+220' },
2282
+ { code: '+995', name: 'Georgia', value: '+995' },
2283
+ { code: '+49', name: 'Germany', value: '+49' },
2284
+ { code: '+233', name: 'Ghana', value: '+233' },
2285
+ { code: '+350', name: 'Gibraltar', value: '+350' },
2286
+ { code: '+30', name: 'Greece', value: '+30' },
2287
+ { code: '+299', name: 'Greenland', value: '+299' },
2288
+ { code: '+1', name: 'Grenada', value: '+1' },
2289
+ { code: '+590', name: 'Guadeloupe', value: '+590' },
2290
+ { code: '+1', name: 'Guam', value: '+1' },
2291
+ { code: '+502', name: 'Guatemala', value: '+502' },
2292
+ { code: '+224', name: 'Guinea', value: '+224' },
2293
+ { code: '+245', name: 'Guinea-Bissau', value: '+245' },
2294
+ { code: '+595', name: 'Guyana', value: '+595' },
2295
+ { code: '+509', name: 'Haiti', value: '+509' },
2296
+ { code: '+504', name: 'Honduras', value: '+504' },
2297
+ { code: '+852', name: 'Hong Kong SAR China', value: '+852' },
2298
+ { code: '+36', name: 'Hungary', value: '+36' },
2299
+ { code: '+354', name: 'Iceland', value: '+354' },
2300
+ { code: '+91', name: 'India', value: '+91' },
2301
+ { code: '+62', name: 'Indonesia', value: '+62' },
2302
+ { code: '+98', name: 'Iran', value: '+98' },
2303
+ { code: '+964', name: 'Iraq', value: '+964' },
2304
+ { code: '+353', name: 'Ireland', value: '+353' },
2305
+ { code: '+972', name: 'Israel', value: '+972' },
2306
+ { code: '+39', name: 'Italy', value: '+39' },
2307
+ { code: '+225', name: 'Ivory Coast', value: '+225' },
2308
+ { code: '+1', name: 'Jamaica', value: '+1' },
2309
+ { code: '+81', name: 'Japan', value: '+81' },
2310
+ { code: '+962', name: 'Jordan', value: '+962' },
2311
+ { code: '+77', name: 'Kazakhstan', value: '+7' },
2312
+ { code: '+254', name: 'Kenya', value: '+254' },
2313
+ { code: '+686', name: 'Kiribati', value: '+686' },
2314
+ { code: '+965', name: 'Kuwait', value: '+965' },
2315
+ { code: '+996', name: 'Kyrgyzstan', value: '+996' },
2316
+ { code: '+856', name: 'Laos', value: '+856' },
2317
+ { code: '+371', name: 'Latvia', value: '+371' },
2318
+ { code: '+961', name: 'Lebanon', value: '+961' },
2319
+ { code: '+266', name: 'Lesotho', value: '+266' },
2320
+ { code: '+231', name: 'Liberia', value: '+231' },
2321
+ { code: '+218', name: 'Libya', value: '+218' },
2322
+ { code: '+423', name: 'Liechtenstein', value: '+423' },
2323
+ { code: '+370', name: 'Lithuania', value: '+370' },
2324
+ { code: '+352', name: 'Luxembourg', value: '+352' },
2325
+ { code: '+853', name: 'Macau SAR China', value: '+853' },
2326
+ { code: '+389', name: 'Macedonia', value: '+389' },
2327
+ { code: '+261', name: 'Madagascar', value: '+261' },
2328
+ { code: '+265', name: 'Malawi', value: '+265' },
2329
+ { code: '+60', name: 'Malaysia', value: '+60' },
2330
+ { code: '+960', name: 'Maldives', value: '+960' },
2331
+ { code: '+223', name: 'Mali', value: '+223' },
2332
+ { code: '+356', name: 'Malta', value: '+356' },
2333
+ { code: '+692', name: 'Marshall Islands', value: '+692' },
2334
+ { code: '+596', name: 'Martinique', value: '+596' },
2335
+ { code: '+222', name: 'Mauritania', value: '+222' },
2336
+ { code: '+230', name: 'Mauritius', value: '+230' },
2337
+ { code: '+262', name: 'Mayotte or Réunion', value: '+262' },
2338
+ { code: '+52', name: 'Mexico', value: '+52' },
2339
+ { code: '+691', name: 'Micronesia', value: '+691' },
2340
+ { code: '+1', name: 'Midway Island', value: '+1' },
2341
+ { code: '+373', name: 'Moldova', value: '+373' },
2342
+ { code: '+377', name: 'Monaco', value: '+377' },
2343
+ { code: '+976', name: 'Mongolia', value: '+976' },
2344
+ { code: '+382', name: 'Montenegro', value: '+382' },
2345
+ { code: '+1', name: 'Montserrat', value: '+1' },
2346
+ { code: '+212', name: 'Morocco', value: '+212' },
2347
+ { code: '+95', name: 'Myanmar', value: '+95' },
2348
+ { code: '+264', name: 'Namibia', value: '+264' },
2349
+ { code: '+674', name: 'Nauru', value: '+674' },
2350
+ { code: '+977', name: 'Nepal', value: '+977' },
2351
+ { code: '+31', name: 'Netherlands', value: '+31' },
2352
+ { code: '+599', name: 'Netherlands Antilles', value: '+599' },
2353
+ { code: '+1', name: 'Nevis', value: '+1' },
2354
+ { code: '+687', name: 'New Caledonia', value: '+687' },
2355
+ { code: '+64', name: 'New Zealand', value: '+64' },
2356
+ { code: '+505', name: 'Nicaragua', value: '+505' },
2357
+ { code: '+227', name: 'Niger', value: '+227' },
2358
+ { code: '+234', name: 'Nigeria', value: '+234' },
2359
+ { code: '+683', name: 'Niue', value: '+683' },
2360
+ { code: '+672', name: 'Norfolk Island', value: '+672' },
2361
+ { code: '+850', name: 'North Korea', value: '+850' },
2362
+ { code: '+1', name: 'Northern Mariana Islands', value: '+1' },
2363
+ { code: '+47', name: 'Norway', value: '+47' },
2364
+ { code: '+968', name: 'Oman', value: '+968' },
2365
+ { code: '+92', name: 'Pakistan', value: '+92' },
2366
+ { code: '+680', name: 'Palau', value: '+680' },
2367
+ { code: '+970', name: 'Palestinian Territory', value: '+970' },
2368
+ { code: '+507', name: 'Panama', value: '+507' },
2369
+ { code: '+675', name: 'Papua New Guinea', value: '+675' },
2370
+ { code: '+595', name: 'Paraguay', value: '+595' },
2371
+ { code: '+51', name: 'Peru', value: '+51' },
2372
+ { code: '+63', name: 'Philippines', value: '+63' },
2373
+ { code: '+48', name: 'Poland', value: '+48' },
2374
+ { code: '+351', name: 'Portugal', value: '+351' },
2375
+ { code: '+1', name: 'Puerto Rico', value: '+1' },
2376
+ { code: '+974', name: 'Qatar', value: '+974' },
2377
+ { code: '+40', name: 'Romania', value: '+40' },
2378
+ { code: '+7', name: 'Russia', value: '+7' },
2379
+ { code: '+250', name: 'Rwanda', value: '+250' },
2380
+ { code: '508', name: 'Saint Pierre and Miquelon', value: '508' },
2381
+ { code: '+685', name: 'Samoa', value: '+685' },
2382
+ { code: '+378', name: 'San Marino', value: '+378' },
2383
+ { code: '+966', name: 'Saudi Arabia', value: '+966' },
2384
+ { code: '+221', name: 'Senegal', value: '+221' },
2385
+ { code: '+381', name: 'Serbia', value: '+381' },
2386
+ { code: '+248', name: 'Seychelles', value: '+248' },
2387
+ { code: '+232', name: 'Sierra Leone', value: '+232' },
2388
+ { code: '+65', name: 'Singapore', value: '+65' },
2389
+ { code: '+421', name: 'Slovakia', value: '+421' },
2390
+ { code: '+386', name: 'Slovenia', value: '+386' },
2391
+ { code: '+677', name: 'Solomon Islands', value: '+677' },
2392
+ { code: '+27', name: 'South Africa', value: '+27' },
2393
+ { code: '+500', name: 'South Georgia and the South Sandwich Islands', value: '+500' },
2394
+ { code: '+82', name: 'South Korea', value: '+82' },
2395
+ { code: '+34', name: 'Spain', value: '+34' },
2396
+ { code: '+94', name: 'Sri Lanka', value: '+94' },
2397
+ { code: '+249', name: 'Sudan', value: '+249' },
2398
+ { code: '+597', name: 'Suriname', value: '+597' },
2399
+ { code: '+268', name: 'Swaziland', value: '+268' },
2400
+ { code: '+46', name: 'Sweden', value: '+46' },
2401
+ { code: '+41', name: 'Switzerland', value: '+41' },
2402
+ { code: '+963', name: 'Syria', value: '+963' },
2403
+ { code: '+886', name: 'Taiwan', value: '+886' },
2404
+ { code: '+992', name: 'Tajikistan', value: '+992' },
2405
+ { code: '+255', name: 'Tanzania', value: '+255' },
2406
+ { code: '+66', name: 'Thailand', value: '+66' },
2407
+ { code: '+670', name: 'Timor Leste', value: '+670' },
2408
+ { code: '+228', name: 'Togo', value: '+228' },
2409
+ { code: '+690', name: 'Tokelau', value: '+690' },
2410
+ { code: '+676', name: 'Tonga', value: '+676' },
2411
+ { code: '+1', name: 'Trinidad and Tobago', value: '+1' },
2412
+ { code: '+216', name: 'Tunisia', value: '+216' },
2413
+ { code: '+90', name: 'Turkey', value: '+90' },
2414
+ { code: '+993', name: 'Turkmenistan', value: '+993' },
2415
+ { code: '+1', name: 'Turks and Caicos Islands', value: '+1' },
2416
+ { code: '+688', name: 'Tuvalu', value: '+688' },
2417
+ { code: '+1', name: 'U.S. Virgin Islands', value: '+1' },
2418
+ { code: '+256', name: 'Uganda', value: '+256' },
2419
+ { code: '+380', name: 'Ukraine', value: '+380' },
2420
+ { code: '+971', name: 'United Arab Emirates', value: '+971' },
2421
+ { code: '+44', name: 'United Kingdom', value: '+44' },
2422
+ { code: '+1', name: 'United States', value: '+1' },
2423
+ { code: '+598', name: 'Uruguay', value: '+598' },
2424
+ { code: '+998', name: 'Uzbekistan', value: '+998' },
2425
+ { code: '+678', name: 'Vanuatu', value: '+678' },
2426
+ { code: '+58', name: 'Venezuela', value: '+58' },
2427
+ { code: '+84', name: 'Vietnam', value: '+84' },
2428
+ { code: '+1', name: 'Wake Island', value: '+1' },
2429
+ { code: '+681', name: 'Wallis and Futuna', value: '+681' },
2430
+ { code: '+967', name: 'Yemen', value: '+967' },
2431
+ { code: '+260', name: 'Zambia', value: '+260' },
2432
+ { code: '+255', name: 'Zanzibar', value: '+255' },
2433
+ { code: '+263', name: 'Zimbabwe', value: '+263' },
2434
+ ];
2435
+ function getCountryByCode(code) {
2436
+ const found = Countries.find((country) => country.code === code);
2437
+ if (found)
2438
+ return found;
2439
+ if (isFrenchGuiana(code)) {
2440
+ return { code: '+594', name: 'French Guiana', value: '+594' };
2441
+ }
2442
+ else if (isGuadeloupe(code)) {
2443
+ return { code: '+590', name: 'Guadeloupe', value: '+590' };
2444
+ }
2445
+ else if (isMartinique(code)) {
2446
+ return { code: '+596', name: 'Martinique', value: '+596' };
2447
+ }
2448
+ else if (isMayotte(code)) {
2449
+ return { code: '+262', name: 'Mayotte or Réunion', value: '+262' };
2450
+ }
2451
+ return null;
2452
+ }
2453
+ function isFrenchGuiana(code) {
2454
+ return '+594' === code.substring(0, 4);
2455
+ }
2456
+ function isGuadeloupe(code) {
2457
+ return '+590' === code.substring(0, 4);
2458
+ }
2459
+ function isMartinique(code) {
2460
+ return '+596' === code.substring(0, 4);
2461
+ }
2462
+ function isMayotte(code) {
2463
+ return '+262' === code.substring(0, 4);
2464
+ }
2465
+ function getPlusOneCountry(code) {
2466
+ let info = null;
2467
+ switch (code.substring(0, 5)) {
2468
+ case '+1684':
2469
+ info = { code: '+1', name: 'American Samoa', value: '+1' };
2470
+ break;
2471
+ case '+1264':
2472
+ info = { code: '+1', name: 'Anguilla', value: '+1' };
2473
+ break;
2474
+ case '+1268':
2475
+ info = { code: '+1', name: 'Antigua and Barbuda', value: '+1' };
2476
+ break;
2477
+ case '+1242':
2478
+ info = { code: '+1', name: 'Bahamas', value: '+1' };
2479
+ break;
2480
+ case '+1246':
2481
+ info = { code: '+1', name: 'Barbados', value: '+1' };
2482
+ break;
2483
+ case '+1441':
2484
+ info = { code: '+1', name: 'Bermuda', value: '+1' };
2485
+ break;
2486
+ case '+1284':
2487
+ info = { code: '+1', name: 'British Virgin Islands', value: '+1' };
2488
+ break;
2489
+ case '+1':
2490
+ info = { code: '+1', name: '', value: '+1' };
2491
+ break;
2492
+ }
2493
+ return info;
2494
+ }
2495
+ function isCanada(code) {
2496
+ const canadianAreaCodes = [
2497
+ '403',
2498
+ '587',
2499
+ '780',
2500
+ '825',
2501
+ '604',
2502
+ '250',
2503
+ '778',
2504
+ '236',
2505
+ '204',
2506
+ '431',
2507
+ '506',
2508
+ '709',
2509
+ '867',
2510
+ '782',
2511
+ '902',
2512
+ '867',
2513
+ '548',
2514
+ '705',
2515
+ '365',
2516
+ '613',
2517
+ '807',
2518
+ '226',
2519
+ '289',
2520
+ '437',
2521
+ '519',
2522
+ '647',
2523
+ '905',
2524
+ '249',
2525
+ '343',
2526
+ '416',
2527
+ '902',
2528
+ '782',
2529
+ '450',
2530
+ '418',
2531
+ '579',
2532
+ '873',
2533
+ '367',
2534
+ '514',
2535
+ '581',
2536
+ '819',
2537
+ '438',
2538
+ '639',
2539
+ '306',
2540
+ '867',
2541
+ ];
2542
+ const areaCode = code.substring(0, 5);
2543
+ return canadianAreaCodes.findIndex((x) => '+1' + x === areaCode) > -1;
2544
+ }
2545
+ function isAmericanSamoa(code) {
2546
+ return code.substring(0, 5) === '+1684';
2547
+ }
2548
+ function isDominicanRepublic(code) {
2549
+ return '+1809' === code.substring(0, 5) || '+1829' === code.substring(0, 5) || '+1849' === code.substring(0, 5);
2550
+ }
2551
+ function isPuertoRico(code) {
2552
+ return code.substring(0, 5) === '+' || code.substring(0, 5) === '+';
2553
+ }
2554
+ // need to finish
2555
+ function getMatchingCountry(code, substrings) {
2556
+ const toMatch = code.substring(0, substrings);
2557
+ return Countries.filter((c) => c.code === toMatch).length;
2558
+ }
2559
+ // const e164Regex = new RegExp(/\+[1-9]\d{6,14}/g);
2560
+ // export function simpleE164Validator(code: string) {
2561
+ // return (code !== null && code.length < 16 && code.length > 6 && e164Regex.test(code)) || code === '' || code === null;
2562
+ // }
2563
+
2564
+ var Locales = /*#__PURE__*/Object.freeze({
2565
+ __proto__: null,
2566
+ Countries: Countries,
2567
+ getCountryByCode: getCountryByCode,
2568
+ getMatchingCountry: getMatchingCountry,
2569
+ getPlusOneCountry: getPlusOneCountry,
2570
+ isAmericanSamoa: isAmericanSamoa,
2571
+ isCanada: isCanada,
2572
+ isDominicanRepublic: isDominicanRepublic,
2573
+ isFrenchGuiana: isFrenchGuiana,
2574
+ isGuadeloupe: isGuadeloupe,
2575
+ isMartinique: isMartinique,
2576
+ isMayotte: isMayotte,
2577
+ isPuertoRico: isPuertoRico
2578
+ });
2579
+
2580
+ /**
2581
+ * Capitalize the first letter of a string.
2582
+ */
2583
+ const capitalize = (str) => str.charAt(0).toUpperCase() + str.slice(1);
2584
+ /**
2585
+ * Convert a phone-number-like string to E164 format.
2586
+ * @see https://46elks.com/kb/e164
2587
+ */
2588
+ const convertToE164 = (input) => {
2589
+ // "(212) 555-1212" => +12125551212
2590
+ // "+46766861004" => "+46766861004"
2591
+ // "212-555-1212" => +12125551212
2592
+ // "212.555.1212" => +12125551212
2593
+ // "212 555 1212" => +12125551212
2594
+ let temp = (input || '').trim();
2595
+ // If we are already prefixed, assume the user did it deliberately and attempt to use what they entered. We also short-circuit blanks.
2596
+ if (!temp || temp.startsWith('+')) {
2597
+ return temp;
2598
+ }
2599
+ // Remove any spaces, parenthesis or other punctuation.
2600
+ temp = temp.replace(/[^0-9]/g, '');
2601
+ // If the number begins with a zero, remove the leading zero. Do not combine this with the previous step because it needs to be removed
2602
+ // whether it's the actual first character e.g. `0(5)` or just the first digit e.g. `(05`.
2603
+ temp = temp.replace(/^0/g, '');
2604
+ // Prepend the country code and +. We're assuming US in this case given the target demographic. Users in other countries would/should be
2605
+ // already entering a prefix so they'd shortcut out of this routine via the + prefix check.
2606
+ return `+1${temp}`;
2607
+ };
2608
+
2609
+ var Strings = /*#__PURE__*/Object.freeze({
2610
+ __proto__: null,
2611
+ capitalize: capitalize,
2612
+ convertToE164: convertToE164
2613
+ });
2614
+
2615
+ /**
2616
+ * Create an array containing a sequence of integers, e.g. [START, START+1, START+2, ...] This is frequently useful
2617
+ * in rendering operations when there is no source array to .map() across.
2618
+ */
2619
+ const integerSequence = (start, count) => Array(count)
2620
+ .fill(1)
2621
+ .map((_, index) => index + start);
2622
+ /**
2623
+ * Format a profile's full name
2624
+ */
2625
+ const formatFullName = (profile) => profile ? `${capitalize(profile.first_name)} ${capitalize(profile.last_name)}` : 'Invalid User';
2626
+ /**
2627
+ * Format a profile's initials
2628
+ */
2629
+ const formatInitials = (profile) => profile ? `${capitalize(profile.first_name).charAt(0)} ${capitalize(profile.last_name).charAt(0)}` : '--';
2630
+ /**
2631
+ * Generate suggested initials for a full name, e.g. "John Doe" will yield "JD".
2632
+ */
2633
+ const fullNameToInitials = (name) => name
2634
+ .split(' ')
2635
+ .map((word) => word[0])
2636
+ .join('');
2637
+
2638
+ var Primitives = /*#__PURE__*/Object.freeze({
2639
+ __proto__: null,
2640
+ formatFullName: formatFullName,
2641
+ formatInitials: formatInitials,
2642
+ fullNameToInitials: fullNameToInitials,
2643
+ integerSequence: integerSequence
2644
+ });
2645
+
2646
+ var Types = /*#__PURE__*/Object.freeze({
2647
+ __proto__: null
2648
+ });
2649
+
2650
+ var index = /*#__PURE__*/Object.freeze({
2651
+ __proto__: null,
2652
+ Colors: Colors,
2653
+ DateTime: DateTime,
2654
+ Fields: Fields,
2655
+ Files: Files,
2656
+ Locales: Locales,
2657
+ Primitives: Primitives,
2658
+ Strings: Strings,
2659
+ Token: Token,
2660
+ Types: Types
2661
+ });
2662
+
2663
+ function getDefaultExportFromCjs (x) {
2664
+ return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
2665
+ }
2666
+
2667
+ // This file provides a polyfill for managing globals in both NodeJS and browser environments. This is
2668
+ // an anti-pattern we'd hoped to avoid, but we have several projects dependending on one common library
2669
+ // (this js-sdk) and we want that library to provide a common endpoint to all callers (so authentication
2670
+ // tokens only need to be tracked in one place). The trouble is, one of those libraries is based on
2671
+ // StencilJS and is compiling its modules into Web Components. Because of how module resolution works,
2672
+ // when those Components load js-sdk they get a separate instance. Without messy options like having to
2673
+ // pass raw data from the caller to each Component, or pass around references to a common Endpoint, they
2674
+ // have no way to access authenticated sessions unless we make the Endpoint a true global.
2675
+ //
2676
+ // @credit https://github.com/medikoo/es5-ext/blob/master/global.js
2677
+ // @credit https://mathiasbynens.be/notes/globalthis
2678
+ var naiveFallback = function () {
2679
+ if (typeof self === 'object' && self)
2680
+ return self;
2681
+ if (typeof window === 'object' && window)
2682
+ return window;
2683
+ throw new Error('Unable to resolve global `this`');
2684
+ };
2685
+ var globalThis_1 = (function () {
2686
+ if (this)
2687
+ return this;
2688
+ // Unexpected strict mode (may happen if e.g. bundled into ESM module)
2689
+ // Fallback to standard globalThis if available
2690
+ if (typeof globalThis === 'object' && globalThis)
2691
+ return globalThis;
2692
+ // Thanks @mathiasbynens -> https://mathiasbynens.be/notes/globalthis
2693
+ // In all ES5+ engines global object inherits from Object.prototype
2694
+ // (if you approached one that doesn't please report)
2695
+ try {
2696
+ Object.defineProperty(Object.prototype, '__global__', {
2697
+ get: function () {
2698
+ return this;
2699
+ },
2700
+ configurable: true,
2701
+ });
2702
+ }
2703
+ catch (error) {
2704
+ // Unfortunate case of updates to Object.prototype being restricted
2705
+ // via preventExtensions, seal or freeze
2706
+ return naiveFallback();
2707
+ }
2708
+ try {
2709
+ // Safari case (window.__global__ works, but __global__ does not)
2710
+ if (!__global__)
2711
+ return naiveFallback();
2712
+ return __global__;
2713
+ }
2714
+ finally {
2715
+ delete Object.prototype.__global__;
2716
+ }
2717
+ })();
2718
+
2719
+ var globalThis$1 = /*@__PURE__*/getDefaultExportFromCjs(globalThis_1);
2720
+
2721
+ // @credit https://derickbailey.com/2016/03/09/creating-a-true-singleton-in-node-js-with-es6-symbols/
2722
+ // Also see globalThis for comments about why we're doing this in the first place.
2723
+ const ENDPOINT_KEY = Symbol.for('verdocs-default-endpoint');
2724
+ const requestLogger = (r) => {
2725
+ // tslint:disable-next-line
2726
+ console.debug(`[JS-SDK] ${r.method.toUpperCase()} ${r.baseURL}${r.url}`, r.data ? JSON.stringify(r.data) : '');
2727
+ return r;
2728
+ };
2729
+ /**
2730
+ * VerdocsEndpoint is a class wrapper for a specific connection and authorization context for calling the Verdocs APIs.
2731
+ * Endpoints can be used for isolated session tasks.
2732
+ *
2733
+ * For instance, ephemeral signing sessions may be created independently of a caller's status as an authenticated user.
2734
+ * In that case, an Endpoint can be created and authenticated, used for calls related to signing operations, then
2735
+ * discarded once signing is complete.
2736
+ *
2737
+ * Note that endpoint configuration functions return the instance, so they can be chained, e.g.
2738
+ *
2739
+ * ```typescript
2740
+ * import {VerdocsEndpoint} from '@verdocs/js-sdk/HTTP';
2741
+ *
2742
+ * const endpoint = new VerdocsEndpoint();
2743
+ * endpoint
2744
+ * .setSessionType('signing')
2745
+ * .logRequests(true)
2746
+ * .setClientID('1234)
2747
+ * .setTimeout(30000);
2748
+ * ```
2749
+ */
2750
+ class VerdocsEndpoint {
2751
+ environment = 'verdocs';
2752
+ sessionType = 'user';
2753
+ baseURL = (window.location.origin === 'https://beta.verdocs.com' || window.location.origin === 'https://stage.verdocs.com'
2754
+ ? 'https://stage-api.verdocs.com'
2755
+ : 'https://api.verdocs.com');
2756
+ clientID = 'not-set';
2757
+ timeout = 60000;
2758
+ token = null;
2759
+ nextListenerId = 0;
2760
+ sessionListeners = new Map();
2761
+ requestLoggerId = null;
2762
+ /**
2763
+ * The current user session, or null if not authenticated. May be either a User or Signing session. If set, the
2764
+ * presence of the `document_id` field can be used to differentiate the types. Only signing sessions are associated
2765
+ * with Envelopes.
2766
+ */
2767
+ session = null;
2768
+ api;
2769
+ /**
2770
+ * Create a new VerdocsEndpoint to call Verdocs platform services.
2771
+ *
2772
+ * ```typescript
2773
+ * import {VerdocsEndpoint} from '@verdocs/js-sdk/HTTP';
2774
+ * const endpoint = new VerdocsEndpoint();
2775
+ * ```
2776
+ */
2777
+ constructor(options) {
2778
+ this.baseURL = options?.baseURL || this.baseURL;
2779
+ this.timeout = options?.timeout || this.timeout;
2780
+ this.environment = options?.environment || this.environment;
2781
+ this.sessionType = options?.sessionType || this.sessionType;
2782
+ this.clientID = options?.clientID || this.clientID;
2783
+ this.api = axios.create({ baseURL: this.baseURL, timeout: this.timeout });
2784
+ }
2785
+ setDefault() {
2786
+ globalThis$1[ENDPOINT_KEY] = this;
2787
+ }
2788
+ static getDefault() {
2789
+ if (!globalThis$1[ENDPOINT_KEY]) {
2790
+ globalThis$1[ENDPOINT_KEY] = new VerdocsEndpoint();
2791
+ window.console.debug('[JS_SDK] Created default endpoint', globalThis$1[ENDPOINT_KEY].baseURL);
2792
+ }
2793
+ return globalThis$1[ENDPOINT_KEY];
2794
+ }
2795
+ /**
2796
+ * Get the current environment.
2797
+ */
2798
+ getEnvironment() {
2799
+ return this.environment;
2800
+ }
2801
+ /**
2802
+ * Get the current session type.
2803
+ */
2804
+ getSessionType() {
2805
+ return this.sessionType;
2806
+ }
2807
+ /**
2808
+ * Get the current base URL. This should rarely be anything other than 'https://api.verdocs.com'.
2809
+ */
2810
+ getBaseURL() {
2811
+ return this.baseURL;
2812
+ }
2813
+ /**
2814
+ * Get the current client ID, if set.
2815
+ */
2816
+ getClientID() {
2817
+ return this.clientID;
2818
+ }
2819
+ /**
2820
+ * Get the current timeout.
2821
+ */
2822
+ getTimeout() {
2823
+ return this.timeout;
2824
+ }
2825
+ /**
2826
+ * Get the current session, if any.
2827
+ */
2828
+ getSession() {
2829
+ return this.session;
2830
+ }
2831
+ /**
2832
+ * Set the operating environment. This should rarely be anything other than 'verdocs'.
2833
+ *
2834
+ * ```typescript
2835
+ * import {VerdocsEndpoint} from '@verdocs/js-sdk/HTTP';
2836
+ *
2837
+ * const endpoint = new VerdocsEndpoint();
2838
+ * endpoint.setEnvironment('verdocs-stage');
2839
+ * ```
2840
+ */
2841
+ setEnvironment(environment) {
2842
+ this.environment = environment;
2843
+ return this;
2844
+ }
2845
+ /**
2846
+ * Set the session type. In general this should be done immediately when the endpoint is created. Changing the
2847
+ * session type may be done at any time, but may have unintended consequences if the endpoint is shared between
2848
+ * multiple widgets.
2849
+ *
2850
+ * Changing the session type will clear/reload the action session. This may trigger notifications to session state
2851
+ * observers. Apps that use observers to trigger UI updates such as logging the user out should be prepared to
2852
+ * handle this event.
2853
+ *
2854
+ * ```typescript
2855
+ * import {VerdocsEndpoint} from '@verdocs/js-sdk/HTTP';
2856
+ *
2857
+ * const endpoint = new VerdocsEndpoint();
2858
+ * endpoint.setEnvironment('verdocs-stage');
2859
+ * ```
2860
+ */
2861
+ setSessionType(sessionType) {
2862
+ this.sessionType = sessionType;
2863
+ return this;
2864
+ }
2865
+ /**
2866
+ * Set the base URL for API calls. Should be called only upon direction from Verdocs Customer Solutions Engineering.
2867
+ *
2868
+ * ```typescript
2869
+ * import {VerdocsEndpoint} from '@verdocs/js-sdk/HTTP';
2870
+ *
2871
+ * const endpoint = new VerdocsEndpoint();
2872
+ * endpoint.setBaseURL('https://api.verdocs.com');
2873
+ * ```
2874
+ */
2875
+ setBaseURL(url) {
2876
+ this.baseURL = url;
2877
+ this.api.defaults.baseURL = url;
2878
+ return this;
2879
+ }
2880
+ /**
2881
+ * Set the Client ID for Verdocs API calls.
2882
+ *
2883
+ * ```typescript
2884
+ * import {VerdocsEndpoint} from '@verdocs/js-sdk/HTTP';
2885
+ *
2886
+ * const endpoint = new VerdocsEndpoint();
2887
+ * endpoint.setClientID('1234);
2888
+ * ```
2889
+ */
2890
+ setClientID(clientID) {
2891
+ this.clientID = clientID;
2892
+ this.api.defaults.headers.common['X-Client-ID'] = clientID;
2893
+ return this;
2894
+ }
2895
+ /**
2896
+ * Set the timeout for API calls in milliseconds. 5000-20000ms is recommended for most purposes. 15000ms is the default.
2897
+ * Note that some calls may involve rendering operations that require some time to complete, so very short timeouts
2898
+ * are not recommended.
2899
+ *
2900
+ * ```typescript
2901
+ * import {VerdocsEndpoint} from '@verdocs/js-sdk/HTTP';
2902
+ *
2903
+ * const endpoint = new VerdocsEndpoint();
2904
+ * endpoint.setTimeout(3000);
2905
+ * ```
2906
+ */
2907
+ setTimeout(timeout) {
2908
+ this.timeout = timeout;
2909
+ this.api.defaults.timeout = timeout;
2910
+ return this;
2911
+ }
2912
+ /**
2913
+ * Enable or disable request logging. This may expose sensitive data in the console log, so it should only be used for debugging.
2914
+ *
2915
+ * ```typescript
2916
+ * import {VerdocsEndpoint} from '@verdocs/js-sdk/HTTP';
2917
+ *
2918
+ * const endpoint = new VerdocsEndpoint();
2919
+ * endpoint.logRequests(true);
2920
+ * ```
2921
+ */
2922
+ logRequests(enable) {
2923
+ if (enable && this.requestLoggerId === null) {
2924
+ this.requestLoggerId = this.api.interceptors.request.use(requestLogger);
2925
+ }
2926
+ else if (!enable && this.requestLoggerId !== null) {
2927
+ this.api.interceptors.request.eject(this.requestLoggerId);
2928
+ }
2929
+ return this;
2930
+ }
2931
+ /**
2932
+ * Set the authorization token that will be used for Verdocs API calls. This will also set the session metadata
2933
+ * and notify any listeners of the new data.
2934
+ *
2935
+ * If this Endpoint will be used for non-default purposes (e.g. signing, or in an alternate environment) those
2936
+ * settings should be made before calling this. Sessions are persisted to localStorage, and the environment and
2937
+ * type become part of the storage key.
2938
+ *
2939
+ * ```typescript
2940
+ * import {VerdocsEndpoint} from '@verdocs/js-sdk/HTTP';
2941
+ *
2942
+ * const endpoint = new VerdocsEndpoint();
2943
+ * endpoint.setToken(accessToken);
2944
+ * ```
2945
+ */
2946
+ setToken(token) {
2947
+ if (!token) {
2948
+ return this.clearSession();
2949
+ }
2950
+ const session = decodeAccessTokenBody(token);
2951
+ if (session === null || (session.exp && session.exp * 1000 < new Date().getTime())) {
2952
+ window.console.warn('[JS_SDK] Ignoring attempt to use expired session token');
2953
+ return this.clearSession();
2954
+ }
2955
+ this.token = token;
2956
+ this.session = session;
2957
+ if (this.sessionType === 'user') {
2958
+ this.api.defaults.headers.common.Authorization = `Bearer ${token}`;
2959
+ }
2960
+ else {
2961
+ this.api.defaults.headers.common.signer = `Bearer ${token}`;
2962
+ }
2963
+ localStorage.setItem(this.sessionStorageKey(), token);
2964
+ this.notifySessionListeners();
2965
+ return this;
2966
+ }
2967
+ /**
2968
+ * Retrieves the current session token, if any. Tokens should rarely be used for direct actions, but this is
2969
+ * required by the `<VerdocsView>` and other components to authorize requests to raw PDF files.
2970
+ */
2971
+ getToken() {
2972
+ return this.token;
2973
+ }
2974
+ sessionStorageKey() {
2975
+ return `verdocs-session-${this.getSessionType()}-${this.getEnvironment()}`;
2976
+ }
2977
+ /**
2978
+ * Clear the active session.
2979
+ */
2980
+ clearSession() {
2981
+ localStorage.removeItem(this.sessionStorageKey());
2982
+ delete this.api.defaults.headers.common.Authorization;
2983
+ delete this.api.defaults.headers.common.signer;
2984
+ this.session = null;
2985
+ this.token = null;
2986
+ this.notifySessionListeners();
2987
+ return this;
2988
+ }
2989
+ /**
2990
+ * Clear the active signing session.
2991
+ */
2992
+ clearSignerSession() {
2993
+ localStorage.removeItem(this.sessionStorageKey());
2994
+ delete this.api.defaults.headers.common.Authorization;
2995
+ this.session = null;
2996
+ this.token = null;
2997
+ this.notifySessionListeners();
2998
+ return this;
2999
+ }
3000
+ notifySessionListeners() {
3001
+ this.sessionListeners.forEach((listener) => {
3002
+ try {
3003
+ listener(this, this.session);
3004
+ }
3005
+ catch (e) {
3006
+ // NOOP
3007
+ }
3008
+ });
3009
+ }
3010
+ /**
3011
+ * Subscribe to session state change events.
3012
+ */
3013
+ onSessionChanged(listener) {
3014
+ // There's no value in randomizing this, a simple counter is fine
3015
+ this.nextListenerId++;
3016
+ const listenerSymbol = Symbol.for('' + this.nextListenerId);
3017
+ this.sessionListeners.set(listenerSymbol, listener);
3018
+ return () => {
3019
+ this.sessionListeners.delete(listenerSymbol);
3020
+ };
3021
+ }
3022
+ /**
3023
+ * Load a persisted session from localStorage. Typically called once after the endpoint is configured when the app
3024
+ * or component starts.
3025
+ */
3026
+ loadSession() {
3027
+ const token = localStorage.getItem(this.sessionStorageKey());
3028
+ if (!token) {
3029
+ return this.clearSession();
3030
+ }
3031
+ return this.setToken(token);
3032
+ }
3033
+ }
3034
+
3035
+ export { index$5 as Envelopes, Models, index$4 as Organizations, index$3 as Sessions, index$2 as Templates, index$1 as Users, index as Utils, VerdocsEndpoint };
3036
+ //# sourceMappingURL=index.mjs.map