@verdocs/js-sdk 3.3.2 → 3.6.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.
@@ -1,4 +1,4 @@
1
- import { IEnvelope, IEnvelopesSummary, IRecipient, IDocumentFieldSettings, IEnvelopeDocument } from './Types';
1
+ import { IEnvelope, IEnvelopesSummary, IRecipient, IEnvelopeDocument, IEnvelopeFieldSettings } from './Types';
2
2
  import { ICreateEnvelopeRole, IEnvelopesSearchResult, ISigningSessionRequest } from './Types';
3
3
  import { TEnvelopeUpdateResult, TEnvelopeStatus, TRecipientStatus } from './Types';
4
4
  import { VerdocsEndpoint } from '../VerdocsEndpoint';
@@ -167,17 +167,17 @@ export declare const getEnvelopeFile: (endpoint: VerdocsEndpoint, envelopeId: st
167
167
  /**
168
168
  * Update a Document field. Typically called during the signing process as a Recipient fills in fields.
169
169
  */
170
- export declare const updateEnvelopeField: (endpoint: VerdocsEndpoint, envelopeId: string, fieldName: string, value: any) => Promise<IDocumentFieldSettings>;
170
+ export declare const updateEnvelopeField: (endpoint: VerdocsEndpoint, envelopeId: string, fieldName: string, value: any) => Promise<IEnvelopeFieldSettings>;
171
171
  /**
172
172
  * Update a Document signature field. Signature fields are ID-driven. Call `Document.createSignature()` first to create a
173
173
  * signature for a Recipient, then call `Documents.updateDocumentFieldSignature()` to attach it to a field.
174
174
  */
175
- export declare const updateEnvelopeFieldSignature: (endpoint: VerdocsEndpoint, envelopeId: string, fieldName: string, signatureId: string) => Promise<IDocumentFieldSettings>;
175
+ export declare const updateEnvelopeFieldSignature: (endpoint: VerdocsEndpoint, envelopeId: string, fieldName: string, signatureId: string) => Promise<IEnvelopeFieldSettings>;
176
176
  /**
177
177
  * Update a Document signature field. Signature fields are ID-driven. Call `Document.createSignature()` first to create a
178
178
  * signature for a Recipient, then call `Documents.updateDocumentFieldSignature()` to attach it to a field.
179
179
  */
180
- export declare const updateEnvelopeFieldInitials: (endpoint: VerdocsEndpoint, envelopeId: string, fieldName: string, initialId: string) => Promise<IDocumentFieldSettings>;
180
+ export declare const updateEnvelopeFieldInitials: (endpoint: VerdocsEndpoint, envelopeId: string, fieldName: string, initialId: string) => Promise<IEnvelopeFieldSettings>;
181
181
  /**
182
182
  * Get the attached file for an attachment field (if any)
183
183
  */
@@ -134,7 +134,7 @@ export interface IRecipient {
134
134
  status: TRecipientStatus;
135
135
  type: TRecipientType;
136
136
  updated_at: string;
137
- fields?: IDocumentField[];
137
+ fields?: IEnvelopeField[];
138
138
  }
139
139
  export interface IEnvelopeDocument {
140
140
  id: string;
@@ -148,7 +148,7 @@ export interface IEnvelopeDocument {
148
148
  created_at: string;
149
149
  updated_at: string;
150
150
  }
151
- export interface IDocumentFieldOptions {
151
+ export interface IEnvelopeFieldOptions {
152
152
  /** The unique ID of the field */
153
153
  id: string;
154
154
  /** The X position of the field on the page. Self-placed fields will have an X value of 0. */
@@ -162,7 +162,7 @@ export interface IDocumentFieldOptions {
162
162
  /** The visible label for the field e.g. 'Not Applicable' */
163
163
  value: string;
164
164
  }
165
- export interface IDocumentFieldSettings {
165
+ export interface IEnvelopeFieldSettings {
166
166
  type?: string;
167
167
  x: number;
168
168
  y: number;
@@ -176,7 +176,7 @@ export interface IDocumentFieldSettings {
176
176
  alignment?: number;
177
177
  upperCase?: boolean;
178
178
  /** Dropdowns, checkboxes, radio groups */
179
- options?: IDocumentFieldOptions[];
179
+ options?: IEnvelopeFieldOptions[];
180
180
  /** Signatures and Initials, result will be "signed" */
181
181
  base64?: string;
182
182
  hash?: string;
@@ -202,9 +202,9 @@ export declare enum DocumentFieldTypes {
202
202
  PAYMENT = "payment"
203
203
  }
204
204
  export type TDocumentFieldType = `${DocumentFieldTypes}`;
205
- export interface IDocumentField {
205
+ export interface IEnvelopeField {
206
206
  /**
207
- * The ID of the document the field is for. For historical reasons, this is called `envelope_id` because documents
207
+ * The ID of the envelope the field is for. For historical reasons, this is called `envelope_id` because documents
208
208
  * were previously called envelopes.
209
209
  */
210
210
  envelope_id: string;
@@ -220,10 +220,26 @@ export interface IDocumentField {
220
220
  type: TDocumentFieldType;
221
221
  /** If true, the field will be required */
222
222
  required: boolean;
223
- settings?: IDocumentFieldSettings;
223
+ settings?: IEnvelopeFieldSettings;
224
224
  validator: string | null;
225
225
  /** Not sent by the server. Used in the UI to identify prepared fields. */
226
226
  prepared?: boolean;
227
+ /** If set, the tab index for the field. */
228
+ tabindex: number;
229
+ /** The X position of the field. */
230
+ x: number;
231
+ /** The Y position of the field. */
232
+ y: number;
233
+ /** The width of the field. */
234
+ width: number;
235
+ /** The height of the field. */
236
+ height: number;
237
+ /** The default value for the field. */
238
+ default?: string;
239
+ /** The placeholder to show in the field. */
240
+ placeholder?: string;
241
+ /** For fields that support grouping (radio buttons and check boxes) the value selected will be stored under this name. */
242
+ group?: string;
227
243
  }
228
244
  /**
229
245
  * An Envelope is a workflow wrapper that shepherds one or more Documents through the various recipients in a signing
@@ -255,7 +271,7 @@ export interface IEnvelope {
255
271
  document?: IEnvelopeDocument | null;
256
272
  /** Documents attached to this envelope */
257
273
  documents?: IEnvelopeDocument[] | null;
258
- fields?: IDocumentField[];
274
+ fields?: IEnvelopeField[];
259
275
  }
260
276
  export type TEnvelopeUpdateResult = Omit<IEnvelope, 'histories' | 'recipients' | 'certificate' | 'document' | 'fields' | 'profile'>;
261
277
  export interface IActivityEntry {
@@ -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;
@@ -4,7 +4,7 @@
4
4
  *
5
5
  * @module
6
6
  */
7
- import { ITemplate, ITemplateOwnerInfo, ITemplatesSearchResult, ITemplatesSummary, TTemplateSender } from './Types';
7
+ import { IRole, ITemplate, ITemplateField, ITemplateOwnerInfo, ITemplatesSearchResult, ITemplatesSummary, TTemplateSender } from './Types';
8
8
  import { VerdocsEndpoint } from '../VerdocsEndpoint';
9
9
  export interface IGetTemplatesParams {
10
10
  is_starred?: boolean;
@@ -44,12 +44,58 @@ export declare const getTemplate: (endpoint: VerdocsEndpoint, templateId: string
44
44
  * ```
45
45
  */
46
46
  export declare const getTemplateOwnerInfo: (endpoint: VerdocsEndpoint, templateId: string) => Promise<ITemplateOwnerInfo>;
47
+ /**
48
+ * Represents a document to be attached to a template via an externally-accessible URI. A copy of the document will be
49
+ * downloaded from the specified URI. Note that the URI will be accessed without headers or other authorization methods
50
+ * set, so the URI itself must encode any security tokens or keys required to access the file.
51
+ */
52
+ export interface IDocumentFromUri {
53
+ /** The URI to retrieve the file from. */
54
+ uri: string;
55
+ /** A name for the attachment. */
56
+ name: string;
57
+ }
58
+ /**
59
+ * Represents a document to be attached to a template via a Base64-encoded string attachment. This is the best option
60
+ * for maximum security but there is a 10MB size limit for the entire creation request. Requests attaching larger files
61
+ * should use `IDocumentFromUri` or add attachments via `createTemplateDocument` after creating the template.
62
+ */
63
+ export interface IDocumentFromData {
64
+ /** Base64-encoded file data. */
65
+ data: string;
66
+ /** A name for the attachment. */
67
+ name: string;
68
+ }
47
69
  export interface ITemplateCreateParams {
70
+ /** Name for the template to create. */
48
71
  name: string;
72
+ /**
73
+ * Optional (defaults to true). Personal templates are only visible to the owner. Non-personal templates are shared
74
+ * within the user's organization.
75
+ */
49
76
  is_personal?: boolean;
77
+ /**
78
+ * Optional (defaults to false). Public templates may be found (via search) and viewed by anyone.
79
+ */
50
80
  is_public?: boolean;
81
+ /** Optional (defaults to EVERYONE_AS_CREATOR). Who may create and send envelopes using this template. */
51
82
  sender?: TTemplateSender;
83
+ /** Optional description for the template to help identify it. */
52
84
  description?: string;
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.
89
+ */
90
+ documents?: File[] | IDocumentFromUri[] | IDocumentFromData[];
91
+ /**
92
+ * Optional list of roles to create. Note that if roles are not included in the request, fields will be ignored.
93
+ */
94
+ roles?: IRole[];
95
+ /**
96
+ * Optional list of fields to create.
97
+ */
98
+ fields?: ITemplateField[];
53
99
  }
54
100
  /**
55
101
  * Create a template.
@@ -60,7 +106,7 @@ export interface ITemplateCreateParams {
60
106
  * const newTemplate = await Templates.createTemplate((VerdocsEndpoint.getDefault(), {...});
61
107
  * ```
62
108
  */
63
- export declare const createTemplate: (endpoint: VerdocsEndpoint, params: ITemplateCreateParams) => Promise<ITemplate>;
109
+ export declare const createTemplate: (endpoint: VerdocsEndpoint, params: ITemplateCreateParams, onUploadProgress?: ((percent: number, loadedBytes: number, totalBytes: number) => void) | undefined) => Promise<ITemplate>;
64
110
  /**
65
111
  * Update a template.
66
112
  *
@@ -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
  /**
@@ -253,8 +254,14 @@ export interface ITemplateDocument {
253
254
  pages?: IPage[];
254
255
  }
255
256
  export interface ITemplateField {
257
+ /** The machine name of the field, e.g. `checkbox_groupP1-18` */
256
258
  name: string;
259
+ /** The ID of the role in the recipients list, e.g. `Recipient 2` */
257
260
  role_name: string;
261
+ /**
262
+ * The ID of the document the field is for. For historical reasons, this is called `envelope_id` because documents
263
+ * were previously called envelopes.
264
+ */
258
265
  template_id: string;
259
266
  type: TDocumentFieldType;
260
267
  required: boolean;
@@ -262,6 +269,22 @@ export interface ITemplateField {
262
269
  page_sequence: number;
263
270
  validator?: string;
264
271
  label?: string;
272
+ /** If set, the tab index for the field. */
273
+ tabindex: number;
274
+ /** The X position of the field. */
275
+ x: number;
276
+ /** The Y position of the field. */
277
+ y: number;
278
+ /** The width of the field. */
279
+ width: number;
280
+ /** The height of the field. */
281
+ height: number;
282
+ /** The default value for the field. */
283
+ default?: string;
284
+ /** The placeholder to show in the field. */
285
+ placeholder?: string;
286
+ /** For fields that support grouping (radio buttons and check boxes) the value selected will be stored under this name. */
287
+ group?: string;
265
288
  }
266
289
  export interface ITextFieldSetting {
267
290
  x: number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@verdocs/js-sdk",
3
- "version": "3.3.2",
3
+ "version": "3.6.0",
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",