@verdocs/js-sdk 3.3.4 → 3.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -142,22 +142,6 @@ export declare const getEnvelopeDocument: (endpoint: VerdocsEndpoint, envelopeId
142
142
  * Cancel an Envelope.
143
143
  */
144
144
  export declare const cancelEnvelope: (endpoint: VerdocsEndpoint, envelopeId: string) => Promise<TEnvelopeUpdateResult>;
145
- /**
146
- * Returns true if the recipient has a pending action. Note that this does not necessarily mean the recipient can act (yet).
147
- */
148
- export declare const recipientHasAction: (recipient: IRecipient) => boolean;
149
- /**
150
- * Returns the recipients who still have a pending action. Note that not all of these recipients may be able to act (yet).
151
- */
152
- export declare const getRecipientsWithActions: (envelope: IEnvelope) => IRecipient[];
153
- /**
154
- * Returns true if the recipient can act.
155
- */
156
- export declare const recipientCanAct: (recipient: IRecipient, recipientsWithActions: IRecipient[]) => boolean;
157
- /**
158
- * Returns true if the user can act.
159
- */
160
- export declare const userCanAct: (email: string, recipientsWithActions: IRecipient[]) => boolean | undefined;
161
145
  /**
162
146
  * Get (binary download) a file attached to an Envelope. It is important to use this method
163
147
  * rather than a direct A HREF or similar link to set the authorization headers for the
@@ -163,26 +163,6 @@ export var cancelEnvelope = function (endpoint, envelopeId) { return __awaiter(v
163
163
  .then(function (r) { return r.data; })];
164
164
  });
165
165
  }); };
166
- /**
167
- * Returns true if the recipient has a pending action. Note that this does not necessarily mean the recipient can act (yet).
168
- */
169
- export var recipientHasAction = function (recipient) { return !['submitted', 'canceled', 'declined'].includes(recipient.status); };
170
- /**
171
- * Returns the recipients who still have a pending action. Note that not all of these recipients may be able to act (yet).
172
- */
173
- export var getRecipientsWithActions = function (envelope) { return ((envelope === null || envelope === void 0 ? void 0 : envelope.recipients) || []).filter(recipientHasAction); };
174
- /**
175
- * Returns true if the recipient can act.
176
- */
177
- export var recipientCanAct = function (recipient, recipientsWithActions) { var _a; return recipient.sequence === ((_a = recipientsWithActions === null || recipientsWithActions === void 0 ? void 0 : recipientsWithActions[0]) === null || _a === void 0 ? void 0 : _a.sequence); };
178
- /**
179
- * Returns true if the user can act.
180
- */
181
- export var userCanAct = function (email, recipientsWithActions) {
182
- var _a;
183
- var recipient = recipientsWithActions.find(function (r) { return r.email === email; });
184
- return recipient && recipient.sequence === ((_a = recipientsWithActions === null || recipientsWithActions === void 0 ? void 0 : recipientsWithActions[0]) === null || _a === void 0 ? void 0 : _a.sequence);
185
- };
186
166
  /**
187
167
  * Get (binary download) a file attached to an Envelope. It is important to use this method
188
168
  * rather than a direct A HREF or similar link to set the authorization headers for the
@@ -3,7 +3,7 @@
3
3
  *
4
4
  * @module
5
5
  */
6
- import { IEnvelope } from './Types';
6
+ import { IEnvelope, IRecipient } from './Types';
7
7
  import { TSession } from '../Sessions/Types';
8
8
  /**
9
9
  * Check to see if the user owns the envelope.
@@ -13,6 +13,14 @@ export declare const userIsEnvelopeOwner: (session: TSession, envelope: IEnvelop
13
13
  * Check to see if the user owns the envelope.
14
14
  */
15
15
  export declare const userIsEnvelopeRecipient: (session: TSession, envelope: IEnvelope) => boolean;
16
+ /**
17
+ * Check to see if the envelope has pending actions.
18
+ */
19
+ export declare const envelopeIsActive: (envelope: IEnvelope) => boolean;
20
+ /**
21
+ * Check to see if the envelope has been completed.
22
+ */
23
+ export declare const envelopeIsComplete: (envelope: IEnvelope) => boolean;
16
24
  /**
17
25
  * Check to see if the user owns the envelope.
18
26
  */
@@ -21,3 +29,23 @@ export declare const userCanCancelEnvelope: (session: TSession, envelope: IEnvel
21
29
  * Check to see if the user owns the envelope.
22
30
  */
23
31
  export declare const userCanFinishEnvelope: (session: TSession, envelope: IEnvelope) => boolean;
32
+ /**
33
+ * Returns true if the recipient has a pending action. Note that this does not necessarily mean the recipient can act (yet).
34
+ */
35
+ export declare const recipientHasAction: (recipient: IRecipient) => boolean;
36
+ /**
37
+ * Returns the recipients who still have a pending action. Note that not all of these recipients may be able to act (yet).
38
+ */
39
+ export declare const getRecipientsWithActions: (envelope: IEnvelope) => IRecipient[];
40
+ /**
41
+ * Returns true if the recipient can act.
42
+ */
43
+ export declare const recipientCanAct: (recipient: IRecipient, recipientsWithActions: IRecipient[]) => boolean;
44
+ /**
45
+ * Returns true if the user can act.
46
+ */
47
+ export declare const userCanAct: (email: string, recipientsWithActions: IRecipient[]) => boolean | undefined;
48
+ /**
49
+ * Returns true if the user can act.
50
+ */
51
+ export declare const userCanSignNow: (session: TSession, envelope: IEnvelope) => boolean | undefined;
@@ -12,6 +12,16 @@ export var userIsEnvelopeOwner = function (session, envelope) { return envelope.
12
12
  * Check to see if the user owns the envelope.
13
13
  */
14
14
  export var userIsEnvelopeRecipient = function (session, envelope) { return envelope.profile_id === (session === null || session === void 0 ? void 0 : session.profile_id); };
15
+ /**
16
+ * Check to see if the envelope has pending actions.
17
+ */
18
+ export var envelopeIsActive = function (envelope) {
19
+ return envelope.status !== EnvelopeStates.COMPLETE && envelope.status !== EnvelopeStates.DECLINED && envelope.status !== EnvelopeStates.CANCELED;
20
+ };
21
+ /**
22
+ * Check to see if the envelope has been completed.
23
+ */
24
+ export var envelopeIsComplete = function (envelope) { return envelope.status !== EnvelopeStates.COMPLETE; };
15
25
  /**
16
26
  * Check to see if the user owns the envelope.
17
27
  */
@@ -31,3 +41,37 @@ export var userCanFinishEnvelope = function (session, envelope) {
31
41
  envelope.status !== EnvelopeStates.DECLINED &&
32
42
  envelope.status !== EnvelopeStates.CANCELED;
33
43
  };
44
+ /**
45
+ * Returns true if the recipient has a pending action. Note that this does not necessarily mean the recipient can act (yet).
46
+ */
47
+ export var recipientHasAction = function (recipient) { return !['submitted', 'canceled', 'declined'].includes(recipient.status); };
48
+ /**
49
+ * Returns the recipients who still have a pending action. Note that not all of these recipients may be able to act (yet).
50
+ */
51
+ export var getRecipientsWithActions = function (envelope) { return ((envelope === null || envelope === void 0 ? void 0 : envelope.recipients) || []).filter(recipientHasAction); };
52
+ /**
53
+ * Returns true if the recipient can act.
54
+ */
55
+ export var recipientCanAct = function (recipient, recipientsWithActions) { var _a; return recipient.sequence === ((_a = recipientsWithActions === null || recipientsWithActions === void 0 ? void 0 : recipientsWithActions[0]) === null || _a === void 0 ? void 0 : _a.sequence); };
56
+ /**
57
+ * Returns true if the user can act.
58
+ */
59
+ export var userCanAct = function (email, recipientsWithActions) {
60
+ var _a;
61
+ var recipient = recipientsWithActions.find(function (r) { return r.email === email; });
62
+ return recipient && recipient.sequence === ((_a = recipientsWithActions === null || recipientsWithActions === void 0 ? void 0 : recipientsWithActions[0]) === null || _a === void 0 ? void 0 : _a.sequence);
63
+ };
64
+ /**
65
+ * Returns true if the user can act.
66
+ */
67
+ export var userCanSignNow = function (session, envelope) {
68
+ if (!session) {
69
+ return false;
70
+ }
71
+ var recipientsWithActions = getRecipientsWithActions(envelope);
72
+ var myRecipient = recipientsWithActions.find(function (r) { return r.profile_id === (session === null || session === void 0 ? void 0 : session.profile_id) || r.email === (session === null || session === void 0 ? void 0 : session.email); });
73
+ return (myRecipient &&
74
+ envelopeIsActive(envelope) &&
75
+ userIsEnvelopeRecipient(session, envelope) &&
76
+ recipientCanAct(myRecipient, recipientsWithActions));
77
+ };
@@ -1,4 +1,4 @@
1
- import { IEnvelope, IRecipient, IInPersonAccessKey } from './Types';
1
+ import { IEnvelope, IRecipient, IInPersonAccessKey, TAccessKey } from './Types';
2
2
  import { VerdocsEndpoint } from '../VerdocsEndpoint';
3
3
  export interface IUpdateRecipientSubmitParams {
4
4
  action: 'submit';
@@ -68,6 +68,12 @@ export interface ISignerTokenResponse {
68
68
  export declare const getSignerToken: (endpoint: VerdocsEndpoint, envelopeId: string, roleName: string) => Promise<ISignerTokenResponse>;
69
69
  export interface IInPersonLinkResponse {
70
70
  link: string;
71
+ envelope_id: string;
72
+ profile_id: string;
73
+ role_name: string;
74
+ access_key: string;
75
+ expiration_date: string;
76
+ type: TAccessKey;
71
77
  }
72
78
  /**
73
79
  * Get an in-person signing link.
@@ -15,6 +15,29 @@ export interface IInPersonAccessKey {
15
15
  first_used: string | null;
16
16
  last_used: string | null;
17
17
  }
18
+ export interface IEmailAccessKey {
19
+ id: string;
20
+ created_at: string;
21
+ recipient_name: string;
22
+ envelope_id: string;
23
+ type: 'email';
24
+ key: string;
25
+ expiration_date: string | null;
26
+ first_used: string | null;
27
+ last_used: string | null;
28
+ }
29
+ export interface ISMSAccessKey {
30
+ id: string;
31
+ created_at: string;
32
+ recipient_name: string;
33
+ envelope_id: string;
34
+ type: 'sms';
35
+ key: string;
36
+ expiration_date: string | null;
37
+ first_used: string | null;
38
+ last_used: string | null;
39
+ }
40
+ export type TAccessKey = IInPersonAccessKey | IEmailAccessKey | ISMSAccessKey;
18
41
  export declare enum RecipientActions {
19
42
  SUBMIT = "submit",
20
43
  DECLINE = "decline",
@@ -45,6 +45,10 @@ export interface IUserSession {
45
45
  */
46
46
  export type TSessionType = 'user' | 'signing';
47
47
  /**
48
- * An authenticated session within Verdocs, either for signing or regular user-based operations.
48
+ * Represents a possibly-authenticated session within Verdocs, either for signing or regular user-based operations.
49
49
  */
50
50
  export type TSession = IUserSession | ISigningSession | null;
51
+ /**
52
+ * An active authenticated session within Verdocs, either for signing or regular user-based operations.
53
+ */
54
+ export type TActiveSession = IUserSession | ISigningSession;
@@ -81,7 +81,7 @@ export var createTemplateDocument = function (endpoint, templateId, file, onUplo
81
81
  formData.append('document', file, file.name);
82
82
  return endpoint.api //
83
83
  .post("/templates/".concat(templateId, "/documents"), formData, {
84
- timeout: 60000,
84
+ timeout: 120000,
85
85
  onUploadProgress: function (event) {
86
86
  var total = event.total || 1;
87
87
  var loaded = event.loaded || 0;
@@ -82,11 +82,20 @@ export interface ITemplateCreateParams {
82
82
  sender?: TTemplateSender;
83
83
  /** Optional description for the template to help identify it. */
84
84
  description?: string;
85
- /** Optional list of roles to create. Documents are required if roles or fields will also be specified. */
86
- documents?: (IDocumentFromUri | IDocumentFromData)[];
87
- /** Optional list of roles to create. Documents are required if fields will also be specified. */
85
+ /**
86
+ * Optional list of roles to create. Documents are required if roles or fields will also be specified. Files may
87
+ * be attached via a number of methods (browser File object, remote URI reference, or Base64-encoded string) but
88
+ * all entries must of of the same type. If browser File objects are provided, the request will use a FORM POST
89
+ * call, otherwise it will use traditional XHR.
90
+ */
91
+ documents?: File[] | IDocumentFromUri[] | IDocumentFromData[];
92
+ /**
93
+ * Optional list of roles to create. Note that if roles are not included in the request, fields will be ignored.
94
+ */
88
95
  roles?: IRole[];
89
- /** Optional list of fields to create. Fields associated with roles or documents that do not exist will be ignored. */
96
+ /**
97
+ * Optional list of fields to create.
98
+ */
90
99
  fields?: ITemplateField[];
91
100
  }
92
101
  /**
@@ -98,7 +107,7 @@ export interface ITemplateCreateParams {
98
107
  * const newTemplate = await Templates.createTemplate((VerdocsEndpoint.getDefault(), {...});
99
108
  * ```
100
109
  */
101
- export declare const createTemplate: (endpoint: VerdocsEndpoint, params: ITemplateCreateParams) => Promise<ITemplate>;
110
+ export declare const createTemplate: (endpoint: VerdocsEndpoint, params: ITemplateCreateParams, onUploadProgress?: ((percent: number, loadedBytes: number, totalBytes: number) => void) | undefined) => Promise<ITemplate>;
102
111
  /**
103
112
  * Update a template.
104
113
  *
@@ -85,6 +85,15 @@ export var getTemplateOwnerInfo = function (endpoint, templateId) {
85
85
  .get("/templates/".concat(templateId))
86
86
  .then(function (r) { return r.data; });
87
87
  };
88
+ var ALLOWED_CREATE_FIELDS = [
89
+ 'name',
90
+ 'is_personal',
91
+ 'is_public',
92
+ 'sender',
93
+ 'description',
94
+ 'roles',
95
+ 'fields',
96
+ ];
88
97
  /**
89
98
  * Create a template.
90
99
  *
@@ -94,10 +103,33 @@ export var getTemplateOwnerInfo = function (endpoint, templateId) {
94
103
  * const newTemplate = await Templates.createTemplate((VerdocsEndpoint.getDefault(), {...});
95
104
  * ```
96
105
  */
97
- export var createTemplate = function (endpoint, params) {
98
- return endpoint.api //
99
- .post('/templates/', params)
100
- .then(function (r) { return r.data; });
106
+ export var createTemplate = function (endpoint, params, onUploadProgress) {
107
+ var options = {
108
+ timeout: 120000,
109
+ onUploadProgress: function (event) {
110
+ var total = event.total || 1;
111
+ var loaded = event.loaded || 0;
112
+ onUploadProgress === null || onUploadProgress === void 0 ? void 0 : onUploadProgress(Math.floor((loaded * 100) / (total || 1)), loaded, total || 1);
113
+ },
114
+ };
115
+ if (params.documents && params.documents[0] instanceof File) {
116
+ if (params.documents.length > 10) {
117
+ throw new Error('createTemplate() has a maximum of 10 documents that can be attached.');
118
+ }
119
+ var formData_1 = new FormData();
120
+ ALLOWED_CREATE_FIELDS.forEach(function (allowedKey) {
121
+ if (params[allowedKey] !== undefined) {
122
+ formData_1.append(allowedKey, params[allowedKey]);
123
+ }
124
+ });
125
+ params.documents.forEach(function (file) {
126
+ formData_1.append('documents', file, file.name);
127
+ });
128
+ return endpoint.api.post('/templates', formData_1, options).then(function (r) { return r.data; });
129
+ }
130
+ else {
131
+ return endpoint.api.post('/templates', params, options).then(function (r) { return r.data; });
132
+ }
101
133
  };
102
134
  /**
103
135
  * Update a template.
@@ -88,6 +88,7 @@ export interface ITemplate {
88
88
  roles?: IRole[];
89
89
  /**
90
90
  * Pages attached to the template. Note that this is all of the pages for all document attachments in sequential order.
91
+ * @deprecated. Use document page counts instead, and accessor functions that take page numbers rather than Page objects.
91
92
  */
92
93
  pages?: IPage[];
93
94
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@verdocs/js-sdk",
3
- "version": "3.3.4",
3
+ "version": "3.6.1",
4
4
  "private": false,
5
5
  "homepage": "https://github.com/Verdocs/js-sdk",
6
6
  "description": "Verdocs JS SDK",
@@ -35,7 +35,6 @@
35
35
  "lint": "tslint -p tsconfig.json",
36
36
  "docs-md": "typedoc --tsconfig ./tsconfig-typedoc.json",
37
37
  "docs-html": "typedoc --tsconfig ./tsconfig-typedoc.json --plugin none --out docs-html",
38
- "Xdocs-html": "typedoc --tsconfig ./tsconfig-typedoc.json --plugin ./typedoc-theme.tsx --out docs-html",
39
38
  "docs": "npm run docs-md && npm run docs-html",
40
39
  "clear-docs": "aws --profile=verdocs cloudfront create-invalidation --distribution-id E29UFGU4KEH1GQ --paths \"/*\"",
41
40
  "deploy-docs": "npm run docs && aws --profile=verdocs s3 sync --acl public-read --delete docs-html s3://verdocs-developers-js-sdk/ && yarn clear-docs",