files.com 1.1.18 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- package/.eslintrc.js +0 -3
- package/_VERSION +1 -1
- package/docs/Errors.md +1 -0
- package/lib/Api.js +1 -1
- package/lib/Errors.js +957 -933
- package/lib/Files.js +1 -1
- package/lib/models/ActionNotificationExport.js +25 -25
- package/lib/models/ActionNotificationExportResult.js +10 -10
- package/lib/models/ActionWebhookFailure.js +5 -9
- package/lib/models/ApiKey.js +62 -70
- package/lib/models/App.js +5 -5
- package/lib/models/As2IncomingMessage.js +7 -7
- package/lib/models/As2OutgoingMessage.js +7 -7
- package/lib/models/As2Partner.js +54 -58
- package/lib/models/As2Station.js +51 -55
- package/lib/models/Automation.js +102 -110
- package/lib/models/AutomationRun.js +13 -13
- package/lib/models/BandwidthSnapshot.js +5 -5
- package/lib/models/Behavior.js +77 -85
- package/lib/models/Bundle.js +102 -110
- package/lib/models/BundleDownload.js +9 -9
- package/lib/models/BundleNotification.js +37 -41
- package/lib/models/BundleRecipient.js +22 -22
- package/lib/models/BundleRegistration.js +7 -7
- package/lib/models/Clickwrap.js +52 -56
- package/lib/models/DnsRecord.js +5 -5
- package/lib/models/EmailIncomingMessage.js +5 -5
- package/lib/models/ExternalEvent.js +18 -18
- package/lib/models/File.js +89 -93
- package/lib/models/FileComment.js +41 -45
- package/lib/models/FileCommentReaction.js +15 -19
- package/lib/models/FileMigration.js +5 -5
- package/lib/models/Folder.js +24 -24
- package/lib/models/FormFieldSet.js +44 -48
- package/lib/models/GpgKey.js +53 -57
- package/lib/models/Group.js +51 -55
- package/lib/models/GroupUser.js +53 -57
- package/lib/models/History.js +72 -72
- package/lib/models/HistoryExport.js +51 -51
- package/lib/models/HistoryExportResult.js +10 -10
- package/lib/models/InboxRecipient.js +22 -22
- package/lib/models/InboxRegistration.js +7 -7
- package/lib/models/InboxUpload.js +9 -9
- package/lib/models/Invoice.js +12 -12
- package/lib/models/IpAddress.js +17 -17
- package/lib/models/Lock.js +27 -31
- package/lib/models/Message.js +60 -64
- package/lib/models/MessageComment.js +46 -50
- package/lib/models/MessageCommentReaction.js +27 -31
- package/lib/models/MessageReaction.js +27 -31
- package/lib/models/Notification.js +66 -70
- package/lib/models/Payment.js +12 -12
- package/lib/models/Permission.js +28 -32
- package/lib/models/Priority.js +9 -9
- package/lib/models/Project.js +39 -43
- package/lib/models/PublicKey.js +46 -50
- package/lib/models/RemoteBandwidthSnapshot.js +5 -5
- package/lib/models/RemoteServer.js +306 -310
- package/lib/models/Request.js +33 -37
- package/lib/models/Session.js +11 -15
- package/lib/models/SettingsChange.js +5 -5
- package/lib/models/SftpHostKey.js +40 -44
- package/lib/models/ShareGroup.js +50 -54
- package/lib/models/Site.js +138 -138
- package/lib/models/Snapshot.js +44 -48
- package/lib/models/SsoStrategy.js +15 -19
- package/lib/models/Style.js +17 -21
- package/lib/models/UsageDailySnapshot.js +5 -5
- package/lib/models/UsageSnapshot.js +5 -5
- package/lib/models/User.js +156 -172
- package/lib/models/UserCipherUse.js +7 -7
- package/lib/models/UserRequest.js +26 -30
- package/lib/models/WebhookTest.js +15 -15
- package/package.json +6 -2
- package/src/Api.js +2 -1
- package/src/Errors.js +189 -177
- package/src/Files.js +1 -1
- package/src/models/AccountLineItem.js +5 -2
- package/src/models/Action.js +5 -2
- package/src/models/ActionNotificationExport.js +36 -35
- package/src/models/ActionNotificationExportResult.js +15 -13
- package/src/models/ActionWebhookFailure.js +9 -8
- package/src/models/ApiKey.js +69 -72
- package/src/models/App.js +10 -8
- package/src/models/As2IncomingMessage.js +12 -10
- package/src/models/As2OutgoingMessage.js +12 -10
- package/src/models/As2Partner.js +61 -60
- package/src/models/As2Station.js +58 -57
- package/src/models/Auto.js +5 -2
- package/src/models/Automation.js +121 -110
- package/src/models/AutomationRun.js +18 -17
- package/src/models/BandwidthSnapshot.js +10 -8
- package/src/models/Behavior.js +85 -86
- package/src/models/Bundle.js +121 -110
- package/src/models/BundleDownload.js +14 -12
- package/src/models/BundleNotification.js +40 -43
- package/src/models/BundleRecipient.js +33 -32
- package/src/models/BundleRegistration.js +12 -10
- package/src/models/Clickwrap.js +60 -58
- package/src/models/DnsRecord.js +10 -8
- package/src/models/EmailIncomingMessage.js +10 -8
- package/src/models/Errors.js +5 -2
- package/src/models/ExternalEvent.js +29 -29
- package/src/models/File.js +116 -108
- package/src/models/FileAction.js +5 -2
- package/src/models/FileComment.js +45 -46
- package/src/models/FileCommentReaction.js +26 -26
- package/src/models/FileMigration.js +10 -8
- package/src/models/FileUploadPart.js +5 -2
- package/src/models/Folder.js +32 -29
- package/src/models/FormField.js +5 -2
- package/src/models/FormFieldSet.js +49 -50
- package/src/models/GpgKey.js +60 -59
- package/src/models/Group.js +58 -57
- package/src/models/GroupUser.js +60 -58
- package/src/models/History.js +77 -74
- package/src/models/HistoryExport.js +62 -61
- package/src/models/HistoryExportResult.js +15 -13
- package/src/models/Image.js +5 -2
- package/src/models/InboxRecipient.js +33 -32
- package/src/models/InboxRegistration.js +12 -10
- package/src/models/InboxUpload.js +14 -12
- package/src/models/Invoice.js +17 -14
- package/src/models/InvoiceLineItem.js +5 -2
- package/src/models/IpAddress.js +22 -20
- package/src/models/Lock.js +36 -36
- package/src/models/Message.js +66 -66
- package/src/models/MessageComment.js +50 -52
- package/src/models/MessageCommentReaction.js +38 -40
- package/src/models/MessageReaction.js +38 -40
- package/src/models/Notification.js +74 -72
- package/src/models/Payment.js +17 -14
- package/src/models/PaymentLineItem.js +5 -2
- package/src/models/Permission.js +39 -40
- package/src/models/Preview.js +5 -2
- package/src/models/Priority.js +14 -12
- package/src/models/Project.js +43 -45
- package/src/models/PublicIpAddress.js +5 -2
- package/src/models/PublicKey.js +50 -52
- package/src/models/RemoteBandwidthSnapshot.js +10 -8
- package/src/models/RemoteServer.js +380 -312
- package/src/models/RemoteServerConfigurationFile.js +5 -2
- package/src/models/Request.js +44 -46
- package/src/models/Session.js +22 -22
- package/src/models/SettingsChange.js +10 -8
- package/src/models/SftpHostKey.js +45 -46
- package/src/models/ShareGroup.js +56 -56
- package/src/models/ShareGroupMember.js +5 -2
- package/src/models/Site.js +143 -142
- package/src/models/Snapshot.js +50 -50
- package/src/models/SsoStrategy.js +20 -21
- package/src/models/Status.js +5 -2
- package/src/models/Style.js +22 -23
- package/src/models/UsageDailySnapshot.js +10 -8
- package/src/models/UsageSnapshot.js +10 -8
- package/src/models/User.js +185 -168
- package/src/models/UserCipherUse.js +12 -10
- package/src/models/UserRequest.js +37 -39
- package/src/models/WebhookTest.js +26 -24
- package/test/Api.test.js +163 -0
- package/test/{package.json → integration/package.json} +1 -1
- package/test/{src → integration/src}/index.js +1 -1
- package/test.sh +2 -1
- /package/test/{.babelrc → integration/.babelrc} +0 -0
- /package/test/{index.js → integration/index.js} +0 -0
@@ -1,7 +1,9 @@
|
|
1
1
|
/* eslint-disable no-unused-vars */
|
2
2
|
import Api from '../Api'
|
3
3
|
import * as errors from '../Errors'
|
4
|
-
import {
|
4
|
+
import {
|
5
|
+
getType, isArray, isInt, isObject, isString,
|
6
|
+
} from '../utils'
|
5
7
|
/* eslint-enable no-unused-vars */
|
6
8
|
|
7
9
|
/**
|
@@ -9,6 +11,7 @@ import { getType, isArray, isInt, isObject, isString } from '../utils'
|
|
9
11
|
*/
|
10
12
|
class UserCipherUse {
|
11
13
|
attributes = {}
|
14
|
+
|
12
15
|
options = {}
|
13
16
|
|
14
17
|
constructor(attributes = {}, options = {}) {
|
@@ -24,6 +27,7 @@ class UserCipherUse {
|
|
24
27
|
}
|
25
28
|
|
26
29
|
isLoaded = () => !!this.attributes.id
|
30
|
+
|
27
31
|
// int64 # UserCipherUse ID
|
28
32
|
getId = () => this.attributes.id
|
29
33
|
|
@@ -42,27 +46,25 @@ class UserCipherUse {
|
|
42
46
|
// int64 # ID of the user who performed this access
|
43
47
|
getUserId = () => this.attributes.user_id
|
44
48
|
|
45
|
-
|
46
49
|
// Parameters:
|
47
50
|
// user_id - int64 - User ID. Provide a value of `0` to operate the current session's user.
|
48
51
|
// 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.
|
49
52
|
// per_page - int64 - Number of records to show per page. (Max: 10,000, 1,000 or less is recommended).
|
50
53
|
static list = async (params = {}, options = {}) => {
|
51
|
-
if (params
|
52
|
-
throw new errors.InvalidParameterError(`Bad parameter: user_id must be of type Int, received ${getType(params
|
54
|
+
if (params.user_id && !isInt(params.user_id)) {
|
55
|
+
throw new errors.InvalidParameterError(`Bad parameter: user_id must be of type Int, received ${getType(params.user_id)}`)
|
53
56
|
}
|
54
57
|
|
55
|
-
if (params
|
56
|
-
throw new errors.InvalidParameterError(`Bad parameter: cursor must be of type String, received ${getType(params
|
58
|
+
if (params.cursor && !isString(params.cursor)) {
|
59
|
+
throw new errors.InvalidParameterError(`Bad parameter: cursor must be of type String, received ${getType(params.cursor)}`)
|
57
60
|
}
|
58
61
|
|
59
|
-
if (params
|
60
|
-
throw new errors.InvalidParameterError(`Bad parameter: per_page must be of type Int, received ${getType(params
|
62
|
+
if (params.per_page && !isInt(params.per_page)) {
|
63
|
+
throw new errors.InvalidParameterError(`Bad parameter: per_page must be of type Int, received ${getType(params.per_page)}`)
|
61
64
|
}
|
62
65
|
|
63
|
-
const response = await Api.sendRequest(
|
66
|
+
const response = await Api.sendRequest('/user_cipher_uses', 'GET', params, options)
|
64
67
|
|
65
|
-
|
66
68
|
return response?.data?.map(obj => new UserCipherUse(obj, options)) || []
|
67
69
|
}
|
68
70
|
|
@@ -1,7 +1,9 @@
|
|
1
1
|
/* eslint-disable no-unused-vars */
|
2
2
|
import Api from '../Api'
|
3
3
|
import * as errors from '../Errors'
|
4
|
-
import {
|
4
|
+
import {
|
5
|
+
getType, isArray, isInt, isObject, isString,
|
6
|
+
} from '../utils'
|
5
7
|
/* eslint-enable no-unused-vars */
|
6
8
|
|
7
9
|
/**
|
@@ -9,6 +11,7 @@ import { getType, isArray, isInt, isObject, isString } from '../utils'
|
|
9
11
|
*/
|
10
12
|
class UserRequest {
|
11
13
|
attributes = {}
|
14
|
+
|
12
15
|
options = {}
|
13
16
|
|
14
17
|
constructor(attributes = {}, options = {}) {
|
@@ -24,6 +27,7 @@ class UserRequest {
|
|
24
27
|
}
|
25
28
|
|
26
29
|
isLoaded = () => !!this.attributes.id
|
30
|
+
|
27
31
|
// int64 # ID
|
28
32
|
getId = () => this.attributes.id
|
29
33
|
|
@@ -52,7 +56,6 @@ class UserRequest {
|
|
52
56
|
this.attributes.details = value
|
53
57
|
}
|
54
58
|
|
55
|
-
|
56
59
|
delete = async (params = {}) => {
|
57
60
|
if (!this.attributes.id) {
|
58
61
|
throw new errors.EmptyPropertyError('Current object has no id')
|
@@ -63,51 +66,48 @@ class UserRequest {
|
|
63
66
|
}
|
64
67
|
|
65
68
|
params.id = this.attributes.id
|
66
|
-
if (params
|
67
|
-
throw new errors.InvalidParameterError(`Bad parameter: id must be of type Int, received ${getType(params
|
69
|
+
if (params.id && !isInt(params.id)) {
|
70
|
+
throw new errors.InvalidParameterError(`Bad parameter: id must be of type Int, received ${getType(params.id)}`)
|
68
71
|
}
|
69
72
|
|
70
|
-
if (!params
|
73
|
+
if (!params.id) {
|
71
74
|
if (this.attributes.id) {
|
72
|
-
params
|
75
|
+
params.id = this.id
|
73
76
|
} else {
|
74
77
|
throw new errors.MissingParameterError('Parameter missing: id')
|
75
78
|
}
|
76
79
|
}
|
77
80
|
|
78
|
-
|
79
|
-
|
80
|
-
return
|
81
|
+
await Api.sendRequest(`/user_requests/${encodeURIComponent(params.id)}`, 'DELETE', params, this.options)
|
81
82
|
}
|
82
83
|
|
83
84
|
destroy = (params = {}) =>
|
84
85
|
this.delete(params)
|
85
86
|
|
86
87
|
save = async () => {
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
88
|
+
if (this.attributes.id) {
|
89
|
+
throw new errors.NotImplementedError('The UserRequest object doesn\'t support updates.')
|
90
|
+
} else {
|
91
|
+
const newObject = await UserRequest.create(this.attributes, this.options)
|
92
|
+
this.attributes = { ...newObject.attributes }
|
93
|
+
return true
|
94
|
+
}
|
94
95
|
}
|
95
96
|
|
96
97
|
// Parameters:
|
97
98
|
// 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.
|
98
99
|
// per_page - int64 - Number of records to show per page. (Max: 10,000, 1,000 or less is recommended).
|
99
100
|
static list = async (params = {}, options = {}) => {
|
100
|
-
if (params
|
101
|
-
throw new errors.InvalidParameterError(`Bad parameter: cursor must be of type String, received ${getType(params
|
101
|
+
if (params.cursor && !isString(params.cursor)) {
|
102
|
+
throw new errors.InvalidParameterError(`Bad parameter: cursor must be of type String, received ${getType(params.cursor)}`)
|
102
103
|
}
|
103
104
|
|
104
|
-
if (params
|
105
|
-
throw new errors.InvalidParameterError(`Bad parameter: per_page must be of type Int, received ${getType(params
|
105
|
+
if (params.per_page && !isInt(params.per_page)) {
|
106
|
+
throw new errors.InvalidParameterError(`Bad parameter: per_page must be of type Int, received ${getType(params.per_page)}`)
|
106
107
|
}
|
107
108
|
|
108
|
-
const response = await Api.sendRequest(
|
109
|
+
const response = await Api.sendRequest('/user_requests', 'GET', params, options)
|
109
110
|
|
110
|
-
|
111
111
|
return response?.data?.map(obj => new UserRequest(obj, options)) || []
|
112
112
|
}
|
113
113
|
|
@@ -121,19 +121,18 @@ class UserRequest {
|
|
121
121
|
throw new errors.InvalidParameterError(`Bad parameter: params must be of type object, received ${getType(params)}`)
|
122
122
|
}
|
123
123
|
|
124
|
-
params
|
124
|
+
params.id = id
|
125
125
|
|
126
|
-
if (!params
|
126
|
+
if (!params.id) {
|
127
127
|
throw new errors.MissingParameterError('Parameter missing: id')
|
128
128
|
}
|
129
129
|
|
130
|
-
if (params
|
131
|
-
throw new errors.InvalidParameterError(`Bad parameter: id must be of type Int, received ${getType(params
|
130
|
+
if (params.id && !isInt(params.id)) {
|
131
|
+
throw new errors.InvalidParameterError(`Bad parameter: id must be of type Int, received ${getType(params.id)}`)
|
132
132
|
}
|
133
133
|
|
134
|
-
const response = await Api.sendRequest(`/user_requests/${encodeURIComponent(params
|
134
|
+
const response = await Api.sendRequest(`/user_requests/${encodeURIComponent(params.id)}`, 'GET', params, options)
|
135
135
|
|
136
|
-
|
137
136
|
return new UserRequest(response?.data, options)
|
138
137
|
}
|
139
138
|
|
@@ -145,33 +144,32 @@ class UserRequest {
|
|
145
144
|
// email (required) - string - Email of user requested
|
146
145
|
// details (required) - string - Details of the user request
|
147
146
|
static create = async (params = {}, options = {}) => {
|
148
|
-
if (!params
|
147
|
+
if (!params.name) {
|
149
148
|
throw new errors.MissingParameterError('Parameter missing: name')
|
150
149
|
}
|
151
150
|
|
152
|
-
if (!params
|
151
|
+
if (!params.email) {
|
153
152
|
throw new errors.MissingParameterError('Parameter missing: email')
|
154
153
|
}
|
155
154
|
|
156
|
-
if (!params
|
155
|
+
if (!params.details) {
|
157
156
|
throw new errors.MissingParameterError('Parameter missing: details')
|
158
157
|
}
|
159
158
|
|
160
|
-
if (params
|
161
|
-
throw new errors.InvalidParameterError(`Bad parameter: name must be of type String, received ${getType(params
|
159
|
+
if (params.name && !isString(params.name)) {
|
160
|
+
throw new errors.InvalidParameterError(`Bad parameter: name must be of type String, received ${getType(params.name)}`)
|
162
161
|
}
|
163
162
|
|
164
|
-
if (params
|
165
|
-
throw new errors.InvalidParameterError(`Bad parameter: email must be of type String, received ${getType(params
|
163
|
+
if (params.email && !isString(params.email)) {
|
164
|
+
throw new errors.InvalidParameterError(`Bad parameter: email must be of type String, received ${getType(params.email)}`)
|
166
165
|
}
|
167
166
|
|
168
|
-
if (params
|
169
|
-
throw new errors.InvalidParameterError(`Bad parameter: details must be of type String, received ${getType(params
|
167
|
+
if (params.details && !isString(params.details)) {
|
168
|
+
throw new errors.InvalidParameterError(`Bad parameter: details must be of type String, received ${getType(params.details)}`)
|
170
169
|
}
|
171
170
|
|
172
|
-
const response = await Api.sendRequest(
|
171
|
+
const response = await Api.sendRequest('/user_requests', 'POST', params, options)
|
173
172
|
|
174
|
-
|
175
173
|
return new UserRequest(response?.data, options)
|
176
174
|
}
|
177
175
|
}
|
@@ -1,7 +1,9 @@
|
|
1
1
|
/* eslint-disable no-unused-vars */
|
2
2
|
import Api from '../Api'
|
3
3
|
import * as errors from '../Errors'
|
4
|
-
import {
|
4
|
+
import {
|
5
|
+
getType, isArray, isInt, isObject, isString,
|
6
|
+
} from '../utils'
|
5
7
|
/* eslint-enable no-unused-vars */
|
6
8
|
|
7
9
|
/**
|
@@ -9,6 +11,7 @@ import { getType, isArray, isInt, isObject, isString } from '../utils'
|
|
9
11
|
*/
|
10
12
|
class WebhookTest {
|
11
13
|
attributes = {}
|
14
|
+
|
12
15
|
options = {}
|
13
16
|
|
14
17
|
constructor(attributes = {}, options = {}) {
|
@@ -24,6 +27,7 @@ class WebhookTest {
|
|
24
27
|
}
|
25
28
|
|
26
29
|
isLoaded = () => !!this.attributes.id
|
30
|
+
|
27
31
|
// int64 # Status HTTP code
|
28
32
|
getCode = () => this.attributes.code
|
29
33
|
|
@@ -129,15 +133,14 @@ class WebhookTest {
|
|
129
133
|
this.attributes.use_dedicated_ips = value
|
130
134
|
}
|
131
135
|
|
132
|
-
|
133
136
|
save = async () => {
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
137
|
+
if (this.attributes.id) {
|
138
|
+
throw new errors.NotImplementedError('The WebhookTest object doesn\'t support updates.')
|
139
|
+
} else {
|
140
|
+
const newObject = await WebhookTest.create(this.attributes, this.options)
|
141
|
+
this.attributes = { ...newObject.attributes }
|
142
|
+
return true
|
143
|
+
}
|
141
144
|
}
|
142
145
|
|
143
146
|
// Parameters:
|
@@ -152,37 +155,36 @@ class WebhookTest {
|
|
152
155
|
// action - string - action for test body
|
153
156
|
// use_dedicated_ips - boolean - Use dedicated IPs for sending the webhook?
|
154
157
|
static create = async (params = {}, options = {}) => {
|
155
|
-
if (!params
|
158
|
+
if (!params.url) {
|
156
159
|
throw new errors.MissingParameterError('Parameter missing: url')
|
157
160
|
}
|
158
161
|
|
159
|
-
if (params
|
160
|
-
throw new errors.InvalidParameterError(`Bad parameter: url must be of type String, received ${getType(params
|
162
|
+
if (params.url && !isString(params.url)) {
|
163
|
+
throw new errors.InvalidParameterError(`Bad parameter: url must be of type String, received ${getType(params.url)}`)
|
161
164
|
}
|
162
165
|
|
163
|
-
if (params
|
164
|
-
throw new errors.InvalidParameterError(`Bad parameter: method must be of type String, received ${getType(params
|
166
|
+
if (params.method && !isString(params.method)) {
|
167
|
+
throw new errors.InvalidParameterError(`Bad parameter: method must be of type String, received ${getType(params.method)}`)
|
165
168
|
}
|
166
169
|
|
167
|
-
if (params
|
168
|
-
throw new errors.InvalidParameterError(`Bad parameter: encoding must be of type String, received ${getType(params
|
170
|
+
if (params.encoding && !isString(params.encoding)) {
|
171
|
+
throw new errors.InvalidParameterError(`Bad parameter: encoding must be of type String, received ${getType(params.encoding)}`)
|
169
172
|
}
|
170
173
|
|
171
|
-
if (params
|
172
|
-
throw new errors.InvalidParameterError(`Bad parameter: raw_body must be of type String, received ${getType(params
|
174
|
+
if (params.raw_body && !isString(params.raw_body)) {
|
175
|
+
throw new errors.InvalidParameterError(`Bad parameter: raw_body must be of type String, received ${getType(params.raw_body)}`)
|
173
176
|
}
|
174
177
|
|
175
|
-
if (params
|
176
|
-
throw new errors.InvalidParameterError(`Bad parameter: file_form_field must be of type String, received ${getType(params
|
178
|
+
if (params.file_form_field && !isString(params.file_form_field)) {
|
179
|
+
throw new errors.InvalidParameterError(`Bad parameter: file_form_field must be of type String, received ${getType(params.file_form_field)}`)
|
177
180
|
}
|
178
181
|
|
179
|
-
if (params
|
180
|
-
throw new errors.InvalidParameterError(`Bad parameter: action must be of type String, received ${getType(params
|
182
|
+
if (params.action && !isString(params.action)) {
|
183
|
+
throw new errors.InvalidParameterError(`Bad parameter: action must be of type String, received ${getType(params.action)}`)
|
181
184
|
}
|
182
185
|
|
183
|
-
const response = await Api.sendRequest(
|
186
|
+
const response = await Api.sendRequest('/webhook_tests', 'POST', params, options)
|
184
187
|
|
185
|
-
|
186
188
|
return new WebhookTest(response?.data, options)
|
187
189
|
}
|
188
190
|
}
|
package/test/Api.test.js
ADDED
@@ -0,0 +1,163 @@
|
|
1
|
+
import nock from 'nock'
|
2
|
+
|
3
|
+
import {
|
4
|
+
FilesError,
|
5
|
+
NotAuthenticated_LockoutRegionMismatchError,
|
6
|
+
NotFound_FolderNotFoundError,
|
7
|
+
} from '../lib/Errors'
|
8
|
+
import Files from '../lib/Files'
|
9
|
+
import ApiKey from '../lib/models/ApiKey'
|
10
|
+
import Folder from '../lib/models/Folder'
|
11
|
+
|
12
|
+
const API_URL = 'http://example.test'
|
13
|
+
Files.setBaseUrl(API_URL)
|
14
|
+
Files.setApiKey('test-key')
|
15
|
+
|
16
|
+
describe('API client', () => {
|
17
|
+
it('lists API keys', () => {
|
18
|
+
const params = { user_id: 1 }
|
19
|
+
nock(API_URL)
|
20
|
+
.get('/api/rest/v1/api_keys')
|
21
|
+
.query(params)
|
22
|
+
.reply(200, [{
|
23
|
+
id: 1,
|
24
|
+
name: 'test1',
|
25
|
+
}, {
|
26
|
+
id: 2,
|
27
|
+
name: 'test2',
|
28
|
+
}])
|
29
|
+
|
30
|
+
return ApiKey.list(params)
|
31
|
+
.then(items => {
|
32
|
+
expect(items.length).toBe(2)
|
33
|
+
expect(items[0].name).toBe('test1')
|
34
|
+
expect(items[0].id).toBe(1)
|
35
|
+
expect(items[1].name).toBe('test2')
|
36
|
+
expect(items[1].id).toBe(2)
|
37
|
+
})
|
38
|
+
})
|
39
|
+
|
40
|
+
it('creates an API key', () => {
|
41
|
+
nock(API_URL)
|
42
|
+
.post('/api/rest/v1/api_keys')
|
43
|
+
.reply(201, {
|
44
|
+
id: 123,
|
45
|
+
name: 'testing',
|
46
|
+
})
|
47
|
+
|
48
|
+
return ApiKey.create({ name: 'testing' })
|
49
|
+
.then(apiKey => {
|
50
|
+
expect(apiKey.name).toBe('testing')
|
51
|
+
expect(apiKey.id).toBe(123)
|
52
|
+
})
|
53
|
+
})
|
54
|
+
|
55
|
+
it('updates an API key', () => {
|
56
|
+
nock(API_URL)
|
57
|
+
.patch('/api/rest/v1/api_keys/123', {
|
58
|
+
id: 123,
|
59
|
+
name: 'testing123',
|
60
|
+
})
|
61
|
+
.reply(200, {
|
62
|
+
id: 123,
|
63
|
+
name: 'testing123',
|
64
|
+
})
|
65
|
+
|
66
|
+
const apiKey = new ApiKey({ id: 123 })
|
67
|
+
apiKey.setName('testing123')
|
68
|
+
return apiKey.save()
|
69
|
+
.then(() => {
|
70
|
+
expect(apiKey.getName()).toBe('testing123')
|
71
|
+
expect(apiKey.getId()).toBe(123)
|
72
|
+
})
|
73
|
+
})
|
74
|
+
|
75
|
+
it('deletes an API key', () => {
|
76
|
+
nock(API_URL)
|
77
|
+
.delete('/api/rest/v1/api_keys/123')
|
78
|
+
.reply(204)
|
79
|
+
|
80
|
+
const apiKey = new ApiKey({ id: 123 })
|
81
|
+
return apiKey.delete()
|
82
|
+
})
|
83
|
+
|
84
|
+
it('handles empty response', () => {
|
85
|
+
const params = { user_id: 1 }
|
86
|
+
nock(API_URL)
|
87
|
+
.get('/api/rest/v1/api_keys')
|
88
|
+
.query(params)
|
89
|
+
.reply(200, [])
|
90
|
+
|
91
|
+
return ApiKey.list(params)
|
92
|
+
.then(items => {
|
93
|
+
expect(items.length).toBe(0)
|
94
|
+
})
|
95
|
+
})
|
96
|
+
|
97
|
+
it('handles not found', () => {
|
98
|
+
nock(API_URL)
|
99
|
+
.get('/api/rest/v1/folders/missing')
|
100
|
+
.query(true)
|
101
|
+
.reply(404, {
|
102
|
+
error: 'Folder missing not found.',
|
103
|
+
'http-code': 404,
|
104
|
+
title: 'Folder Not Found',
|
105
|
+
type: 'not-found/folder-not-found',
|
106
|
+
})
|
107
|
+
|
108
|
+
return Folder.listFor('missing')
|
109
|
+
.then(() => {
|
110
|
+
throw new Error('Missing folder did not throw an error')
|
111
|
+
})
|
112
|
+
.catch(error => {
|
113
|
+
expect(error).toBeInstanceOf(NotFound_FolderNotFoundError)
|
114
|
+
expect(error.error).toBe('Folder missing not found.')
|
115
|
+
expect(error.httpCode).toBe(404)
|
116
|
+
expect(error.title).toBe('Folder Not Found')
|
117
|
+
expect(error.type).toBe('not-found/folder-not-found')
|
118
|
+
})
|
119
|
+
})
|
120
|
+
|
121
|
+
it('handles bad gateway', () => {
|
122
|
+
nock(API_URL)
|
123
|
+
.get('/api/rest/v1/api_keys')
|
124
|
+
.reply(502, '<html><head><title>502 Bad Gateway</title></head><body><center><h1>502 Bad Gateway</h1></center><hr><center>files.com</center></body></html>')
|
125
|
+
|
126
|
+
return ApiKey.list()
|
127
|
+
.then(() => {
|
128
|
+
throw new Error('Missing folder did not throw an error')
|
129
|
+
})
|
130
|
+
.catch(error => {
|
131
|
+
expect(error).toBeInstanceOf(FilesError)
|
132
|
+
expect(error.code).toBe(502)
|
133
|
+
})
|
134
|
+
})
|
135
|
+
|
136
|
+
it('handles region mismatch', () => {
|
137
|
+
nock(API_URL)
|
138
|
+
.get('/api/rest/v1/folders/test')
|
139
|
+
.query(true)
|
140
|
+
.reply(401, {
|
141
|
+
data: {
|
142
|
+
host: 'test.host',
|
143
|
+
},
|
144
|
+
error: 'Your account must login using a different server, test.host.',
|
145
|
+
'http-code': 401,
|
146
|
+
title: 'Lockout Region Mismatch',
|
147
|
+
type: 'not-authenticated/lockout-region-mismatch',
|
148
|
+
})
|
149
|
+
|
150
|
+
return Folder.listFor('test')
|
151
|
+
.then(() => {
|
152
|
+
throw new Error('Missing folder did not throw an error')
|
153
|
+
})
|
154
|
+
.catch(error => {
|
155
|
+
expect(error).toBeInstanceOf(NotAuthenticated_LockoutRegionMismatchError)
|
156
|
+
expect(error.error).toBe('Your account must login using a different server, test.host.')
|
157
|
+
expect(error.httpCode).toBe(401)
|
158
|
+
expect(error.title).toBe('Lockout Region Mismatch')
|
159
|
+
expect(error.type).toBe('not-authenticated/lockout-region-mismatch')
|
160
|
+
expect(error.data.host).toBe('test.host')
|
161
|
+
})
|
162
|
+
})
|
163
|
+
})
|
@@ -71,7 +71,7 @@ const testSuite = async () => {
|
|
71
71
|
}
|
72
72
|
|
73
73
|
const testUploadAndDownloadToFile = async () => {
|
74
|
-
const sourceFilePath = '
|
74
|
+
const sourceFilePath = '../../files.com-logo.png'
|
75
75
|
|
76
76
|
const displayName = `files.com-logo__${nonce}.png`
|
77
77
|
const destinationPath = `${SDK_TEST_ROOT_FOLDER}/${displayName}`
|
package/test.sh
CHANGED
File without changes
|
File without changes
|