files.com 1.0.255 → 1.0.257
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +3 -0
- package/_VERSION +1 -1
- package/docs/models/File.md +1 -0
- package/docs/models/FileUploadPart.md +2 -0
- package/docs/models/InboxRecipient.md +0 -5
- package/lib/isomorphic/File.node.js +39 -9
- package/lib/models/File.js +303 -277
- package/lib/models/FileUploadPart.js +4 -0
- package/lib/models/InboxRecipient.js +22 -43
- package/package.json +1 -1
- package/src/isomorphic/File.node.js +14 -0
- package/src/models/File.js +15 -0
- package/src/models/FileUploadPart.js +3 -0
- package/src/models/InboxRecipient.js +0 -17
- package/test/src/index.js +34 -3
@@ -65,6 +65,10 @@ var FileUploadPart = /*#__PURE__*/(0, _createClass2.default)(function FileUpload
|
|
65
65
|
(0, _defineProperty2.default)(this, "getParallelParts", function () {
|
66
66
|
return _this.attributes.parallel_parts;
|
67
67
|
});
|
68
|
+
// boolean # If `true`, parts may be retried. If `false`, a part cannot be retried and the upload should be restarted.
|
69
|
+
(0, _defineProperty2.default)(this, "getRetryParts", function () {
|
70
|
+
return _this.attributes.retry_parts;
|
71
|
+
});
|
68
72
|
// object # Additional HTTP parameters to send with the upload
|
69
73
|
(0, _defineProperty2.default)(this, "getParameters", function () {
|
70
74
|
return _this.attributes.parameters;
|
@@ -66,13 +66,6 @@ var InboxRecipient = /*#__PURE__*/(0, _createClass2.default)(function InboxRecip
|
|
66
66
|
(0, _defineProperty2.default)(this, "setSentAt", function (value) {
|
67
67
|
_this.attributes.sent_at = value;
|
68
68
|
});
|
69
|
-
// int64 # User ID. Provide a value of `0` to operate the current session's user.
|
70
|
-
(0, _defineProperty2.default)(this, "getUserId", function () {
|
71
|
-
return _this.attributes.user_id;
|
72
|
-
});
|
73
|
-
(0, _defineProperty2.default)(this, "setUserId", function (value) {
|
74
|
-
_this.attributes.user_id = value;
|
75
|
-
});
|
76
69
|
// int64 # Inbox to share.
|
77
70
|
(0, _defineProperty2.default)(this, "getInboxId", function () {
|
78
71
|
return _this.attributes.inbox_id;
|
@@ -110,7 +103,6 @@ var InboxRecipient = /*#__PURE__*/(0, _createClass2.default)(function InboxRecip
|
|
110
103
|
this.options = _objectSpread({}, options);
|
111
104
|
});
|
112
105
|
// Parameters:
|
113
|
-
// user_id - int64 - User ID. Provide a value of `0` to operate the current session's user.
|
114
106
|
// cursor - string - Used for pagination. When a list request has more records available, cursors are provided in the response headers `X-Files-Cursor-Next` and `X-Files-Cursor-Prev`. Send one of those cursor value here to resume an existing list from the next available record. Note: many of our SDKs have iterator methods that will automatically handle cursor-based pagination.
|
115
107
|
// per_page - int64 - Number of records to show per page. (Max: 10,000, 1,000 or less is recommended).
|
116
108
|
// sort_by - object - If set, sort records by the specified field in either `asc` or `desc` direction (e.g. `sort_by[has_registrations]=desc`). Valid fields are `has_registrations`.
|
@@ -133,38 +125,32 @@ var InboxRecipient = /*#__PURE__*/(0, _createClass2.default)(function InboxRecip
|
|
133
125
|
}
|
134
126
|
throw new errors.MissingParameterError('Parameter missing: inbox_id');
|
135
127
|
case 4:
|
136
|
-
if (!(params['user_id'] && !(0, _utils.isInt)(params['user_id']))) {
|
137
|
-
_context.next = 6;
|
138
|
-
break;
|
139
|
-
}
|
140
|
-
throw new errors.InvalidParameterError("Bad parameter: user_id must be of type Int, received ".concat((0, _utils.getType)(params['user_id'])));
|
141
|
-
case 6:
|
142
128
|
if (!(params['cursor'] && !(0, _utils.isString)(params['cursor']))) {
|
143
|
-
_context.next =
|
129
|
+
_context.next = 6;
|
144
130
|
break;
|
145
131
|
}
|
146
132
|
throw new errors.InvalidParameterError("Bad parameter: cursor must be of type String, received ".concat((0, _utils.getType)(params['cursor'])));
|
147
|
-
case
|
133
|
+
case 6:
|
148
134
|
if (!(params['per_page'] && !(0, _utils.isInt)(params['per_page']))) {
|
149
|
-
_context.next =
|
135
|
+
_context.next = 8;
|
150
136
|
break;
|
151
137
|
}
|
152
138
|
throw new errors.InvalidParameterError("Bad parameter: per_page must be of type Int, received ".concat((0, _utils.getType)(params['per_page'])));
|
153
|
-
case
|
139
|
+
case 8:
|
154
140
|
if (!(params['inbox_id'] && !(0, _utils.isInt)(params['inbox_id']))) {
|
155
|
-
_context.next =
|
141
|
+
_context.next = 10;
|
156
142
|
break;
|
157
143
|
}
|
158
144
|
throw new errors.InvalidParameterError("Bad parameter: inbox_id must be of type Int, received ".concat((0, _utils.getType)(params['inbox_id'])));
|
159
|
-
case
|
160
|
-
_context.next =
|
145
|
+
case 10:
|
146
|
+
_context.next = 12;
|
161
147
|
return _Api.default.sendRequest("/inbox_recipients", 'GET', params, options);
|
162
|
-
case
|
148
|
+
case 12:
|
163
149
|
response = _context.sent;
|
164
150
|
return _context.abrupt("return", (response === null || response === void 0 ? void 0 : (_response$data = response.data) === null || _response$data === void 0 ? void 0 : _response$data.map(function (obj) {
|
165
151
|
return new InboxRecipient(obj, options);
|
166
152
|
})) || []);
|
167
|
-
case
|
153
|
+
case 14:
|
168
154
|
case "end":
|
169
155
|
return _context.stop();
|
170
156
|
}
|
@@ -176,7 +162,6 @@ var InboxRecipient = /*#__PURE__*/(0, _createClass2.default)(function InboxRecip
|
|
176
162
|
return InboxRecipient.list(params, options);
|
177
163
|
});
|
178
164
|
// Parameters:
|
179
|
-
// user_id - int64 - User ID. Provide a value of `0` to operate the current session's user.
|
180
165
|
// inbox_id (required) - int64 - Inbox to share.
|
181
166
|
// recipient (required) - string - Email address to share this inbox with.
|
182
167
|
// name - string - Name of recipient.
|
@@ -205,48 +190,42 @@ var InboxRecipient = /*#__PURE__*/(0, _createClass2.default)(function InboxRecip
|
|
205
190
|
}
|
206
191
|
throw new errors.MissingParameterError('Parameter missing: recipient');
|
207
192
|
case 6:
|
208
|
-
if (!(params['user_id'] && !(0, _utils.isInt)(params['user_id']))) {
|
209
|
-
_context2.next = 8;
|
210
|
-
break;
|
211
|
-
}
|
212
|
-
throw new errors.InvalidParameterError("Bad parameter: user_id must be of type Int, received ".concat((0, _utils.getType)(params['user_id'])));
|
213
|
-
case 8:
|
214
193
|
if (!(params['inbox_id'] && !(0, _utils.isInt)(params['inbox_id']))) {
|
215
|
-
_context2.next =
|
194
|
+
_context2.next = 8;
|
216
195
|
break;
|
217
196
|
}
|
218
197
|
throw new errors.InvalidParameterError("Bad parameter: inbox_id must be of type Int, received ".concat((0, _utils.getType)(params['inbox_id'])));
|
219
|
-
case
|
198
|
+
case 8:
|
220
199
|
if (!(params['recipient'] && !(0, _utils.isString)(params['recipient']))) {
|
221
|
-
_context2.next =
|
200
|
+
_context2.next = 10;
|
222
201
|
break;
|
223
202
|
}
|
224
203
|
throw new errors.InvalidParameterError("Bad parameter: recipient must be of type String, received ".concat((0, _utils.getType)(params['recipient'])));
|
225
|
-
case
|
204
|
+
case 10:
|
226
205
|
if (!(params['name'] && !(0, _utils.isString)(params['name']))) {
|
227
|
-
_context2.next =
|
206
|
+
_context2.next = 12;
|
228
207
|
break;
|
229
208
|
}
|
230
209
|
throw new errors.InvalidParameterError("Bad parameter: name must be of type String, received ".concat((0, _utils.getType)(params['name'])));
|
231
|
-
case
|
210
|
+
case 12:
|
232
211
|
if (!(params['company'] && !(0, _utils.isString)(params['company']))) {
|
233
|
-
_context2.next =
|
212
|
+
_context2.next = 14;
|
234
213
|
break;
|
235
214
|
}
|
236
215
|
throw new errors.InvalidParameterError("Bad parameter: company must be of type String, received ".concat((0, _utils.getType)(params['company'])));
|
237
|
-
case
|
216
|
+
case 14:
|
238
217
|
if (!(params['note'] && !(0, _utils.isString)(params['note']))) {
|
239
|
-
_context2.next =
|
218
|
+
_context2.next = 16;
|
240
219
|
break;
|
241
220
|
}
|
242
221
|
throw new errors.InvalidParameterError("Bad parameter: note must be of type String, received ".concat((0, _utils.getType)(params['note'])));
|
243
|
-
case
|
244
|
-
_context2.next =
|
222
|
+
case 16:
|
223
|
+
_context2.next = 18;
|
245
224
|
return _Api.default.sendRequest("/inbox_recipients", 'POST', params, options);
|
246
|
-
case
|
225
|
+
case 18:
|
247
226
|
response = _context2.sent;
|
248
227
|
return _context2.abrupt("return", new InboxRecipient(response === null || response === void 0 ? void 0 : response.data, options));
|
249
|
-
case
|
228
|
+
case 20:
|
250
229
|
case "end":
|
251
230
|
return _context2.stop();
|
252
231
|
}
|
package/package.json
CHANGED
@@ -21,6 +21,19 @@ const saveUrlToStream = async (url, stream) => new Promise((resolve, reject) =>
|
|
21
21
|
})
|
22
22
|
})
|
23
23
|
|
24
|
+
const saveUrlToString = async url => new Promise((resolve, reject) => {
|
25
|
+
const https = require('https')
|
26
|
+
|
27
|
+
https.get(url, response => {
|
28
|
+
const chunks = []
|
29
|
+
response.on('data', chunk => chunks.push(Buffer.from(chunk)))
|
30
|
+
response.on('end', () => resolve(Buffer.concat(chunks).toString('utf8')))
|
31
|
+
})
|
32
|
+
.on('error', error => {
|
33
|
+
reject(error)
|
34
|
+
})
|
35
|
+
})
|
36
|
+
|
24
37
|
const saveUrlToFile = async (url, destinationPath) => {
|
25
38
|
const stream = openDiskFileWriteStream(destinationPath)
|
26
39
|
await saveUrlToStream(url, stream)
|
@@ -32,4 +45,5 @@ export {
|
|
32
45
|
openDiskFileWriteStream,
|
33
46
|
saveUrlToFile,
|
34
47
|
saveUrlToStream,
|
48
|
+
saveUrlToString,
|
35
49
|
}
|
package/src/models/File.js
CHANGED
@@ -199,6 +199,21 @@ class File {
|
|
199
199
|
return saveUrlToStream(downloadUri, writableStream)
|
200
200
|
}
|
201
201
|
|
202
|
+
downloadToString = async () => {
|
203
|
+
if (isBrowser()) {
|
204
|
+
throw new errors.NotImplementedError('String downloads are only available in a NodeJS environment')
|
205
|
+
}
|
206
|
+
|
207
|
+
const downloadUri = this.getDownloadUri()
|
208
|
+
|
209
|
+
if (!downloadUri) {
|
210
|
+
throw new errors.EmptyPropertyError('Current object has no download URI')
|
211
|
+
}
|
212
|
+
|
213
|
+
const { saveUrlToString } = require('../isomorphic/File.node.js')
|
214
|
+
return saveUrlToString(downloadUri)
|
215
|
+
}
|
216
|
+
|
202
217
|
downloadToFile = async destinationPath => {
|
203
218
|
if (isBrowser()) {
|
204
219
|
throw new errors.NotImplementedError('Disk file downloads are only available in a NodeJS environment')
|
@@ -50,6 +50,9 @@ class FileUploadPart {
|
|
50
50
|
// boolean # If `true`, multiple parts may be uploaded in parallel. If `false`, be sure to only upload one part at a time, in order.
|
51
51
|
getParallelParts = () => this.attributes.parallel_parts
|
52
52
|
|
53
|
+
// boolean # If `true`, parts may be retried. If `false`, a part cannot be retried and the upload should be restarted.
|
54
|
+
getRetryParts = () => this.attributes.retry_parts
|
55
|
+
|
53
56
|
// object # Additional HTTP parameters to send with the upload
|
54
57
|
getParameters = () => this.attributes.parameters
|
55
58
|
|
@@ -58,13 +58,6 @@ class InboxRecipient {
|
|
58
58
|
this.attributes.sent_at = value
|
59
59
|
}
|
60
60
|
|
61
|
-
// int64 # User ID. Provide a value of `0` to operate the current session's user.
|
62
|
-
getUserId = () => this.attributes.user_id
|
63
|
-
|
64
|
-
setUserId = value => {
|
65
|
-
this.attributes.user_id = value
|
66
|
-
}
|
67
|
-
|
68
61
|
// int64 # Inbox to share.
|
69
62
|
getInboxId = () => this.attributes.inbox_id
|
70
63
|
|
@@ -91,7 +84,6 @@ class InboxRecipient {
|
|
91
84
|
}
|
92
85
|
|
93
86
|
// Parameters:
|
94
|
-
// user_id - int64 - User ID. Provide a value of `0` to operate the current session's user.
|
95
87
|
// cursor - string - Used for pagination. When a list request has more records available, cursors are provided in the response headers `X-Files-Cursor-Next` and `X-Files-Cursor-Prev`. Send one of those cursor value here to resume an existing list from the next available record. Note: many of our SDKs have iterator methods that will automatically handle cursor-based pagination.
|
96
88
|
// per_page - int64 - Number of records to show per page. (Max: 10,000, 1,000 or less is recommended).
|
97
89
|
// sort_by - object - If set, sort records by the specified field in either `asc` or `desc` direction (e.g. `sort_by[has_registrations]=desc`). Valid fields are `has_registrations`.
|
@@ -102,10 +94,6 @@ class InboxRecipient {
|
|
102
94
|
throw new errors.MissingParameterError('Parameter missing: inbox_id')
|
103
95
|
}
|
104
96
|
|
105
|
-
if (params['user_id'] && !isInt(params['user_id'])) {
|
106
|
-
throw new errors.InvalidParameterError(`Bad parameter: user_id must be of type Int, received ${getType(params['user_id'])}`)
|
107
|
-
}
|
108
|
-
|
109
97
|
if (params['cursor'] && !isString(params['cursor'])) {
|
110
98
|
throw new errors.InvalidParameterError(`Bad parameter: cursor must be of type String, received ${getType(params['cursor'])}`)
|
111
99
|
}
|
@@ -127,7 +115,6 @@ class InboxRecipient {
|
|
127
115
|
InboxRecipient.list(params, options)
|
128
116
|
|
129
117
|
// Parameters:
|
130
|
-
// user_id - int64 - User ID. Provide a value of `0` to operate the current session's user.
|
131
118
|
// inbox_id (required) - int64 - Inbox to share.
|
132
119
|
// recipient (required) - string - Email address to share this inbox with.
|
133
120
|
// name - string - Name of recipient.
|
@@ -143,10 +130,6 @@ class InboxRecipient {
|
|
143
130
|
throw new errors.MissingParameterError('Parameter missing: recipient')
|
144
131
|
}
|
145
132
|
|
146
|
-
if (params['user_id'] && !isInt(params['user_id'])) {
|
147
|
-
throw new errors.InvalidParameterError(`Bad parameter: user_id must be of type Int, received ${getType(params['user_id'])}`)
|
148
|
-
}
|
149
|
-
|
150
133
|
if (params['inbox_id'] && !isInt(params['inbox_id'])) {
|
151
134
|
throw new errors.InvalidParameterError(`Bad parameter: inbox_id must be of type Int, received ${getType(params['inbox_id'])}`)
|
152
135
|
}
|
package/test/src/index.js
CHANGED
@@ -64,7 +64,7 @@ const testSuite = async () => {
|
|
64
64
|
Logger.info('***** testFolderListAutoPagination() succeeded! *****')
|
65
65
|
}
|
66
66
|
|
67
|
-
const
|
67
|
+
const testUploadAndDownloadToFile = async () => {
|
68
68
|
const sourceFilePath = '../files.com-logo.png'
|
69
69
|
|
70
70
|
const displayName = `files.com-logo__${nonce}.png`
|
@@ -99,7 +99,37 @@ const testSuite = async () => {
|
|
99
99
|
|
100
100
|
await file.delete()
|
101
101
|
|
102
|
-
Logger.info('*****
|
102
|
+
Logger.info('***** testUploadAndDownloadToFile() succeeded! *****')
|
103
|
+
}
|
104
|
+
|
105
|
+
const testUploadAndDownloadToString = async () => {
|
106
|
+
const displayName = `test-text__${nonce}.txt`
|
107
|
+
const destinationPath = `${SDK_TEST_ROOT_FOLDER}/${displayName}`
|
108
|
+
|
109
|
+
const sourceFileContents = 'The quick brown fox jumped over the lazy dogs.'
|
110
|
+
const file = await File.uploadData(destinationPath, sourceFileContents)
|
111
|
+
|
112
|
+
assert(!!file.path)
|
113
|
+
assert(file.display_name === displayName)
|
114
|
+
|
115
|
+
const foundFile = await File.find(destinationPath)
|
116
|
+
|
117
|
+
assert(foundFile.path === destinationPath)
|
118
|
+
assert(foundFile.display_name === displayName)
|
119
|
+
assert(typeof foundFile.getDownloadUri() === 'undefined')
|
120
|
+
|
121
|
+
if (!isBrowser()) {
|
122
|
+
const downloadableFile = await foundFile.download()
|
123
|
+
assert(typeof downloadableFile.getDownloadUri() !== 'undefined')
|
124
|
+
|
125
|
+
const downloadedFileContents = await downloadableFile.downloadToString()
|
126
|
+
|
127
|
+
assert(sourceFileContents === downloadedFileContents)
|
128
|
+
}
|
129
|
+
|
130
|
+
await file.delete()
|
131
|
+
|
132
|
+
Logger.info('***** testUploadAndDownloadToString() succeeded! *****')
|
103
133
|
}
|
104
134
|
|
105
135
|
/* to run this test, put a file (or symlink) at huge-file.ext * /
|
@@ -200,7 +230,8 @@ const testSuite = async () => {
|
|
200
230
|
//
|
201
231
|
|
202
232
|
await testFolderListAutoPagination()
|
203
|
-
await
|
233
|
+
await testUploadAndDownloadToFile()
|
234
|
+
await testUploadAndDownloadToString()
|
204
235
|
// await testUploadHugeFile() // to run this test, put a file (or symlink) at huge-file.ext
|
205
236
|
await testSession()
|
206
237
|
await testFailure()
|