@prismatic-io/components-box 0.0.0-stage → 0.0.1
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/README.md +64 -2
- package/dist/icon.png +0 -0
- package/dist/index.js +259 -0
- package/npm-dist/icon.png +0 -0
- package/npm-dist/index.cjs +3688 -0
- package/npm-dist/index.d.cts +1343 -0
- package/package.json +50 -4
|
@@ -0,0 +1,3688 @@
|
|
|
1
|
+
let _prismatic_io_spectral = require("@prismatic-io/spectral");
|
|
2
|
+
let _prismatic_io_spectral_http = require("@prismatic-io/spectral/http");
|
|
3
|
+
let box_node_sdk = require("box-node-sdk");
|
|
4
|
+
let node_crypto = require("node:crypto");
|
|
5
|
+
let node_stream = require("node:stream");
|
|
6
|
+
//#region src/connections/apiKey.ts
|
|
7
|
+
const apiKey = (0, _prismatic_io_spectral.connection)({
|
|
8
|
+
key: "apiKey",
|
|
9
|
+
display: {
|
|
10
|
+
label: "Developer Token",
|
|
11
|
+
description: "Authenticate requests using a developer token."
|
|
12
|
+
},
|
|
13
|
+
inputs: { apiKey: {
|
|
14
|
+
label: "Developer Token",
|
|
15
|
+
placeholder: "Enter developer token",
|
|
16
|
+
type: "password",
|
|
17
|
+
required: true,
|
|
18
|
+
shown: true,
|
|
19
|
+
comments: "A short-lived developer token for testing purposes. Obtain from [Box Developer Console](https://app.box.com/developers/console).",
|
|
20
|
+
example: "ABCDEFGHIJKLMNOPQRSTUVWXYZ123456"
|
|
21
|
+
} }
|
|
22
|
+
});
|
|
23
|
+
//#endregion
|
|
24
|
+
//#region src/connections/oauth2.ts
|
|
25
|
+
const oauth2 = (0, _prismatic_io_spectral.oauth2Connection)({
|
|
26
|
+
oauth2Type: _prismatic_io_spectral.OAuth2Type.AuthorizationCode,
|
|
27
|
+
key: "oauth2",
|
|
28
|
+
display: {
|
|
29
|
+
label: "OAuth 2.0",
|
|
30
|
+
description: "Authenticate using OAuth 2.0."
|
|
31
|
+
},
|
|
32
|
+
inputs: {
|
|
33
|
+
authorizeUrl: {
|
|
34
|
+
label: "Authorize URL",
|
|
35
|
+
placeholder: "Enter authorization URL",
|
|
36
|
+
type: "string",
|
|
37
|
+
required: true,
|
|
38
|
+
shown: false,
|
|
39
|
+
comments: "The OAuth 2.0 Authorization URL for Box.",
|
|
40
|
+
default: "https://account.box.com/api/oauth2/authorize"
|
|
41
|
+
},
|
|
42
|
+
tokenUrl: {
|
|
43
|
+
label: "Token URL",
|
|
44
|
+
placeholder: "Enter token URL",
|
|
45
|
+
type: "string",
|
|
46
|
+
required: true,
|
|
47
|
+
shown: false,
|
|
48
|
+
comments: "The OAuth 2.0 Token URL for Box.",
|
|
49
|
+
default: "https://api.box.com/oauth2/token"
|
|
50
|
+
},
|
|
51
|
+
clientId: {
|
|
52
|
+
label: "Client ID",
|
|
53
|
+
placeholder: "Enter client ID",
|
|
54
|
+
type: "string",
|
|
55
|
+
required: true,
|
|
56
|
+
shown: true,
|
|
57
|
+
comments: "The OAuth 2.0 client ID from the Box app configuration. Obtain from [Box Developer Console](https://app.box.com/developers/console).",
|
|
58
|
+
example: "abc123def456ghi789jkl012mno345pq"
|
|
59
|
+
},
|
|
60
|
+
clientSecret: {
|
|
61
|
+
label: "Client Secret",
|
|
62
|
+
placeholder: "Enter client secret",
|
|
63
|
+
type: "password",
|
|
64
|
+
required: true,
|
|
65
|
+
shown: true,
|
|
66
|
+
comments: "The OAuth 2.0 client secret from the Box app configuration. Obtain from [Box Developer Console](https://app.box.com/developers/console)."
|
|
67
|
+
},
|
|
68
|
+
scopes: {
|
|
69
|
+
label: "Scopes",
|
|
70
|
+
placeholder: "Enter OAuth scopes",
|
|
71
|
+
type: "string",
|
|
72
|
+
required: false,
|
|
73
|
+
shown: true,
|
|
74
|
+
comments: "A space-delimited set of one or more scopes. Leave blank to use the app's configured default scopes. See [Box OAuth Scopes](https://developer.box.com/guides/api-calls/permissions-and-errors/scopes) for available options.",
|
|
75
|
+
default: "root_readwrite manage_webhook"
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
//#endregion
|
|
80
|
+
//#region src/connections/index.ts
|
|
81
|
+
var connections_default = [oauth2, apiKey];
|
|
82
|
+
//#endregion
|
|
83
|
+
//#region src/constants.ts
|
|
84
|
+
const BASE_URL = "https://api.box.com/2.0";
|
|
85
|
+
const API_ROOT_URL = "https://api.box.com";
|
|
86
|
+
const FOLDER_TYPE = "folder";
|
|
87
|
+
const FILE_TYPE = "file";
|
|
88
|
+
const MAX_PAGE_SIZE = 1e3;
|
|
89
|
+
const LOOK_BACK_DATE_PATTERN = /^(\d{4})-(\d{2})-(\d{2})$/;
|
|
90
|
+
const SHARED_LINK_FIELD = "shared_link";
|
|
91
|
+
const SHARED_ITEMS_PATH = "/shared_items";
|
|
92
|
+
const SHARED_LINK_PERMISSION_DOWNLOAD = "can_download";
|
|
93
|
+
const SHARED_LINK_PERMISSION_PREVIEW = "can_preview";
|
|
94
|
+
const BOX_SIGNATURE_PRIMARY_HEADER = "box-signature-primary";
|
|
95
|
+
const BOX_SIGNATURE_SECONDARY_HEADER = "box-signature-secondary";
|
|
96
|
+
//#endregion
|
|
97
|
+
//#region src/client.ts
|
|
98
|
+
const getAccessToken = ({ boxConnection }) => {
|
|
99
|
+
switch (boxConnection.key) {
|
|
100
|
+
case apiKey.key: {
|
|
101
|
+
const token = _prismatic_io_spectral.util.types.toString(boxConnection.fields.apiKey);
|
|
102
|
+
if (!token) throw new _prismatic_io_spectral.ConnectionError(boxConnection, "The Developer Token is empty. Provide a token on the connection.");
|
|
103
|
+
return token;
|
|
104
|
+
}
|
|
105
|
+
case oauth2.key: {
|
|
106
|
+
const token = _prismatic_io_spectral.util.types.toString(boxConnection?.token?.access_token);
|
|
107
|
+
if (!token) throw new _prismatic_io_spectral.ConnectionError(boxConnection, "The OAuth 2.0 connection has no access token. Reauthorize the connection.");
|
|
108
|
+
return token;
|
|
109
|
+
}
|
|
110
|
+
default: throw new _prismatic_io_spectral.ConnectionError(boxConnection, `Unsupported connection: ${boxConnection.key}`);
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
const createAuthorizedClient = (params) => {
|
|
114
|
+
return new box_node_sdk.BoxClient({ auth: new box_node_sdk.BoxDeveloperTokenAuth({ token: getAccessToken(params) }) });
|
|
115
|
+
};
|
|
116
|
+
const createBoxHttpClient = (connection, debug = false) => {
|
|
117
|
+
return (0, _prismatic_io_spectral_http.createClient)({
|
|
118
|
+
baseUrl: BASE_URL,
|
|
119
|
+
responseType: "json",
|
|
120
|
+
headers: {
|
|
121
|
+
Accept: "application/json",
|
|
122
|
+
Authorization: `Bearer ${getAccessToken({ boxConnection: connection })}`
|
|
123
|
+
},
|
|
124
|
+
debug
|
|
125
|
+
});
|
|
126
|
+
};
|
|
127
|
+
//#endregion
|
|
128
|
+
//#region src/examplePayloads/dataSources.ts
|
|
129
|
+
const selectContentExamplePayload = { result: [{
|
|
130
|
+
label: "Quarterly Reports (folder)",
|
|
131
|
+
key: "47892301654"
|
|
132
|
+
}, {
|
|
133
|
+
label: "invoice.pdf (file)",
|
|
134
|
+
key: "1234567890"
|
|
135
|
+
}] };
|
|
136
|
+
const selectWebhookExamplePayload = { result: [{
|
|
137
|
+
label: "https://example.com/webhook",
|
|
138
|
+
key: "1234"
|
|
139
|
+
}, {
|
|
140
|
+
label: "https://example.com/webhook-secondary",
|
|
141
|
+
key: "5678"
|
|
142
|
+
}] };
|
|
143
|
+
//#endregion
|
|
144
|
+
//#region src/examplePayloads/files.ts
|
|
145
|
+
const downloadFileExamplePayload = {
|
|
146
|
+
data: Buffer.from("example"),
|
|
147
|
+
contentType: "application/octet-stream"
|
|
148
|
+
};
|
|
149
|
+
const uploadFileExamplePayload = { data: {
|
|
150
|
+
total_count: 1,
|
|
151
|
+
entries: [{
|
|
152
|
+
id: "54321",
|
|
153
|
+
type: "file",
|
|
154
|
+
name: "report.pdf",
|
|
155
|
+
sha1: "85136c79cbf9fe36bb9d05d0639c70c265c18d37",
|
|
156
|
+
file_version: {
|
|
157
|
+
id: "12345",
|
|
158
|
+
type: "file_version",
|
|
159
|
+
sha1: "134b65991ed521fcfe4724b7d814ab8ded5185dc"
|
|
160
|
+
},
|
|
161
|
+
parent: {
|
|
162
|
+
id: "0",
|
|
163
|
+
type: "folder",
|
|
164
|
+
name: "All Files"
|
|
165
|
+
}
|
|
166
|
+
}]
|
|
167
|
+
} };
|
|
168
|
+
const getFileDownloadUrlExamplePayload = { data: "https://dl.boxcloud.com/d/1/b1!abc123-example-download-url/download" };
|
|
169
|
+
//#endregion
|
|
170
|
+
//#region src/examplePayloads/folders.ts
|
|
171
|
+
const listFolderWithPaginationExamplePayload = { data: {
|
|
172
|
+
entries: [{
|
|
173
|
+
id: "12345",
|
|
174
|
+
type: "folder",
|
|
175
|
+
name: "Contracts",
|
|
176
|
+
etag: "1",
|
|
177
|
+
sequence_id: "3"
|
|
178
|
+
}, {
|
|
179
|
+
id: "67890",
|
|
180
|
+
type: "file",
|
|
181
|
+
name: "contract.pdf",
|
|
182
|
+
etag: "1",
|
|
183
|
+
sequence_id: "3",
|
|
184
|
+
sha1: "85136c79cbf9fe36bb9d05d0639c70c265c18d37",
|
|
185
|
+
file_version: {
|
|
186
|
+
id: "12345",
|
|
187
|
+
type: "file_version",
|
|
188
|
+
sha1: "134b65991ed521fcfe4724b7d814ab8ded5185dc"
|
|
189
|
+
},
|
|
190
|
+
description: "Contract for Q1 renewal",
|
|
191
|
+
size: 629644,
|
|
192
|
+
created_at: "2012-12-12T10:53:43-08:00",
|
|
193
|
+
modified_at: "2012-12-12T10:53:43-08:00",
|
|
194
|
+
created_by: {
|
|
195
|
+
id: "11446498",
|
|
196
|
+
type: "user",
|
|
197
|
+
name: "Aaron Levie",
|
|
198
|
+
login: "ceo@example.com"
|
|
199
|
+
},
|
|
200
|
+
owned_by: {
|
|
201
|
+
id: "11446498",
|
|
202
|
+
type: "user",
|
|
203
|
+
name: "Aaron Levie",
|
|
204
|
+
login: "ceo@example.com"
|
|
205
|
+
},
|
|
206
|
+
item_status: "active"
|
|
207
|
+
}],
|
|
208
|
+
pagination: {
|
|
209
|
+
next_marker: "JV9IRGZmieiBasejOG9yDCRNgd2ymoZIbjsxbJMjIs3kioVii",
|
|
210
|
+
limit: 1e3
|
|
211
|
+
}
|
|
212
|
+
} };
|
|
213
|
+
const createFolderExamplePayload = { data: {
|
|
214
|
+
type: "folder",
|
|
215
|
+
id: "47892301654",
|
|
216
|
+
etag: "0",
|
|
217
|
+
sequence_id: "0",
|
|
218
|
+
name: "New Project Folder",
|
|
219
|
+
created_at: "2024-03-15T09:30:00-07:00",
|
|
220
|
+
modified_at: "2024-03-15T09:30:00-07:00",
|
|
221
|
+
description: "",
|
|
222
|
+
path_collection: {
|
|
223
|
+
total_count: 1,
|
|
224
|
+
entries: [{
|
|
225
|
+
id: "0",
|
|
226
|
+
type: "folder",
|
|
227
|
+
name: "All Files"
|
|
228
|
+
}]
|
|
229
|
+
},
|
|
230
|
+
created_by: {
|
|
231
|
+
id: "11446498",
|
|
232
|
+
type: "user",
|
|
233
|
+
name: "Aaron Levie",
|
|
234
|
+
login: "ceo@example.com"
|
|
235
|
+
},
|
|
236
|
+
owned_by: {
|
|
237
|
+
id: "11446498",
|
|
238
|
+
type: "user",
|
|
239
|
+
name: "Aaron Levie",
|
|
240
|
+
login: "ceo@example.com"
|
|
241
|
+
},
|
|
242
|
+
item_status: "active",
|
|
243
|
+
parent: {
|
|
244
|
+
id: "0",
|
|
245
|
+
type: "folder",
|
|
246
|
+
name: "All Files"
|
|
247
|
+
}
|
|
248
|
+
} };
|
|
249
|
+
//#endregion
|
|
250
|
+
//#region src/examplePayloads/objects.ts
|
|
251
|
+
const pathDetailsExamplePayload = { data: [{
|
|
252
|
+
id: "0",
|
|
253
|
+
type: "folder",
|
|
254
|
+
name: ""
|
|
255
|
+
}, {
|
|
256
|
+
id: "12345",
|
|
257
|
+
type: "file",
|
|
258
|
+
name: "Quarterly Report.pdf"
|
|
259
|
+
}] };
|
|
260
|
+
const moveObjectExamplePayload = { data: {
|
|
261
|
+
type: "folder",
|
|
262
|
+
id: "67890",
|
|
263
|
+
name: "Archive",
|
|
264
|
+
parent: {
|
|
265
|
+
id: "0",
|
|
266
|
+
type: "folder",
|
|
267
|
+
name: "All Files"
|
|
268
|
+
}
|
|
269
|
+
} };
|
|
270
|
+
const copyObjectExamplePayload = { data: {
|
|
271
|
+
type: "folder",
|
|
272
|
+
id: "98765",
|
|
273
|
+
name: "Documents Backup",
|
|
274
|
+
parent: {
|
|
275
|
+
id: "0",
|
|
276
|
+
type: "folder",
|
|
277
|
+
name: "All Files"
|
|
278
|
+
}
|
|
279
|
+
} };
|
|
280
|
+
const deleteObjectExamplePayload = { data: {} };
|
|
281
|
+
//#endregion
|
|
282
|
+
//#region src/examplePayloads/sharedLinks.ts
|
|
283
|
+
const findFileForSharedLinkExamplePayload = { data: {
|
|
284
|
+
type: "file",
|
|
285
|
+
id: "53286756412",
|
|
286
|
+
etag: "1",
|
|
287
|
+
sequence_id: "3",
|
|
288
|
+
name: "Contract_2024.pdf",
|
|
289
|
+
sha1: "85136c79cbf9fe36bb9d05d0639c70c265c18d37",
|
|
290
|
+
description: "Contract for Q1 renewal",
|
|
291
|
+
size: 629644,
|
|
292
|
+
created_at: "2012-12-12T10:53:43-08:00",
|
|
293
|
+
modified_at: "2012-12-12T10:53:43-08:00",
|
|
294
|
+
created_by: {
|
|
295
|
+
id: "11446498",
|
|
296
|
+
type: "user",
|
|
297
|
+
name: "Aaron Levie",
|
|
298
|
+
login: "ceo@example.com"
|
|
299
|
+
},
|
|
300
|
+
owned_by: {
|
|
301
|
+
id: "11446498",
|
|
302
|
+
type: "user",
|
|
303
|
+
name: "Aaron Levie",
|
|
304
|
+
login: "ceo@example.com"
|
|
305
|
+
},
|
|
306
|
+
item_status: "active",
|
|
307
|
+
shared_link: {
|
|
308
|
+
url: "https://app.box.com/s/abbvr71aw8a4gb7u2541hlv45l806u5h",
|
|
309
|
+
download_url: "https://app.box.com/shared/static/abbvr71aw8a4gb7u2541hlv45l806u5h.pdf",
|
|
310
|
+
access: "open",
|
|
311
|
+
effective_access: "company",
|
|
312
|
+
effective_permission: "can_download",
|
|
313
|
+
is_password_enabled: true,
|
|
314
|
+
permissions: {
|
|
315
|
+
can_download: true,
|
|
316
|
+
can_preview: true,
|
|
317
|
+
can_edit: false
|
|
318
|
+
},
|
|
319
|
+
download_count: 3,
|
|
320
|
+
preview_count: 3
|
|
321
|
+
}
|
|
322
|
+
} };
|
|
323
|
+
const getSharedLinkForFileExamplePayload = { data: { sharedLink: "https://app.box.com/s/abbvr71aw8a4gb7u2541hlv45l806u5h" } };
|
|
324
|
+
const findFolderForSharedLinkExamplePayload = { data: {
|
|
325
|
+
type: "folder",
|
|
326
|
+
id: "84759261038",
|
|
327
|
+
etag: "1",
|
|
328
|
+
sequence_id: "3",
|
|
329
|
+
name: "Shared Documents",
|
|
330
|
+
description: "Documents shared with partners",
|
|
331
|
+
created_at: "2012-12-12T10:53:43-08:00",
|
|
332
|
+
modified_at: "2012-12-12T10:53:43-08:00",
|
|
333
|
+
created_by: {
|
|
334
|
+
id: "11446498",
|
|
335
|
+
type: "user",
|
|
336
|
+
name: "Aaron Levie",
|
|
337
|
+
login: "ceo@example.com"
|
|
338
|
+
},
|
|
339
|
+
owned_by: {
|
|
340
|
+
id: "11446498",
|
|
341
|
+
type: "user",
|
|
342
|
+
name: "Aaron Levie",
|
|
343
|
+
login: "ceo@example.com"
|
|
344
|
+
},
|
|
345
|
+
item_status: "active",
|
|
346
|
+
shared_link: {
|
|
347
|
+
url: "https://app.box.com/s/9f2a1c7be4d84e0fa1b2c3d4e5f60718",
|
|
348
|
+
download_url: null,
|
|
349
|
+
access: "open",
|
|
350
|
+
effective_access: "company",
|
|
351
|
+
effective_permission: "can_download",
|
|
352
|
+
is_password_enabled: true,
|
|
353
|
+
permissions: {
|
|
354
|
+
can_download: true,
|
|
355
|
+
can_preview: true,
|
|
356
|
+
can_edit: false
|
|
357
|
+
},
|
|
358
|
+
download_count: 3,
|
|
359
|
+
preview_count: 3
|
|
360
|
+
}
|
|
361
|
+
} };
|
|
362
|
+
const getSharedLinkForFolderExamplePayload = { data: { sharedLink: "https://app.box.com/s/abbvr71aw8a4gb7u2541hlv45l806u5h" } };
|
|
363
|
+
const addSharedLinkToFileExamplePayload = { data: {
|
|
364
|
+
type: "file",
|
|
365
|
+
id: "53286756412",
|
|
366
|
+
etag: "1",
|
|
367
|
+
sequence_id: "3",
|
|
368
|
+
name: "Contract_2024.pdf",
|
|
369
|
+
sha1: "85136c79cbf9fe36bb9d05d0639c70c265c18d37",
|
|
370
|
+
file_version: {
|
|
371
|
+
id: "12345",
|
|
372
|
+
type: "file_version",
|
|
373
|
+
sha1: "134b65991ed521fcfe4724b7d814ab8ded5185dc"
|
|
374
|
+
},
|
|
375
|
+
shared_link: {
|
|
376
|
+
url: "https://app.box.com/s/abbvr71aw8a4gb7u2541hlv45l806u5h",
|
|
377
|
+
download_url: "https://app.box.com/shared/static/abbvr71aw8a4gb7u2541hlv45l806u5h.pdf",
|
|
378
|
+
vanity_url: null,
|
|
379
|
+
effective_access: "open",
|
|
380
|
+
effective_permission: "can_download",
|
|
381
|
+
is_password_enabled: false,
|
|
382
|
+
access: "open",
|
|
383
|
+
permissions: {
|
|
384
|
+
can_download: true,
|
|
385
|
+
can_preview: true,
|
|
386
|
+
can_edit: false
|
|
387
|
+
},
|
|
388
|
+
download_count: 0,
|
|
389
|
+
preview_count: 0
|
|
390
|
+
}
|
|
391
|
+
} };
|
|
392
|
+
const updateSharedLinkToFileExamplePayload = { data: {
|
|
393
|
+
type: "file",
|
|
394
|
+
id: "53286756412",
|
|
395
|
+
etag: "1",
|
|
396
|
+
sequence_id: "3",
|
|
397
|
+
name: "Contract_2024.pdf",
|
|
398
|
+
sha1: "85136c79cbf9fe36bb9d05d0639c70c265c18d37",
|
|
399
|
+
file_version: {
|
|
400
|
+
id: "12345",
|
|
401
|
+
type: "file_version",
|
|
402
|
+
sha1: "134b65991ed521fcfe4724b7d814ab8ded5185dc"
|
|
403
|
+
},
|
|
404
|
+
shared_link: {
|
|
405
|
+
url: "https://app.box.com/s/abbvr71aw8a4gb7u2541hlv45l806u5h",
|
|
406
|
+
download_url: "https://app.box.com/shared/static/abbvr71aw8a4gb7u2541hlv45l806u5h.pdf",
|
|
407
|
+
vanity_url: null,
|
|
408
|
+
effective_access: "company",
|
|
409
|
+
effective_permission: "can_download",
|
|
410
|
+
is_password_enabled: true,
|
|
411
|
+
access: "company",
|
|
412
|
+
permissions: {
|
|
413
|
+
can_download: true,
|
|
414
|
+
can_preview: true,
|
|
415
|
+
can_edit: false
|
|
416
|
+
},
|
|
417
|
+
download_count: 3,
|
|
418
|
+
preview_count: 12
|
|
419
|
+
}
|
|
420
|
+
} };
|
|
421
|
+
const removeSharedLinkFromFileExamplePayload = { data: {
|
|
422
|
+
type: "file",
|
|
423
|
+
id: "53286756412",
|
|
424
|
+
etag: "1",
|
|
425
|
+
sequence_id: "3",
|
|
426
|
+
name: "Contract_2024.pdf",
|
|
427
|
+
sha1: "85136c79cbf9fe36bb9d05d0639c70c265c18d37",
|
|
428
|
+
file_version: {
|
|
429
|
+
id: "12345",
|
|
430
|
+
type: "file_version",
|
|
431
|
+
sha1: "134b65991ed521fcfe4724b7d814ab8ded5185dc"
|
|
432
|
+
},
|
|
433
|
+
shared_link: null
|
|
434
|
+
} };
|
|
435
|
+
const addSharedLinkToFolderExamplePayload = { data: {
|
|
436
|
+
type: "folder",
|
|
437
|
+
id: "84759261038",
|
|
438
|
+
etag: "1",
|
|
439
|
+
sequence_id: "3",
|
|
440
|
+
name: "Shared Documents",
|
|
441
|
+
shared_link: {
|
|
442
|
+
url: "https://app.box.com/s/9f2a1c7be4d84e0fa1b2c3d4e5f60718",
|
|
443
|
+
download_url: null,
|
|
444
|
+
vanity_url: null,
|
|
445
|
+
effective_access: "open",
|
|
446
|
+
effective_permission: "can_download",
|
|
447
|
+
is_password_enabled: false,
|
|
448
|
+
access: "open",
|
|
449
|
+
permissions: {
|
|
450
|
+
can_download: true,
|
|
451
|
+
can_preview: true,
|
|
452
|
+
can_edit: false
|
|
453
|
+
},
|
|
454
|
+
download_count: 0,
|
|
455
|
+
preview_count: 0
|
|
456
|
+
}
|
|
457
|
+
} };
|
|
458
|
+
const updateSharedLinkOnFolderExamplePayload = { data: {
|
|
459
|
+
type: "folder",
|
|
460
|
+
id: "84759261038",
|
|
461
|
+
etag: "1",
|
|
462
|
+
sequence_id: "3",
|
|
463
|
+
name: "Shared Documents",
|
|
464
|
+
shared_link: {
|
|
465
|
+
url: "https://app.box.com/s/9f2a1c7be4d84e0fa1b2c3d4e5f60718",
|
|
466
|
+
download_url: null,
|
|
467
|
+
vanity_url: null,
|
|
468
|
+
effective_access: "company",
|
|
469
|
+
effective_permission: "can_preview",
|
|
470
|
+
is_password_enabled: true,
|
|
471
|
+
access: "company",
|
|
472
|
+
permissions: {
|
|
473
|
+
can_download: false,
|
|
474
|
+
can_preview: true,
|
|
475
|
+
can_edit: false
|
|
476
|
+
},
|
|
477
|
+
download_count: 5,
|
|
478
|
+
preview_count: 42
|
|
479
|
+
}
|
|
480
|
+
} };
|
|
481
|
+
const removeSharedLinkFromFolderExamplePayload = { data: {
|
|
482
|
+
type: "folder",
|
|
483
|
+
id: "84759261038",
|
|
484
|
+
etag: "1",
|
|
485
|
+
sequence_id: "3",
|
|
486
|
+
name: "Shared Documents",
|
|
487
|
+
shared_link: null
|
|
488
|
+
} };
|
|
489
|
+
//#endregion
|
|
490
|
+
//#region src/examplePayloads/triggers.ts
|
|
491
|
+
const triggerPayloadEnvelope = {
|
|
492
|
+
queryParameters: {},
|
|
493
|
+
rawBody: { data: null },
|
|
494
|
+
pathFragment: "",
|
|
495
|
+
webhookUrls: {},
|
|
496
|
+
webhookApiKeys: {},
|
|
497
|
+
invokeUrl: "",
|
|
498
|
+
executionId: "RXhhbXBsZUV4ZWN1dGlvblJlc3VsdElk",
|
|
499
|
+
customer: {
|
|
500
|
+
id: "testCustomerId",
|
|
501
|
+
name: "Test Customer",
|
|
502
|
+
externalId: "testExternalId"
|
|
503
|
+
},
|
|
504
|
+
instance: {
|
|
505
|
+
id: "testInstanceId",
|
|
506
|
+
name: "Test Instance"
|
|
507
|
+
},
|
|
508
|
+
user: {
|
|
509
|
+
id: "testUserId",
|
|
510
|
+
email: "user@example.com",
|
|
511
|
+
name: "Test User",
|
|
512
|
+
externalId: "testUserExternalId"
|
|
513
|
+
},
|
|
514
|
+
integration: {
|
|
515
|
+
id: "testIntegrationId",
|
|
516
|
+
name: "Test Integration",
|
|
517
|
+
versionSequenceId: "1",
|
|
518
|
+
externalVersion: ""
|
|
519
|
+
},
|
|
520
|
+
flow: {
|
|
521
|
+
id: "testFlowId",
|
|
522
|
+
name: "Test Flow",
|
|
523
|
+
stableId: "testFlowStableId"
|
|
524
|
+
},
|
|
525
|
+
startedAt: "2024-01-15T00:00:00.000Z",
|
|
526
|
+
globalDebug: false
|
|
527
|
+
};
|
|
528
|
+
const boxWebhookHeaders = {
|
|
529
|
+
"box-delivery-id": "f96bb54b-ee16-4fc5-aa65-8c2d9e5b546f",
|
|
530
|
+
"box-delivery-timestamp": "2026-01-14T18:07:45Z",
|
|
531
|
+
"box-signature-algorithm": "HmacSHA256",
|
|
532
|
+
"box-signature-version": "1",
|
|
533
|
+
"box-signature-primary": "4KvFa5/unRL8aaqOlnbInTwkOmieZkn1ZVzsAJuRipE=",
|
|
534
|
+
"box-signature-secondary": "yxxwBNk7tFyQSy95/VNKAf1o+j8WMPJuo/KcFc7OS0Q="
|
|
535
|
+
};
|
|
536
|
+
const boxWebhookEvent = {
|
|
537
|
+
type: "webhook_event",
|
|
538
|
+
id: "0f46a6ca-86bf-44ab-8cf5-f08e1e02876b",
|
|
539
|
+
created_at: "2026-01-14T18:07:45Z",
|
|
540
|
+
trigger: "FILE.UPLOADED",
|
|
541
|
+
webhook: {
|
|
542
|
+
id: "1234",
|
|
543
|
+
type: "webhook"
|
|
544
|
+
},
|
|
545
|
+
created_by: {
|
|
546
|
+
type: "user",
|
|
547
|
+
id: "33333",
|
|
548
|
+
name: "Example User",
|
|
549
|
+
login: "user@example.com"
|
|
550
|
+
},
|
|
551
|
+
source: {
|
|
552
|
+
id: "54321",
|
|
553
|
+
type: "file",
|
|
554
|
+
name: "report.pdf",
|
|
555
|
+
sha1: "85136c79cbf9fe36bb9d05d0639c70c265c18d37",
|
|
556
|
+
parent: {
|
|
557
|
+
id: "0",
|
|
558
|
+
type: "folder",
|
|
559
|
+
name: "All Files"
|
|
560
|
+
}
|
|
561
|
+
},
|
|
562
|
+
additional_info: []
|
|
563
|
+
};
|
|
564
|
+
const webhookExamplePayload = { payload: {
|
|
565
|
+
...triggerPayloadEnvelope,
|
|
566
|
+
headers: boxWebhookHeaders,
|
|
567
|
+
body: { data: boxWebhookEvent }
|
|
568
|
+
} };
|
|
569
|
+
const managedWebhookExamplePayload = { payload: {
|
|
570
|
+
...triggerPayloadEnvelope,
|
|
571
|
+
headers: boxWebhookHeaders,
|
|
572
|
+
body: { data: boxWebhookEvent }
|
|
573
|
+
} };
|
|
574
|
+
const newOrUpdatedFileExamplePayload = { payload: {
|
|
575
|
+
...triggerPayloadEnvelope,
|
|
576
|
+
headers: {},
|
|
577
|
+
body: { data: {
|
|
578
|
+
newFiles: {
|
|
579
|
+
data: [{
|
|
580
|
+
id: "54321",
|
|
581
|
+
type: "file",
|
|
582
|
+
name: "report.pdf",
|
|
583
|
+
created_at: "2026-01-14T18:07:45.000Z",
|
|
584
|
+
modified_at: "2026-01-14T18:07:45.000Z"
|
|
585
|
+
}],
|
|
586
|
+
polledNoChanges: false
|
|
587
|
+
},
|
|
588
|
+
updatedFiles: {
|
|
589
|
+
data: [{
|
|
590
|
+
id: "67890",
|
|
591
|
+
type: "file",
|
|
592
|
+
name: "contract.pdf",
|
|
593
|
+
created_at: "2025-11-03T15:22:10.000Z",
|
|
594
|
+
modified_at: "2026-01-14T17:45:02.000Z"
|
|
595
|
+
}],
|
|
596
|
+
polledNoChanges: false
|
|
597
|
+
}
|
|
598
|
+
} }
|
|
599
|
+
} };
|
|
600
|
+
const newFolderExamplePayload = { payload: {
|
|
601
|
+
...triggerPayloadEnvelope,
|
|
602
|
+
headers: {},
|
|
603
|
+
body: { data: { newFolders: {
|
|
604
|
+
data: [{
|
|
605
|
+
id: "12345",
|
|
606
|
+
type: "folder",
|
|
607
|
+
name: "Contracts",
|
|
608
|
+
created_at: "2026-01-14T18:07:45.000Z"
|
|
609
|
+
}],
|
|
610
|
+
polledNoChanges: false
|
|
611
|
+
} } }
|
|
612
|
+
} };
|
|
613
|
+
const newFileCommentsExamplePayload = { payload: {
|
|
614
|
+
...triggerPayloadEnvelope,
|
|
615
|
+
headers: {},
|
|
616
|
+
body: { data: { newComments: { data: [{
|
|
617
|
+
id: "8826473150",
|
|
618
|
+
type: "comment",
|
|
619
|
+
message: "Please review the figures in section 2.",
|
|
620
|
+
created_at: "2026-01-14T18:07:45.000Z"
|
|
621
|
+
}] } } }
|
|
622
|
+
} };
|
|
623
|
+
//#endregion
|
|
624
|
+
//#region src/examplePayloads/users.ts
|
|
625
|
+
const getCurrentUserExamplePayload = { data: {
|
|
626
|
+
type: "user",
|
|
627
|
+
id: "33333",
|
|
628
|
+
name: "Example User",
|
|
629
|
+
login: "user@example.com",
|
|
630
|
+
created_at: "2012-03-26T15:43:07-07:00",
|
|
631
|
+
modified_at: "2012-12-12T11:34:29-08:00",
|
|
632
|
+
language: "en",
|
|
633
|
+
space_amount: 5368709120,
|
|
634
|
+
space_used: 2377016,
|
|
635
|
+
max_upload_size: 262144e3,
|
|
636
|
+
status: "active",
|
|
637
|
+
job_title: "Employee",
|
|
638
|
+
phone: "5555555555",
|
|
639
|
+
address: "555 Office Drive",
|
|
640
|
+
avatar_url: "https://app.box.com/api/avatar/deprecated"
|
|
641
|
+
} };
|
|
642
|
+
//#endregion
|
|
643
|
+
//#region src/examplePayloads/webhooks.ts
|
|
644
|
+
const listWebhooksExamplePayload = { data: {
|
|
645
|
+
next_marker: "ZmlQZS0xLTE%3D",
|
|
646
|
+
entries: [{
|
|
647
|
+
id: "1234",
|
|
648
|
+
type: "webhook",
|
|
649
|
+
target: {
|
|
650
|
+
id: "22222",
|
|
651
|
+
type: "folder"
|
|
652
|
+
}
|
|
653
|
+
}, {
|
|
654
|
+
id: "5678",
|
|
655
|
+
type: "webhook",
|
|
656
|
+
target: {
|
|
657
|
+
id: "11111",
|
|
658
|
+
type: "file"
|
|
659
|
+
}
|
|
660
|
+
}],
|
|
661
|
+
limit: 2
|
|
662
|
+
} };
|
|
663
|
+
const createWebhookExamplePayload = {
|
|
664
|
+
data: {
|
|
665
|
+
id: "1234",
|
|
666
|
+
type: "webhook",
|
|
667
|
+
target: {
|
|
668
|
+
id: "22222",
|
|
669
|
+
type: "folder"
|
|
670
|
+
},
|
|
671
|
+
created_by: {
|
|
672
|
+
type: "user",
|
|
673
|
+
id: "33333",
|
|
674
|
+
name: "Example User",
|
|
675
|
+
login: "user@example.com"
|
|
676
|
+
},
|
|
677
|
+
created_at: "2016-05-09T17:41:27-07:00",
|
|
678
|
+
address: "https://example.com/webhook",
|
|
679
|
+
triggers: ["FILE.DOWNLOADED", "FILE.UPLOADED"]
|
|
680
|
+
},
|
|
681
|
+
crossFlowState: { primarySignatureKey: "example-primary-signature-key-0000" }
|
|
682
|
+
};
|
|
683
|
+
const deleteWebhookExamplePayload = { data: null };
|
|
684
|
+
const deleteInstanceWebhooksExamplePayload = { data: {} };
|
|
685
|
+
//#endregion
|
|
686
|
+
//#region src/types/webhooks.ts
|
|
687
|
+
const WEBHOOK_TRIGGER_TYPES = [
|
|
688
|
+
"FILE.UPLOADED",
|
|
689
|
+
"FILE.PREVIEWED",
|
|
690
|
+
"FILE.DOWNLOADED",
|
|
691
|
+
"FILE.TRASHED",
|
|
692
|
+
"FILE.DELETED",
|
|
693
|
+
"FILE.RESTORED",
|
|
694
|
+
"FILE.COPIED",
|
|
695
|
+
"FILE.MOVED",
|
|
696
|
+
"FILE.LOCKED",
|
|
697
|
+
"FILE.UNLOCKED",
|
|
698
|
+
"FILE.RENAMED",
|
|
699
|
+
"COMMENT.CREATED",
|
|
700
|
+
"COMMENT.UPDATED",
|
|
701
|
+
"COMMENT.DELETED",
|
|
702
|
+
"TASK_ASSIGNMENT.CREATED",
|
|
703
|
+
"TASK_ASSIGNMENT.UPDATED",
|
|
704
|
+
"METADATA_INSTANCE.CREATED",
|
|
705
|
+
"METADATA_INSTANCE.UPDATED",
|
|
706
|
+
"METADATA_INSTANCE.DELETED",
|
|
707
|
+
"FOLDER.CREATED",
|
|
708
|
+
"FOLDER.DOWNLOADED",
|
|
709
|
+
"FOLDER.RESTORED",
|
|
710
|
+
"FOLDER.DELETED",
|
|
711
|
+
"FOLDER.COPIED",
|
|
712
|
+
"FOLDER.MOVED",
|
|
713
|
+
"FOLDER.TRASHED",
|
|
714
|
+
"FOLDER.RENAMED",
|
|
715
|
+
"WEBHOOK.DELETED",
|
|
716
|
+
"COLLABORATION.CREATED",
|
|
717
|
+
"COLLABORATION.ACCEPTED",
|
|
718
|
+
"COLLABORATION.REJECTED",
|
|
719
|
+
"COLLABORATION.REMOVED",
|
|
720
|
+
"COLLABORATION.UPDATED",
|
|
721
|
+
"SHARED_LINK.DELETED",
|
|
722
|
+
"SHARED_LINK.CREATED",
|
|
723
|
+
"SHARED_LINK.UPDATED",
|
|
724
|
+
"SIGN_REQUEST.COMPLETED",
|
|
725
|
+
"SIGN_REQUEST.DECLINED",
|
|
726
|
+
"SIGN_REQUEST.EXPIRED"
|
|
727
|
+
];
|
|
728
|
+
//#endregion
|
|
729
|
+
//#region src/util/clean.ts
|
|
730
|
+
const lookBackDateClean = (value) => {
|
|
731
|
+
const str = _prismatic_io_spectral.util.types.toString(value).trim();
|
|
732
|
+
if (!str) return "";
|
|
733
|
+
if (!LOOK_BACK_DATE_PATTERN.test(str)) throw new Error("Look-back Date must be in YYYY-MM-DD format.");
|
|
734
|
+
const parts = str.split("-");
|
|
735
|
+
const year = _prismatic_io_spectral.util.types.toNumber(parts[0]);
|
|
736
|
+
const month = _prismatic_io_spectral.util.types.toNumber(parts[1]);
|
|
737
|
+
const day = _prismatic_io_spectral.util.types.toNumber(parts[2]);
|
|
738
|
+
const parsed = new Date(year, month - 1, day);
|
|
739
|
+
if (parsed.getFullYear() !== year || parsed.getMonth() !== month - 1 || parsed.getDate() !== day) throw new Error(`Look-back Date "${str}" is not a valid calendar date.`);
|
|
740
|
+
if (parsed > /* @__PURE__ */ new Date()) throw new Error("Look-back Date cannot be a future date.");
|
|
741
|
+
return str;
|
|
742
|
+
};
|
|
743
|
+
const cleanString = (value) => value ? _prismatic_io_spectral.util.types.toString(value) : void 0;
|
|
744
|
+
const cleanCommaSeparatedString = (value) => {
|
|
745
|
+
if (!value) return void 0;
|
|
746
|
+
return _prismatic_io_spectral.util.types.toString(value).split(",").map((item) => item.trim()).filter((item) => item !== "").join(",");
|
|
747
|
+
};
|
|
748
|
+
const toStringList = (values) => (values || []).map((value) => _prismatic_io_spectral.util.types.toString(value));
|
|
749
|
+
const humanizeEnumLabel = (value) => {
|
|
750
|
+
return value.replace(/_/g, " ").replace(/\./g, " ").toLowerCase().replace(/\b\w/g, (char) => char.toUpperCase());
|
|
751
|
+
};
|
|
752
|
+
const pathLeafName = (path) => _prismatic_io_spectral.util.types.toString(path).split("/").filter(Boolean).slice(-1)[0] ?? "";
|
|
753
|
+
const sharedLinkVanityUrl = (vanityName) => {
|
|
754
|
+
const name = _prismatic_io_spectral.util.types.toString(vanityName);
|
|
755
|
+
return name ? `https://app.box.com/v/${name}` : null;
|
|
756
|
+
};
|
|
757
|
+
const sharedLinkEffectivePermission = (permissions) => permissions.can_download ? SHARED_LINK_PERMISSION_DOWNLOAD : SHARED_LINK_PERMISSION_PREVIEW;
|
|
758
|
+
//#endregion
|
|
759
|
+
//#region src/util/comments.ts
|
|
760
|
+
const getAllFileComments = async (client, fileId) => {
|
|
761
|
+
const limit = MAX_PAGE_SIZE;
|
|
762
|
+
let allEntries = [];
|
|
763
|
+
let offset = 0;
|
|
764
|
+
while (true) {
|
|
765
|
+
const rawEntries = (await client.comments.getFileComments(fileId, { queryParams: {
|
|
766
|
+
fields: [
|
|
767
|
+
"created_at",
|
|
768
|
+
"id",
|
|
769
|
+
"message"
|
|
770
|
+
],
|
|
771
|
+
offset,
|
|
772
|
+
limit
|
|
773
|
+
} })).rawData?.entries ?? [];
|
|
774
|
+
allEntries = allEntries.concat(rawEntries);
|
|
775
|
+
if (rawEntries.length < limit) break;
|
|
776
|
+
offset += rawEntries.length;
|
|
777
|
+
}
|
|
778
|
+
return allEntries;
|
|
779
|
+
};
|
|
780
|
+
//#endregion
|
|
781
|
+
//#region src/util/folders.ts
|
|
782
|
+
const getFolderEntries = async ({ client, id, limit, marker, offset, fields }) => {
|
|
783
|
+
let initial = true;
|
|
784
|
+
let allEntries = [];
|
|
785
|
+
while (initial || marker) {
|
|
786
|
+
const response = await client.folders.getFolderItems(id, { queryParams: {
|
|
787
|
+
usemarker: true,
|
|
788
|
+
marker,
|
|
789
|
+
limit,
|
|
790
|
+
offset,
|
|
791
|
+
fields: fields ? fields.split(",") : void 0
|
|
792
|
+
} });
|
|
793
|
+
initial = false;
|
|
794
|
+
const rawEntries = response.rawData?.entries ?? [];
|
|
795
|
+
allEntries = allEntries.concat(rawEntries);
|
|
796
|
+
marker = response.nextMarker;
|
|
797
|
+
}
|
|
798
|
+
return allEntries;
|
|
799
|
+
};
|
|
800
|
+
const getPathEntries = async (client, path, lastShouldExist = true) => {
|
|
801
|
+
if (!path.startsWith("/")) throw Error("Path must start with '/'");
|
|
802
|
+
if (path === "/") path = "";
|
|
803
|
+
let allEntries = [{
|
|
804
|
+
id: "0",
|
|
805
|
+
name: "",
|
|
806
|
+
type: FOLDER_TYPE
|
|
807
|
+
}];
|
|
808
|
+
const pathEntries = [];
|
|
809
|
+
const pathParts = path.split("/");
|
|
810
|
+
for (const [i, part] of pathParts.entries()) {
|
|
811
|
+
const isLastPart = i === pathParts.length - 1;
|
|
812
|
+
const found = allEntries.find((entry) => entry.name === part) || {};
|
|
813
|
+
const id = found.id !== void 0 ? _prismatic_io_spectral.util.types.toString(found.id) : void 0;
|
|
814
|
+
const type = found.type !== void 0 ? _prismatic_io_spectral.util.types.toString(found.type) : void 0;
|
|
815
|
+
const name = found.name !== void 0 ? _prismatic_io_spectral.util.types.toString(found.name) : void 0;
|
|
816
|
+
if (id) {
|
|
817
|
+
if (isLastPart && !lastShouldExist) throw Error(`Expected '${part}' to not exist`);
|
|
818
|
+
pathEntries.push({
|
|
819
|
+
id,
|
|
820
|
+
type,
|
|
821
|
+
name
|
|
822
|
+
});
|
|
823
|
+
if (type === "folder" && !isLastPart) allEntries = await getFolderEntries({
|
|
824
|
+
client,
|
|
825
|
+
id
|
|
826
|
+
});
|
|
827
|
+
} else if (isLastPart && !lastShouldExist) pathEntries.push({ name: part });
|
|
828
|
+
else throw Error(`Expected '${part}' to exist in path '${path}'`);
|
|
829
|
+
}
|
|
830
|
+
return pathEntries;
|
|
831
|
+
};
|
|
832
|
+
//#endregion
|
|
833
|
+
//#region src/util/polling.ts
|
|
834
|
+
const buildPollingResult = (payload, data) => ({
|
|
835
|
+
payload: {
|
|
836
|
+
...payload,
|
|
837
|
+
body: { data }
|
|
838
|
+
},
|
|
839
|
+
polledNoChanges: Object.values(data).every(({ polledNoChanges }) => polledNoChanges)
|
|
840
|
+
});
|
|
841
|
+
const getLastPolledAt = (context, defaultLastPolledAt) => {
|
|
842
|
+
return context.polling.getState().lastPolledAt || defaultLastPolledAt;
|
|
843
|
+
};
|
|
844
|
+
const normalizeDatesBetweenEntries = (entries) => {
|
|
845
|
+
return entries.map(({ created_at, modified_at, ...entry }) => {
|
|
846
|
+
return {
|
|
847
|
+
...entry,
|
|
848
|
+
created_at: created_at ? new Date(created_at).toISOString() : void 0,
|
|
849
|
+
modified_at: modified_at ? new Date(modified_at).toISOString() : void 0
|
|
850
|
+
};
|
|
851
|
+
});
|
|
852
|
+
};
|
|
853
|
+
const computeNewEntries = (entries, lastPolledAt) => {
|
|
854
|
+
return entries.filter((entry) => entry.created_at > lastPolledAt);
|
|
855
|
+
};
|
|
856
|
+
const computeUpdatedEntries = (entries, lastPolledAt, excludeIds) => {
|
|
857
|
+
return entries.filter(({ modified_at, id }) => modified_at > lastPolledAt && !excludeIds.includes(id));
|
|
858
|
+
};
|
|
859
|
+
const resolvePollingRecordChanges = (data) => {
|
|
860
|
+
const changesObject = data ?? {};
|
|
861
|
+
return [...(changesObject.newFiles?.data ?? []).map((record) => ({
|
|
862
|
+
changeType: "new",
|
|
863
|
+
record
|
|
864
|
+
})), ...(changesObject.updatedFiles?.data ?? []).map((record) => ({
|
|
865
|
+
changeType: "updated",
|
|
866
|
+
record
|
|
867
|
+
}))];
|
|
868
|
+
};
|
|
869
|
+
const resolveFolderChanges = (data) => {
|
|
870
|
+
return ((data ?? {}).newFolders?.data ?? []).map((record) => ({
|
|
871
|
+
changeType: "new",
|
|
872
|
+
record
|
|
873
|
+
}));
|
|
874
|
+
};
|
|
875
|
+
const resolveCommentChanges = (data) => {
|
|
876
|
+
return ((data ?? {}).newComments?.data ?? []).map((record) => ({
|
|
877
|
+
changeType: "new",
|
|
878
|
+
record
|
|
879
|
+
}));
|
|
880
|
+
};
|
|
881
|
+
//#endregion
|
|
882
|
+
//#region src/util/webhooks.ts
|
|
883
|
+
const getAllWebhookEntries = async (client) => {
|
|
884
|
+
let initial = true;
|
|
885
|
+
let allEntries = [];
|
|
886
|
+
let marker;
|
|
887
|
+
while (initial || marker) {
|
|
888
|
+
const response = await client.webhooks.getWebhooks({
|
|
889
|
+
limit: MAX_PAGE_SIZE,
|
|
890
|
+
marker
|
|
891
|
+
});
|
|
892
|
+
initial = false;
|
|
893
|
+
allEntries = allEntries.concat(response.rawData?.entries ?? []);
|
|
894
|
+
marker = response.nextMarker;
|
|
895
|
+
}
|
|
896
|
+
return { entries: allEntries };
|
|
897
|
+
};
|
|
898
|
+
const getInstanceWebhookIds = async (client, entries, webhookUrls) => {
|
|
899
|
+
const webhookDetails = (await Promise.all((entries || []).map((entry) => client.webhooks.getWebhookById(_prismatic_io_spectral.util.types.toString(entry.id))))).map((webhook) => ({
|
|
900
|
+
id: _prismatic_io_spectral.util.types.toString(webhook.id),
|
|
901
|
+
address: _prismatic_io_spectral.util.types.toString(webhook.address)
|
|
902
|
+
}));
|
|
903
|
+
const instanceWebhookUrls = new Set(Object.values(webhookUrls));
|
|
904
|
+
return new Set(webhookDetails.filter(({ address }) => instanceWebhookUrls.has(address)).map(({ id }) => id));
|
|
905
|
+
};
|
|
906
|
+
const getBoxErrorStatus = (error) => error?.responseInfo?.statusCode;
|
|
907
|
+
const assertTargetType = (targetType) => {
|
|
908
|
+
if (!["file", "folder"].includes(targetType)) throw new Error(`Invalid target type specified: ${targetType}`);
|
|
909
|
+
return targetType;
|
|
910
|
+
};
|
|
911
|
+
const createWebhookFN = async (client, targetId, targetType, address, triggerTypes, storeKey, logger, primarySignatureKey, secondarySignatureKey) => {
|
|
912
|
+
const validTargetType = assertTargetType(targetType);
|
|
913
|
+
const { id: webhookId } = await client.webhooks.createWebhook({
|
|
914
|
+
target: {
|
|
915
|
+
id: targetId,
|
|
916
|
+
type: validTargetType
|
|
917
|
+
},
|
|
918
|
+
address,
|
|
919
|
+
triggers: triggerTypes
|
|
920
|
+
});
|
|
921
|
+
logger.info("New webhook created, storing state...");
|
|
922
|
+
return {
|
|
923
|
+
crossFlowState: { [storeKey]: {
|
|
924
|
+
existingWebhookId: webhookId,
|
|
925
|
+
primarySignatureKey,
|
|
926
|
+
secondarySignatureKey,
|
|
927
|
+
previousTargetId: targetId,
|
|
928
|
+
previousTargetType: validTargetType,
|
|
929
|
+
previousTriggerTypes: triggerTypes
|
|
930
|
+
} },
|
|
931
|
+
webhookId
|
|
932
|
+
};
|
|
933
|
+
};
|
|
934
|
+
const deleteWebhookIfPresent = async (client, webhookId, logger) => {
|
|
935
|
+
try {
|
|
936
|
+
await client.webhooks.deleteWebhookById(webhookId);
|
|
937
|
+
} catch (error) {
|
|
938
|
+
if (getBoxErrorStatus(error) !== 404) throw error;
|
|
939
|
+
logger.info(`Webhook ${webhookId} no longer exists in Box, skipping.`);
|
|
940
|
+
}
|
|
941
|
+
};
|
|
942
|
+
const getTargetWebhookIdsForAddress = async (client, targetId, targetType, address) => {
|
|
943
|
+
const { entries } = await getAllWebhookEntries(client);
|
|
944
|
+
const onTarget = entries.filter((entry) => {
|
|
945
|
+
const target = entry.target;
|
|
946
|
+
return _prismatic_io_spectral.util.types.toString(target?.id) === targetId && _prismatic_io_spectral.util.types.toString(target?.type) === targetType;
|
|
947
|
+
});
|
|
948
|
+
return getInstanceWebhookIds(client, onTarget, { address });
|
|
949
|
+
};
|
|
950
|
+
const getStoreKey = (flowName) => `boxTrigger-${flowName}`;
|
|
951
|
+
const getLegacyStoreKey = (targetId, targetType, flowName) => `boxTrigger-${targetId}-${targetType}-${flowName}`;
|
|
952
|
+
const resolveStoreState = (crossFlowState, storeKey, legacyStoreKey) => {
|
|
953
|
+
const state = crossFlowState[storeKey];
|
|
954
|
+
if (state?.existingWebhookId) return {
|
|
955
|
+
state,
|
|
956
|
+
adoptedFromLegacyKey: false
|
|
957
|
+
};
|
|
958
|
+
const legacyState = crossFlowState[legacyStoreKey];
|
|
959
|
+
if (legacyState?.existingWebhookId) return {
|
|
960
|
+
state: legacyState,
|
|
961
|
+
adoptedFromLegacyKey: true
|
|
962
|
+
};
|
|
963
|
+
return {
|
|
964
|
+
state,
|
|
965
|
+
adoptedFromLegacyKey: false
|
|
966
|
+
};
|
|
967
|
+
};
|
|
968
|
+
const MAX_MESSAGE_AGE_SECONDS = 600;
|
|
969
|
+
const computeBoxSignature = (body, timestamp, key) => {
|
|
970
|
+
const hmac = (0, node_crypto.createHmac)("sha256", key);
|
|
971
|
+
hmac.update(body);
|
|
972
|
+
hmac.update(timestamp);
|
|
973
|
+
return hmac.digest("base64");
|
|
974
|
+
};
|
|
975
|
+
const signatureMatches = (body, timestamp, key, received) => {
|
|
976
|
+
if (!key || !received) return false;
|
|
977
|
+
const expected = Buffer.from(computeBoxSignature(body, timestamp, key), "base64");
|
|
978
|
+
const actual = Buffer.from(received, "base64");
|
|
979
|
+
return expected.length === actual.length && (0, node_crypto.timingSafeEqual)(expected, actual);
|
|
980
|
+
};
|
|
981
|
+
const validateBoxWebhookSignature = ({ body, headers, primaryKey, secondaryKey }) => {
|
|
982
|
+
if (headers["box-signature-version"] !== "1") return false;
|
|
983
|
+
if (headers["box-signature-algorithm"] !== "HmacSHA256") return false;
|
|
984
|
+
const timestamp = headers["box-delivery-timestamp"];
|
|
985
|
+
if (!timestamp) return false;
|
|
986
|
+
const deliveredAt = Date.parse(timestamp);
|
|
987
|
+
if (Number.isNaN(deliveredAt)) return false;
|
|
988
|
+
if ((Date.now() - deliveredAt) / 1e3 > MAX_MESSAGE_AGE_SECONDS) return false;
|
|
989
|
+
return signatureMatches(body, timestamp, primaryKey, headers["box-signature-primary"]) || signatureMatches(body, timestamp, secondaryKey, headers["box-signature-secondary"]);
|
|
990
|
+
};
|
|
991
|
+
//#endregion
|
|
992
|
+
//#region src/inputs/common.ts
|
|
993
|
+
const connectionInput = (0, _prismatic_io_spectral.input)({
|
|
994
|
+
label: "Connection",
|
|
995
|
+
type: "connection",
|
|
996
|
+
required: true,
|
|
997
|
+
comments: "The Box connection to use."
|
|
998
|
+
});
|
|
999
|
+
const path = (0, _prismatic_io_spectral.input)({
|
|
1000
|
+
label: "Path",
|
|
1001
|
+
placeholder: "Enter file or folder path",
|
|
1002
|
+
type: "string",
|
|
1003
|
+
required: true,
|
|
1004
|
+
comments: "The full path to the file or folder. Must include a leading forward slash (/).",
|
|
1005
|
+
example: "/Marketing/Documents/Q4_Report.pdf",
|
|
1006
|
+
clean: _prismatic_io_spectral.util.types.toString
|
|
1007
|
+
});
|
|
1008
|
+
const limit = (0, _prismatic_io_spectral.input)({
|
|
1009
|
+
label: "Limit",
|
|
1010
|
+
type: "string",
|
|
1011
|
+
required: false,
|
|
1012
|
+
placeholder: "Enter maximum number of items",
|
|
1013
|
+
comments: "The maximum number of items to return (1-1000).",
|
|
1014
|
+
example: "100",
|
|
1015
|
+
clean: _prismatic_io_spectral.util.types.toNumber
|
|
1016
|
+
});
|
|
1017
|
+
const marker = (0, _prismatic_io_spectral.input)({
|
|
1018
|
+
label: "Marker",
|
|
1019
|
+
type: "string",
|
|
1020
|
+
required: false,
|
|
1021
|
+
placeholder: "Enter pagination marker",
|
|
1022
|
+
comments: "The pagination marker returned by a previous request to retrieve the next page of results.",
|
|
1023
|
+
example: "lslTXFcbLQKkb0vP9Kgh5hy0Y0OnC7Z9ZPHPwPmMnxSk3eiDRMkct7D8E",
|
|
1024
|
+
clean: cleanString
|
|
1025
|
+
});
|
|
1026
|
+
const offset = (0, _prismatic_io_spectral.input)({
|
|
1027
|
+
label: "Offset",
|
|
1028
|
+
type: "string",
|
|
1029
|
+
required: false,
|
|
1030
|
+
placeholder: "Enter offset position",
|
|
1031
|
+
comments: "The position to start returning results from (zero-based index).",
|
|
1032
|
+
example: "0",
|
|
1033
|
+
clean: _prismatic_io_spectral.util.types.toNumber
|
|
1034
|
+
});
|
|
1035
|
+
const fetchAll = (0, _prismatic_io_spectral.input)({
|
|
1036
|
+
label: "Fetch All",
|
|
1037
|
+
type: "boolean",
|
|
1038
|
+
required: false,
|
|
1039
|
+
default: "false",
|
|
1040
|
+
comments: "When true, automatically fetches all pages of results using pagination.",
|
|
1041
|
+
clean: _prismatic_io_spectral.util.types.toBool
|
|
1042
|
+
});
|
|
1043
|
+
const targetId = (0, _prismatic_io_spectral.input)({
|
|
1044
|
+
label: "Target ID",
|
|
1045
|
+
placeholder: "Enter target file or folder ID",
|
|
1046
|
+
comments: "The unique identifier of the file or folder that will trigger the webhook.",
|
|
1047
|
+
type: "string",
|
|
1048
|
+
example: "123456789012",
|
|
1049
|
+
required: true,
|
|
1050
|
+
dataSource: "selectContent",
|
|
1051
|
+
clean: _prismatic_io_spectral.util.types.toString
|
|
1052
|
+
});
|
|
1053
|
+
const targetType = (0, _prismatic_io_spectral.input)({
|
|
1054
|
+
label: "Target Type",
|
|
1055
|
+
placeholder: "Select target type",
|
|
1056
|
+
comments: "The type of item that will trigger the webhook (file or folder).",
|
|
1057
|
+
type: "string",
|
|
1058
|
+
example: "file",
|
|
1059
|
+
model: [{
|
|
1060
|
+
label: "File",
|
|
1061
|
+
value: "file"
|
|
1062
|
+
}, {
|
|
1063
|
+
label: "Folder",
|
|
1064
|
+
value: "folder"
|
|
1065
|
+
}],
|
|
1066
|
+
required: true,
|
|
1067
|
+
clean: _prismatic_io_spectral.util.types.toString
|
|
1068
|
+
});
|
|
1069
|
+
const triggerTypes = (0, _prismatic_io_spectral.input)({
|
|
1070
|
+
label: "Trigger Type",
|
|
1071
|
+
placeholder: "Select event types",
|
|
1072
|
+
comments: "Select which event types will trigger this webhook. See [Box Events](https://developer.box.com/guides/webhooks/triggers) for available options.",
|
|
1073
|
+
type: "string",
|
|
1074
|
+
required: true,
|
|
1075
|
+
collection: "valuelist",
|
|
1076
|
+
model: WEBHOOK_TRIGGER_TYPES.map((value) => ({
|
|
1077
|
+
label: humanizeEnumLabel(value),
|
|
1078
|
+
value
|
|
1079
|
+
})),
|
|
1080
|
+
clean: toStringList
|
|
1081
|
+
});
|
|
1082
|
+
const signatureKey = (0, _prismatic_io_spectral.input)({
|
|
1083
|
+
label: "Signature Key",
|
|
1084
|
+
placeholder: "Enter signature key",
|
|
1085
|
+
comments: "A signature key used to validate webhook requests. See [Box Webhook Signatures](https://developer.box.com/guides/webhooks/v2/signatures-v2) for details.",
|
|
1086
|
+
type: "password",
|
|
1087
|
+
example: "example-primary-signature-key-0000",
|
|
1088
|
+
required: false,
|
|
1089
|
+
clean: _prismatic_io_spectral.util.types.toString
|
|
1090
|
+
});
|
|
1091
|
+
const fileIdInput = (0, _prismatic_io_spectral.input)({
|
|
1092
|
+
label: "File ID",
|
|
1093
|
+
placeholder: "Enter file ID",
|
|
1094
|
+
type: "string",
|
|
1095
|
+
required: true,
|
|
1096
|
+
comments: "The unique identifier of the file.",
|
|
1097
|
+
example: "987654321012",
|
|
1098
|
+
dataSource: "selectContent",
|
|
1099
|
+
clean: _prismatic_io_spectral.util.types.toString
|
|
1100
|
+
});
|
|
1101
|
+
const folderIdInput = (0, _prismatic_io_spectral.input)({
|
|
1102
|
+
label: "Folder ID",
|
|
1103
|
+
placeholder: "Enter folder ID",
|
|
1104
|
+
type: "string",
|
|
1105
|
+
required: true,
|
|
1106
|
+
comments: "The unique identifier of the folder.",
|
|
1107
|
+
example: "123456789012",
|
|
1108
|
+
dataSource: "selectContent",
|
|
1109
|
+
clean: _prismatic_io_spectral.util.types.toString
|
|
1110
|
+
});
|
|
1111
|
+
const selectContentInputs = {
|
|
1112
|
+
boxConnection: connectionInput,
|
|
1113
|
+
contentType: (0, _prismatic_io_spectral.input)({
|
|
1114
|
+
label: "Content Type",
|
|
1115
|
+
placeholder: "Select content type",
|
|
1116
|
+
comments: "The type of content to select (files, folders, or both).",
|
|
1117
|
+
type: "string",
|
|
1118
|
+
example: "file",
|
|
1119
|
+
model: [
|
|
1120
|
+
{
|
|
1121
|
+
label: "Files and Folders",
|
|
1122
|
+
value: "all"
|
|
1123
|
+
},
|
|
1124
|
+
{
|
|
1125
|
+
label: "Files",
|
|
1126
|
+
value: "file"
|
|
1127
|
+
},
|
|
1128
|
+
{
|
|
1129
|
+
label: "Folders",
|
|
1130
|
+
value: "folder"
|
|
1131
|
+
}
|
|
1132
|
+
],
|
|
1133
|
+
default: "all",
|
|
1134
|
+
required: true,
|
|
1135
|
+
clean: _prismatic_io_spectral.util.types.toString
|
|
1136
|
+
}),
|
|
1137
|
+
limit,
|
|
1138
|
+
marker,
|
|
1139
|
+
offset
|
|
1140
|
+
};
|
|
1141
|
+
const selectWebhookInputs = { boxConnection: connectionInput };
|
|
1142
|
+
//#endregion
|
|
1143
|
+
//#region src/inputs/files.ts
|
|
1144
|
+
const fileContents = (0, _prismatic_io_spectral.input)({
|
|
1145
|
+
label: "File Contents",
|
|
1146
|
+
placeholder: "Select file data from previous step",
|
|
1147
|
+
type: "data",
|
|
1148
|
+
required: true,
|
|
1149
|
+
comments: "The file content to upload. Accepts text, binary data (images, PDFs), or output from a previous step.",
|
|
1150
|
+
example: "My File Contents"
|
|
1151
|
+
});
|
|
1152
|
+
const downloadFileInputs = {
|
|
1153
|
+
path,
|
|
1154
|
+
boxConnection: connectionInput
|
|
1155
|
+
};
|
|
1156
|
+
const getFileDownloadUrlInputs = {
|
|
1157
|
+
path,
|
|
1158
|
+
boxConnection: connectionInput
|
|
1159
|
+
};
|
|
1160
|
+
const uploadFileInputs = {
|
|
1161
|
+
path,
|
|
1162
|
+
fileContents,
|
|
1163
|
+
boxConnection: connectionInput
|
|
1164
|
+
};
|
|
1165
|
+
//#endregion
|
|
1166
|
+
//#region src/inputs/folders.ts
|
|
1167
|
+
const fields = (0, _prismatic_io_spectral.input)({
|
|
1168
|
+
label: "Fields/Metadata",
|
|
1169
|
+
type: "string",
|
|
1170
|
+
required: false,
|
|
1171
|
+
placeholder: "Enter comma-separated field names",
|
|
1172
|
+
comments: "Comma-separated attributes to include in the response. Supports metadata queries (e.g., metadata.enterprise_12345.contractTemplate). See [Box File Fields](https://developer.box.com/reference/files-resources#file-full) for available options.",
|
|
1173
|
+
example: "content_created_at,name,size,modified_at",
|
|
1174
|
+
clean: cleanCommaSeparatedString
|
|
1175
|
+
});
|
|
1176
|
+
const folderPagination = (0, _prismatic_io_spectral.structuredObjectInput)({
|
|
1177
|
+
label: "Pagination",
|
|
1178
|
+
required: false,
|
|
1179
|
+
comments: "Marker, limit, and offset controls for paging through results.",
|
|
1180
|
+
inputs: {
|
|
1181
|
+
limit,
|
|
1182
|
+
marker,
|
|
1183
|
+
offset
|
|
1184
|
+
}
|
|
1185
|
+
});
|
|
1186
|
+
const createFolderInputs = {
|
|
1187
|
+
path,
|
|
1188
|
+
boxConnection: connectionInput
|
|
1189
|
+
};
|
|
1190
|
+
const listFolderWithPaginationInputs = {
|
|
1191
|
+
path,
|
|
1192
|
+
fetchAll,
|
|
1193
|
+
pagination: folderPagination,
|
|
1194
|
+
fields,
|
|
1195
|
+
boxConnection: connectionInput
|
|
1196
|
+
};
|
|
1197
|
+
//#endregion
|
|
1198
|
+
//#region src/inputs/misc.ts
|
|
1199
|
+
const rawRequestInputs = {
|
|
1200
|
+
connection: connectionInput,
|
|
1201
|
+
..._prismatic_io_spectral_http.inputs,
|
|
1202
|
+
url: {
|
|
1203
|
+
..._prismatic_io_spectral_http.inputs.url,
|
|
1204
|
+
comments: "Input the path only, such as `/2.0/folders`. The base URL `https://api.box.com` is already included. For example, to call `https://api.box.com/2.0/folders`, enter `/2.0/folders` in this field.",
|
|
1205
|
+
example: "/2.0/folders"
|
|
1206
|
+
}
|
|
1207
|
+
};
|
|
1208
|
+
//#endregion
|
|
1209
|
+
//#region src/inputs/objects.ts
|
|
1210
|
+
const fromPath = (0, _prismatic_io_spectral.input)({
|
|
1211
|
+
label: "From Path",
|
|
1212
|
+
placeholder: "Enter source path",
|
|
1213
|
+
type: "string",
|
|
1214
|
+
required: true,
|
|
1215
|
+
comments: "The full path to the source file or folder. Must include a leading forward slash (/).",
|
|
1216
|
+
example: "/Marketing/Documents/OldReport.pdf",
|
|
1217
|
+
clean: _prismatic_io_spectral.util.types.toString
|
|
1218
|
+
});
|
|
1219
|
+
const toPath = (0, _prismatic_io_spectral.input)({
|
|
1220
|
+
label: "To Path",
|
|
1221
|
+
placeholder: "Enter destination path",
|
|
1222
|
+
type: "string",
|
|
1223
|
+
required: true,
|
|
1224
|
+
comments: "The full path to the destination location including the new filename. Must include a leading forward slash (/).",
|
|
1225
|
+
example: "/Archive/2024/OldReport.pdf",
|
|
1226
|
+
clean: _prismatic_io_spectral.util.types.toString
|
|
1227
|
+
});
|
|
1228
|
+
const copyObjectInputs = {
|
|
1229
|
+
fromPath,
|
|
1230
|
+
toPath,
|
|
1231
|
+
boxConnection: connectionInput
|
|
1232
|
+
};
|
|
1233
|
+
const moveObjectInputs = {
|
|
1234
|
+
fromPath,
|
|
1235
|
+
toPath,
|
|
1236
|
+
boxConnection: connectionInput
|
|
1237
|
+
};
|
|
1238
|
+
const deleteObjectInputs = {
|
|
1239
|
+
path,
|
|
1240
|
+
boxConnection: connectionInput
|
|
1241
|
+
};
|
|
1242
|
+
const pathDetailsInputs = {
|
|
1243
|
+
path,
|
|
1244
|
+
boxConnection: connectionInput
|
|
1245
|
+
};
|
|
1246
|
+
//#endregion
|
|
1247
|
+
//#region src/inputs/sharedLinks.ts
|
|
1248
|
+
const sharedLinkInput = (0, _prismatic_io_spectral.input)({
|
|
1249
|
+
label: "Shared Link",
|
|
1250
|
+
placeholder: "Enter shared link URL",
|
|
1251
|
+
type: "string",
|
|
1252
|
+
required: true,
|
|
1253
|
+
comments: "The URL of the shared link.",
|
|
1254
|
+
example: "https://app.box.com/s/abcd1234efgh5678ijkl",
|
|
1255
|
+
clean: _prismatic_io_spectral.util.types.toString
|
|
1256
|
+
});
|
|
1257
|
+
const sharedLinkPasswordInput = (0, _prismatic_io_spectral.input)({
|
|
1258
|
+
label: "Shared Link Password",
|
|
1259
|
+
placeholder: "Enter shared link password",
|
|
1260
|
+
type: "password",
|
|
1261
|
+
required: false,
|
|
1262
|
+
comments: "The password for the shared link, if one is set.",
|
|
1263
|
+
clean: _prismatic_io_spectral.util.types.toString
|
|
1264
|
+
});
|
|
1265
|
+
const fieldsInput = (0, _prismatic_io_spectral.input)({
|
|
1266
|
+
label: "Fields",
|
|
1267
|
+
placeholder: "Enter comma-separated field names",
|
|
1268
|
+
type: "string",
|
|
1269
|
+
required: false,
|
|
1270
|
+
comments: "A comma-separated list of attributes to include in the response. See [Box File Fields](https://developer.box.com/reference/files-resources#file) for available options.",
|
|
1271
|
+
example: "type,id,name,size,created_at",
|
|
1272
|
+
clean: cleanString
|
|
1273
|
+
});
|
|
1274
|
+
const sharedLinkAccessInput = (0, _prismatic_io_spectral.input)({
|
|
1275
|
+
label: "Shared Link Access",
|
|
1276
|
+
placeholder: "Enter access level",
|
|
1277
|
+
type: "string",
|
|
1278
|
+
required: true,
|
|
1279
|
+
comments: "The level of access for the shared link. Values: open, company, collaborators. See [Box Shared Links](https://developer.box.com/guides/shared-links) for details.",
|
|
1280
|
+
example: "open",
|
|
1281
|
+
clean: _prismatic_io_spectral.util.types.toString
|
|
1282
|
+
});
|
|
1283
|
+
const sharedLinkPermissionsInput = (0, _prismatic_io_spectral.input)({
|
|
1284
|
+
label: "Shared Link Permissions",
|
|
1285
|
+
placeholder: "Enter shared link permissions as JSON",
|
|
1286
|
+
type: "code",
|
|
1287
|
+
language: "json",
|
|
1288
|
+
default: JSON.stringify({
|
|
1289
|
+
can_download: true,
|
|
1290
|
+
can_edit: true,
|
|
1291
|
+
can_preview: true
|
|
1292
|
+
}, null, 2),
|
|
1293
|
+
required: false,
|
|
1294
|
+
comments: "The permissions for the shared link (file). Specify which actions are allowed. See [Box Shared Link Permissions](https://developer.box.com/reference/put-files-id#request-body) for details.",
|
|
1295
|
+
clean: _prismatic_io_spectral.util.types.toObject
|
|
1296
|
+
});
|
|
1297
|
+
const sharedLinkPermissionsFolderInput = (0, _prismatic_io_spectral.input)({
|
|
1298
|
+
label: "Shared Link Permissions Folder",
|
|
1299
|
+
placeholder: "Enter shared link permissions as JSON",
|
|
1300
|
+
type: "code",
|
|
1301
|
+
language: "json",
|
|
1302
|
+
default: JSON.stringify({
|
|
1303
|
+
can_download: true,
|
|
1304
|
+
can_preview: true
|
|
1305
|
+
}, null, 2),
|
|
1306
|
+
required: false,
|
|
1307
|
+
comments: "The permissions for the shared link (folder). Specify which actions are allowed. See [Box Shared Link Permissions](https://developer.box.com/reference/put-folders-id#request-body) for details.",
|
|
1308
|
+
clean: _prismatic_io_spectral.util.types.toObject
|
|
1309
|
+
});
|
|
1310
|
+
const sharedLinkVanityNameInput = (0, _prismatic_io_spectral.input)({
|
|
1311
|
+
label: "Shared Link Vanity Name",
|
|
1312
|
+
placeholder: "Enter custom vanity name",
|
|
1313
|
+
type: "string",
|
|
1314
|
+
required: false,
|
|
1315
|
+
comments: "The custom vanity name for the shared link URL. Creates a URL like `https://app.box.com/v/your-vanity-name`.",
|
|
1316
|
+
example: "q4-financial-report",
|
|
1317
|
+
clean: cleanString
|
|
1318
|
+
});
|
|
1319
|
+
const fileAdditionalFields = (0, _prismatic_io_spectral.structuredObjectInput)({
|
|
1320
|
+
label: "Additional Fields",
|
|
1321
|
+
required: false,
|
|
1322
|
+
comments: "Additional optional fields: includes Shared Link Password, Shared Link Permissions, and Shared Link Vanity Name.",
|
|
1323
|
+
inputs: {
|
|
1324
|
+
sharedLinkPassword: sharedLinkPasswordInput,
|
|
1325
|
+
sharedLinkPermissions: sharedLinkPermissionsInput,
|
|
1326
|
+
sharedLinkVanityName: sharedLinkVanityNameInput
|
|
1327
|
+
}
|
|
1328
|
+
});
|
|
1329
|
+
const folderAdditionalFields = (0, _prismatic_io_spectral.structuredObjectInput)({
|
|
1330
|
+
label: "Additional Fields",
|
|
1331
|
+
required: false,
|
|
1332
|
+
comments: "Additional optional fields: includes Shared Link Password, Shared Link Permissions Folder, and Shared Link Vanity Name.",
|
|
1333
|
+
inputs: {
|
|
1334
|
+
sharedLinkPassword: sharedLinkPasswordInput,
|
|
1335
|
+
sharedLinkPermissions: sharedLinkPermissionsFolderInput,
|
|
1336
|
+
sharedLinkVanityName: sharedLinkVanityNameInput
|
|
1337
|
+
}
|
|
1338
|
+
});
|
|
1339
|
+
const findFileForSharedLinkInputs = {
|
|
1340
|
+
sharedLink: sharedLinkInput,
|
|
1341
|
+
sharedLinkPassword: sharedLinkPasswordInput,
|
|
1342
|
+
fields: fieldsInput,
|
|
1343
|
+
boxConnection: connectionInput
|
|
1344
|
+
};
|
|
1345
|
+
const getSharedLinkForFileInputs = {
|
|
1346
|
+
fileId: fileIdInput,
|
|
1347
|
+
boxConnection: connectionInput
|
|
1348
|
+
};
|
|
1349
|
+
const addSharedLinkToFileInputs = {
|
|
1350
|
+
fileId: fileIdInput,
|
|
1351
|
+
fields: sharedLinkInput,
|
|
1352
|
+
sharedLinkAccess: sharedLinkAccessInput,
|
|
1353
|
+
additionalFields: fileAdditionalFields,
|
|
1354
|
+
boxConnection: connectionInput
|
|
1355
|
+
};
|
|
1356
|
+
const updateSharedLinkToFileInputs = {
|
|
1357
|
+
fileId: fileIdInput,
|
|
1358
|
+
sharedLink: sharedLinkInput,
|
|
1359
|
+
sharedLinkAccess: sharedLinkAccessInput,
|
|
1360
|
+
additionalFields: fileAdditionalFields,
|
|
1361
|
+
boxConnection: connectionInput
|
|
1362
|
+
};
|
|
1363
|
+
const removeSharedLinkFromFileInputs = {
|
|
1364
|
+
fileId: fileIdInput,
|
|
1365
|
+
boxConnection: connectionInput
|
|
1366
|
+
};
|
|
1367
|
+
const findFolderForSharedLinkInputs = {
|
|
1368
|
+
sharedLink: sharedLinkInput,
|
|
1369
|
+
sharedLinkPassword: sharedLinkPasswordInput,
|
|
1370
|
+
fields: fieldsInput,
|
|
1371
|
+
boxConnection: connectionInput
|
|
1372
|
+
};
|
|
1373
|
+
const getSharedLinkForFolderInputs = {
|
|
1374
|
+
folderId: folderIdInput,
|
|
1375
|
+
boxConnection: connectionInput
|
|
1376
|
+
};
|
|
1377
|
+
const addSharedLinkToFolderInputs = {
|
|
1378
|
+
folderId: folderIdInput,
|
|
1379
|
+
sharedLink: sharedLinkInput,
|
|
1380
|
+
sharedLinkAccess: sharedLinkAccessInput,
|
|
1381
|
+
additionalFields: folderAdditionalFields,
|
|
1382
|
+
boxConnection: connectionInput
|
|
1383
|
+
};
|
|
1384
|
+
const updateSharedLinkOnFolderInputs = {
|
|
1385
|
+
folderId: folderIdInput,
|
|
1386
|
+
sharedLink: sharedLinkInput,
|
|
1387
|
+
sharedLinkAccess: sharedLinkAccessInput,
|
|
1388
|
+
additionalFields: folderAdditionalFields,
|
|
1389
|
+
boxConnection: connectionInput
|
|
1390
|
+
};
|
|
1391
|
+
const removeSharedLinkFromFolderInputs = {
|
|
1392
|
+
folderId: folderIdInput,
|
|
1393
|
+
boxConnection: connectionInput
|
|
1394
|
+
};
|
|
1395
|
+
//#endregion
|
|
1396
|
+
//#region src/inputs/triggers.ts
|
|
1397
|
+
const lookBackDate = (0, _prismatic_io_spectral.input)({
|
|
1398
|
+
label: "Look-back Date",
|
|
1399
|
+
placeholder: "Enter look-back date (YYYY-MM-DD)",
|
|
1400
|
+
type: "string",
|
|
1401
|
+
required: false,
|
|
1402
|
+
comments: "The date the initial sync starts from, in YYYY-MM-DD format. Cannot be a future date. Leave empty to start from the first recurrence with no backfill.",
|
|
1403
|
+
example: "2026-01-01",
|
|
1404
|
+
clean: lookBackDateClean
|
|
1405
|
+
});
|
|
1406
|
+
const webhookInputs = {
|
|
1407
|
+
primarySignatureKey: {
|
|
1408
|
+
...signatureKey,
|
|
1409
|
+
label: "Primary Signature Key"
|
|
1410
|
+
},
|
|
1411
|
+
secondarySignatureKey: {
|
|
1412
|
+
...signatureKey,
|
|
1413
|
+
label: "Secondary Signature Key"
|
|
1414
|
+
}
|
|
1415
|
+
};
|
|
1416
|
+
const managedWebhookInputs = {
|
|
1417
|
+
connection: connectionInput,
|
|
1418
|
+
targetId,
|
|
1419
|
+
targetType,
|
|
1420
|
+
triggerTypes,
|
|
1421
|
+
primarySignatureKey: {
|
|
1422
|
+
...signatureKey,
|
|
1423
|
+
label: "Primary Signature Key"
|
|
1424
|
+
},
|
|
1425
|
+
secondarySignatureKey: {
|
|
1426
|
+
...signatureKey,
|
|
1427
|
+
label: "Secondary Signature Key"
|
|
1428
|
+
}
|
|
1429
|
+
};
|
|
1430
|
+
const newOrUpdatedFileInputs = {
|
|
1431
|
+
connection: connectionInput,
|
|
1432
|
+
folderId: folderIdInput,
|
|
1433
|
+
lookBackDate
|
|
1434
|
+
};
|
|
1435
|
+
const newFolderInputs = {
|
|
1436
|
+
connection: connectionInput,
|
|
1437
|
+
folderId: folderIdInput,
|
|
1438
|
+
lookBackDate
|
|
1439
|
+
};
|
|
1440
|
+
const newFileCommentsInputs = {
|
|
1441
|
+
connection: connectionInput,
|
|
1442
|
+
fileId: fileIdInput,
|
|
1443
|
+
lookBackDate
|
|
1444
|
+
};
|
|
1445
|
+
//#endregion
|
|
1446
|
+
//#region src/inputs/users.ts
|
|
1447
|
+
const getCurrentUserInputs = { boxConnection: connectionInput };
|
|
1448
|
+
//#endregion
|
|
1449
|
+
//#region src/inputs/webhooks.ts
|
|
1450
|
+
const address = (0, _prismatic_io_spectral.input)({
|
|
1451
|
+
label: "Webhook URL",
|
|
1452
|
+
placeholder: "Enter webhook URL",
|
|
1453
|
+
comments: "The URL where webhook events will be sent. Reference a flow's URL from the trigger payload.",
|
|
1454
|
+
type: "string",
|
|
1455
|
+
required: true,
|
|
1456
|
+
example: "https://hooks.example.com/box/abc123",
|
|
1457
|
+
clean: _prismatic_io_spectral.util.types.toString
|
|
1458
|
+
});
|
|
1459
|
+
const webhookId = (0, _prismatic_io_spectral.input)({
|
|
1460
|
+
label: "Webhook ID",
|
|
1461
|
+
placeholder: "Enter webhook ID",
|
|
1462
|
+
comments: "The unique identifier of the webhook.",
|
|
1463
|
+
type: "string",
|
|
1464
|
+
example: "375893453",
|
|
1465
|
+
required: true,
|
|
1466
|
+
dataSource: "selectWebhook",
|
|
1467
|
+
clean: _prismatic_io_spectral.util.types.toString
|
|
1468
|
+
});
|
|
1469
|
+
const showOnlyInstanceWebhooks = (0, _prismatic_io_spectral.input)({
|
|
1470
|
+
label: "Show Only Instance Webhooks",
|
|
1471
|
+
comments: "When true, returns only webhooks that point to this instance.",
|
|
1472
|
+
type: "boolean",
|
|
1473
|
+
required: false,
|
|
1474
|
+
default: "true",
|
|
1475
|
+
clean: _prismatic_io_spectral.util.types.toBool
|
|
1476
|
+
});
|
|
1477
|
+
const listWebhooksInputs = {
|
|
1478
|
+
boxConnection: connectionInput,
|
|
1479
|
+
fetchAll,
|
|
1480
|
+
pagination: (0, _prismatic_io_spectral.structuredObjectInput)({
|
|
1481
|
+
label: "Pagination",
|
|
1482
|
+
required: false,
|
|
1483
|
+
comments: "Marker and limit controls for paging through results.",
|
|
1484
|
+
inputs: {
|
|
1485
|
+
limit,
|
|
1486
|
+
marker
|
|
1487
|
+
}
|
|
1488
|
+
}),
|
|
1489
|
+
showOnlyInstanceWebhooks
|
|
1490
|
+
};
|
|
1491
|
+
const createWebhookInputs = {
|
|
1492
|
+
address,
|
|
1493
|
+
targetId,
|
|
1494
|
+
targetType,
|
|
1495
|
+
triggerTypes,
|
|
1496
|
+
primarySignatureKey: {
|
|
1497
|
+
...signatureKey,
|
|
1498
|
+
label: "Primary Signature Key"
|
|
1499
|
+
},
|
|
1500
|
+
secondarySignatureKey: {
|
|
1501
|
+
...signatureKey,
|
|
1502
|
+
label: "Secondary Signature Key"
|
|
1503
|
+
},
|
|
1504
|
+
boxConnection: connectionInput
|
|
1505
|
+
};
|
|
1506
|
+
const deleteWebhookInputs = {
|
|
1507
|
+
boxConnection: connectionInput,
|
|
1508
|
+
webhookId
|
|
1509
|
+
};
|
|
1510
|
+
const deleteInstanceWebhooksInputs = { boxConnection: connectionInput };
|
|
1511
|
+
//#endregion
|
|
1512
|
+
//#region src/actions/files/downloadFile.ts
|
|
1513
|
+
const downloadFile = (0, _prismatic_io_spectral.action)({
|
|
1514
|
+
display: {
|
|
1515
|
+
label: "Download File",
|
|
1516
|
+
description: "Download the file at the specified path."
|
|
1517
|
+
},
|
|
1518
|
+
performSafety: "notAllowed",
|
|
1519
|
+
perform: async (_context, { path, boxConnection }) => {
|
|
1520
|
+
const client = createAuthorizedClient({ boxConnection });
|
|
1521
|
+
const { id, type, name } = (await getPathEntries(client, _prismatic_io_spectral.util.types.toString(path))).slice(-1)[0];
|
|
1522
|
+
if (type !== "file") throw Error(`'${name}' is not a file`);
|
|
1523
|
+
const { data, headers: { "content-type": contentType } } = await (0, _prismatic_io_spectral_http.createClient)({
|
|
1524
|
+
baseUrl: await client.downloads.getDownloadFileUrl(_prismatic_io_spectral.util.types.toString(id)),
|
|
1525
|
+
responseType: "arraybuffer"
|
|
1526
|
+
}).get("");
|
|
1527
|
+
return {
|
|
1528
|
+
data,
|
|
1529
|
+
contentType: _prismatic_io_spectral.util.types.toString(contentType)
|
|
1530
|
+
};
|
|
1531
|
+
},
|
|
1532
|
+
examplePerform: async () => ({
|
|
1533
|
+
data: downloadFileExamplePayload.data,
|
|
1534
|
+
contentType: downloadFileExamplePayload.contentType
|
|
1535
|
+
}),
|
|
1536
|
+
inputs: downloadFileInputs,
|
|
1537
|
+
examplePayload: downloadFileExamplePayload
|
|
1538
|
+
});
|
|
1539
|
+
//#endregion
|
|
1540
|
+
//#region src/outputSchemas/common.ts
|
|
1541
|
+
const userMiniSchema = {
|
|
1542
|
+
type: "object",
|
|
1543
|
+
properties: {
|
|
1544
|
+
id: { type: "string" },
|
|
1545
|
+
type: {
|
|
1546
|
+
type: "string",
|
|
1547
|
+
enum: ["user"]
|
|
1548
|
+
},
|
|
1549
|
+
name: { type: "string" },
|
|
1550
|
+
login: {
|
|
1551
|
+
type: "string",
|
|
1552
|
+
format: "email"
|
|
1553
|
+
}
|
|
1554
|
+
},
|
|
1555
|
+
required: ["id", "type"]
|
|
1556
|
+
};
|
|
1557
|
+
const folderMiniSchema = {
|
|
1558
|
+
type: "object",
|
|
1559
|
+
properties: {
|
|
1560
|
+
id: { type: "string" },
|
|
1561
|
+
type: {
|
|
1562
|
+
type: "string",
|
|
1563
|
+
enum: ["folder"]
|
|
1564
|
+
},
|
|
1565
|
+
etag: { type: ["string", "null"] },
|
|
1566
|
+
sequence_id: { type: ["string", "null"] },
|
|
1567
|
+
name: { type: "string" }
|
|
1568
|
+
},
|
|
1569
|
+
required: ["id", "type"]
|
|
1570
|
+
};
|
|
1571
|
+
const fileVersionMiniSchema = {
|
|
1572
|
+
type: "object",
|
|
1573
|
+
properties: {
|
|
1574
|
+
id: { type: "string" },
|
|
1575
|
+
type: {
|
|
1576
|
+
type: "string",
|
|
1577
|
+
enum: ["file_version"]
|
|
1578
|
+
},
|
|
1579
|
+
sha1: { type: "string" }
|
|
1580
|
+
},
|
|
1581
|
+
required: ["id", "type"]
|
|
1582
|
+
};
|
|
1583
|
+
const fileMiniSchema = {
|
|
1584
|
+
type: "object",
|
|
1585
|
+
properties: {
|
|
1586
|
+
id: { type: "string" },
|
|
1587
|
+
type: {
|
|
1588
|
+
type: "string",
|
|
1589
|
+
enum: ["file"]
|
|
1590
|
+
},
|
|
1591
|
+
etag: { type: ["string", "null"] },
|
|
1592
|
+
sequence_id: { type: ["string", "null"] },
|
|
1593
|
+
name: { type: "string" },
|
|
1594
|
+
sha1: { type: "string" },
|
|
1595
|
+
file_version: fileVersionMiniSchema
|
|
1596
|
+
},
|
|
1597
|
+
required: ["id", "type"]
|
|
1598
|
+
};
|
|
1599
|
+
const pathCollectionSchema = {
|
|
1600
|
+
type: "object",
|
|
1601
|
+
properties: {
|
|
1602
|
+
total_count: { type: "integer" },
|
|
1603
|
+
entries: {
|
|
1604
|
+
type: "array",
|
|
1605
|
+
items: folderMiniSchema
|
|
1606
|
+
}
|
|
1607
|
+
},
|
|
1608
|
+
required: ["total_count", "entries"]
|
|
1609
|
+
};
|
|
1610
|
+
const nullableSharedLinkSchema = {
|
|
1611
|
+
type: "object",
|
|
1612
|
+
properties: {
|
|
1613
|
+
url: {
|
|
1614
|
+
type: "string",
|
|
1615
|
+
format: "uri"
|
|
1616
|
+
},
|
|
1617
|
+
download_url: {
|
|
1618
|
+
type: ["string", "null"],
|
|
1619
|
+
format: "uri"
|
|
1620
|
+
},
|
|
1621
|
+
vanity_url: {
|
|
1622
|
+
type: ["string", "null"],
|
|
1623
|
+
format: "uri"
|
|
1624
|
+
},
|
|
1625
|
+
vanity_name: { type: ["string", "null"] },
|
|
1626
|
+
access: {
|
|
1627
|
+
type: "string",
|
|
1628
|
+
enum: [
|
|
1629
|
+
"open",
|
|
1630
|
+
"company",
|
|
1631
|
+
"collaborators"
|
|
1632
|
+
]
|
|
1633
|
+
},
|
|
1634
|
+
effective_access: {
|
|
1635
|
+
type: "string",
|
|
1636
|
+
enum: [
|
|
1637
|
+
"open",
|
|
1638
|
+
"company",
|
|
1639
|
+
"collaborators"
|
|
1640
|
+
]
|
|
1641
|
+
},
|
|
1642
|
+
effective_permission: {
|
|
1643
|
+
type: "string",
|
|
1644
|
+
enum: [
|
|
1645
|
+
"can_edit",
|
|
1646
|
+
"can_download",
|
|
1647
|
+
"can_preview",
|
|
1648
|
+
"no_access"
|
|
1649
|
+
]
|
|
1650
|
+
},
|
|
1651
|
+
unshared_at: {
|
|
1652
|
+
type: ["string", "null"],
|
|
1653
|
+
format: "date-time"
|
|
1654
|
+
},
|
|
1655
|
+
is_password_enabled: { type: "boolean" },
|
|
1656
|
+
permissions: {
|
|
1657
|
+
type: "object",
|
|
1658
|
+
properties: {
|
|
1659
|
+
can_download: { type: "boolean" },
|
|
1660
|
+
can_preview: { type: "boolean" },
|
|
1661
|
+
can_edit: { type: "boolean" }
|
|
1662
|
+
}
|
|
1663
|
+
},
|
|
1664
|
+
download_count: { type: "integer" },
|
|
1665
|
+
preview_count: { type: "integer" },
|
|
1666
|
+
one_time_passcode: {
|
|
1667
|
+
type: "object",
|
|
1668
|
+
properties: {
|
|
1669
|
+
mode: { type: "string" },
|
|
1670
|
+
allowlist: {
|
|
1671
|
+
type: "array",
|
|
1672
|
+
items: {
|
|
1673
|
+
type: "object",
|
|
1674
|
+
properties: {
|
|
1675
|
+
type: {
|
|
1676
|
+
type: "string",
|
|
1677
|
+
enum: ["email", "domain"]
|
|
1678
|
+
},
|
|
1679
|
+
value: { type: "string" },
|
|
1680
|
+
created_at: {
|
|
1681
|
+
type: "string",
|
|
1682
|
+
format: "date-time"
|
|
1683
|
+
},
|
|
1684
|
+
created_by: {
|
|
1685
|
+
type: "object",
|
|
1686
|
+
properties: {
|
|
1687
|
+
id: { type: "string" },
|
|
1688
|
+
type: {
|
|
1689
|
+
type: "string",
|
|
1690
|
+
enum: ["user"]
|
|
1691
|
+
}
|
|
1692
|
+
},
|
|
1693
|
+
required: ["id", "type"]
|
|
1694
|
+
}
|
|
1695
|
+
},
|
|
1696
|
+
required: [
|
|
1697
|
+
"type",
|
|
1698
|
+
"value",
|
|
1699
|
+
"created_at",
|
|
1700
|
+
"created_by"
|
|
1701
|
+
]
|
|
1702
|
+
}
|
|
1703
|
+
}
|
|
1704
|
+
},
|
|
1705
|
+
required: ["mode"]
|
|
1706
|
+
}
|
|
1707
|
+
},
|
|
1708
|
+
required: ["url"],
|
|
1709
|
+
type: ["object", "null"]
|
|
1710
|
+
};
|
|
1711
|
+
const watermarkInfoSchema = {
|
|
1712
|
+
type: "object",
|
|
1713
|
+
properties: {
|
|
1714
|
+
is_watermarked: { type: "boolean" },
|
|
1715
|
+
is_watermark_inherited: { type: "boolean" },
|
|
1716
|
+
is_watermarked_by_access_policy: { type: "boolean" }
|
|
1717
|
+
}
|
|
1718
|
+
};
|
|
1719
|
+
const classificationSchema = {
|
|
1720
|
+
type: ["object", "null"],
|
|
1721
|
+
properties: {
|
|
1722
|
+
name: { type: "string" },
|
|
1723
|
+
definition: { type: "string" },
|
|
1724
|
+
color: { type: "string" }
|
|
1725
|
+
}
|
|
1726
|
+
};
|
|
1727
|
+
const collectionSchema = {
|
|
1728
|
+
type: "object",
|
|
1729
|
+
properties: {
|
|
1730
|
+
id: { type: "string" },
|
|
1731
|
+
type: {
|
|
1732
|
+
type: "string",
|
|
1733
|
+
enum: ["collection"]
|
|
1734
|
+
},
|
|
1735
|
+
name: {
|
|
1736
|
+
type: "string",
|
|
1737
|
+
enum: ["Favorites"]
|
|
1738
|
+
},
|
|
1739
|
+
collection_type: {
|
|
1740
|
+
type: "string",
|
|
1741
|
+
enum: ["favorites"]
|
|
1742
|
+
}
|
|
1743
|
+
}
|
|
1744
|
+
};
|
|
1745
|
+
const metadataSchema = {
|
|
1746
|
+
type: "object",
|
|
1747
|
+
additionalProperties: true
|
|
1748
|
+
};
|
|
1749
|
+
const fileFullSchema = {
|
|
1750
|
+
type: "object",
|
|
1751
|
+
properties: {
|
|
1752
|
+
id: { type: "string" },
|
|
1753
|
+
type: {
|
|
1754
|
+
type: "string",
|
|
1755
|
+
enum: ["file"]
|
|
1756
|
+
},
|
|
1757
|
+
etag: { type: ["string", "null"] },
|
|
1758
|
+
sequence_id: { type: ["string", "null"] },
|
|
1759
|
+
name: { type: "string" },
|
|
1760
|
+
sha1: { type: "string" },
|
|
1761
|
+
file_version: fileVersionMiniSchema,
|
|
1762
|
+
description: { type: "string" },
|
|
1763
|
+
size: { type: "integer" },
|
|
1764
|
+
path_collection: pathCollectionSchema,
|
|
1765
|
+
created_at: {
|
|
1766
|
+
type: "string",
|
|
1767
|
+
format: "date-time"
|
|
1768
|
+
},
|
|
1769
|
+
modified_at: {
|
|
1770
|
+
type: "string",
|
|
1771
|
+
format: "date-time"
|
|
1772
|
+
},
|
|
1773
|
+
trashed_at: {
|
|
1774
|
+
type: ["string", "null"],
|
|
1775
|
+
format: "date-time"
|
|
1776
|
+
},
|
|
1777
|
+
purged_at: {
|
|
1778
|
+
type: ["string", "null"],
|
|
1779
|
+
format: "date-time"
|
|
1780
|
+
},
|
|
1781
|
+
content_created_at: {
|
|
1782
|
+
type: ["string", "null"],
|
|
1783
|
+
format: "date-time"
|
|
1784
|
+
},
|
|
1785
|
+
content_modified_at: {
|
|
1786
|
+
type: ["string", "null"],
|
|
1787
|
+
format: "date-time"
|
|
1788
|
+
},
|
|
1789
|
+
created_by: userMiniSchema,
|
|
1790
|
+
modified_by: userMiniSchema,
|
|
1791
|
+
owned_by: userMiniSchema,
|
|
1792
|
+
shared_link: nullableSharedLinkSchema,
|
|
1793
|
+
parent: {
|
|
1794
|
+
...folderMiniSchema,
|
|
1795
|
+
type: ["object", "null"]
|
|
1796
|
+
},
|
|
1797
|
+
item_status: {
|
|
1798
|
+
type: "string",
|
|
1799
|
+
enum: [
|
|
1800
|
+
"active",
|
|
1801
|
+
"trashed",
|
|
1802
|
+
"deleted"
|
|
1803
|
+
]
|
|
1804
|
+
},
|
|
1805
|
+
version_number: { type: "string" },
|
|
1806
|
+
comment_count: { type: "integer" },
|
|
1807
|
+
permissions: {
|
|
1808
|
+
type: "object",
|
|
1809
|
+
properties: {
|
|
1810
|
+
can_delete: { type: "boolean" },
|
|
1811
|
+
can_download: { type: "boolean" },
|
|
1812
|
+
can_invite_collaborator: { type: "boolean" },
|
|
1813
|
+
can_rename: { type: "boolean" },
|
|
1814
|
+
can_set_share_access: { type: "boolean" },
|
|
1815
|
+
can_share: { type: "boolean" },
|
|
1816
|
+
can_annotate: { type: "boolean" },
|
|
1817
|
+
can_comment: { type: "boolean" },
|
|
1818
|
+
can_preview: { type: "boolean" },
|
|
1819
|
+
can_upload: { type: "boolean" },
|
|
1820
|
+
can_view_annotations_all: { type: "boolean" },
|
|
1821
|
+
can_view_annotations_self: { type: "boolean" },
|
|
1822
|
+
can_apply_watermark: { type: "boolean" }
|
|
1823
|
+
}
|
|
1824
|
+
},
|
|
1825
|
+
tags: {
|
|
1826
|
+
type: "array",
|
|
1827
|
+
items: { type: "string" }
|
|
1828
|
+
},
|
|
1829
|
+
lock: {
|
|
1830
|
+
type: ["object", "null"],
|
|
1831
|
+
properties: {
|
|
1832
|
+
id: { type: "string" },
|
|
1833
|
+
type: {
|
|
1834
|
+
type: "string",
|
|
1835
|
+
enum: ["lock"]
|
|
1836
|
+
},
|
|
1837
|
+
created_by: userMiniSchema,
|
|
1838
|
+
created_at: {
|
|
1839
|
+
type: "string",
|
|
1840
|
+
format: "date-time"
|
|
1841
|
+
},
|
|
1842
|
+
expired_at: {
|
|
1843
|
+
type: "string",
|
|
1844
|
+
format: "date-time"
|
|
1845
|
+
},
|
|
1846
|
+
is_download_prevented: { type: "boolean" },
|
|
1847
|
+
app_type: {
|
|
1848
|
+
type: ["string", "null"],
|
|
1849
|
+
enum: [
|
|
1850
|
+
"gsuite",
|
|
1851
|
+
"office_wopi",
|
|
1852
|
+
"office_wopiplus",
|
|
1853
|
+
"other",
|
|
1854
|
+
null
|
|
1855
|
+
]
|
|
1856
|
+
}
|
|
1857
|
+
}
|
|
1858
|
+
},
|
|
1859
|
+
extension: { type: "string" },
|
|
1860
|
+
is_package: { type: "boolean" },
|
|
1861
|
+
expiring_embed_link: {
|
|
1862
|
+
type: ["object", "null"],
|
|
1863
|
+
properties: {
|
|
1864
|
+
access_token: { type: "string" },
|
|
1865
|
+
expires_in: { type: "integer" },
|
|
1866
|
+
token_type: {
|
|
1867
|
+
type: "string",
|
|
1868
|
+
enum: ["bearer"]
|
|
1869
|
+
},
|
|
1870
|
+
url: {
|
|
1871
|
+
type: "string",
|
|
1872
|
+
format: "uri"
|
|
1873
|
+
},
|
|
1874
|
+
restricted_to: {
|
|
1875
|
+
type: "array",
|
|
1876
|
+
items: {
|
|
1877
|
+
type: "object",
|
|
1878
|
+
properties: {
|
|
1879
|
+
scope: {
|
|
1880
|
+
type: "string",
|
|
1881
|
+
enum: [
|
|
1882
|
+
"annotation_edit",
|
|
1883
|
+
"annotation_view_all",
|
|
1884
|
+
"annotation_view_self",
|
|
1885
|
+
"base_explorer",
|
|
1886
|
+
"base_picker",
|
|
1887
|
+
"base_preview",
|
|
1888
|
+
"base_upload",
|
|
1889
|
+
"item_delete",
|
|
1890
|
+
"item_download",
|
|
1891
|
+
"item_preview",
|
|
1892
|
+
"item_rename",
|
|
1893
|
+
"item_share",
|
|
1894
|
+
"item_upload",
|
|
1895
|
+
"item_read"
|
|
1896
|
+
]
|
|
1897
|
+
},
|
|
1898
|
+
object: {
|
|
1899
|
+
type: "object",
|
|
1900
|
+
properties: {
|
|
1901
|
+
...fileMiniSchema.properties,
|
|
1902
|
+
type: {
|
|
1903
|
+
type: "string",
|
|
1904
|
+
enum: ["folder", "file"]
|
|
1905
|
+
}
|
|
1906
|
+
},
|
|
1907
|
+
required: ["id", "type"]
|
|
1908
|
+
}
|
|
1909
|
+
}
|
|
1910
|
+
}
|
|
1911
|
+
}
|
|
1912
|
+
}
|
|
1913
|
+
},
|
|
1914
|
+
watermark_info: watermarkInfoSchema,
|
|
1915
|
+
is_accessible_via_shared_link: { type: "boolean" },
|
|
1916
|
+
allowed_invitee_roles: {
|
|
1917
|
+
type: "array",
|
|
1918
|
+
items: {
|
|
1919
|
+
type: "string",
|
|
1920
|
+
enum: [
|
|
1921
|
+
"editor",
|
|
1922
|
+
"viewer",
|
|
1923
|
+
"previewer",
|
|
1924
|
+
"uploader",
|
|
1925
|
+
"previewer uploader",
|
|
1926
|
+
"viewer uploader",
|
|
1927
|
+
"co-owner"
|
|
1928
|
+
]
|
|
1929
|
+
}
|
|
1930
|
+
},
|
|
1931
|
+
is_externally_owned: { type: "boolean" },
|
|
1932
|
+
has_collaborations: { type: "boolean" },
|
|
1933
|
+
metadata: metadataSchema,
|
|
1934
|
+
expires_at: {
|
|
1935
|
+
type: ["string", "null"],
|
|
1936
|
+
format: "date-time"
|
|
1937
|
+
},
|
|
1938
|
+
representations: {
|
|
1939
|
+
type: "object",
|
|
1940
|
+
properties: { entries: {
|
|
1941
|
+
type: "array",
|
|
1942
|
+
items: {
|
|
1943
|
+
type: "object",
|
|
1944
|
+
properties: {
|
|
1945
|
+
representation: { type: "string" },
|
|
1946
|
+
content: {
|
|
1947
|
+
type: "object",
|
|
1948
|
+
properties: { url_template: { type: "string" } }
|
|
1949
|
+
},
|
|
1950
|
+
info: {
|
|
1951
|
+
type: "object",
|
|
1952
|
+
properties: { url: {
|
|
1953
|
+
type: "string",
|
|
1954
|
+
format: "uri"
|
|
1955
|
+
} }
|
|
1956
|
+
},
|
|
1957
|
+
properties: {
|
|
1958
|
+
type: "object",
|
|
1959
|
+
properties: {
|
|
1960
|
+
dimensions: { type: "string" },
|
|
1961
|
+
paged: { type: "string" },
|
|
1962
|
+
thumb: { type: "string" }
|
|
1963
|
+
}
|
|
1964
|
+
},
|
|
1965
|
+
status: {
|
|
1966
|
+
type: "object",
|
|
1967
|
+
properties: { state: {
|
|
1968
|
+
type: "string",
|
|
1969
|
+
enum: [
|
|
1970
|
+
"success",
|
|
1971
|
+
"viewable",
|
|
1972
|
+
"pending",
|
|
1973
|
+
"none"
|
|
1974
|
+
]
|
|
1975
|
+
} }
|
|
1976
|
+
}
|
|
1977
|
+
}
|
|
1978
|
+
}
|
|
1979
|
+
} }
|
|
1980
|
+
},
|
|
1981
|
+
classification: classificationSchema,
|
|
1982
|
+
uploader_display_name: { type: "string" },
|
|
1983
|
+
disposition_at: {
|
|
1984
|
+
type: ["string", "null"],
|
|
1985
|
+
format: "date-time"
|
|
1986
|
+
},
|
|
1987
|
+
shared_link_permission_options: {
|
|
1988
|
+
type: ["array", "null"],
|
|
1989
|
+
items: {
|
|
1990
|
+
type: "string",
|
|
1991
|
+
enum: [
|
|
1992
|
+
"can_preview",
|
|
1993
|
+
"can_download",
|
|
1994
|
+
"can_edit"
|
|
1995
|
+
]
|
|
1996
|
+
}
|
|
1997
|
+
},
|
|
1998
|
+
is_associated_with_app_item: { type: "boolean" },
|
|
1999
|
+
collections: {
|
|
2000
|
+
type: "array",
|
|
2001
|
+
items: collectionSchema
|
|
2002
|
+
},
|
|
2003
|
+
is_download_available: { type: "boolean" },
|
|
2004
|
+
download_url: {
|
|
2005
|
+
type: ["string", "null"],
|
|
2006
|
+
format: "uri"
|
|
2007
|
+
},
|
|
2008
|
+
authenticated_download_url: {
|
|
2009
|
+
type: ["string", "null"],
|
|
2010
|
+
format: "uri"
|
|
2011
|
+
},
|
|
2012
|
+
allowed_shared_link_access_levels: {
|
|
2013
|
+
type: "array",
|
|
2014
|
+
items: {
|
|
2015
|
+
type: "string",
|
|
2016
|
+
enum: [
|
|
2017
|
+
"open",
|
|
2018
|
+
"company",
|
|
2019
|
+
"collaborators"
|
|
2020
|
+
]
|
|
2021
|
+
}
|
|
2022
|
+
}
|
|
2023
|
+
},
|
|
2024
|
+
required: ["id", "type"]
|
|
2025
|
+
};
|
|
2026
|
+
const folderItemSchema = {
|
|
2027
|
+
type: "object",
|
|
2028
|
+
properties: {
|
|
2029
|
+
...fileFullSchema.properties,
|
|
2030
|
+
type: {
|
|
2031
|
+
type: "string",
|
|
2032
|
+
enum: [
|
|
2033
|
+
"file",
|
|
2034
|
+
"folder",
|
|
2035
|
+
"web_link"
|
|
2036
|
+
]
|
|
2037
|
+
},
|
|
2038
|
+
url: {
|
|
2039
|
+
type: "string",
|
|
2040
|
+
format: "uri"
|
|
2041
|
+
},
|
|
2042
|
+
created_at: {
|
|
2043
|
+
type: ["string", "null"],
|
|
2044
|
+
format: "date-time"
|
|
2045
|
+
},
|
|
2046
|
+
modified_at: {
|
|
2047
|
+
type: ["string", "null"],
|
|
2048
|
+
format: "date-time"
|
|
2049
|
+
}
|
|
2050
|
+
},
|
|
2051
|
+
required: ["id", "type"],
|
|
2052
|
+
additionalProperties: true
|
|
2053
|
+
};
|
|
2054
|
+
const folderFullSchema = {
|
|
2055
|
+
type: "object",
|
|
2056
|
+
properties: {
|
|
2057
|
+
id: { type: "string" },
|
|
2058
|
+
type: {
|
|
2059
|
+
type: "string",
|
|
2060
|
+
enum: ["folder"]
|
|
2061
|
+
},
|
|
2062
|
+
etag: { type: ["string", "null"] },
|
|
2063
|
+
sequence_id: { type: ["string", "null"] },
|
|
2064
|
+
name: { type: "string" },
|
|
2065
|
+
created_at: {
|
|
2066
|
+
type: ["string", "null"],
|
|
2067
|
+
format: "date-time"
|
|
2068
|
+
},
|
|
2069
|
+
modified_at: {
|
|
2070
|
+
type: ["string", "null"],
|
|
2071
|
+
format: "date-time"
|
|
2072
|
+
},
|
|
2073
|
+
description: { type: "string" },
|
|
2074
|
+
size: { type: "integer" },
|
|
2075
|
+
path_collection: pathCollectionSchema,
|
|
2076
|
+
created_by: userMiniSchema,
|
|
2077
|
+
modified_by: userMiniSchema,
|
|
2078
|
+
trashed_at: {
|
|
2079
|
+
type: ["string", "null"],
|
|
2080
|
+
format: "date-time"
|
|
2081
|
+
},
|
|
2082
|
+
purged_at: {
|
|
2083
|
+
type: ["string", "null"],
|
|
2084
|
+
format: "date-time"
|
|
2085
|
+
},
|
|
2086
|
+
content_created_at: {
|
|
2087
|
+
type: ["string", "null"],
|
|
2088
|
+
format: "date-time"
|
|
2089
|
+
},
|
|
2090
|
+
content_modified_at: {
|
|
2091
|
+
type: ["string", "null"],
|
|
2092
|
+
format: "date-time"
|
|
2093
|
+
},
|
|
2094
|
+
owned_by: userMiniSchema,
|
|
2095
|
+
shared_link: nullableSharedLinkSchema,
|
|
2096
|
+
folder_upload_email: {
|
|
2097
|
+
type: ["object", "null"],
|
|
2098
|
+
properties: {
|
|
2099
|
+
access: {
|
|
2100
|
+
type: "string",
|
|
2101
|
+
enum: ["open", "collaborators"]
|
|
2102
|
+
},
|
|
2103
|
+
email: {
|
|
2104
|
+
type: "string",
|
|
2105
|
+
format: "email"
|
|
2106
|
+
}
|
|
2107
|
+
}
|
|
2108
|
+
},
|
|
2109
|
+
parent: {
|
|
2110
|
+
...folderMiniSchema,
|
|
2111
|
+
type: ["object", "null"]
|
|
2112
|
+
},
|
|
2113
|
+
item_status: {
|
|
2114
|
+
type: "string",
|
|
2115
|
+
enum: [
|
|
2116
|
+
"active",
|
|
2117
|
+
"trashed",
|
|
2118
|
+
"deleted"
|
|
2119
|
+
]
|
|
2120
|
+
},
|
|
2121
|
+
item_collection: {
|
|
2122
|
+
type: "object",
|
|
2123
|
+
properties: {
|
|
2124
|
+
total_count: { type: "integer" },
|
|
2125
|
+
offset: { type: "integer" },
|
|
2126
|
+
limit: { type: "integer" },
|
|
2127
|
+
next_marker: { type: ["string", "null"] },
|
|
2128
|
+
prev_marker: { type: ["string", "null"] },
|
|
2129
|
+
entries: {
|
|
2130
|
+
type: "array",
|
|
2131
|
+
items: folderItemSchema
|
|
2132
|
+
},
|
|
2133
|
+
order: {
|
|
2134
|
+
type: "array",
|
|
2135
|
+
items: {
|
|
2136
|
+
type: "object",
|
|
2137
|
+
properties: {
|
|
2138
|
+
by: { type: "string" },
|
|
2139
|
+
direction: {
|
|
2140
|
+
type: "string",
|
|
2141
|
+
enum: ["ASC", "DESC"]
|
|
2142
|
+
}
|
|
2143
|
+
}
|
|
2144
|
+
}
|
|
2145
|
+
}
|
|
2146
|
+
}
|
|
2147
|
+
},
|
|
2148
|
+
sync_state: {
|
|
2149
|
+
type: "string",
|
|
2150
|
+
enum: [
|
|
2151
|
+
"synced",
|
|
2152
|
+
"not_synced",
|
|
2153
|
+
"partially_synced"
|
|
2154
|
+
]
|
|
2155
|
+
},
|
|
2156
|
+
has_collaborations: { type: "boolean" },
|
|
2157
|
+
permissions: {
|
|
2158
|
+
type: "object",
|
|
2159
|
+
properties: {
|
|
2160
|
+
can_delete: { type: "boolean" },
|
|
2161
|
+
can_download: { type: "boolean" },
|
|
2162
|
+
can_invite_collaborator: { type: "boolean" },
|
|
2163
|
+
can_rename: { type: "boolean" },
|
|
2164
|
+
can_set_share_access: { type: "boolean" },
|
|
2165
|
+
can_share: { type: "boolean" },
|
|
2166
|
+
can_upload: { type: "boolean" },
|
|
2167
|
+
can_apply_watermark: { type: "boolean" }
|
|
2168
|
+
}
|
|
2169
|
+
},
|
|
2170
|
+
tags: {
|
|
2171
|
+
type: "array",
|
|
2172
|
+
items: { type: "string" }
|
|
2173
|
+
},
|
|
2174
|
+
can_non_owners_invite: { type: "boolean" },
|
|
2175
|
+
is_externally_owned: { type: "boolean" },
|
|
2176
|
+
metadata: metadataSchema,
|
|
2177
|
+
is_collaboration_restricted_to_enterprise: { type: "boolean" },
|
|
2178
|
+
allowed_shared_link_access_levels: {
|
|
2179
|
+
type: "array",
|
|
2180
|
+
items: {
|
|
2181
|
+
type: "string",
|
|
2182
|
+
enum: [
|
|
2183
|
+
"open",
|
|
2184
|
+
"company",
|
|
2185
|
+
"collaborators"
|
|
2186
|
+
]
|
|
2187
|
+
}
|
|
2188
|
+
},
|
|
2189
|
+
allowed_invitee_roles: {
|
|
2190
|
+
type: "array",
|
|
2191
|
+
items: {
|
|
2192
|
+
type: "string",
|
|
2193
|
+
enum: [
|
|
2194
|
+
"editor",
|
|
2195
|
+
"viewer",
|
|
2196
|
+
"previewer",
|
|
2197
|
+
"uploader",
|
|
2198
|
+
"previewer uploader",
|
|
2199
|
+
"viewer uploader",
|
|
2200
|
+
"co-owner"
|
|
2201
|
+
]
|
|
2202
|
+
}
|
|
2203
|
+
},
|
|
2204
|
+
watermark_info: watermarkInfoSchema,
|
|
2205
|
+
is_accessible_via_shared_link: { type: "boolean" },
|
|
2206
|
+
can_non_owners_view_collaborators: { type: "boolean" },
|
|
2207
|
+
classification: classificationSchema,
|
|
2208
|
+
is_associated_with_app_item: { type: "boolean" },
|
|
2209
|
+
collections: {
|
|
2210
|
+
type: "array",
|
|
2211
|
+
items: collectionSchema
|
|
2212
|
+
}
|
|
2213
|
+
},
|
|
2214
|
+
required: ["id", "type"]
|
|
2215
|
+
};
|
|
2216
|
+
//#endregion
|
|
2217
|
+
//#region src/outputSchemas/files.ts
|
|
2218
|
+
const uploadFileOutputSchema = {
|
|
2219
|
+
type: "object",
|
|
2220
|
+
properties: {
|
|
2221
|
+
total_count: { type: "integer" },
|
|
2222
|
+
entries: {
|
|
2223
|
+
type: "array",
|
|
2224
|
+
items: fileFullSchema
|
|
2225
|
+
}
|
|
2226
|
+
}
|
|
2227
|
+
};
|
|
2228
|
+
const getFileDownloadUrlOutputSchema = {
|
|
2229
|
+
type: "string",
|
|
2230
|
+
format: "uri"
|
|
2231
|
+
};
|
|
2232
|
+
//#endregion
|
|
2233
|
+
//#region src/outputSchemas/folders.ts
|
|
2234
|
+
const createFolderOutputSchema = folderFullSchema;
|
|
2235
|
+
const listFolderWithPaginationOutputSchema = {
|
|
2236
|
+
type: "object",
|
|
2237
|
+
properties: {
|
|
2238
|
+
entries: {
|
|
2239
|
+
type: "array",
|
|
2240
|
+
items: folderItemSchema
|
|
2241
|
+
},
|
|
2242
|
+
pagination: {
|
|
2243
|
+
type: ["object", "number"],
|
|
2244
|
+
properties: {
|
|
2245
|
+
next_marker: { type: ["string", "null"] },
|
|
2246
|
+
limit: { type: "integer" }
|
|
2247
|
+
}
|
|
2248
|
+
}
|
|
2249
|
+
},
|
|
2250
|
+
required: ["entries", "pagination"]
|
|
2251
|
+
};
|
|
2252
|
+
//#endregion
|
|
2253
|
+
//#region src/outputSchemas/objects.ts
|
|
2254
|
+
const copiedOrMovedObjectSchema = {
|
|
2255
|
+
type: "object",
|
|
2256
|
+
properties: {
|
|
2257
|
+
...folderFullSchema.properties,
|
|
2258
|
+
type: {
|
|
2259
|
+
type: "string",
|
|
2260
|
+
enum: ["file", "folder"]
|
|
2261
|
+
}
|
|
2262
|
+
},
|
|
2263
|
+
required: ["id", "type"],
|
|
2264
|
+
additionalProperties: true
|
|
2265
|
+
};
|
|
2266
|
+
const copyObjectOutputSchema = copiedOrMovedObjectSchema;
|
|
2267
|
+
const moveObjectOutputSchema = copiedOrMovedObjectSchema;
|
|
2268
|
+
const pathDetailsOutputSchema = {
|
|
2269
|
+
type: "array",
|
|
2270
|
+
items: {
|
|
2271
|
+
type: "object",
|
|
2272
|
+
properties: {
|
|
2273
|
+
id: { type: "string" },
|
|
2274
|
+
type: { type: "string" },
|
|
2275
|
+
name: { type: "string" }
|
|
2276
|
+
},
|
|
2277
|
+
required: []
|
|
2278
|
+
}
|
|
2279
|
+
};
|
|
2280
|
+
const deleteObjectOutputSchema = {
|
|
2281
|
+
type: "object",
|
|
2282
|
+
properties: {},
|
|
2283
|
+
required: [],
|
|
2284
|
+
additionalProperties: false
|
|
2285
|
+
};
|
|
2286
|
+
//#endregion
|
|
2287
|
+
//#region src/outputSchemas/sharedLinks.ts
|
|
2288
|
+
const fileSharedLinkProjectionSchema = {
|
|
2289
|
+
type: "object",
|
|
2290
|
+
properties: {
|
|
2291
|
+
id: { type: "string" },
|
|
2292
|
+
type: {
|
|
2293
|
+
type: "string",
|
|
2294
|
+
enum: ["file"]
|
|
2295
|
+
},
|
|
2296
|
+
etag: { type: ["string", "null"] },
|
|
2297
|
+
sequence_id: { type: ["string", "null"] },
|
|
2298
|
+
name: { type: "string" },
|
|
2299
|
+
sha1: { type: "string" },
|
|
2300
|
+
file_version: fileVersionMiniSchema,
|
|
2301
|
+
shared_link: nullableSharedLinkSchema
|
|
2302
|
+
},
|
|
2303
|
+
required: [
|
|
2304
|
+
"id",
|
|
2305
|
+
"type",
|
|
2306
|
+
"shared_link"
|
|
2307
|
+
]
|
|
2308
|
+
};
|
|
2309
|
+
const folderSharedLinkProjectionSchema = {
|
|
2310
|
+
type: "object",
|
|
2311
|
+
properties: {
|
|
2312
|
+
id: { type: "string" },
|
|
2313
|
+
type: {
|
|
2314
|
+
type: "string",
|
|
2315
|
+
enum: ["folder"]
|
|
2316
|
+
},
|
|
2317
|
+
etag: { type: ["string", "null"] },
|
|
2318
|
+
sequence_id: { type: ["string", "null"] },
|
|
2319
|
+
name: { type: "string" },
|
|
2320
|
+
shared_link: nullableSharedLinkSchema
|
|
2321
|
+
},
|
|
2322
|
+
required: [
|
|
2323
|
+
"id",
|
|
2324
|
+
"type",
|
|
2325
|
+
"shared_link"
|
|
2326
|
+
]
|
|
2327
|
+
};
|
|
2328
|
+
const findFileForSharedLinkOutputSchema = {
|
|
2329
|
+
type: "object",
|
|
2330
|
+
properties: {
|
|
2331
|
+
...fileFullSchema.properties,
|
|
2332
|
+
type: { type: "string" }
|
|
2333
|
+
},
|
|
2334
|
+
required: ["id", "type"],
|
|
2335
|
+
additionalProperties: true
|
|
2336
|
+
};
|
|
2337
|
+
const findFolderForSharedLinkOutputSchema = {
|
|
2338
|
+
type: "object",
|
|
2339
|
+
properties: {
|
|
2340
|
+
...folderFullSchema.properties,
|
|
2341
|
+
type: { type: "string" }
|
|
2342
|
+
},
|
|
2343
|
+
required: ["id", "type"],
|
|
2344
|
+
additionalProperties: true
|
|
2345
|
+
};
|
|
2346
|
+
const addSharedLinkToFileOutputSchema = fileSharedLinkProjectionSchema;
|
|
2347
|
+
const updateSharedLinkToFileOutputSchema = fileSharedLinkProjectionSchema;
|
|
2348
|
+
const removeSharedLinkFromFileOutputSchema = fileSharedLinkProjectionSchema;
|
|
2349
|
+
const addSharedLinkToFolderOutputSchema = folderSharedLinkProjectionSchema;
|
|
2350
|
+
const updateSharedLinkOnFolderOutputSchema = folderSharedLinkProjectionSchema;
|
|
2351
|
+
const removeSharedLinkFromFolderOutputSchema = folderSharedLinkProjectionSchema;
|
|
2352
|
+
const getSharedLinkResultSchema = {
|
|
2353
|
+
type: "object",
|
|
2354
|
+
properties: { sharedLink: {
|
|
2355
|
+
type: "string",
|
|
2356
|
+
format: "uri"
|
|
2357
|
+
} },
|
|
2358
|
+
required: ["sharedLink"]
|
|
2359
|
+
};
|
|
2360
|
+
const getSharedLinkForFileOutputSchema = getSharedLinkResultSchema;
|
|
2361
|
+
const getSharedLinkForFolderOutputSchema = getSharedLinkResultSchema;
|
|
2362
|
+
//#endregion
|
|
2363
|
+
//#region src/outputSchemas/users.ts
|
|
2364
|
+
const getCurrentUserOutputSchema = {
|
|
2365
|
+
type: "object",
|
|
2366
|
+
properties: {
|
|
2367
|
+
id: { type: "string" },
|
|
2368
|
+
type: {
|
|
2369
|
+
type: "string",
|
|
2370
|
+
enum: ["user"]
|
|
2371
|
+
},
|
|
2372
|
+
name: { type: "string" },
|
|
2373
|
+
login: {
|
|
2374
|
+
type: "string",
|
|
2375
|
+
format: "email"
|
|
2376
|
+
},
|
|
2377
|
+
created_at: {
|
|
2378
|
+
type: "string",
|
|
2379
|
+
format: "date-time"
|
|
2380
|
+
},
|
|
2381
|
+
modified_at: {
|
|
2382
|
+
type: "string",
|
|
2383
|
+
format: "date-time"
|
|
2384
|
+
},
|
|
2385
|
+
language: { type: "string" },
|
|
2386
|
+
timezone: { type: "string" },
|
|
2387
|
+
space_amount: { type: "integer" },
|
|
2388
|
+
space_used: { type: "integer" },
|
|
2389
|
+
max_upload_size: { type: "integer" },
|
|
2390
|
+
status: {
|
|
2391
|
+
type: "string",
|
|
2392
|
+
enum: [
|
|
2393
|
+
"active",
|
|
2394
|
+
"inactive",
|
|
2395
|
+
"cannot_delete_edit",
|
|
2396
|
+
"cannot_delete_edit_upload"
|
|
2397
|
+
]
|
|
2398
|
+
},
|
|
2399
|
+
job_title: { type: "string" },
|
|
2400
|
+
phone: { type: "string" },
|
|
2401
|
+
address: { type: "string" },
|
|
2402
|
+
avatar_url: {
|
|
2403
|
+
type: "string",
|
|
2404
|
+
format: "uri"
|
|
2405
|
+
},
|
|
2406
|
+
notification_email: {
|
|
2407
|
+
type: ["object", "null"],
|
|
2408
|
+
properties: {
|
|
2409
|
+
email: {
|
|
2410
|
+
type: "string",
|
|
2411
|
+
format: "email"
|
|
2412
|
+
},
|
|
2413
|
+
is_confirmed: { type: "boolean" }
|
|
2414
|
+
}
|
|
2415
|
+
},
|
|
2416
|
+
role: {
|
|
2417
|
+
type: "string",
|
|
2418
|
+
enum: [
|
|
2419
|
+
"admin",
|
|
2420
|
+
"coadmin",
|
|
2421
|
+
"user"
|
|
2422
|
+
]
|
|
2423
|
+
},
|
|
2424
|
+
tracking_codes: {
|
|
2425
|
+
type: "array",
|
|
2426
|
+
items: {
|
|
2427
|
+
type: "object",
|
|
2428
|
+
properties: {
|
|
2429
|
+
type: {
|
|
2430
|
+
type: "string",
|
|
2431
|
+
enum: ["tracking_code"]
|
|
2432
|
+
},
|
|
2433
|
+
name: { type: "string" },
|
|
2434
|
+
value: { type: "string" }
|
|
2435
|
+
}
|
|
2436
|
+
}
|
|
2437
|
+
},
|
|
2438
|
+
can_see_managed_users: { type: "boolean" },
|
|
2439
|
+
is_sync_enabled: { type: "boolean" },
|
|
2440
|
+
is_external_collab_restricted: { type: "boolean" },
|
|
2441
|
+
is_exempt_from_device_limits: { type: "boolean" },
|
|
2442
|
+
is_exempt_from_login_verification: { type: "boolean" },
|
|
2443
|
+
is_collaborated_content_available_when_owner_inactive: { type: "boolean" },
|
|
2444
|
+
enterprise: {
|
|
2445
|
+
type: "object",
|
|
2446
|
+
properties: {
|
|
2447
|
+
id: { type: "string" },
|
|
2448
|
+
type: {
|
|
2449
|
+
type: "string",
|
|
2450
|
+
enum: ["enterprise"]
|
|
2451
|
+
},
|
|
2452
|
+
name: { type: "string" }
|
|
2453
|
+
}
|
|
2454
|
+
},
|
|
2455
|
+
my_tags: {
|
|
2456
|
+
type: "array",
|
|
2457
|
+
items: { type: "string" }
|
|
2458
|
+
},
|
|
2459
|
+
hostname: { type: "string" },
|
|
2460
|
+
is_platform_access_only: { type: "boolean" },
|
|
2461
|
+
external_app_user_id: { type: "string" }
|
|
2462
|
+
},
|
|
2463
|
+
required: ["id", "type"]
|
|
2464
|
+
};
|
|
2465
|
+
//#endregion
|
|
2466
|
+
//#region src/outputSchemas/webhooks.ts
|
|
2467
|
+
const webhookTargetSchema = {
|
|
2468
|
+
type: "object",
|
|
2469
|
+
properties: {
|
|
2470
|
+
id: { type: "string" },
|
|
2471
|
+
type: {
|
|
2472
|
+
type: "string",
|
|
2473
|
+
enum: ["file", "folder"]
|
|
2474
|
+
}
|
|
2475
|
+
}
|
|
2476
|
+
};
|
|
2477
|
+
const createWebhookOutputSchema = {
|
|
2478
|
+
type: ["object", "null"],
|
|
2479
|
+
properties: {
|
|
2480
|
+
id: { type: "string" },
|
|
2481
|
+
type: {
|
|
2482
|
+
type: "string",
|
|
2483
|
+
enum: ["webhook"]
|
|
2484
|
+
},
|
|
2485
|
+
target: webhookTargetSchema,
|
|
2486
|
+
created_by: userMiniSchema,
|
|
2487
|
+
created_at: {
|
|
2488
|
+
type: "string",
|
|
2489
|
+
format: "date-time"
|
|
2490
|
+
},
|
|
2491
|
+
address: {
|
|
2492
|
+
type: "string",
|
|
2493
|
+
format: "uri"
|
|
2494
|
+
},
|
|
2495
|
+
triggers: {
|
|
2496
|
+
type: "array",
|
|
2497
|
+
items: {
|
|
2498
|
+
type: "string",
|
|
2499
|
+
enum: [
|
|
2500
|
+
"FILE.UPLOADED",
|
|
2501
|
+
"FILE.PREVIEWED",
|
|
2502
|
+
"FILE.DOWNLOADED",
|
|
2503
|
+
"FILE.TRASHED",
|
|
2504
|
+
"FILE.DELETED",
|
|
2505
|
+
"FILE.RESTORED",
|
|
2506
|
+
"FILE.COPIED",
|
|
2507
|
+
"FILE.MOVED",
|
|
2508
|
+
"FILE.LOCKED",
|
|
2509
|
+
"FILE.UNLOCKED",
|
|
2510
|
+
"FILE.RENAMED",
|
|
2511
|
+
"COMMENT.CREATED",
|
|
2512
|
+
"COMMENT.UPDATED",
|
|
2513
|
+
"COMMENT.DELETED",
|
|
2514
|
+
"TASK_ASSIGNMENT.CREATED",
|
|
2515
|
+
"TASK_ASSIGNMENT.UPDATED",
|
|
2516
|
+
"METADATA_INSTANCE.CREATED",
|
|
2517
|
+
"METADATA_INSTANCE.UPDATED",
|
|
2518
|
+
"METADATA_INSTANCE.DELETED",
|
|
2519
|
+
"FOLDER.CREATED",
|
|
2520
|
+
"FOLDER.RENAMED",
|
|
2521
|
+
"FOLDER.DOWNLOADED",
|
|
2522
|
+
"FOLDER.RESTORED",
|
|
2523
|
+
"FOLDER.DELETED",
|
|
2524
|
+
"FOLDER.COPIED",
|
|
2525
|
+
"FOLDER.MOVED",
|
|
2526
|
+
"FOLDER.TRASHED",
|
|
2527
|
+
"WEBHOOK.DELETED",
|
|
2528
|
+
"COLLABORATION.CREATED",
|
|
2529
|
+
"COLLABORATION.ACCEPTED",
|
|
2530
|
+
"COLLABORATION.REJECTED",
|
|
2531
|
+
"COLLABORATION.REMOVED",
|
|
2532
|
+
"COLLABORATION.UPDATED",
|
|
2533
|
+
"SHARED_LINK.DELETED",
|
|
2534
|
+
"SHARED_LINK.CREATED",
|
|
2535
|
+
"SHARED_LINK.UPDATED",
|
|
2536
|
+
"SIGN_REQUEST.COMPLETED",
|
|
2537
|
+
"SIGN_REQUEST.DECLINED",
|
|
2538
|
+
"SIGN_REQUEST.EXPIRED",
|
|
2539
|
+
"SIGN_REQUEST.SIGNER_EMAIL_BOUNCED",
|
|
2540
|
+
"SIGN_REQUEST.SIGN_SIGNER_SIGNED",
|
|
2541
|
+
"SIGN_REQUEST.SIGN_DOCUMENT_CREATED",
|
|
2542
|
+
"SIGN_REQUEST.SIGN_ERROR_FINALIZING"
|
|
2543
|
+
]
|
|
2544
|
+
}
|
|
2545
|
+
}
|
|
2546
|
+
}
|
|
2547
|
+
};
|
|
2548
|
+
const listWebhooksOutputSchema = {
|
|
2549
|
+
type: "object",
|
|
2550
|
+
properties: {
|
|
2551
|
+
limit: { type: "integer" },
|
|
2552
|
+
next_marker: { type: ["string", "null"] },
|
|
2553
|
+
entries: {
|
|
2554
|
+
type: "array",
|
|
2555
|
+
items: {
|
|
2556
|
+
type: "object",
|
|
2557
|
+
properties: {
|
|
2558
|
+
id: { type: "string" },
|
|
2559
|
+
type: {
|
|
2560
|
+
type: "string",
|
|
2561
|
+
enum: ["webhook"]
|
|
2562
|
+
},
|
|
2563
|
+
target: webhookTargetSchema
|
|
2564
|
+
}
|
|
2565
|
+
}
|
|
2566
|
+
}
|
|
2567
|
+
},
|
|
2568
|
+
required: ["entries"]
|
|
2569
|
+
};
|
|
2570
|
+
const deleteWebhookOutputSchema = { type: "null" };
|
|
2571
|
+
const deleteInstanceWebhooksOutputSchema = {
|
|
2572
|
+
type: "object",
|
|
2573
|
+
properties: {},
|
|
2574
|
+
required: [],
|
|
2575
|
+
additionalProperties: false
|
|
2576
|
+
};
|
|
2577
|
+
//#endregion
|
|
2578
|
+
//#region src/actions/files/index.ts
|
|
2579
|
+
var files_default = {
|
|
2580
|
+
downloadFile,
|
|
2581
|
+
getFileDownloadUrl: (0, _prismatic_io_spectral.action)({
|
|
2582
|
+
display: {
|
|
2583
|
+
label: "Get File Download URL",
|
|
2584
|
+
description: "Get a URL to download the file at the specified path."
|
|
2585
|
+
},
|
|
2586
|
+
performSafety: "notAllowed",
|
|
2587
|
+
perform: async (_context, { path, boxConnection }) => {
|
|
2588
|
+
const client = createAuthorizedClient({ boxConnection });
|
|
2589
|
+
const { id, type, name } = (await getPathEntries(client, _prismatic_io_spectral.util.types.toString(path))).slice(-1)[0];
|
|
2590
|
+
if (type !== "file") throw Error(`'${name}' is not a file`);
|
|
2591
|
+
return { data: await client.downloads.getDownloadFileUrl(_prismatic_io_spectral.util.types.toString(id)) };
|
|
2592
|
+
},
|
|
2593
|
+
examplePerform: async () => ({ data: getFileDownloadUrlExamplePayload.data }),
|
|
2594
|
+
inputs: getFileDownloadUrlInputs,
|
|
2595
|
+
outputSchema: (0, _prismatic_io_spectral.outputSchema)({
|
|
2596
|
+
type: "actionOutput",
|
|
2597
|
+
schema: getFileDownloadUrlOutputSchema
|
|
2598
|
+
}),
|
|
2599
|
+
examplePayload: getFileDownloadUrlExamplePayload
|
|
2600
|
+
}),
|
|
2601
|
+
uploadFile: (0, _prismatic_io_spectral.action)({
|
|
2602
|
+
display: {
|
|
2603
|
+
label: "Upload File",
|
|
2604
|
+
description: "Upload a file to the specified path."
|
|
2605
|
+
},
|
|
2606
|
+
performSafety: "notAllowed",
|
|
2607
|
+
perform: async (_context, { path, fileContents, boxConnection }) => {
|
|
2608
|
+
const client = createAuthorizedClient({ boxConnection });
|
|
2609
|
+
const pathEntries = await getPathEntries(client, _prismatic_io_spectral.util.types.toString(path), false);
|
|
2610
|
+
const { id, type, name } = pathEntries.slice(-2)[0];
|
|
2611
|
+
const { name: fileName } = pathEntries.slice(-1)[0];
|
|
2612
|
+
if (type !== "folder") throw Error(`'${name}' is not a folder`);
|
|
2613
|
+
const { data } = _prismatic_io_spectral.util.types.toData(fileContents);
|
|
2614
|
+
return { data: (await client.uploads.uploadFile({
|
|
2615
|
+
attributes: {
|
|
2616
|
+
name: _prismatic_io_spectral.util.types.toString(fileName),
|
|
2617
|
+
parent: { id: _prismatic_io_spectral.util.types.toString(id) }
|
|
2618
|
+
},
|
|
2619
|
+
file: node_stream.Readable.from(data)
|
|
2620
|
+
})).rawData };
|
|
2621
|
+
},
|
|
2622
|
+
examplePerform: async (_context, { path }) => ({ data: {
|
|
2623
|
+
...uploadFileExamplePayload.data,
|
|
2624
|
+
entries: [{
|
|
2625
|
+
...uploadFileExamplePayload.data.entries[0],
|
|
2626
|
+
name: pathLeafName(path)
|
|
2627
|
+
}]
|
|
2628
|
+
} }),
|
|
2629
|
+
inputs: uploadFileInputs,
|
|
2630
|
+
outputSchema: (0, _prismatic_io_spectral.outputSchema)({
|
|
2631
|
+
type: "actionOutput",
|
|
2632
|
+
schema: uploadFileOutputSchema
|
|
2633
|
+
}),
|
|
2634
|
+
examplePayload: uploadFileExamplePayload
|
|
2635
|
+
})
|
|
2636
|
+
};
|
|
2637
|
+
//#endregion
|
|
2638
|
+
//#region src/actions/folders/index.ts
|
|
2639
|
+
var folders_default = {
|
|
2640
|
+
createFolder: (0, _prismatic_io_spectral.action)({
|
|
2641
|
+
display: {
|
|
2642
|
+
label: "Create Folder",
|
|
2643
|
+
description: "Create a Folder at the specified path."
|
|
2644
|
+
},
|
|
2645
|
+
performSafety: "notAllowed",
|
|
2646
|
+
perform: async (_context, { path, boxConnection }) => {
|
|
2647
|
+
const client = createAuthorizedClient({ boxConnection });
|
|
2648
|
+
const pathEntries = await getPathEntries(client, _prismatic_io_spectral.util.types.toString(path), false);
|
|
2649
|
+
const { name: newFolderName } = pathEntries.slice(-1)[0];
|
|
2650
|
+
const { id, type, name } = pathEntries.slice(-2)[0];
|
|
2651
|
+
if (type !== "folder") throw Error(`'${name}' is not a folder`);
|
|
2652
|
+
return { data: (await client.folders.createFolder({
|
|
2653
|
+
name: _prismatic_io_spectral.util.types.toString(newFolderName),
|
|
2654
|
+
parent: { id: _prismatic_io_spectral.util.types.toString(id) }
|
|
2655
|
+
})).rawData };
|
|
2656
|
+
},
|
|
2657
|
+
examplePerform: async (_context, { path }) => ({ data: {
|
|
2658
|
+
...createFolderExamplePayload.data,
|
|
2659
|
+
name: pathLeafName(path)
|
|
2660
|
+
} }),
|
|
2661
|
+
inputs: createFolderInputs,
|
|
2662
|
+
outputSchema: (0, _prismatic_io_spectral.outputSchema)({
|
|
2663
|
+
type: "actionOutput",
|
|
2664
|
+
schema: createFolderOutputSchema
|
|
2665
|
+
}),
|
|
2666
|
+
examplePayload: createFolderExamplePayload
|
|
2667
|
+
}),
|
|
2668
|
+
listFolderWithPagination: (0, _prismatic_io_spectral.action)({
|
|
2669
|
+
display: {
|
|
2670
|
+
label: "List Folder",
|
|
2671
|
+
description: "List Folder contents at the specified path. "
|
|
2672
|
+
},
|
|
2673
|
+
performSafety: "notAllowed",
|
|
2674
|
+
perform: async (_context, params) => {
|
|
2675
|
+
const client = createAuthorizedClient({ boxConnection: params.boxConnection });
|
|
2676
|
+
const { id, type, name } = (await getPathEntries(client, _prismatic_io_spectral.util.types.toString(params.path))).slice(-1)[0];
|
|
2677
|
+
if (type !== "folder") throw Error(`'${name}' is not a folder`);
|
|
2678
|
+
if (params.fetchAll) return { data: {
|
|
2679
|
+
entries: await getFolderEntries({
|
|
2680
|
+
client,
|
|
2681
|
+
id,
|
|
2682
|
+
limit: MAX_PAGE_SIZE,
|
|
2683
|
+
marker: void 0,
|
|
2684
|
+
offset: 0,
|
|
2685
|
+
fields: params.fields ? _prismatic_io_spectral.util.types.toString(params.fields) : void 0
|
|
2686
|
+
}),
|
|
2687
|
+
pagination: MAX_PAGE_SIZE
|
|
2688
|
+
} };
|
|
2689
|
+
const result = await client.folders.getFolderItems(_prismatic_io_spectral.util.types.toString(id), { queryParams: {
|
|
2690
|
+
usemarker: true,
|
|
2691
|
+
marker: _prismatic_io_spectral.util.types.toString(params.pagination.marker) || void 0,
|
|
2692
|
+
limit: _prismatic_io_spectral.util.types.toInt(params.pagination.limit) || void 0,
|
|
2693
|
+
offset: _prismatic_io_spectral.util.types.toInt(params.pagination.offset) || void 0,
|
|
2694
|
+
fields: params.fields ? _prismatic_io_spectral.util.types.toString(params.fields).split(",") : void 0
|
|
2695
|
+
} });
|
|
2696
|
+
return { data: {
|
|
2697
|
+
entries: result.rawData?.entries ?? [],
|
|
2698
|
+
pagination: {
|
|
2699
|
+
next_marker: result.nextMarker,
|
|
2700
|
+
limit: result.limit
|
|
2701
|
+
}
|
|
2702
|
+
} };
|
|
2703
|
+
},
|
|
2704
|
+
examplePerform: async (_context, params) => {
|
|
2705
|
+
const { entries } = listFolderWithPaginationExamplePayload.data;
|
|
2706
|
+
if (params.fetchAll) return { data: {
|
|
2707
|
+
entries,
|
|
2708
|
+
pagination: MAX_PAGE_SIZE
|
|
2709
|
+
} };
|
|
2710
|
+
return { data: {
|
|
2711
|
+
entries,
|
|
2712
|
+
pagination: {
|
|
2713
|
+
...listFolderWithPaginationExamplePayload.data.pagination,
|
|
2714
|
+
limit: _prismatic_io_spectral.util.types.toInt(params.pagination.limit) || listFolderWithPaginationExamplePayload.data.pagination.limit
|
|
2715
|
+
}
|
|
2716
|
+
} };
|
|
2717
|
+
},
|
|
2718
|
+
inputs: listFolderWithPaginationInputs,
|
|
2719
|
+
outputSchema: (0, _prismatic_io_spectral.outputSchema)({
|
|
2720
|
+
type: "actionOutput",
|
|
2721
|
+
schema: listFolderWithPaginationOutputSchema
|
|
2722
|
+
}),
|
|
2723
|
+
examplePayload: listFolderWithPaginationExamplePayload
|
|
2724
|
+
})
|
|
2725
|
+
};
|
|
2726
|
+
//#endregion
|
|
2727
|
+
//#region src/actions/misc/index.ts
|
|
2728
|
+
var misc_default = { rawRequest: (0, _prismatic_io_spectral.action)({
|
|
2729
|
+
display: {
|
|
2730
|
+
label: "Raw Request",
|
|
2731
|
+
description: "Send raw HTTP request to Box."
|
|
2732
|
+
},
|
|
2733
|
+
inputs: rawRequestInputs,
|
|
2734
|
+
performSafety: "notAllowed",
|
|
2735
|
+
perform: async (_context, { connection, ...httpClientInputs }) => {
|
|
2736
|
+
const { data } = await (0, _prismatic_io_spectral_http.sendRawRequest)(API_ROOT_URL, httpClientInputs, { Authorization: `Bearer ${getAccessToken({ boxConnection: connection })}` });
|
|
2737
|
+
return { data };
|
|
2738
|
+
}
|
|
2739
|
+
}) };
|
|
2740
|
+
//#endregion
|
|
2741
|
+
//#region src/actions/objects/index.ts
|
|
2742
|
+
var objects_default = {
|
|
2743
|
+
copyObject: (0, _prismatic_io_spectral.action)({
|
|
2744
|
+
display: {
|
|
2745
|
+
label: "Copy Object",
|
|
2746
|
+
description: "Copy a Folder or File from one path to another."
|
|
2747
|
+
},
|
|
2748
|
+
performSafety: "notAllowed",
|
|
2749
|
+
perform: async (_context, { fromPath, toPath, boxConnection }) => {
|
|
2750
|
+
const client = createAuthorizedClient({ boxConnection });
|
|
2751
|
+
const fromPathEntries = await getPathEntries(client, _prismatic_io_spectral.util.types.toString(fromPath));
|
|
2752
|
+
const toPathEntries = await getPathEntries(client, _prismatic_io_spectral.util.types.toString(toPath), false);
|
|
2753
|
+
const { id: sourceId, type: sourceType, name: sourceName } = fromPathEntries.slice(-1)[0];
|
|
2754
|
+
const { name: newName } = toPathEntries.slice(-1)[0];
|
|
2755
|
+
const { id: destId, type: destType, name: destName } = toPathEntries.slice(-2)[0];
|
|
2756
|
+
if (destType !== "folder") throw Error(`'${destName}' is not a folder`);
|
|
2757
|
+
let data;
|
|
2758
|
+
if (sourceType === "folder") data = (await client.folders.copyFolder(_prismatic_io_spectral.util.types.toString(sourceId), {
|
|
2759
|
+
parent: { id: _prismatic_io_spectral.util.types.toString(destId) },
|
|
2760
|
+
name: newName
|
|
2761
|
+
})).rawData;
|
|
2762
|
+
else if (sourceType === "file") data = (await client.files.copyFile(_prismatic_io_spectral.util.types.toString(sourceId), {
|
|
2763
|
+
parent: { id: _prismatic_io_spectral.util.types.toString(destId) },
|
|
2764
|
+
name: newName
|
|
2765
|
+
})).rawData;
|
|
2766
|
+
else throw Error(`'${sourceName}' is neither a file nor a folder`);
|
|
2767
|
+
return { data };
|
|
2768
|
+
},
|
|
2769
|
+
examplePerform: async (_context, { fromPath, toPath }) => {
|
|
2770
|
+
const sourceName = pathLeafName(fromPath);
|
|
2771
|
+
return { data: {
|
|
2772
|
+
...copyObjectExamplePayload.data,
|
|
2773
|
+
name: pathLeafName(toPath),
|
|
2774
|
+
type: sourceName.includes(".") ? FILE_TYPE : FOLDER_TYPE
|
|
2775
|
+
} };
|
|
2776
|
+
},
|
|
2777
|
+
inputs: copyObjectInputs,
|
|
2778
|
+
outputSchema: (0, _prismatic_io_spectral.outputSchema)({
|
|
2779
|
+
type: "actionOutput",
|
|
2780
|
+
schema: copyObjectOutputSchema
|
|
2781
|
+
}),
|
|
2782
|
+
examplePayload: copyObjectExamplePayload
|
|
2783
|
+
}),
|
|
2784
|
+
deleteObject: (0, _prismatic_io_spectral.action)({
|
|
2785
|
+
display: {
|
|
2786
|
+
label: "Delete Object",
|
|
2787
|
+
description: "Delete a Folder or File at the specified path."
|
|
2788
|
+
},
|
|
2789
|
+
performSafety: "notAllowed",
|
|
2790
|
+
perform: async (_context, { path, boxConnection }) => {
|
|
2791
|
+
const client = createAuthorizedClient({ boxConnection });
|
|
2792
|
+
const { id, type, name } = (await getPathEntries(client, _prismatic_io_spectral.util.types.toString(path))).slice(-1)[0];
|
|
2793
|
+
if (type === "folder") await client.folders.deleteFolderById(_prismatic_io_spectral.util.types.toString(id));
|
|
2794
|
+
else if (type === "file") await client.files.deleteFileById(_prismatic_io_spectral.util.types.toString(id));
|
|
2795
|
+
else throw Error(`'${name}' is neither a file nor a folder`);
|
|
2796
|
+
return { data: {} };
|
|
2797
|
+
},
|
|
2798
|
+
examplePerform: async () => ({ data: deleteObjectExamplePayload.data }),
|
|
2799
|
+
inputs: deleteObjectInputs,
|
|
2800
|
+
outputSchema: (0, _prismatic_io_spectral.outputSchema)({
|
|
2801
|
+
type: "actionOutput",
|
|
2802
|
+
schema: deleteObjectOutputSchema
|
|
2803
|
+
}),
|
|
2804
|
+
examplePayload: deleteObjectExamplePayload
|
|
2805
|
+
}),
|
|
2806
|
+
moveObject: (0, _prismatic_io_spectral.action)({
|
|
2807
|
+
display: {
|
|
2808
|
+
label: "Move Object",
|
|
2809
|
+
description: "Move a Folder or File from one path to another."
|
|
2810
|
+
},
|
|
2811
|
+
performSafety: "notAllowed",
|
|
2812
|
+
perform: async (_context, { fromPath, toPath, boxConnection }) => {
|
|
2813
|
+
const client = createAuthorizedClient({ boxConnection });
|
|
2814
|
+
const fromPathEntries = await getPathEntries(client, _prismatic_io_spectral.util.types.toString(fromPath));
|
|
2815
|
+
const toPathEntries = await getPathEntries(client, _prismatic_io_spectral.util.types.toString(toPath));
|
|
2816
|
+
const { id: sourceId, type: sourceType, name: sourceName } = fromPathEntries.slice(-1)[0];
|
|
2817
|
+
const { id: destId, type: destType, name: destName } = toPathEntries.slice(-1)[0];
|
|
2818
|
+
if (destType !== "folder") throw Error(`'${destName}' is not a folder`);
|
|
2819
|
+
let data;
|
|
2820
|
+
if (sourceType === "folder") data = (await client.folders.updateFolderById(_prismatic_io_spectral.util.types.toString(sourceId), { requestBody: { parent: { id: _prismatic_io_spectral.util.types.toString(destId) } } })).rawData;
|
|
2821
|
+
else if (sourceType === "file") data = (await client.files.updateFileById(_prismatic_io_spectral.util.types.toString(sourceId), { requestBody: { parent: { id: _prismatic_io_spectral.util.types.toString(destId) } } })).rawData;
|
|
2822
|
+
else throw Error(`'${sourceName}' is neither a file nor a folder`);
|
|
2823
|
+
return { data };
|
|
2824
|
+
},
|
|
2825
|
+
examplePerform: async (_context, { fromPath, toPath }) => {
|
|
2826
|
+
const name = pathLeafName(fromPath);
|
|
2827
|
+
return { data: {
|
|
2828
|
+
...moveObjectExamplePayload.data,
|
|
2829
|
+
name,
|
|
2830
|
+
type: name.includes(".") ? FILE_TYPE : FOLDER_TYPE,
|
|
2831
|
+
parent: {
|
|
2832
|
+
...moveObjectExamplePayload.data.parent,
|
|
2833
|
+
name: pathLeafName(toPath)
|
|
2834
|
+
}
|
|
2835
|
+
} };
|
|
2836
|
+
},
|
|
2837
|
+
inputs: moveObjectInputs,
|
|
2838
|
+
outputSchema: (0, _prismatic_io_spectral.outputSchema)({
|
|
2839
|
+
type: "actionOutput",
|
|
2840
|
+
schema: moveObjectOutputSchema
|
|
2841
|
+
}),
|
|
2842
|
+
examplePayload: moveObjectExamplePayload
|
|
2843
|
+
}),
|
|
2844
|
+
pathDetails: (0, _prismatic_io_spectral.action)({
|
|
2845
|
+
display: {
|
|
2846
|
+
label: "Get Path Details",
|
|
2847
|
+
description: "Get detailed information about folders/files in the specified path."
|
|
2848
|
+
},
|
|
2849
|
+
performSafety: "notAllowed",
|
|
2850
|
+
perform: async (_context, { path, boxConnection }) => {
|
|
2851
|
+
return { data: await getPathEntries(createAuthorizedClient({ boxConnection }), _prismatic_io_spectral.util.types.toString(path)) };
|
|
2852
|
+
},
|
|
2853
|
+
examplePerform: async (_context, { path }) => {
|
|
2854
|
+
const name = pathLeafName(path);
|
|
2855
|
+
return { data: [pathDetailsExamplePayload.data[0], {
|
|
2856
|
+
...pathDetailsExamplePayload.data[1],
|
|
2857
|
+
name,
|
|
2858
|
+
type: name.includes(".") ? FILE_TYPE : FOLDER_TYPE
|
|
2859
|
+
}] };
|
|
2860
|
+
},
|
|
2861
|
+
inputs: pathDetailsInputs,
|
|
2862
|
+
outputSchema: (0, _prismatic_io_spectral.outputSchema)({
|
|
2863
|
+
type: "actionOutput",
|
|
2864
|
+
schema: pathDetailsOutputSchema
|
|
2865
|
+
}),
|
|
2866
|
+
examplePayload: pathDetailsExamplePayload
|
|
2867
|
+
})
|
|
2868
|
+
};
|
|
2869
|
+
//#endregion
|
|
2870
|
+
//#region src/actions/sharedLinks/index.ts
|
|
2871
|
+
var sharedLinks_default = {
|
|
2872
|
+
addSharedLinkToFile: (0, _prismatic_io_spectral.action)({
|
|
2873
|
+
display: {
|
|
2874
|
+
label: "Add Shared Link to File",
|
|
2875
|
+
description: "Adds a shared link to a file."
|
|
2876
|
+
},
|
|
2877
|
+
performSafety: "notAllowed",
|
|
2878
|
+
perform: async (context, params) => {
|
|
2879
|
+
const fileId = params.fileId;
|
|
2880
|
+
const sharedLinkAccess = params.sharedLinkAccess;
|
|
2881
|
+
const sharedLinkPassword = params.additionalFields.sharedLinkPassword || null;
|
|
2882
|
+
const sharedLinkVanityName = params.additionalFields.sharedLinkVanityName || null;
|
|
2883
|
+
const sharedLinkPermissions = params.additionalFields.sharedLinkPermissions || {};
|
|
2884
|
+
const client = createBoxHttpClient(params.boxConnection, context.debug.enabled);
|
|
2885
|
+
const body = { shared_link: {
|
|
2886
|
+
access: sharedLinkAccess,
|
|
2887
|
+
password: sharedLinkPassword,
|
|
2888
|
+
permissions: sharedLinkPermissions,
|
|
2889
|
+
vanity_name: sharedLinkVanityName
|
|
2890
|
+
} };
|
|
2891
|
+
const { data } = await client.put(`/files/${fileId}`, body, { params: { fields: SHARED_LINK_FIELD } });
|
|
2892
|
+
return { data };
|
|
2893
|
+
},
|
|
2894
|
+
examplePerform: async (_context, { fileId, sharedLinkAccess, additionalFields: { sharedLinkPassword, sharedLinkPermissions, sharedLinkVanityName } }) => {
|
|
2895
|
+
const permissions = {
|
|
2896
|
+
...addSharedLinkToFileExamplePayload.data.shared_link.permissions,
|
|
2897
|
+
...sharedLinkPermissions
|
|
2898
|
+
};
|
|
2899
|
+
return { data: {
|
|
2900
|
+
...addSharedLinkToFileExamplePayload.data,
|
|
2901
|
+
id: fileId,
|
|
2902
|
+
shared_link: {
|
|
2903
|
+
...addSharedLinkToFileExamplePayload.data.shared_link,
|
|
2904
|
+
access: sharedLinkAccess,
|
|
2905
|
+
effective_access: sharedLinkAccess,
|
|
2906
|
+
effective_permission: sharedLinkEffectivePermission(permissions),
|
|
2907
|
+
is_password_enabled: Boolean(sharedLinkPassword),
|
|
2908
|
+
permissions,
|
|
2909
|
+
vanity_url: sharedLinkVanityUrl(sharedLinkVanityName)
|
|
2910
|
+
}
|
|
2911
|
+
} };
|
|
2912
|
+
},
|
|
2913
|
+
inputs: addSharedLinkToFileInputs,
|
|
2914
|
+
outputSchema: (0, _prismatic_io_spectral.outputSchema)({
|
|
2915
|
+
type: "actionOutput",
|
|
2916
|
+
schema: addSharedLinkToFileOutputSchema
|
|
2917
|
+
}),
|
|
2918
|
+
examplePayload: addSharedLinkToFileExamplePayload
|
|
2919
|
+
}),
|
|
2920
|
+
addSharedLinkToFolder: (0, _prismatic_io_spectral.action)({
|
|
2921
|
+
display: {
|
|
2922
|
+
label: "Add Shared Link to Folder",
|
|
2923
|
+
description: "Adds a shared link to a folder."
|
|
2924
|
+
},
|
|
2925
|
+
performSafety: "notAllowed",
|
|
2926
|
+
perform: async (context, params) => {
|
|
2927
|
+
const folderId = params.folderId;
|
|
2928
|
+
const sharedLinkAccess = params.sharedLinkAccess;
|
|
2929
|
+
const sharedLinkPassword = params.additionalFields.sharedLinkPassword ? params.additionalFields.sharedLinkPassword : null;
|
|
2930
|
+
const sharedLinkVanityName = params.additionalFields.sharedLinkVanityName ? params.additionalFields.sharedLinkVanityName : null;
|
|
2931
|
+
let sharedLinkPermissions = params.additionalFields.sharedLinkPermissions || {};
|
|
2932
|
+
const client = createBoxHttpClient(params.boxConnection, context.debug.enabled);
|
|
2933
|
+
sharedLinkPermissions = {
|
|
2934
|
+
...sharedLinkPermissions,
|
|
2935
|
+
can_edit: false
|
|
2936
|
+
};
|
|
2937
|
+
const { data } = await client.put(`/folders/${folderId}`, { shared_link: {
|
|
2938
|
+
access: sharedLinkAccess,
|
|
2939
|
+
password: sharedLinkPassword,
|
|
2940
|
+
permissions: sharedLinkPermissions,
|
|
2941
|
+
vanity_name: sharedLinkVanityName
|
|
2942
|
+
} }, { params: { fields: SHARED_LINK_FIELD } });
|
|
2943
|
+
return { data };
|
|
2944
|
+
},
|
|
2945
|
+
examplePerform: async (_context, { folderId, sharedLinkAccess, additionalFields: { sharedLinkPassword, sharedLinkPermissions, sharedLinkVanityName } }) => {
|
|
2946
|
+
const permissions = {
|
|
2947
|
+
...addSharedLinkToFolderExamplePayload.data.shared_link.permissions,
|
|
2948
|
+
...sharedLinkPermissions,
|
|
2949
|
+
can_edit: false
|
|
2950
|
+
};
|
|
2951
|
+
return { data: {
|
|
2952
|
+
...addSharedLinkToFolderExamplePayload.data,
|
|
2953
|
+
id: folderId,
|
|
2954
|
+
shared_link: {
|
|
2955
|
+
...addSharedLinkToFolderExamplePayload.data.shared_link,
|
|
2956
|
+
access: sharedLinkAccess,
|
|
2957
|
+
effective_access: sharedLinkAccess,
|
|
2958
|
+
effective_permission: sharedLinkEffectivePermission(permissions),
|
|
2959
|
+
is_password_enabled: Boolean(sharedLinkPassword),
|
|
2960
|
+
permissions,
|
|
2961
|
+
vanity_url: sharedLinkVanityUrl(sharedLinkVanityName)
|
|
2962
|
+
}
|
|
2963
|
+
} };
|
|
2964
|
+
},
|
|
2965
|
+
inputs: addSharedLinkToFolderInputs,
|
|
2966
|
+
outputSchema: (0, _prismatic_io_spectral.outputSchema)({
|
|
2967
|
+
type: "actionOutput",
|
|
2968
|
+
schema: addSharedLinkToFolderOutputSchema
|
|
2969
|
+
}),
|
|
2970
|
+
examplePayload: addSharedLinkToFolderExamplePayload
|
|
2971
|
+
}),
|
|
2972
|
+
findFileForSharedLink: (0, _prismatic_io_spectral.action)({
|
|
2973
|
+
display: {
|
|
2974
|
+
label: "Find File for Shared Link",
|
|
2975
|
+
description: "Returns the file represented by a shared link."
|
|
2976
|
+
},
|
|
2977
|
+
performSafety: "safe",
|
|
2978
|
+
perform: async (context, params) => {
|
|
2979
|
+
const sharedLink = _prismatic_io_spectral.util.types.toString(params.sharedLink);
|
|
2980
|
+
const sharedLinkPassword = params.sharedLinkPassword;
|
|
2981
|
+
const fields = params.fields || null;
|
|
2982
|
+
const { data } = await createBoxHttpClient(params.boxConnection, context.debug.enabled).get(SHARED_ITEMS_PATH, {
|
|
2983
|
+
headers: { boxapi: sharedLinkPassword ? `shared_link=${sharedLink}&shared_link_password=${sharedLinkPassword}` : `shared_link=${sharedLink}` },
|
|
2984
|
+
params: { fields }
|
|
2985
|
+
});
|
|
2986
|
+
return { data };
|
|
2987
|
+
},
|
|
2988
|
+
inputs: findFileForSharedLinkInputs,
|
|
2989
|
+
outputSchema: (0, _prismatic_io_spectral.outputSchema)({
|
|
2990
|
+
type: "actionOutput",
|
|
2991
|
+
schema: findFileForSharedLinkOutputSchema
|
|
2992
|
+
}),
|
|
2993
|
+
examplePayload: findFileForSharedLinkExamplePayload
|
|
2994
|
+
}),
|
|
2995
|
+
findFolderForSharedLink: (0, _prismatic_io_spectral.action)({
|
|
2996
|
+
display: {
|
|
2997
|
+
label: "Find Folder for Shared Link",
|
|
2998
|
+
description: "Returns the folder represented by a shared link."
|
|
2999
|
+
},
|
|
3000
|
+
performSafety: "safe",
|
|
3001
|
+
perform: async (context, params) => {
|
|
3002
|
+
const sharedLink = params.sharedLink;
|
|
3003
|
+
const sharedLinkPassword = params.sharedLinkPassword;
|
|
3004
|
+
const fields = params.fields || null;
|
|
3005
|
+
const { data } = await createBoxHttpClient(params.boxConnection, context.debug.enabled).get(SHARED_ITEMS_PATH, {
|
|
3006
|
+
headers: { boxapi: sharedLinkPassword ? `shared_link=${sharedLink}&shared_link_password=${sharedLinkPassword}` : `shared_link=${sharedLink}` },
|
|
3007
|
+
params: { fields }
|
|
3008
|
+
});
|
|
3009
|
+
return { data };
|
|
3010
|
+
},
|
|
3011
|
+
inputs: findFolderForSharedLinkInputs,
|
|
3012
|
+
outputSchema: (0, _prismatic_io_spectral.outputSchema)({
|
|
3013
|
+
type: "actionOutput",
|
|
3014
|
+
schema: findFolderForSharedLinkOutputSchema
|
|
3015
|
+
}),
|
|
3016
|
+
examplePayload: findFolderForSharedLinkExamplePayload
|
|
3017
|
+
}),
|
|
3018
|
+
getSharedLinkForFile: (0, _prismatic_io_spectral.action)({
|
|
3019
|
+
display: {
|
|
3020
|
+
label: "Get Shared Link for File",
|
|
3021
|
+
description: "Gets the shared link for a file."
|
|
3022
|
+
},
|
|
3023
|
+
performSafety: "safe",
|
|
3024
|
+
perform: async (context, { fileId, boxConnection }) => {
|
|
3025
|
+
const { data } = await createBoxHttpClient(boxConnection, context.debug.enabled).get(`/files/${fileId}`, { params: { fields: SHARED_LINK_FIELD } });
|
|
3026
|
+
if (!data.shared_link) throw new Error(`File ${fileId} has no shared link.`);
|
|
3027
|
+
return { data: { sharedLink: data.shared_link.url } };
|
|
3028
|
+
},
|
|
3029
|
+
inputs: getSharedLinkForFileInputs,
|
|
3030
|
+
outputSchema: (0, _prismatic_io_spectral.outputSchema)({
|
|
3031
|
+
type: "actionOutput",
|
|
3032
|
+
schema: getSharedLinkForFileOutputSchema
|
|
3033
|
+
}),
|
|
3034
|
+
examplePayload: getSharedLinkForFileExamplePayload
|
|
3035
|
+
}),
|
|
3036
|
+
getSharedLinkForFolder: (0, _prismatic_io_spectral.action)({
|
|
3037
|
+
display: {
|
|
3038
|
+
label: "Get Shared Link for Folder",
|
|
3039
|
+
description: "Gets the shared link for a folder."
|
|
3040
|
+
},
|
|
3041
|
+
performSafety: "safe",
|
|
3042
|
+
perform: async (context, params) => {
|
|
3043
|
+
const folderId = _prismatic_io_spectral.util.types.toString(params.folderId);
|
|
3044
|
+
const { data } = await createBoxHttpClient(params.boxConnection, context.debug.enabled).get(`/folders/${folderId}`, { params: { fields: SHARED_LINK_FIELD } });
|
|
3045
|
+
if (!data.shared_link) throw new Error(`Folder ${folderId} has no shared link.`);
|
|
3046
|
+
return { data: { sharedLink: data.shared_link.url } };
|
|
3047
|
+
},
|
|
3048
|
+
inputs: getSharedLinkForFolderInputs,
|
|
3049
|
+
outputSchema: (0, _prismatic_io_spectral.outputSchema)({
|
|
3050
|
+
type: "actionOutput",
|
|
3051
|
+
schema: getSharedLinkForFolderOutputSchema
|
|
3052
|
+
}),
|
|
3053
|
+
examplePayload: getSharedLinkForFolderExamplePayload
|
|
3054
|
+
}),
|
|
3055
|
+
removeSharedLinkFromFile: (0, _prismatic_io_spectral.action)({
|
|
3056
|
+
display: {
|
|
3057
|
+
label: "Remove Shared Link from File",
|
|
3058
|
+
description: "Removes a shared link from a file."
|
|
3059
|
+
},
|
|
3060
|
+
performSafety: "notAllowed",
|
|
3061
|
+
perform: async (context, params) => {
|
|
3062
|
+
const fileId = params.fileId;
|
|
3063
|
+
const { data } = await createBoxHttpClient(params.boxConnection, context.debug.enabled).put(`/files/${fileId}`, { shared_link: null }, { params: { fields: SHARED_LINK_FIELD } });
|
|
3064
|
+
return { data };
|
|
3065
|
+
},
|
|
3066
|
+
examplePerform: async (_context, { fileId }) => ({ data: {
|
|
3067
|
+
...removeSharedLinkFromFileExamplePayload.data,
|
|
3068
|
+
id: fileId
|
|
3069
|
+
} }),
|
|
3070
|
+
inputs: removeSharedLinkFromFileInputs,
|
|
3071
|
+
outputSchema: (0, _prismatic_io_spectral.outputSchema)({
|
|
3072
|
+
type: "actionOutput",
|
|
3073
|
+
schema: removeSharedLinkFromFileOutputSchema
|
|
3074
|
+
}),
|
|
3075
|
+
examplePayload: removeSharedLinkFromFileExamplePayload
|
|
3076
|
+
}),
|
|
3077
|
+
removeSharedLinkFromFolder: (0, _prismatic_io_spectral.action)({
|
|
3078
|
+
display: {
|
|
3079
|
+
label: "Remove Shared Link from Folder",
|
|
3080
|
+
description: "Removes a shared link from a folder."
|
|
3081
|
+
},
|
|
3082
|
+
performSafety: "notAllowed",
|
|
3083
|
+
perform: async (context, params) => {
|
|
3084
|
+
const folderId = params.folderId;
|
|
3085
|
+
const { data } = await createBoxHttpClient(params.boxConnection, context.debug.enabled).put(`/folders/${folderId}`, { shared_link: null }, { params: { fields: SHARED_LINK_FIELD } });
|
|
3086
|
+
return { data };
|
|
3087
|
+
},
|
|
3088
|
+
examplePerform: async (_context, { folderId }) => ({ data: {
|
|
3089
|
+
...removeSharedLinkFromFolderExamplePayload.data,
|
|
3090
|
+
id: folderId
|
|
3091
|
+
} }),
|
|
3092
|
+
inputs: removeSharedLinkFromFolderInputs,
|
|
3093
|
+
outputSchema: (0, _prismatic_io_spectral.outputSchema)({
|
|
3094
|
+
type: "actionOutput",
|
|
3095
|
+
schema: removeSharedLinkFromFolderOutputSchema
|
|
3096
|
+
}),
|
|
3097
|
+
examplePayload: removeSharedLinkFromFolderExamplePayload
|
|
3098
|
+
}),
|
|
3099
|
+
updateSharedLinkOnFolder: (0, _prismatic_io_spectral.action)({
|
|
3100
|
+
display: {
|
|
3101
|
+
label: "Update Shared Link on Folder",
|
|
3102
|
+
description: "Updates a shared link on a folder."
|
|
3103
|
+
},
|
|
3104
|
+
performSafety: "notAllowed",
|
|
3105
|
+
perform: async (context, params) => {
|
|
3106
|
+
const folderId = params.folderId;
|
|
3107
|
+
const sharedLink = params.sharedLink;
|
|
3108
|
+
const sharedLinkAccess = params.sharedLinkAccess;
|
|
3109
|
+
const sharedLinkPassword = params.additionalFields.sharedLinkPassword || null;
|
|
3110
|
+
const sharedLinkVanityName = params.additionalFields.sharedLinkVanityName || null;
|
|
3111
|
+
let sharedLinkPermissions = params.additionalFields.sharedLinkPermissions || {};
|
|
3112
|
+
const client = createBoxHttpClient(params.boxConnection, context.debug.enabled);
|
|
3113
|
+
sharedLinkPermissions = {
|
|
3114
|
+
...sharedLinkPermissions,
|
|
3115
|
+
can_edit: false
|
|
3116
|
+
};
|
|
3117
|
+
const { data } = await client.put(`/folders/${folderId}`, { shared_link: {
|
|
3118
|
+
url: sharedLink,
|
|
3119
|
+
access: sharedLinkAccess,
|
|
3120
|
+
password: sharedLinkPassword,
|
|
3121
|
+
permissions: sharedLinkPermissions,
|
|
3122
|
+
vanity_name: sharedLinkVanityName
|
|
3123
|
+
} }, { params: { fields: SHARED_LINK_FIELD } });
|
|
3124
|
+
return { data };
|
|
3125
|
+
},
|
|
3126
|
+
examplePerform: async (_context, { folderId, sharedLink, sharedLinkAccess, additionalFields: { sharedLinkPassword, sharedLinkPermissions, sharedLinkVanityName } }) => {
|
|
3127
|
+
const permissions = {
|
|
3128
|
+
...updateSharedLinkOnFolderExamplePayload.data.shared_link.permissions,
|
|
3129
|
+
...sharedLinkPermissions,
|
|
3130
|
+
can_edit: false
|
|
3131
|
+
};
|
|
3132
|
+
return { data: {
|
|
3133
|
+
...updateSharedLinkOnFolderExamplePayload.data,
|
|
3134
|
+
id: folderId,
|
|
3135
|
+
shared_link: {
|
|
3136
|
+
...updateSharedLinkOnFolderExamplePayload.data.shared_link,
|
|
3137
|
+
url: sharedLink,
|
|
3138
|
+
access: sharedLinkAccess,
|
|
3139
|
+
effective_access: sharedLinkAccess,
|
|
3140
|
+
effective_permission: sharedLinkEffectivePermission(permissions),
|
|
3141
|
+
is_password_enabled: Boolean(sharedLinkPassword),
|
|
3142
|
+
permissions,
|
|
3143
|
+
vanity_url: sharedLinkVanityUrl(sharedLinkVanityName)
|
|
3144
|
+
}
|
|
3145
|
+
} };
|
|
3146
|
+
},
|
|
3147
|
+
inputs: updateSharedLinkOnFolderInputs,
|
|
3148
|
+
outputSchema: (0, _prismatic_io_spectral.outputSchema)({
|
|
3149
|
+
type: "actionOutput",
|
|
3150
|
+
schema: updateSharedLinkOnFolderOutputSchema
|
|
3151
|
+
}),
|
|
3152
|
+
examplePayload: updateSharedLinkOnFolderExamplePayload
|
|
3153
|
+
}),
|
|
3154
|
+
updateSharedLinkToFile: (0, _prismatic_io_spectral.action)({
|
|
3155
|
+
display: {
|
|
3156
|
+
label: "Update Shared Link on File",
|
|
3157
|
+
description: "Updates a shared link on a file."
|
|
3158
|
+
},
|
|
3159
|
+
performSafety: "notAllowed",
|
|
3160
|
+
perform: async (context, params) => {
|
|
3161
|
+
const fileId = params.fileId;
|
|
3162
|
+
const sharedLinkAccess = params.sharedLinkAccess;
|
|
3163
|
+
const sharedLinkPassword = params.additionalFields.sharedLinkPassword || null;
|
|
3164
|
+
const sharedLinkVanityName = params.additionalFields.sharedLinkVanityName || null;
|
|
3165
|
+
const sharedLinkPermissions = params.additionalFields.sharedLinkPermissions || {};
|
|
3166
|
+
const { data } = await createBoxHttpClient(params.boxConnection, context.debug.enabled).put(`/files/${fileId}`, { shared_link: {
|
|
3167
|
+
access: sharedLinkAccess,
|
|
3168
|
+
password: sharedLinkPassword,
|
|
3169
|
+
permissions: sharedLinkPermissions,
|
|
3170
|
+
vanity_name: sharedLinkVanityName
|
|
3171
|
+
} }, { params: { fields: SHARED_LINK_FIELD } });
|
|
3172
|
+
return { data };
|
|
3173
|
+
},
|
|
3174
|
+
examplePerform: async (_context, { fileId, sharedLinkAccess, additionalFields: { sharedLinkPassword, sharedLinkPermissions, sharedLinkVanityName } }) => {
|
|
3175
|
+
const permissions = {
|
|
3176
|
+
...updateSharedLinkToFileExamplePayload.data.shared_link.permissions,
|
|
3177
|
+
...sharedLinkPermissions
|
|
3178
|
+
};
|
|
3179
|
+
return { data: {
|
|
3180
|
+
...updateSharedLinkToFileExamplePayload.data,
|
|
3181
|
+
id: fileId,
|
|
3182
|
+
shared_link: {
|
|
3183
|
+
...updateSharedLinkToFileExamplePayload.data.shared_link,
|
|
3184
|
+
access: sharedLinkAccess,
|
|
3185
|
+
effective_access: sharedLinkAccess,
|
|
3186
|
+
effective_permission: sharedLinkEffectivePermission(permissions),
|
|
3187
|
+
is_password_enabled: Boolean(sharedLinkPassword),
|
|
3188
|
+
permissions,
|
|
3189
|
+
vanity_url: sharedLinkVanityUrl(sharedLinkVanityName)
|
|
3190
|
+
}
|
|
3191
|
+
} };
|
|
3192
|
+
},
|
|
3193
|
+
inputs: updateSharedLinkToFileInputs,
|
|
3194
|
+
outputSchema: (0, _prismatic_io_spectral.outputSchema)({
|
|
3195
|
+
type: "actionOutput",
|
|
3196
|
+
schema: updateSharedLinkToFileOutputSchema
|
|
3197
|
+
}),
|
|
3198
|
+
examplePayload: updateSharedLinkToFileExamplePayload
|
|
3199
|
+
})
|
|
3200
|
+
};
|
|
3201
|
+
//#endregion
|
|
3202
|
+
//#region src/actions/users/index.ts
|
|
3203
|
+
var users_default = { getCurrentUser: (0, _prismatic_io_spectral.action)({
|
|
3204
|
+
display: {
|
|
3205
|
+
label: "Get Current User",
|
|
3206
|
+
description: "Get the information and metadata of the user that is currently logged in."
|
|
3207
|
+
},
|
|
3208
|
+
perform: async (_context, { boxConnection }) => {
|
|
3209
|
+
return { data: (await createAuthorizedClient({ boxConnection }).users.getUserMe()).rawData };
|
|
3210
|
+
},
|
|
3211
|
+
inputs: getCurrentUserInputs,
|
|
3212
|
+
performSafety: "safe",
|
|
3213
|
+
outputSchema: (0, _prismatic_io_spectral.outputSchema)({
|
|
3214
|
+
type: "actionOutput",
|
|
3215
|
+
schema: getCurrentUserOutputSchema
|
|
3216
|
+
}),
|
|
3217
|
+
examplePayload: getCurrentUserExamplePayload
|
|
3218
|
+
}) };
|
|
3219
|
+
//#endregion
|
|
3220
|
+
//#region src/actions/webhooks/createWebhook.ts
|
|
3221
|
+
const createWebhook = (0, _prismatic_io_spectral.action)({
|
|
3222
|
+
display: {
|
|
3223
|
+
label: "Create Webhook",
|
|
3224
|
+
description: "Create a webhook to send data from Box to an instance URL."
|
|
3225
|
+
},
|
|
3226
|
+
inputs: createWebhookInputs,
|
|
3227
|
+
performSafety: "notAllowed",
|
|
3228
|
+
perform: async ({ logger, crossFlowState }, { boxConnection, address, targetId, targetType, triggerTypes, primarySignatureKey, secondarySignatureKey }) => {
|
|
3229
|
+
const client = createAuthorizedClient({ boxConnection });
|
|
3230
|
+
assertTargetType(targetType);
|
|
3231
|
+
let data = null;
|
|
3232
|
+
try {
|
|
3233
|
+
data = (await client.webhooks.createWebhook({
|
|
3234
|
+
target: {
|
|
3235
|
+
id: targetId,
|
|
3236
|
+
type: targetType
|
|
3237
|
+
},
|
|
3238
|
+
address,
|
|
3239
|
+
triggers: triggerTypes
|
|
3240
|
+
})).rawData;
|
|
3241
|
+
} catch (error) {
|
|
3242
|
+
if (getBoxErrorStatus(error) === 409) logger.warn(`Skipping creation of webhook. A webhook with this target (${targetId}), application, and user already exists.`);
|
|
3243
|
+
else throw error;
|
|
3244
|
+
}
|
|
3245
|
+
if (primarySignatureKey) crossFlowState.primarySignatureKey = primarySignatureKey;
|
|
3246
|
+
if (secondarySignatureKey) crossFlowState.secondarySignatureKey = secondarySignatureKey;
|
|
3247
|
+
return {
|
|
3248
|
+
data,
|
|
3249
|
+
crossFlowState
|
|
3250
|
+
};
|
|
3251
|
+
},
|
|
3252
|
+
examplePerform: async (_context, { address, targetId, targetType, triggerTypes }) => ({ data: {
|
|
3253
|
+
...createWebhookExamplePayload.data,
|
|
3254
|
+
target: {
|
|
3255
|
+
id: targetId,
|
|
3256
|
+
type: targetType
|
|
3257
|
+
},
|
|
3258
|
+
address,
|
|
3259
|
+
triggers: triggerTypes
|
|
3260
|
+
} }),
|
|
3261
|
+
outputSchema: (0, _prismatic_io_spectral.outputSchema)({
|
|
3262
|
+
type: "actionOutput",
|
|
3263
|
+
schema: createWebhookOutputSchema
|
|
3264
|
+
}),
|
|
3265
|
+
examplePayload: createWebhookExamplePayload
|
|
3266
|
+
});
|
|
3267
|
+
//#endregion
|
|
3268
|
+
//#region src/actions/webhooks/deleteInstanceWebhooks.ts
|
|
3269
|
+
const deleteInstanceWebhooks = (0, _prismatic_io_spectral.action)({
|
|
3270
|
+
display: {
|
|
3271
|
+
label: "Delete Instance Webhooks",
|
|
3272
|
+
description: "Delete all Box webhooks that point to a flow in this instance."
|
|
3273
|
+
},
|
|
3274
|
+
inputs: deleteInstanceWebhooksInputs,
|
|
3275
|
+
performSafety: "notAllowed",
|
|
3276
|
+
perform: async ({ logger, webhookUrls }, { boxConnection }) => {
|
|
3277
|
+
const client = createAuthorizedClient({ boxConnection });
|
|
3278
|
+
const { entries } = await getAllWebhookEntries(client);
|
|
3279
|
+
const instanceWebhookIds = await getInstanceWebhookIds(client, entries, webhookUrls);
|
|
3280
|
+
for (const webhookId of instanceWebhookIds) {
|
|
3281
|
+
logger.info(`Deleting webhook ${webhookId}...`);
|
|
3282
|
+
await client.webhooks.deleteWebhookById(_prismatic_io_spectral.util.types.toString(webhookId));
|
|
3283
|
+
}
|
|
3284
|
+
return { data: {} };
|
|
3285
|
+
},
|
|
3286
|
+
examplePerform: async () => ({ data: deleteInstanceWebhooksExamplePayload.data }),
|
|
3287
|
+
outputSchema: (0, _prismatic_io_spectral.outputSchema)({
|
|
3288
|
+
type: "actionOutput",
|
|
3289
|
+
schema: deleteInstanceWebhooksOutputSchema
|
|
3290
|
+
}),
|
|
3291
|
+
examplePayload: deleteInstanceWebhooksExamplePayload
|
|
3292
|
+
});
|
|
3293
|
+
//#endregion
|
|
3294
|
+
//#region src/actions/webhooks/index.ts
|
|
3295
|
+
var webhooks_default = {
|
|
3296
|
+
createWebhook,
|
|
3297
|
+
deleteWebhook: (0, _prismatic_io_spectral.action)({
|
|
3298
|
+
display: {
|
|
3299
|
+
label: "Delete Webhook",
|
|
3300
|
+
description: "Delete a webhook by ID."
|
|
3301
|
+
},
|
|
3302
|
+
inputs: deleteWebhookInputs,
|
|
3303
|
+
performSafety: "notAllowed",
|
|
3304
|
+
perform: async (_context, { boxConnection, webhookId }) => {
|
|
3305
|
+
await createAuthorizedClient({ boxConnection }).webhooks.deleteWebhookById(_prismatic_io_spectral.util.types.toString(webhookId));
|
|
3306
|
+
return { data: null };
|
|
3307
|
+
},
|
|
3308
|
+
examplePerform: async () => ({ data: deleteWebhookExamplePayload.data }),
|
|
3309
|
+
outputSchema: (0, _prismatic_io_spectral.outputSchema)({
|
|
3310
|
+
type: "actionOutput",
|
|
3311
|
+
schema: deleteWebhookOutputSchema
|
|
3312
|
+
}),
|
|
3313
|
+
examplePayload: deleteWebhookExamplePayload
|
|
3314
|
+
}),
|
|
3315
|
+
listWebhooks: (0, _prismatic_io_spectral.action)({
|
|
3316
|
+
display: {
|
|
3317
|
+
label: "List Webhooks",
|
|
3318
|
+
description: "List all webhooks configured in Box, including those for other integrations."
|
|
3319
|
+
},
|
|
3320
|
+
inputs: listWebhooksInputs,
|
|
3321
|
+
performSafety: "notAllowed",
|
|
3322
|
+
perform: async ({ webhookUrls }, { boxConnection, pagination, showOnlyInstanceWebhooks, fetchAll }) => {
|
|
3323
|
+
const client = createAuthorizedClient({ boxConnection });
|
|
3324
|
+
let entries;
|
|
3325
|
+
let extra = {};
|
|
3326
|
+
if (fetchAll) ({entries} = await getAllWebhookEntries(client));
|
|
3327
|
+
else {
|
|
3328
|
+
const options = {};
|
|
3329
|
+
if (pagination.limit) options.limit = _prismatic_io_spectral.util.types.toInt(pagination.limit);
|
|
3330
|
+
if (pagination.marker) options.marker = _prismatic_io_spectral.util.types.toString(pagination.marker);
|
|
3331
|
+
const result = await client.webhooks.getWebhooks(options);
|
|
3332
|
+
entries = result.rawData?.entries ?? [];
|
|
3333
|
+
extra = {
|
|
3334
|
+
limit: result.limit,
|
|
3335
|
+
next_marker: result.nextMarker
|
|
3336
|
+
};
|
|
3337
|
+
}
|
|
3338
|
+
if (showOnlyInstanceWebhooks) {
|
|
3339
|
+
const instanceWebhookIds = await getInstanceWebhookIds(client, entries, webhookUrls);
|
|
3340
|
+
entries = entries.filter((entry) => instanceWebhookIds.has(_prismatic_io_spectral.util.types.toString(entry.id)));
|
|
3341
|
+
}
|
|
3342
|
+
return { data: {
|
|
3343
|
+
...extra,
|
|
3344
|
+
entries
|
|
3345
|
+
} };
|
|
3346
|
+
},
|
|
3347
|
+
examplePerform: async (_context, params) => {
|
|
3348
|
+
const { entries, limit, next_marker } = listWebhooksExamplePayload.data;
|
|
3349
|
+
if (params.fetchAll) return { data: { entries } };
|
|
3350
|
+
return { data: {
|
|
3351
|
+
limit: _prismatic_io_spectral.util.types.toInt(params.pagination.limit) || limit,
|
|
3352
|
+
next_marker,
|
|
3353
|
+
entries
|
|
3354
|
+
} };
|
|
3355
|
+
},
|
|
3356
|
+
outputSchema: (0, _prismatic_io_spectral.outputSchema)({
|
|
3357
|
+
type: "actionOutput",
|
|
3358
|
+
schema: listWebhooksOutputSchema
|
|
3359
|
+
}),
|
|
3360
|
+
examplePayload: listWebhooksExamplePayload
|
|
3361
|
+
}),
|
|
3362
|
+
deleteInstanceWebhooks
|
|
3363
|
+
};
|
|
3364
|
+
//#endregion
|
|
3365
|
+
//#region src/actions/index.ts
|
|
3366
|
+
var actions_default = {
|
|
3367
|
+
...files_default,
|
|
3368
|
+
...folders_default,
|
|
3369
|
+
...objects_default,
|
|
3370
|
+
...sharedLinks_default,
|
|
3371
|
+
...users_default,
|
|
3372
|
+
...webhooks_default,
|
|
3373
|
+
...misc_default
|
|
3374
|
+
};
|
|
3375
|
+
//#endregion
|
|
3376
|
+
//#region src/dataSources/index.ts
|
|
3377
|
+
var dataSources_default = {
|
|
3378
|
+
selectContent: (0, _prismatic_io_spectral.dataSource)({
|
|
3379
|
+
display: {
|
|
3380
|
+
label: "Select File or Folder",
|
|
3381
|
+
description: "Select file or folder from Box account base path."
|
|
3382
|
+
},
|
|
3383
|
+
dataSourceType: "picklist",
|
|
3384
|
+
perform: async (_context, params) => {
|
|
3385
|
+
const client = createAuthorizedClient({ boxConnection: params.boxConnection });
|
|
3386
|
+
const { id, type, name } = (await getPathEntries(client, "/")).slice(-1)[0];
|
|
3387
|
+
if (type !== "folder") throw Error(`'${name}' is not a folder`);
|
|
3388
|
+
let allEntries = await getFolderEntries({
|
|
3389
|
+
client,
|
|
3390
|
+
id,
|
|
3391
|
+
limit: _prismatic_io_spectral.util.types.toInt(params.limit) || void 0,
|
|
3392
|
+
marker: _prismatic_io_spectral.util.types.toString(params.marker) || void 0,
|
|
3393
|
+
offset: _prismatic_io_spectral.util.types.toInt(params.offset) || void 0
|
|
3394
|
+
});
|
|
3395
|
+
switch (params.contentType) {
|
|
3396
|
+
case FILE_TYPE:
|
|
3397
|
+
allEntries = allEntries.filter((entry) => entry.type === FILE_TYPE);
|
|
3398
|
+
break;
|
|
3399
|
+
case FOLDER_TYPE:
|
|
3400
|
+
allEntries = allEntries.filter((entry) => entry.type === FOLDER_TYPE);
|
|
3401
|
+
break;
|
|
3402
|
+
case "all": break;
|
|
3403
|
+
default: throw new Error(`Invalid content type specified: ${params.contentType}`);
|
|
3404
|
+
}
|
|
3405
|
+
return { result: allEntries.map((entry) => ({
|
|
3406
|
+
label: `${_prismatic_io_spectral.util.types.toString(entry.name)} (${_prismatic_io_spectral.util.types.toString(entry.type)})`,
|
|
3407
|
+
key: _prismatic_io_spectral.util.types.toString(entry.id)
|
|
3408
|
+
})) };
|
|
3409
|
+
},
|
|
3410
|
+
inputs: selectContentInputs,
|
|
3411
|
+
examplePayload: selectContentExamplePayload
|
|
3412
|
+
}),
|
|
3413
|
+
selectWebhook: (0, _prismatic_io_spectral.dataSource)({
|
|
3414
|
+
display: {
|
|
3415
|
+
label: "Select Webhook",
|
|
3416
|
+
description: "Select webhook from Box account."
|
|
3417
|
+
},
|
|
3418
|
+
dataSourceType: "picklist",
|
|
3419
|
+
perform: async (_context, { boxConnection }) => {
|
|
3420
|
+
const client = createAuthorizedClient({ boxConnection });
|
|
3421
|
+
const { entries } = await getAllWebhookEntries(client);
|
|
3422
|
+
return { result: (await Promise.all((entries || []).map((entry) => client.webhooks.getWebhookById(_prismatic_io_spectral.util.types.toString(entry.id)))) || []).map((webhook) => ({
|
|
3423
|
+
label: _prismatic_io_spectral.util.types.toString(webhook.address),
|
|
3424
|
+
key: _prismatic_io_spectral.util.types.toString(webhook.id)
|
|
3425
|
+
})) };
|
|
3426
|
+
},
|
|
3427
|
+
inputs: selectWebhookInputs,
|
|
3428
|
+
examplePayload: selectWebhookExamplePayload
|
|
3429
|
+
})
|
|
3430
|
+
};
|
|
3431
|
+
//#endregion
|
|
3432
|
+
//#region src/triggers/managedWebhook.ts
|
|
3433
|
+
const managedWebhook = (0, _prismatic_io_spectral.trigger)({
|
|
3434
|
+
display: {
|
|
3435
|
+
label: "Managed Webhook",
|
|
3436
|
+
description: "Receive and validate webhook requests from Box. Automatically creates and manages a webhook subscription when the instance is deployed, and removes the subscription when the instance is deleted."
|
|
3437
|
+
},
|
|
3438
|
+
webhookLifecycleHandlers: {
|
|
3439
|
+
create: async ({ crossFlowState, logger, flow: flowProperties, webhookUrls }, { connection, targetId, targetType, triggerTypes, primarySignatureKey, secondarySignatureKey }) => {
|
|
3440
|
+
const client = createAuthorizedClient({ boxConnection: connection });
|
|
3441
|
+
const storeKey = getStoreKey(flowProperties.name);
|
|
3442
|
+
const legacyStoreKey = getLegacyStoreKey(targetId, targetType, flowProperties.name);
|
|
3443
|
+
const { state, adoptedFromLegacyKey } = resolveStoreState(crossFlowState, storeKey, legacyStoreKey);
|
|
3444
|
+
const persist = (newCrossFlowState) => {
|
|
3445
|
+
Object.assign(crossFlowState, newCrossFlowState);
|
|
3446
|
+
if (adoptedFromLegacyKey) crossFlowState[legacyStoreKey] = void 0;
|
|
3447
|
+
return { crossFlowState };
|
|
3448
|
+
};
|
|
3449
|
+
logger.info("Checking for existing webhook...");
|
|
3450
|
+
if (state?.existingWebhookId) {
|
|
3451
|
+
if (adoptedFromLegacyKey) logger.info("Adopted webhook state stored under the legacy composite key.");
|
|
3452
|
+
logger.info("Existing webhook found, checking for changes...");
|
|
3453
|
+
if (!(state.previousTargetId !== targetId || state.previousTargetType !== targetType || state.previousTriggerTypes?.join(",") !== triggerTypes.join(","))) {
|
|
3454
|
+
logger.info("No changes found, skipping...");
|
|
3455
|
+
return adoptedFromLegacyKey ? persist({ [storeKey]: state }) : void 0;
|
|
3456
|
+
}
|
|
3457
|
+
logger.info("Changes found, deleting previous webhook and creating a new one...");
|
|
3458
|
+
await deleteWebhookIfPresent(client, _prismatic_io_spectral.util.types.toString(state.existingWebhookId), logger);
|
|
3459
|
+
} else logger.info("No existing webhook found, creating new one...");
|
|
3460
|
+
const address = _prismatic_io_spectral.util.types.toString(webhookUrls[flowProperties.name]);
|
|
3461
|
+
const create = () => createWebhookFN(client, targetId, targetType, address, triggerTypes, storeKey, logger, primarySignatureKey, secondarySignatureKey);
|
|
3462
|
+
try {
|
|
3463
|
+
return persist((await create()).crossFlowState);
|
|
3464
|
+
} catch (error) {
|
|
3465
|
+
if (getBoxErrorStatus(error) !== 409) throw error;
|
|
3466
|
+
const ownWebhookIds = await getTargetWebhookIdsForAddress(client, targetId, targetType, address);
|
|
3467
|
+
if (ownWebhookIds.size === 0) throw new Error(`A Box webhook for ${targetType} ${targetId} already exists for this application and user, and it delivers to a different URL. Box allows one webhook per target, application and user: delete that webhook or choose a different target.`);
|
|
3468
|
+
logger.info("A webhook for this flow already exists in Box, replacing it...");
|
|
3469
|
+
for (const webhookId of ownWebhookIds) await deleteWebhookIfPresent(client, webhookId, logger);
|
|
3470
|
+
return persist((await create()).crossFlowState);
|
|
3471
|
+
}
|
|
3472
|
+
},
|
|
3473
|
+
delete: async ({ flow: flowProperties, crossFlowState, logger }, { connection, targetId, targetType }) => {
|
|
3474
|
+
const storeKey = getStoreKey(flowProperties.name);
|
|
3475
|
+
const legacyStoreKey = getLegacyStoreKey(targetId, targetType, flowProperties.name);
|
|
3476
|
+
const client = createAuthorizedClient({ boxConnection: connection });
|
|
3477
|
+
const { state } = resolveStoreState(crossFlowState, storeKey, legacyStoreKey);
|
|
3478
|
+
logger.info("Checking for existing webhook...");
|
|
3479
|
+
if (state?.existingWebhookId) {
|
|
3480
|
+
logger.info("Existing webhook found, deleting...");
|
|
3481
|
+
await deleteWebhookIfPresent(client, _prismatic_io_spectral.util.types.toString(state.existingWebhookId), logger);
|
|
3482
|
+
crossFlowState[storeKey] = void 0;
|
|
3483
|
+
crossFlowState[legacyStoreKey] = void 0;
|
|
3484
|
+
return { crossFlowState };
|
|
3485
|
+
} else logger.info("No existing webhook found, skipping...");
|
|
3486
|
+
}
|
|
3487
|
+
},
|
|
3488
|
+
perform: async (context, payload, { primarySignatureKey, secondarySignatureKey }) => {
|
|
3489
|
+
if (context.isSimulatedTestExecution) return Promise.resolve({ payload });
|
|
3490
|
+
const { rawBody, headers } = payload;
|
|
3491
|
+
const lowerHeaders = _prismatic_io_spectral.util.types.lowerCaseHeaders(headers);
|
|
3492
|
+
const primarySignature = lowerHeaders[BOX_SIGNATURE_PRIMARY_HEADER];
|
|
3493
|
+
const secondarySignature = lowerHeaders[BOX_SIGNATURE_SECONDARY_HEADER];
|
|
3494
|
+
const storeKey = getStoreKey(context.flow.name);
|
|
3495
|
+
const state = context.crossFlowState[storeKey];
|
|
3496
|
+
const primaryKey = primarySignatureKey || (state?.primarySignatureKey ?? context.crossFlowState.primarySignatureKey);
|
|
3497
|
+
const secondaryKey = secondarySignatureKey || (state?.secondarySignatureKey ?? context.crossFlowState.secondarySignatureKey);
|
|
3498
|
+
if (primaryKey || secondaryKey || primarySignature || secondarySignature) {
|
|
3499
|
+
if (!validateBoxWebhookSignature({
|
|
3500
|
+
body: _prismatic_io_spectral.util.types.toString(rawBody.data),
|
|
3501
|
+
headers: lowerHeaders,
|
|
3502
|
+
primaryKey,
|
|
3503
|
+
secondaryKey
|
|
3504
|
+
})) throw new Error("The request has failed Box signature validation. Rejecting.");
|
|
3505
|
+
}
|
|
3506
|
+
return Promise.resolve({ payload });
|
|
3507
|
+
},
|
|
3508
|
+
inputs: managedWebhookInputs,
|
|
3509
|
+
examplePayload: managedWebhookExamplePayload,
|
|
3510
|
+
synchronousResponseSupport: "invalid",
|
|
3511
|
+
scheduleSupport: "invalid"
|
|
3512
|
+
});
|
|
3513
|
+
//#endregion
|
|
3514
|
+
//#region src/triggers/newFileComments.ts
|
|
3515
|
+
const newFileComments = (0, _prismatic_io_spectral.pollingTrigger)({
|
|
3516
|
+
display: {
|
|
3517
|
+
label: "New File Comments",
|
|
3518
|
+
description: "Retrieves existing and ongoing comments on a specified Box file. Load history once, check for changes on a schedule, or both."
|
|
3519
|
+
},
|
|
3520
|
+
inputs: newFileCommentsInputs,
|
|
3521
|
+
examplePayload: newFileCommentsExamplePayload,
|
|
3522
|
+
allowsBranching: false,
|
|
3523
|
+
triggerResolverSupport: "valid",
|
|
3524
|
+
batchConfig: { batchSize: 50 },
|
|
3525
|
+
triggerResolver: { resolveItems: (_context, { payload }) => resolveCommentChanges(payload.body.data) },
|
|
3526
|
+
perform: async (context, payload, { connection, fileId, lookBackDate }) => {
|
|
3527
|
+
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
3528
|
+
const client = createAuthorizedClient({ boxConnection: connection });
|
|
3529
|
+
const lastPolledAt = getLastPolledAt(context, lookBackDate || now);
|
|
3530
|
+
context.logger.debug(`Polling for comments from: ${lastPolledAt} to ${now}`);
|
|
3531
|
+
const allComments = await getAllFileComments(client, _prismatic_io_spectral.util.types.toString(fileId));
|
|
3532
|
+
context.logger.info(`Polled ${allComments.length} comments`);
|
|
3533
|
+
context.logger.info("Normalizing comment dates...");
|
|
3534
|
+
const normalizedComments = normalizeDatesBetweenEntries(allComments);
|
|
3535
|
+
context.logger.info("Computing new comments...");
|
|
3536
|
+
const newComments = computeNewEntries(normalizedComments, lastPolledAt);
|
|
3537
|
+
context.logger.info("Setting polling state...");
|
|
3538
|
+
context.polling.setState({ lastPolledAt: now });
|
|
3539
|
+
return {
|
|
3540
|
+
payload: {
|
|
3541
|
+
...payload,
|
|
3542
|
+
body: { data: { newComments: { data: newComments } } }
|
|
3543
|
+
},
|
|
3544
|
+
polledNoChanges: newComments.length === 0
|
|
3545
|
+
};
|
|
3546
|
+
}
|
|
3547
|
+
});
|
|
3548
|
+
//#endregion
|
|
3549
|
+
//#region src/triggers/newFolder.ts
|
|
3550
|
+
const newFolder = (0, _prismatic_io_spectral.pollingTrigger)({
|
|
3551
|
+
display: {
|
|
3552
|
+
label: "New Folders",
|
|
3553
|
+
description: "Retrieves existing and ongoing folders in a specified Box folder. Load history once, check for changes on a schedule, or both."
|
|
3554
|
+
},
|
|
3555
|
+
inputs: newFolderInputs,
|
|
3556
|
+
examplePayload: newFolderExamplePayload,
|
|
3557
|
+
triggerResolverSupport: "valid",
|
|
3558
|
+
batchConfig: { batchSize: 50 },
|
|
3559
|
+
triggerResolver: { resolveItems: (_context, { payload }) => resolveFolderChanges(payload.body.data) },
|
|
3560
|
+
perform: async (context, payload, { connection, folderId, lookBackDate }) => {
|
|
3561
|
+
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
3562
|
+
const client = createAuthorizedClient({ boxConnection: connection });
|
|
3563
|
+
const lastPolledAt = getLastPolledAt(context, lookBackDate || now);
|
|
3564
|
+
const fields = "name,created_at,id,type";
|
|
3565
|
+
context.logger.debug(`Polling for changes from: ${lastPolledAt} to ${now}`);
|
|
3566
|
+
const entries = await getFolderEntries({
|
|
3567
|
+
client,
|
|
3568
|
+
id: folderId,
|
|
3569
|
+
fields,
|
|
3570
|
+
limit: MAX_PAGE_SIZE
|
|
3571
|
+
});
|
|
3572
|
+
context.logger.info(`Polled ${entries.length} entries`);
|
|
3573
|
+
context.logger.info("Normalizing entry dates...");
|
|
3574
|
+
const normalizedEntries = normalizeDatesBetweenEntries(entries.filter(({ type }) => type === FOLDER_TYPE));
|
|
3575
|
+
context.logger.info("Computing new folders...");
|
|
3576
|
+
const newFolders = computeNewEntries(normalizedEntries, lastPolledAt);
|
|
3577
|
+
context.logger.info("Setting polling state...");
|
|
3578
|
+
context.polling.setState({ lastPolledAt: now });
|
|
3579
|
+
return buildPollingResult(payload, { newFolders: {
|
|
3580
|
+
data: newFolders,
|
|
3581
|
+
polledNoChanges: newFolders.length === 0
|
|
3582
|
+
} });
|
|
3583
|
+
}
|
|
3584
|
+
});
|
|
3585
|
+
//#endregion
|
|
3586
|
+
//#region src/triggers/newOrUpdatedFile.ts
|
|
3587
|
+
const newOrUpdatedFile = (0, _prismatic_io_spectral.pollingTrigger)({
|
|
3588
|
+
display: {
|
|
3589
|
+
label: "New and Updated Files",
|
|
3590
|
+
description: "Retrieves existing and ongoing files in a specified Box folder. Load history once, check for changes on a schedule, or both."
|
|
3591
|
+
},
|
|
3592
|
+
inputs: newOrUpdatedFileInputs,
|
|
3593
|
+
examplePayload: newOrUpdatedFileExamplePayload,
|
|
3594
|
+
triggerResolverSupport: "valid",
|
|
3595
|
+
batchConfig: { batchSize: 50 },
|
|
3596
|
+
triggerResolver: { resolveItems: (_context, { payload }) => resolvePollingRecordChanges(payload.body.data) },
|
|
3597
|
+
perform: async (context, payload, { connection, folderId, lookBackDate }) => {
|
|
3598
|
+
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
3599
|
+
const client = createAuthorizedClient({ boxConnection: connection });
|
|
3600
|
+
const lastPolledAt = context.polling.getState()?.lastPolledAt ?? (lookBackDate || now);
|
|
3601
|
+
const fields = "name,created_at,modified_at,id,type";
|
|
3602
|
+
context.logger.debug(`Polling for changes from: ${lastPolledAt} to ${now}`);
|
|
3603
|
+
const entries = await getFolderEntries({
|
|
3604
|
+
client,
|
|
3605
|
+
id: folderId,
|
|
3606
|
+
fields,
|
|
3607
|
+
limit: MAX_PAGE_SIZE
|
|
3608
|
+
});
|
|
3609
|
+
context.logger.info(`Polled ${entries.length} entries`);
|
|
3610
|
+
context.logger.info("Normalizing entry dates...");
|
|
3611
|
+
const normalizedEntries = normalizeDatesBetweenEntries(entries.filter(({ type }) => type !== FOLDER_TYPE));
|
|
3612
|
+
context.logger.info("Computing new files...");
|
|
3613
|
+
const newFiles = computeNewEntries(normalizedEntries, lastPolledAt);
|
|
3614
|
+
context.logger.info("Computing updated files...");
|
|
3615
|
+
const updatedFiles = computeUpdatedEntries(normalizedEntries, lastPolledAt, newFiles.map((entry) => entry.id));
|
|
3616
|
+
context.logger.info("Setting polling state...");
|
|
3617
|
+
context.polling.setState({ lastPolledAt: now });
|
|
3618
|
+
return buildPollingResult(payload, {
|
|
3619
|
+
newFiles: {
|
|
3620
|
+
data: newFiles,
|
|
3621
|
+
polledNoChanges: newFiles.length === 0
|
|
3622
|
+
},
|
|
3623
|
+
updatedFiles: {
|
|
3624
|
+
data: updatedFiles,
|
|
3625
|
+
polledNoChanges: updatedFiles.length === 0
|
|
3626
|
+
}
|
|
3627
|
+
});
|
|
3628
|
+
}
|
|
3629
|
+
});
|
|
3630
|
+
//#endregion
|
|
3631
|
+
//#region src/triggers/index.ts
|
|
3632
|
+
var triggers_default = {
|
|
3633
|
+
webhook: (0, _prismatic_io_spectral.trigger)({
|
|
3634
|
+
display: {
|
|
3635
|
+
label: "Manual Webhook",
|
|
3636
|
+
description: "Receive and validate webhook requests from Box for manually configured webhook subscriptions."
|
|
3637
|
+
},
|
|
3638
|
+
perform: async (context, payload, { primarySignatureKey, secondarySignatureKey }) => {
|
|
3639
|
+
if (context.isSimulatedTestExecution) return Promise.resolve({ payload });
|
|
3640
|
+
const { rawBody, headers } = payload;
|
|
3641
|
+
const lowerHeaders = _prismatic_io_spectral.util.types.lowerCaseHeaders(headers);
|
|
3642
|
+
const primarySignature = lowerHeaders[BOX_SIGNATURE_PRIMARY_HEADER];
|
|
3643
|
+
const secondarySignature = lowerHeaders[BOX_SIGNATURE_SECONDARY_HEADER];
|
|
3644
|
+
const primaryKey = primarySignatureKey || context.crossFlowState.primarySignatureKey;
|
|
3645
|
+
const secondaryKey = secondarySignatureKey || context.crossFlowState.secondarySignatureKey;
|
|
3646
|
+
if (primaryKey || secondaryKey || primarySignature || secondarySignature) {
|
|
3647
|
+
if (!validateBoxWebhookSignature({
|
|
3648
|
+
body: _prismatic_io_spectral.util.types.toString(rawBody.data),
|
|
3649
|
+
headers: lowerHeaders,
|
|
3650
|
+
primaryKey,
|
|
3651
|
+
secondaryKey
|
|
3652
|
+
})) throw new Error("The request has failed Box signature validation. Rejecting.");
|
|
3653
|
+
}
|
|
3654
|
+
return Promise.resolve({ payload });
|
|
3655
|
+
},
|
|
3656
|
+
inputs: webhookInputs,
|
|
3657
|
+
examplePayload: webhookExamplePayload,
|
|
3658
|
+
synchronousResponseSupport: "invalid",
|
|
3659
|
+
scheduleSupport: "invalid"
|
|
3660
|
+
}),
|
|
3661
|
+
managedWebhook,
|
|
3662
|
+
newOrUpdatedFile,
|
|
3663
|
+
newFolder,
|
|
3664
|
+
newFileComments
|
|
3665
|
+
};
|
|
3666
|
+
//#endregion
|
|
3667
|
+
//#region src/index.ts
|
|
3668
|
+
var src_default = (0, _prismatic_io_spectral.component)({
|
|
3669
|
+
key: "box",
|
|
3670
|
+
documentationUrl: "https://prismatic.io/docs/components/box/",
|
|
3671
|
+
public: true,
|
|
3672
|
+
display: {
|
|
3673
|
+
label: "Box",
|
|
3674
|
+
description: "Manage files stored in Box",
|
|
3675
|
+
iconPath: "icon.png",
|
|
3676
|
+
category: "Data Platforms"
|
|
3677
|
+
},
|
|
3678
|
+
actions: actions_default,
|
|
3679
|
+
connections: connections_default,
|
|
3680
|
+
triggers: triggers_default,
|
|
3681
|
+
dataSources: dataSources_default,
|
|
3682
|
+
hooks: { error: _prismatic_io_spectral_http.handleErrors }
|
|
3683
|
+
});
|
|
3684
|
+
//#endregion
|
|
3685
|
+
//#region npm-dist/.entry.ts
|
|
3686
|
+
var _entry_default = (0, _prismatic_io_spectral.callableComponent)(src_default);
|
|
3687
|
+
//#endregion
|
|
3688
|
+
module.exports = _entry_default;
|