box-node-sdk 1.35.0 → 1.37.2
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.
- package/CHANGELOG.md +37 -2
- package/README.md +1 -1
- package/lib/api-request-manager.d.ts +38 -0
- package/lib/api-request-manager.js +48 -55
- package/lib/api-request-manager.js.map +1 -0
- package/lib/api-request.d.ts +141 -0
- package/lib/api-request.js +202 -281
- package/lib/api-request.js.map +1 -0
- package/lib/box-client.d.ts +269 -0
- package/lib/box-client.js +551 -713
- package/lib/box-client.js.map +1 -0
- package/lib/box-node-sdk.d.ts +216 -0
- package/lib/box-node-sdk.js +317 -352
- package/lib/box-node-sdk.js.map +1 -0
- package/lib/chunked-uploader.d.ts +129 -0
- package/lib/chunked-uploader.js +287 -358
- package/lib/chunked-uploader.js.map +1 -0
- package/lib/enterprise-event-stream.d.ts +82 -0
- package/lib/enterprise-event-stream.js +189 -203
- package/lib/enterprise-event-stream.js.map +1 -0
- package/lib/event-stream.d.ts +92 -0
- package/lib/event-stream.js +274 -302
- package/lib/event-stream.js.map +1 -0
- package/lib/managers/collaboration-allowlist.d.ts +137 -0
- package/lib/managers/collaboration-allowlist.js +200 -0
- package/lib/managers/collaboration-allowlist.js.map +1 -0
- package/lib/managers/collaboration-whitelist.d.ts +3 -0
- package/lib/managers/collaboration-whitelist.js +8 -222
- package/lib/managers/collaboration-whitelist.js.map +1 -0
- package/lib/managers/collaborations.d.ts +166 -0
- package/lib/managers/collaborations.js +225 -258
- package/lib/managers/collaborations.js.map +1 -0
- package/lib/managers/collections.d.ts +42 -0
- package/lib/managers/collections.js +45 -50
- package/lib/managers/collections.js.map +1 -0
- package/lib/managers/comments.d.ts +103 -0
- package/lib/managers/comments.js +158 -173
- package/lib/managers/comments.js.map +1 -0
- package/lib/managers/device-pins.d.ts +52 -0
- package/lib/managers/device-pins.js +75 -88
- package/lib/managers/device-pins.js.map +1 -0
- package/lib/managers/enterprise.d.ts +162 -0
- package/lib/managers/enterprise.js +168 -199
- package/lib/managers/enterprise.js.map +1 -0
- package/lib/managers/events.d.ts +177 -0
- package/lib/managers/events.js +230 -254
- package/lib/managers/events.js.map +1 -0
- package/lib/managers/files.d.ts +772 -0
- package/lib/managers/files.js +1400 -1602
- package/lib/managers/files.js.map +1 -0
- package/lib/managers/folders.d.ts +347 -0
- package/lib/managers/folders.js +551 -567
- package/lib/managers/folders.js.map +1 -0
- package/lib/managers/groups.d.ts +202 -0
- package/lib/managers/groups.js +238 -287
- package/lib/managers/groups.js.map +1 -0
- package/lib/managers/legal-hold-policies.d.ts +190 -0
- package/lib/managers/legal-hold-policies.js +228 -272
- package/lib/managers/legal-hold-policies.js.map +1 -0
- package/lib/managers/metadata.d.ts +228 -0
- package/lib/managers/metadata.js +265 -328
- package/lib/managers/metadata.js.map +1 -0
- package/lib/managers/recent-items.d.ts +38 -0
- package/lib/managers/recent-items.js +32 -39
- package/lib/managers/recent-items.js.map +1 -0
- package/lib/managers/retention-policies.d.ts +213 -0
- package/lib/managers/retention-policies.js +235 -281
- package/lib/managers/retention-policies.js.map +1 -0
- package/lib/managers/search.d.ts +82 -0
- package/lib/managers/search.js +68 -88
- package/lib/managers/search.js.map +1 -0
- package/lib/managers/shared-items.d.ts +33 -0
- package/lib/managers/shared-items.js +54 -62
- package/lib/managers/shared-items.js.map +1 -0
- package/lib/managers/storage-policies.d.ts +86 -0
- package/lib/managers/storage-policies.js +108 -142
- package/lib/managers/storage-policies.js.map +1 -0
- package/lib/managers/tasks.d.ts +161 -0
- package/lib/managers/tasks.js +219 -260
- package/lib/managers/tasks.js.map +1 -0
- package/lib/managers/terms-of-service.d.ts +161 -0
- package/lib/managers/terms-of-service.js +250 -273
- package/lib/managers/terms-of-service.js.map +1 -0
- package/lib/managers/trash.d.ts +30 -0
- package/lib/managers/trash.js +30 -41
- package/lib/managers/trash.js.map +1 -0
- package/lib/managers/users.d.ts +131 -0
- package/lib/managers/users.js +160 -203
- package/lib/managers/users.js.map +1 -0
- package/lib/managers/web-links.d.ts +127 -0
- package/lib/managers/web-links.js +183 -209
- package/lib/managers/web-links.js.map +1 -0
- package/lib/managers/webhooks.d.ts +166 -0
- package/lib/managers/webhooks.js +312 -305
- package/lib/managers/webhooks.js.map +1 -0
- package/lib/sessions/anonymous-session.d.ts +69 -0
- package/lib/sessions/anonymous-session.js +88 -102
- package/lib/sessions/anonymous-session.js.map +1 -0
- package/lib/sessions/app-auth-session.d.ts +92 -0
- package/lib/sessions/app-auth-session.js +140 -160
- package/lib/sessions/app-auth-session.js.map +1 -0
- package/lib/sessions/basic-session.d.ts +56 -0
- package/lib/sessions/basic-session.js +40 -50
- package/lib/sessions/basic-session.js.map +1 -0
- package/lib/sessions/persistent-session.d.ts +96 -0
- package/lib/sessions/persistent-session.js +191 -211
- package/lib/sessions/persistent-session.js.map +1 -0
- package/lib/token-manager.d.ts +191 -0
- package/lib/token-manager.js +390 -465
- package/lib/token-manager.js.map +1 -0
- package/lib/util/config.d.ts +86 -0
- package/lib/util/config.js +124 -152
- package/lib/util/config.js.map +1 -0
- package/lib/util/errors.d.ts +50 -0
- package/lib/util/errors.js +134 -145
- package/lib/util/errors.js.map +1 -0
- package/lib/util/exponential-backoff.d.ts +11 -0
- package/lib/util/exponential-backoff.js +10 -22
- package/lib/util/exponential-backoff.js.map +1 -0
- package/lib/util/paging-iterator.d.ts +53 -0
- package/lib/util/paging-iterator.js +202 -218
- package/lib/util/paging-iterator.js.map +1 -0
- package/lib/util/url-path.d.ts +16 -0
- package/lib/util/url-path.js +20 -35
- package/lib/util/url-path.js.map +1 -0
- package/package.json +24 -9
package/lib/managers/webhooks.js
CHANGED
|
@@ -1,34 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
/**
|
|
2
3
|
* @fileoverview Manager for the Box Webhooks resource
|
|
3
4
|
*/
|
|
4
|
-
|
|
5
|
-
|
|
5
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
6
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
7
|
+
};
|
|
8
|
+
// -----------------------------------------------------------------------------
|
|
9
|
+
// Requirements
|
|
10
|
+
// -----------------------------------------------------------------------------
|
|
11
|
+
var url_path_1 = __importDefault(require("../util/url-path"));
|
|
12
|
+
var crypto_1 = __importDefault(require("crypto"));
|
|
6
13
|
// -----------------------------------------------------------------------------
|
|
7
14
|
// Typedefs
|
|
8
15
|
// -----------------------------------------------------------------------------
|
|
9
|
-
|
|
10
16
|
/**
|
|
11
17
|
* A webhook trigger type constant
|
|
12
18
|
* @typedef {string} WebhookTriggerType
|
|
13
19
|
*/
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
var WebhookTriggerType;
|
|
21
|
+
(function (WebhookTriggerType) {
|
|
22
|
+
WebhookTriggerType["FILE_UPLOADED"] = "FILE.UPLOADED";
|
|
23
|
+
WebhookTriggerType["FILE_PREVIEWED"] = "FILE.PREVIEWED";
|
|
24
|
+
WebhookTriggerType["FILE_DOWNLOADED"] = "FILE.DOWNLOADED";
|
|
25
|
+
WebhookTriggerType["FILE_TRASHED"] = "FILE.TRASHED";
|
|
26
|
+
WebhookTriggerType["FILE_DELETED"] = "FILE.DELETED";
|
|
27
|
+
WebhookTriggerType["FILE_RESTORED"] = "FILE.RESTORED";
|
|
28
|
+
WebhookTriggerType["FILE_COPIED"] = "FILE.COPIED";
|
|
29
|
+
WebhookTriggerType["FILE_MOVED"] = "FILE.MOVED";
|
|
30
|
+
WebhookTriggerType["FILE_LOCKED"] = "FILE.LOCKED";
|
|
31
|
+
WebhookTriggerType["FILE_UNLOCKED"] = "FILE.UNLOCKED";
|
|
32
|
+
WebhookTriggerType["FILE_RENAMED"] = "FILE.RENAMED";
|
|
33
|
+
WebhookTriggerType["COMMENT_CREATED"] = "COMMENT.CREATED";
|
|
34
|
+
WebhookTriggerType["COMMENT_UPDATED"] = "COMMENT.UPDATED";
|
|
35
|
+
WebhookTriggerType["COMMENT_DELETED"] = "COMMENT.DELETED";
|
|
36
|
+
WebhookTriggerType["TASK_ASSIGNMENT_CREATED"] = "TASK_ASSIGNMENT.CREATED";
|
|
37
|
+
WebhookTriggerType["TASK_ASSIGNMENT_UPDATED"] = "TASK_ASSIGNMENT.UPDATED";
|
|
38
|
+
WebhookTriggerType["METADATA_INSTANCE_CREATED"] = "METADATA_INSTANCE.CREATED";
|
|
39
|
+
WebhookTriggerType["METADATA_INSTANCE_UPDATED"] = "METADATA_INSTANCE.UPDATED";
|
|
40
|
+
WebhookTriggerType["METADATA_INSTANCE_DELETED"] = "METADATA_INSTANCE.DELETED";
|
|
41
|
+
WebhookTriggerType["FOLDER_CREATED"] = "FOLDER.CREATED";
|
|
42
|
+
WebhookTriggerType["FOLDER_DOWNLOADED"] = "FOLDER.DOWNLOADED";
|
|
43
|
+
WebhookTriggerType["FOLDER_RESTORED"] = "FOLDER.RESTORED";
|
|
44
|
+
WebhookTriggerType["FOLDER_DELETED"] = "FOLDER.DELETED";
|
|
45
|
+
WebhookTriggerType["FOLDER_COPIED"] = "FOLDER.COPIED";
|
|
46
|
+
WebhookTriggerType["FOLDER_MOVED"] = "FOLDER.MOVED";
|
|
47
|
+
WebhookTriggerType["FOLDER_TRASHED"] = "FOLDER.TRASHED";
|
|
48
|
+
WebhookTriggerType["FOLDER_RENAMED"] = "FOLDER.RENAMED";
|
|
49
|
+
WebhookTriggerType["WEBHOOK_DELETED"] = "WEBHOOK.DELETED";
|
|
50
|
+
WebhookTriggerType["COLLABORATION_CREATED"] = "COLLABORATION.CREATED";
|
|
51
|
+
WebhookTriggerType["COLLABORATION_ACCEPTED"] = "COLLABORATION.ACCEPTED";
|
|
52
|
+
WebhookTriggerType["COLLABORATION_REJECTED"] = "COLLABORATION.REJECTED";
|
|
53
|
+
WebhookTriggerType["COLLABORATION_REMOVED"] = "COLLABORATION.REMOVED";
|
|
54
|
+
WebhookTriggerType["COLLABORATION_UPDATED"] = "COLLABORATION.UPDATED";
|
|
55
|
+
WebhookTriggerType["SHARED_LINK_DELETED"] = "SHARED_LINK.DELETED";
|
|
56
|
+
WebhookTriggerType["SHARED_LINK_CREATED"] = "SHARED_LINK.CREATED";
|
|
57
|
+
WebhookTriggerType["SHARED_LINK_UPDATED"] = "SHARED_LINK.UPDATED";
|
|
58
|
+
})(WebhookTriggerType || (WebhookTriggerType = {}));
|
|
22
59
|
// -----------------------------------------------------------------------------
|
|
23
60
|
// Private
|
|
24
61
|
// -----------------------------------------------------------------------------
|
|
25
|
-
|
|
26
62
|
// Base path for all webhooks endpoints
|
|
27
63
|
var BASE_PATH = '/webhooks';
|
|
28
|
-
|
|
29
64
|
// This prevents replay attacks
|
|
30
|
-
|
|
31
|
-
|
|
65
|
+
var MAX_MESSAGE_AGE = 10 * 60; // 10 minutes
|
|
32
66
|
/**
|
|
33
67
|
* Compute the message signature
|
|
34
68
|
* @see {@Link https://developer.box.com/en/guides/webhooks/handle/setup-signatures/}
|
|
@@ -40,56 +74,47 @@ const MAX_MESSAGE_AGE = 10 * 60; // 10 minutes
|
|
|
40
74
|
* @private
|
|
41
75
|
*/
|
|
42
76
|
function computeSignature(body, headers, signatureKey) {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
hmac.update(headers['box-delivery-timestamp']);
|
|
58
|
-
|
|
59
|
-
const signature = hmac.digest('base64');
|
|
60
|
-
|
|
61
|
-
return signature;
|
|
77
|
+
if (!signatureKey) {
|
|
78
|
+
return null;
|
|
79
|
+
}
|
|
80
|
+
if (headers['box-signature-version'] !== '1') {
|
|
81
|
+
return null;
|
|
82
|
+
}
|
|
83
|
+
if (headers['box-signature-algorithm'] !== 'HmacSHA256') {
|
|
84
|
+
return null;
|
|
85
|
+
}
|
|
86
|
+
var hmac = crypto_1.default.createHmac('sha256', signatureKey);
|
|
87
|
+
hmac.update(body);
|
|
88
|
+
hmac.update(headers['box-delivery-timestamp']);
|
|
89
|
+
var signature = hmac.digest('base64');
|
|
90
|
+
return signature;
|
|
62
91
|
}
|
|
63
|
-
|
|
64
92
|
/**
|
|
65
93
|
* Validate the message signature
|
|
66
94
|
* @see {@Link https://developer.box.com/en/guides/webhooks/handle/verify-signatures/}
|
|
67
95
|
*
|
|
68
96
|
* @param {string} body - The request body of the webhook message
|
|
69
97
|
* @param {Object} headers - The request headers of the webhook message
|
|
70
|
-
* @param {string} primarySignatureKey - The primary signature to verify the message with
|
|
98
|
+
* @param {string} [primarySignatureKey] - The primary signature to verify the message with
|
|
71
99
|
* @param {string} [secondarySignatureKey] - The secondary signature to verify the message with
|
|
72
100
|
* @returns {boolean} - True or false
|
|
73
101
|
* @private
|
|
74
102
|
*/
|
|
75
103
|
function validateSignature(body, headers, primarySignatureKey, secondarySignatureKey) {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
return false;
|
|
104
|
+
// Either the primary or secondary signature must match the corresponding signature from Box
|
|
105
|
+
// (The use of two signatures allows the signing keys to be rotated one at a time)
|
|
106
|
+
var primarySignature = computeSignature(body, headers, primarySignatureKey);
|
|
107
|
+
if (primarySignature &&
|
|
108
|
+
primarySignature === headers['box-signature-primary']) {
|
|
109
|
+
return true;
|
|
110
|
+
}
|
|
111
|
+
var secondarySignature = computeSignature(body, headers, secondarySignatureKey);
|
|
112
|
+
if (secondarySignature &&
|
|
113
|
+
secondarySignature === headers['box-signature-secondary']) {
|
|
114
|
+
return true;
|
|
115
|
+
}
|
|
116
|
+
return false;
|
|
91
117
|
}
|
|
92
|
-
|
|
93
118
|
/**
|
|
94
119
|
* Validate that the delivery timestamp is not too far in the past (to prevent replay attacks)
|
|
95
120
|
*
|
|
@@ -99,47 +124,198 @@ function validateSignature(body, headers, primarySignatureKey, secondarySignatur
|
|
|
99
124
|
* @private
|
|
100
125
|
*/
|
|
101
126
|
function validateDeliveryTimestamp(headers, maxMessageAge) {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
127
|
+
var deliveryTime = Date.parse(headers['box-delivery-timestamp']);
|
|
128
|
+
var currentTime = Date.now();
|
|
129
|
+
var messageAge = (currentTime - deliveryTime) / 1000;
|
|
130
|
+
if (messageAge > maxMessageAge) {
|
|
131
|
+
return false;
|
|
132
|
+
}
|
|
133
|
+
return true;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Stringify JSON with escaped multibyte Unicode characters to ensure computed signatures match PHP's default behavior
|
|
137
|
+
*
|
|
138
|
+
* @param {Object} body - The parsed JSON object
|
|
139
|
+
* @returns {string} - Stringified JSON with escaped multibyte Unicode characters
|
|
140
|
+
* @private
|
|
141
|
+
*/
|
|
142
|
+
function jsonStringifyWithEscapedUnicode(body) {
|
|
143
|
+
return JSON.stringify(body).replace(/[\u007f-\uffff]/g, function (char) { return "\\u" + ("0000" + char.charCodeAt(0).toString(16)).slice(-4); });
|
|
111
144
|
}
|
|
112
|
-
|
|
113
145
|
// -----------------------------------------------------------------------------
|
|
114
146
|
// Public
|
|
115
147
|
// -----------------------------------------------------------------------------
|
|
116
|
-
|
|
117
148
|
/**
|
|
118
149
|
* Simple manager for interacting with all 'Webhooks' endpoints and actions.
|
|
119
150
|
*
|
|
120
151
|
* @param {BoxClient} client The Box API Client that is responsible for making calls to the API
|
|
121
152
|
* @constructor
|
|
122
153
|
*/
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
/**
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
154
|
+
var Webhooks = /** @class */ (function () {
|
|
155
|
+
function Webhooks(client) {
|
|
156
|
+
// Attach the client, for making API calls
|
|
157
|
+
this.client = client;
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Sets primary and secondary signatures that are used to verify the Webhooks messages
|
|
161
|
+
*
|
|
162
|
+
* @param {string} primaryKey - The primary signature to verify the message with
|
|
163
|
+
* @param {string} [secondaryKey] - The secondary signature to verify the message with
|
|
164
|
+
* @returns {void}
|
|
165
|
+
*/
|
|
166
|
+
Webhooks.setSignatureKeys = function (primaryKey, secondaryKey) {
|
|
167
|
+
Webhooks.primarySignatureKey = primaryKey;
|
|
168
|
+
if (typeof secondaryKey === 'string') {
|
|
169
|
+
Webhooks.secondarySignatureKey = secondaryKey;
|
|
170
|
+
}
|
|
171
|
+
};
|
|
172
|
+
/**
|
|
173
|
+
* Validate a webhook message by verifying the signature and the delivery timestamp
|
|
174
|
+
*
|
|
175
|
+
* @param {string|Object} body - The request body of the webhook message
|
|
176
|
+
* @param {Object} headers - The request headers of the webhook message
|
|
177
|
+
* @param {string} [primaryKey] - The primary signature to verify the message with. If it is sent as a parameter,
|
|
178
|
+
it overrides the static variable primarySignatureKey
|
|
179
|
+
* @param {string} [secondaryKey] - The secondary signature to verify the message with. If it is sent as a parameter,
|
|
180
|
+
it overrides the static variable primarySignatureKey
|
|
181
|
+
* @param {int} [maxMessageAge] - The maximum message age (in seconds). Defaults to 10 minutes
|
|
182
|
+
* @returns {boolean} - True or false
|
|
183
|
+
*/
|
|
184
|
+
Webhooks.validateMessage = function (body, headers, primaryKey, secondaryKey, maxMessageAge) {
|
|
185
|
+
if (!primaryKey && Webhooks.primarySignatureKey) {
|
|
186
|
+
primaryKey = Webhooks.primarySignatureKey;
|
|
187
|
+
}
|
|
188
|
+
if (!secondaryKey && Webhooks.secondarySignatureKey) {
|
|
189
|
+
secondaryKey = Webhooks.secondarySignatureKey;
|
|
190
|
+
}
|
|
191
|
+
if (typeof maxMessageAge !== 'number') {
|
|
192
|
+
maxMessageAge = MAX_MESSAGE_AGE;
|
|
193
|
+
}
|
|
194
|
+
// For frameworks like Express that automatically parse JSON
|
|
195
|
+
// bodies into Objects, re-stringify for signature testing
|
|
196
|
+
if (typeof body === 'object') {
|
|
197
|
+
// Escape forward slashes to ensure a matching signature
|
|
198
|
+
body = jsonStringifyWithEscapedUnicode(body).replace(/\//g, '\\/');
|
|
199
|
+
}
|
|
200
|
+
if (!validateSignature(body, headers, primaryKey, secondaryKey)) {
|
|
201
|
+
return false;
|
|
202
|
+
}
|
|
203
|
+
if (!validateDeliveryTimestamp(headers, maxMessageAge)) {
|
|
204
|
+
return false;
|
|
205
|
+
}
|
|
206
|
+
return true;
|
|
207
|
+
};
|
|
208
|
+
/**
|
|
209
|
+
* Create a new webhook on a given Box object, specified by type and ID.
|
|
210
|
+
*
|
|
211
|
+
* API Endpoint: '/webhooks'
|
|
212
|
+
* Method: POST
|
|
213
|
+
*
|
|
214
|
+
* @param {string} targetID - Box ID of the item to create webhook on
|
|
215
|
+
* @param {ItemType} targetType - Type of item the webhook will be created on
|
|
216
|
+
* @param {string} notificationURL - The URL of your application where Box will notify you of events triggers
|
|
217
|
+
* @param {WebhookTriggerType[]} triggerTypes - Array of event types that trigger notification for the target
|
|
218
|
+
* @param {Function} [callback] - Passed the new webhook information if it was acquired successfully
|
|
219
|
+
* @returns {Promise<Object>} A promise resolving to the new webhook object
|
|
220
|
+
*/
|
|
221
|
+
Webhooks.prototype.create = function (targetID, targetType, notificationURL, triggerTypes, callback) {
|
|
222
|
+
var params = {
|
|
223
|
+
body: {
|
|
224
|
+
target: {
|
|
225
|
+
id: targetID,
|
|
226
|
+
type: targetType,
|
|
227
|
+
},
|
|
228
|
+
address: notificationURL,
|
|
229
|
+
triggers: triggerTypes,
|
|
230
|
+
},
|
|
231
|
+
};
|
|
232
|
+
var apiPath = url_path_1.default(BASE_PATH);
|
|
233
|
+
return this.client.wrapWithDefaultHandler(this.client.post)(apiPath, params, callback);
|
|
234
|
+
};
|
|
235
|
+
/**
|
|
236
|
+
* Returns a webhook object with the specified Webhook ID
|
|
237
|
+
*
|
|
238
|
+
* API Endpoint: '/webhooks/:webhookID'
|
|
239
|
+
* Method: GET
|
|
240
|
+
*
|
|
241
|
+
* @param {string} webhookID - ID of the webhook to retrieve
|
|
242
|
+
* @param {Object} [options] - Additional options for the request. Can be left null in most cases.
|
|
243
|
+
* @param {Function} [callback] - Passed the webhook information if it was acquired successfully
|
|
244
|
+
* @returns {Promise<Object>} A promise resolving to the webhook object
|
|
245
|
+
*/
|
|
246
|
+
Webhooks.prototype.get = function (webhookID, options, callback) {
|
|
247
|
+
var params = {
|
|
248
|
+
qs: options,
|
|
249
|
+
};
|
|
250
|
+
var apiPath = url_path_1.default(BASE_PATH, webhookID);
|
|
251
|
+
return this.client.wrapWithDefaultHandler(this.client.get)(apiPath, params, callback);
|
|
252
|
+
};
|
|
253
|
+
/**
|
|
254
|
+
* Get a list of webhooks that are active for the current application and user.
|
|
255
|
+
*
|
|
256
|
+
* API Endpoint: '/webhooks'
|
|
257
|
+
* Method: GET
|
|
258
|
+
*
|
|
259
|
+
* @param {Object} [options] - Additional options for the request. Can be left null in most cases.
|
|
260
|
+
* @param {int} [options.limit=100] - The number of webhooks to return
|
|
261
|
+
* @param {string} [options.marker] - Pagination marker
|
|
262
|
+
* @param {Function} [callback] - Passed the list of webhooks if successful, error otherwise
|
|
263
|
+
* @returns {Promise<Object>} A promise resolving to the collection of webhooks
|
|
264
|
+
*/
|
|
265
|
+
Webhooks.prototype.getAll = function (options, callback) {
|
|
266
|
+
var params = {
|
|
267
|
+
qs: options,
|
|
268
|
+
};
|
|
269
|
+
var apiPath = url_path_1.default(BASE_PATH);
|
|
270
|
+
return this.client.wrapWithDefaultHandler(this.client.get)(apiPath, params, callback);
|
|
271
|
+
};
|
|
272
|
+
/**
|
|
273
|
+
* Update a webhook
|
|
274
|
+
*
|
|
275
|
+
* API Endpoint: '/webhooks/:webhookID'
|
|
276
|
+
* Method: PUT
|
|
277
|
+
*
|
|
278
|
+
* @param {string} webhookID - The ID of the webhook to be updated
|
|
279
|
+
* @param {Object} updates - Webhook fields to update
|
|
280
|
+
* @param {string} [updates.address] - The new URL used by Box to send a notification when webhook is triggered
|
|
281
|
+
* @param {WebhookTriggerType[]} [updates.triggers] - The new events that triggers a notification
|
|
282
|
+
* @param {Function} [callback] - Passed the updated webhook information if successful, error otherwise
|
|
283
|
+
* @returns {Promise<Object>} A promise resolving to the updated webhook object
|
|
284
|
+
*/
|
|
285
|
+
Webhooks.prototype.update = function (webhookID, updates, callback) {
|
|
286
|
+
var apiPath = url_path_1.default(BASE_PATH, webhookID), params = {
|
|
287
|
+
body: updates,
|
|
288
|
+
};
|
|
289
|
+
return this.client.wrapWithDefaultHandler(this.client.put)(apiPath, params, callback);
|
|
290
|
+
};
|
|
291
|
+
/**
|
|
292
|
+
* Delete a specified webhook by ID
|
|
293
|
+
*
|
|
294
|
+
* API Endpoint: '/webhooks/:webhookID'
|
|
295
|
+
* Method: DELETE
|
|
296
|
+
*
|
|
297
|
+
* @param {string} webhookID - ID of webhook to be deleted
|
|
298
|
+
* @param {Function} [callback] - Empty response body passed if successful.
|
|
299
|
+
* @returns {Promise<void>} A promise resolving to nothing
|
|
300
|
+
*/
|
|
301
|
+
Webhooks.prototype.delete = function (webhookID, callback) {
|
|
302
|
+
var apiPath = url_path_1.default(BASE_PATH, webhookID);
|
|
303
|
+
return this.client.wrapWithDefaultHandler(this.client.del)(apiPath, null, callback);
|
|
304
|
+
};
|
|
305
|
+
/**
|
|
306
|
+
* Primary signature key to protect webhooks against attacks.
|
|
307
|
+
* @static
|
|
308
|
+
* @type {?string}
|
|
309
|
+
*/
|
|
310
|
+
Webhooks.primarySignatureKey = null;
|
|
311
|
+
/**
|
|
312
|
+
* Secondary signature key to protect webhooks against attacks.
|
|
313
|
+
* @static
|
|
314
|
+
* @type {?string}
|
|
315
|
+
*/
|
|
316
|
+
Webhooks.secondarySignatureKey = null;
|
|
317
|
+
return Webhooks;
|
|
318
|
+
}());
|
|
143
319
|
/**
|
|
144
320
|
* Enum of valid webhooks event triggers
|
|
145
321
|
*
|
|
@@ -147,228 +323,59 @@ Webhooks.secondarySignatureKey = null;
|
|
|
147
323
|
* @enum {WebhookTriggerType}
|
|
148
324
|
*/
|
|
149
325
|
Webhooks.prototype.triggerTypes = {
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
};
|
|
203
|
-
|
|
204
|
-
/**
|
|
205
|
-
* Create a new webhook on a given Box object, specified by type and ID.
|
|
206
|
-
*
|
|
207
|
-
* API Endpoint: '/webhooks'
|
|
208
|
-
* Method: POST
|
|
209
|
-
*
|
|
210
|
-
* @param {string} targetID - Box ID of the item to create webhook on
|
|
211
|
-
* @param {ItemType} targetType - Type of item the webhook will be created on
|
|
212
|
-
* @param {string} notificationURL - The URL of your application where Box will notify you of events triggers
|
|
213
|
-
* @param {WebhookTriggerType[]} triggerTypes - Array of event types that trigger notification for the target
|
|
214
|
-
* @param {Function} [callback] - Passed the new webhook information if it was acquired successfully
|
|
215
|
-
* @returns {Promise<Object>} A promise resolving to the new webhook object
|
|
216
|
-
*/
|
|
217
|
-
Webhooks.prototype.create = function(targetID, targetType, notificationURL, triggerTypes, callback) {
|
|
218
|
-
var params = {
|
|
219
|
-
body: {
|
|
220
|
-
target: {
|
|
221
|
-
id: targetID,
|
|
222
|
-
type: targetType
|
|
223
|
-
},
|
|
224
|
-
address: notificationURL,
|
|
225
|
-
triggers: triggerTypes
|
|
226
|
-
}
|
|
227
|
-
};
|
|
228
|
-
|
|
229
|
-
var apiPath = urlPath(BASE_PATH);
|
|
230
|
-
return this.client.wrapWithDefaultHandler(this.client.post)(apiPath, params, callback);
|
|
231
|
-
};
|
|
232
|
-
|
|
233
|
-
/**
|
|
234
|
-
* Returns a webhook object with the specified Webhook ID
|
|
235
|
-
*
|
|
236
|
-
* API Endpoint: '/webhooks/:webhookID'
|
|
237
|
-
* Method: GET
|
|
238
|
-
*
|
|
239
|
-
* @param {string} webhookID - ID of the webhook to retrieve
|
|
240
|
-
* @param {Object} [options] - Additional options for the request. Can be left null in most cases.
|
|
241
|
-
* @param {Function} [callback] - Passed the webhook information if it was acquired successfully
|
|
242
|
-
* @returns {Promise<Object>} A promise resolving to the webhook object
|
|
243
|
-
*/
|
|
244
|
-
Webhooks.prototype.get = function(webhookID, options, callback) {
|
|
245
|
-
var params = {
|
|
246
|
-
qs: options
|
|
247
|
-
};
|
|
248
|
-
|
|
249
|
-
var apiPath = urlPath(BASE_PATH, webhookID);
|
|
250
|
-
return this.client.wrapWithDefaultHandler(this.client.get)(apiPath, params, callback);
|
|
326
|
+
FILE: {
|
|
327
|
+
UPLOADED: WebhookTriggerType.FILE_UPLOADED,
|
|
328
|
+
PREVIEWED: WebhookTriggerType.FILE_PREVIEWED,
|
|
329
|
+
DOWNLOADED: WebhookTriggerType.FILE_DOWNLOADED,
|
|
330
|
+
TRASHED: WebhookTriggerType.FILE_TRASHED,
|
|
331
|
+
DELETED: WebhookTriggerType.FILE_DELETED,
|
|
332
|
+
RESTORED: WebhookTriggerType.FILE_RESTORED,
|
|
333
|
+
COPIED: WebhookTriggerType.FILE_COPIED,
|
|
334
|
+
MOVED: WebhookTriggerType.FILE_MOVED,
|
|
335
|
+
LOCKED: WebhookTriggerType.FILE_LOCKED,
|
|
336
|
+
UNLOCKED: WebhookTriggerType.FILE_UNLOCKED,
|
|
337
|
+
RENAMED: WebhookTriggerType.FILE_RENAMED,
|
|
338
|
+
},
|
|
339
|
+
COMMENT: {
|
|
340
|
+
CREATED: WebhookTriggerType.COMMENT_CREATED,
|
|
341
|
+
UPDATED: WebhookTriggerType.COMMENT_UPDATED,
|
|
342
|
+
DELETED: WebhookTriggerType.COMMENT_DELETED,
|
|
343
|
+
},
|
|
344
|
+
TASK_ASSIGNMENT: {
|
|
345
|
+
CREATED: WebhookTriggerType.TASK_ASSIGNMENT_CREATED,
|
|
346
|
+
UPDATED: WebhookTriggerType.TASK_ASSIGNMENT_UPDATED,
|
|
347
|
+
},
|
|
348
|
+
METADATA_INSTANCE: {
|
|
349
|
+
CREATED: WebhookTriggerType.METADATA_INSTANCE_CREATED,
|
|
350
|
+
UPDATED: WebhookTriggerType.METADATA_INSTANCE_UPDATED,
|
|
351
|
+
DELETED: WebhookTriggerType.METADATA_INSTANCE_DELETED,
|
|
352
|
+
},
|
|
353
|
+
FOLDER: {
|
|
354
|
+
CREATED: WebhookTriggerType.FOLDER_CREATED,
|
|
355
|
+
DOWNLOADED: WebhookTriggerType.FOLDER_DOWNLOADED,
|
|
356
|
+
RESTORED: WebhookTriggerType.FOLDER_RESTORED,
|
|
357
|
+
DELETED: WebhookTriggerType.FOLDER_DELETED,
|
|
358
|
+
COPIED: WebhookTriggerType.FOLDER_COPIED,
|
|
359
|
+
MOVED: WebhookTriggerType.FOLDER_MOVED,
|
|
360
|
+
TRASHED: WebhookTriggerType.FOLDER_TRASHED,
|
|
361
|
+
RENAMED: WebhookTriggerType.FOLDER_RENAMED,
|
|
362
|
+
},
|
|
363
|
+
WEBHOOK: {
|
|
364
|
+
DELETED: WebhookTriggerType.WEBHOOK_DELETED,
|
|
365
|
+
},
|
|
366
|
+
COLLABORATION: {
|
|
367
|
+
CREATED: WebhookTriggerType.COLLABORATION_CREATED,
|
|
368
|
+
ACCEPTED: WebhookTriggerType.COLLABORATION_ACCEPTED,
|
|
369
|
+
REJECTED: WebhookTriggerType.COLLABORATION_REJECTED,
|
|
370
|
+
REMOVED: WebhookTriggerType.COLLABORATION_REMOVED,
|
|
371
|
+
UPDATED: WebhookTriggerType.COLLABORATION_UPDATED,
|
|
372
|
+
},
|
|
373
|
+
SHARED_LINK: {
|
|
374
|
+
DELETED: WebhookTriggerType.SHARED_LINK_DELETED,
|
|
375
|
+
CREATED: WebhookTriggerType.SHARED_LINK_CREATED,
|
|
376
|
+
UPDATED: WebhookTriggerType.SHARED_LINK_UPDATED,
|
|
377
|
+
},
|
|
251
378
|
};
|
|
252
|
-
|
|
253
|
-
/**
|
|
254
|
-
* Get a list of webhooks that are active for the current application and user.
|
|
255
|
-
*
|
|
256
|
-
* API Endpoint: '/webhooks'
|
|
257
|
-
* Method: GET
|
|
258
|
-
*
|
|
259
|
-
* @param {Object} [options] - Additional options for the request. Can be left null in most cases.
|
|
260
|
-
* @param {int} [options.limit=100] - The number of webhooks to return
|
|
261
|
-
* @param {string} [options.marker] - Pagination marker
|
|
262
|
-
* @param {Function} [callback] - Passed the list of webhooks if successful, error otherwise
|
|
263
|
-
* @returns {Promise<Object>} A promise resolving to the collection of webhooks
|
|
264
|
-
*/
|
|
265
|
-
Webhooks.prototype.getAll = function(options, callback) {
|
|
266
|
-
var params = {
|
|
267
|
-
qs: options
|
|
268
|
-
};
|
|
269
|
-
|
|
270
|
-
var apiPath = urlPath(BASE_PATH);
|
|
271
|
-
return this.client.wrapWithDefaultHandler(this.client.get)(apiPath, params, callback);
|
|
272
|
-
};
|
|
273
|
-
|
|
274
|
-
/**
|
|
275
|
-
* Update a webhook
|
|
276
|
-
*
|
|
277
|
-
* API Endpoint: '/webhooks/:webhookID'
|
|
278
|
-
* Method: PUT
|
|
279
|
-
*
|
|
280
|
-
* @param {string} webhookID - The ID of the webhook to be updated
|
|
281
|
-
* @param {Object} updates - Webhook fields to update
|
|
282
|
-
* @param {string} [updates.address] - The new URL used by Box to send a notification when webhook is triggered
|
|
283
|
-
* @param {WebhookTriggerType[]} [updates.triggers] - The new events that triggers a notification
|
|
284
|
-
* @param {Function} [callback] - Passed the updated webhook information if successful, error otherwise
|
|
285
|
-
* @returns {Promise<Object>} A promise resolving to the updated webhook object
|
|
286
|
-
*/
|
|
287
|
-
Webhooks.prototype.update = function(webhookID, updates, callback) {
|
|
288
|
-
var apiPath = urlPath(BASE_PATH, webhookID),
|
|
289
|
-
params = {
|
|
290
|
-
body: updates
|
|
291
|
-
};
|
|
292
|
-
|
|
293
|
-
return this.client.wrapWithDefaultHandler(this.client.put)(apiPath, params, callback);
|
|
294
|
-
};
|
|
295
|
-
|
|
296
|
-
/**
|
|
297
|
-
* Delete a specified webhook by ID
|
|
298
|
-
*
|
|
299
|
-
* API Endpoint: '/webhooks/:webhookID'
|
|
300
|
-
* Method: DELETE
|
|
301
|
-
*
|
|
302
|
-
* @param {string} webhookID - ID of webhook to be deleted
|
|
303
|
-
* @param {Function} [callback] - Empty response body passed if successful.
|
|
304
|
-
* @returns {Promise<void>} A promise resolving to nothing
|
|
305
|
-
*/
|
|
306
|
-
Webhooks.prototype.delete = function(webhookID, callback) {
|
|
307
|
-
var apiPath = urlPath(BASE_PATH, webhookID);
|
|
308
|
-
return this.client.wrapWithDefaultHandler(this.client.del)(apiPath, null, callback);
|
|
309
|
-
};
|
|
310
|
-
|
|
311
|
-
/**
|
|
312
|
-
* Sets primary and secondary signatures that are used to verify the Webhooks messages
|
|
313
|
-
*
|
|
314
|
-
* @param {string} primaryKey - The primary signature to verify the message with
|
|
315
|
-
* @param {string} [secondaryKey] - The secondary signature to verify the message with
|
|
316
|
-
* @returns {void}
|
|
317
|
-
*/
|
|
318
|
-
Webhooks.setSignatureKeys = function(primaryKey, secondaryKey) {
|
|
319
|
-
Webhooks.primarySignatureKey = primaryKey;
|
|
320
|
-
|
|
321
|
-
if (typeof secondaryKey === 'string') {
|
|
322
|
-
Webhooks.secondarySignatureKey = secondaryKey;
|
|
323
|
-
}
|
|
324
|
-
};
|
|
325
|
-
|
|
326
|
-
/**
|
|
327
|
-
* Validate a webhook message by verifying the signature and the delivery timestamp
|
|
328
|
-
*
|
|
329
|
-
* @param {string|Object} body - The request body of the webhook message
|
|
330
|
-
* @param {Object} headers - The request headers of the webhook message
|
|
331
|
-
* @param {string} [primaryKey] - The primary signature to verify the message with. If it is sent as a parameter,
|
|
332
|
-
it overrides the static variable primarySignatureKey
|
|
333
|
-
* @param {string} [secondaryKey] - The secondary signature to verify the message with. If it is sent as a parameter,
|
|
334
|
-
it overrides the static variable primarySignatureKey
|
|
335
|
-
* @param {int} [maxMessageAge] - The maximum message age (in seconds). Defaults to 10 minutes
|
|
336
|
-
* @returns {boolean} - True or false
|
|
337
|
-
*/
|
|
338
|
-
Webhooks.validateMessage = function(body, headers, primaryKey, secondaryKey, maxMessageAge) {
|
|
339
|
-
if (!primaryKey && Webhooks.primarySignatureKey) {
|
|
340
|
-
primaryKey = Webhooks.primarySignatureKey;
|
|
341
|
-
}
|
|
342
|
-
|
|
343
|
-
if (!secondaryKey && Webhooks.secondarySignatureKey) {
|
|
344
|
-
secondaryKey = Webhooks.secondarySignatureKey;
|
|
345
|
-
}
|
|
346
|
-
|
|
347
|
-
if (typeof maxMessageAge !== 'number') {
|
|
348
|
-
maxMessageAge = MAX_MESSAGE_AGE;
|
|
349
|
-
}
|
|
350
|
-
|
|
351
|
-
// For frameworks like Express that automatically parse JSON
|
|
352
|
-
// bodies into Objects, re-stringify for signature testing
|
|
353
|
-
if (typeof body === 'object') {
|
|
354
|
-
body = JSON.stringify(body);
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
if (!validateSignature(body, headers, primaryKey, secondaryKey)) {
|
|
358
|
-
return false;
|
|
359
|
-
}
|
|
360
|
-
|
|
361
|
-
if (!validateDeliveryTimestamp(headers, maxMessageAge)) {
|
|
362
|
-
return false;
|
|
363
|
-
}
|
|
364
|
-
|
|
365
|
-
return true;
|
|
366
|
-
};
|
|
367
|
-
|
|
368
379
|
Webhooks.prototype.validateMessage = Webhooks.validateMessage;
|
|
369
|
-
|
|
370
|
-
/**
|
|
371
|
-
* @module box-node-sdk/lib/managers/webhooks
|
|
372
|
-
* @see {@Link Webhooks}
|
|
373
|
-
*/
|
|
374
380
|
module.exports = Webhooks;
|
|
381
|
+
//# sourceMappingURL=webhooks.js.map
|