@verdocs/js-sdk 3.3.4 → 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.
@@ -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,19 @@ 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.
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
+ */
88
94
  roles?: IRole[];
89
- /** Optional list of fields to create. Fields associated with roles or documents that do not exist will be ignored. */
95
+ /**
96
+ * Optional list of fields to create.
97
+ */
90
98
  fields?: ITemplateField[];
91
99
  }
92
100
  /**
@@ -98,7 +106,7 @@ export interface ITemplateCreateParams {
98
106
  * const newTemplate = await Templates.createTemplate((VerdocsEndpoint.getDefault(), {...});
99
107
  * ```
100
108
  */
101
- 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>;
102
110
  /**
103
111
  * Update a template.
104
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
  /**
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.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",