box-node-sdk 1.35.0 → 1.37.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (126) hide show
  1. package/CHANGELOG.md +37 -2
  2. package/README.md +1 -1
  3. package/lib/api-request-manager.d.ts +38 -0
  4. package/lib/api-request-manager.js +48 -55
  5. package/lib/api-request-manager.js.map +1 -0
  6. package/lib/api-request.d.ts +141 -0
  7. package/lib/api-request.js +202 -281
  8. package/lib/api-request.js.map +1 -0
  9. package/lib/box-client.d.ts +269 -0
  10. package/lib/box-client.js +551 -713
  11. package/lib/box-client.js.map +1 -0
  12. package/lib/box-node-sdk.d.ts +216 -0
  13. package/lib/box-node-sdk.js +317 -352
  14. package/lib/box-node-sdk.js.map +1 -0
  15. package/lib/chunked-uploader.d.ts +129 -0
  16. package/lib/chunked-uploader.js +287 -358
  17. package/lib/chunked-uploader.js.map +1 -0
  18. package/lib/enterprise-event-stream.d.ts +82 -0
  19. package/lib/enterprise-event-stream.js +189 -203
  20. package/lib/enterprise-event-stream.js.map +1 -0
  21. package/lib/event-stream.d.ts +92 -0
  22. package/lib/event-stream.js +274 -302
  23. package/lib/event-stream.js.map +1 -0
  24. package/lib/managers/collaboration-allowlist.d.ts +137 -0
  25. package/lib/managers/collaboration-allowlist.js +200 -0
  26. package/lib/managers/collaboration-allowlist.js.map +1 -0
  27. package/lib/managers/collaboration-whitelist.d.ts +3 -0
  28. package/lib/managers/collaboration-whitelist.js +8 -222
  29. package/lib/managers/collaboration-whitelist.js.map +1 -0
  30. package/lib/managers/collaborations.d.ts +166 -0
  31. package/lib/managers/collaborations.js +225 -258
  32. package/lib/managers/collaborations.js.map +1 -0
  33. package/lib/managers/collections.d.ts +42 -0
  34. package/lib/managers/collections.js +45 -50
  35. package/lib/managers/collections.js.map +1 -0
  36. package/lib/managers/comments.d.ts +103 -0
  37. package/lib/managers/comments.js +158 -173
  38. package/lib/managers/comments.js.map +1 -0
  39. package/lib/managers/device-pins.d.ts +52 -0
  40. package/lib/managers/device-pins.js +75 -88
  41. package/lib/managers/device-pins.js.map +1 -0
  42. package/lib/managers/enterprise.d.ts +162 -0
  43. package/lib/managers/enterprise.js +168 -199
  44. package/lib/managers/enterprise.js.map +1 -0
  45. package/lib/managers/events.d.ts +177 -0
  46. package/lib/managers/events.js +230 -254
  47. package/lib/managers/events.js.map +1 -0
  48. package/lib/managers/files.d.ts +772 -0
  49. package/lib/managers/files.js +1400 -1602
  50. package/lib/managers/files.js.map +1 -0
  51. package/lib/managers/folders.d.ts +347 -0
  52. package/lib/managers/folders.js +551 -567
  53. package/lib/managers/folders.js.map +1 -0
  54. package/lib/managers/groups.d.ts +202 -0
  55. package/lib/managers/groups.js +238 -287
  56. package/lib/managers/groups.js.map +1 -0
  57. package/lib/managers/legal-hold-policies.d.ts +190 -0
  58. package/lib/managers/legal-hold-policies.js +228 -272
  59. package/lib/managers/legal-hold-policies.js.map +1 -0
  60. package/lib/managers/metadata.d.ts +228 -0
  61. package/lib/managers/metadata.js +265 -328
  62. package/lib/managers/metadata.js.map +1 -0
  63. package/lib/managers/recent-items.d.ts +38 -0
  64. package/lib/managers/recent-items.js +32 -39
  65. package/lib/managers/recent-items.js.map +1 -0
  66. package/lib/managers/retention-policies.d.ts +213 -0
  67. package/lib/managers/retention-policies.js +235 -281
  68. package/lib/managers/retention-policies.js.map +1 -0
  69. package/lib/managers/search.d.ts +82 -0
  70. package/lib/managers/search.js +68 -88
  71. package/lib/managers/search.js.map +1 -0
  72. package/lib/managers/shared-items.d.ts +33 -0
  73. package/lib/managers/shared-items.js +54 -62
  74. package/lib/managers/shared-items.js.map +1 -0
  75. package/lib/managers/storage-policies.d.ts +86 -0
  76. package/lib/managers/storage-policies.js +108 -142
  77. package/lib/managers/storage-policies.js.map +1 -0
  78. package/lib/managers/tasks.d.ts +161 -0
  79. package/lib/managers/tasks.js +219 -260
  80. package/lib/managers/tasks.js.map +1 -0
  81. package/lib/managers/terms-of-service.d.ts +161 -0
  82. package/lib/managers/terms-of-service.js +250 -273
  83. package/lib/managers/terms-of-service.js.map +1 -0
  84. package/lib/managers/trash.d.ts +30 -0
  85. package/lib/managers/trash.js +30 -41
  86. package/lib/managers/trash.js.map +1 -0
  87. package/lib/managers/users.d.ts +131 -0
  88. package/lib/managers/users.js +160 -203
  89. package/lib/managers/users.js.map +1 -0
  90. package/lib/managers/web-links.d.ts +127 -0
  91. package/lib/managers/web-links.js +183 -209
  92. package/lib/managers/web-links.js.map +1 -0
  93. package/lib/managers/webhooks.d.ts +166 -0
  94. package/lib/managers/webhooks.js +312 -305
  95. package/lib/managers/webhooks.js.map +1 -0
  96. package/lib/sessions/anonymous-session.d.ts +69 -0
  97. package/lib/sessions/anonymous-session.js +88 -102
  98. package/lib/sessions/anonymous-session.js.map +1 -0
  99. package/lib/sessions/app-auth-session.d.ts +92 -0
  100. package/lib/sessions/app-auth-session.js +140 -160
  101. package/lib/sessions/app-auth-session.js.map +1 -0
  102. package/lib/sessions/basic-session.d.ts +56 -0
  103. package/lib/sessions/basic-session.js +40 -50
  104. package/lib/sessions/basic-session.js.map +1 -0
  105. package/lib/sessions/persistent-session.d.ts +96 -0
  106. package/lib/sessions/persistent-session.js +191 -211
  107. package/lib/sessions/persistent-session.js.map +1 -0
  108. package/lib/token-manager.d.ts +191 -0
  109. package/lib/token-manager.js +390 -465
  110. package/lib/token-manager.js.map +1 -0
  111. package/lib/util/config.d.ts +86 -0
  112. package/lib/util/config.js +124 -152
  113. package/lib/util/config.js.map +1 -0
  114. package/lib/util/errors.d.ts +50 -0
  115. package/lib/util/errors.js +134 -145
  116. package/lib/util/errors.js.map +1 -0
  117. package/lib/util/exponential-backoff.d.ts +11 -0
  118. package/lib/util/exponential-backoff.js +10 -22
  119. package/lib/util/exponential-backoff.js.map +1 -0
  120. package/lib/util/paging-iterator.d.ts +53 -0
  121. package/lib/util/paging-iterator.js +202 -218
  122. package/lib/util/paging-iterator.js.map +1 -0
  123. package/lib/util/url-path.d.ts +16 -0
  124. package/lib/util/url-path.js +20 -35
  125. package/lib/util/url-path.js.map +1 -0
  126. package/package.json +24 -9
@@ -0,0 +1,127 @@
1
+ /**
2
+ * @fileoverview Manager for the Web Links Resource
3
+ */
4
+ import BoxClient from '../box-client';
5
+ /**
6
+ * Simple manager for interacting with all 'Weblinks' endpoints and actions.
7
+ *
8
+ * @constructor
9
+ * @param {BoxClient} client - The Box API Client that is responsible for making calls to the API
10
+ * @returns {void}
11
+ */
12
+ declare class WebLinks {
13
+ client: BoxClient;
14
+ constructor(client: BoxClient);
15
+ /**
16
+ * Creates a web link object within a given folder.
17
+ *
18
+ * API Endpoint: '/web_links'
19
+ * Method: POST
20
+ *
21
+ * @param {string} url - URL you want the web link to point to. Must include http:// or https://
22
+ * @param {string} parentID - The ID of the parent folder where you're creating the web link
23
+ * @param {Object} [options] - Additional parameters
24
+ * @param {string} [options.name] - Name for the web link. Will default to the URL if empty.
25
+ * @param {string} [options.description] - Description of the web link. Will provide more context to users about the web link.
26
+ * @param {Function} [callback] - Passed the new web link information if it was acquired successfully, error otherwise
27
+ * @returns {Promise<Object>} A promise resolving to the created weblink object
28
+ */
29
+ create(url: string, parentID: string, options?: {
30
+ name?: string;
31
+ description?: string;
32
+ }, callback?: Function): any;
33
+ /**
34
+ * Use to get information about the web link.
35
+ *
36
+ * API Endpoint: '/web_links/:weblinkID'
37
+ * Method: GET
38
+ *
39
+ * @param {string} weblinkID - The Box ID of web link being requested
40
+ * @param {Object} [options] - Additional options for the request. Can be left null in most cases.
41
+ * @param {Function} [callback] - Passed the web-link information if it was acquired successfully, error otherwise
42
+ * @returns {Promise<Object>} A promise resolving to the weblink object
43
+ */
44
+ get(weblinkID: string, options?: Record<string, any>, callback?: Function): any;
45
+ /**
46
+ * Updates information for a web link.
47
+ *
48
+ * API Endpoint: '/web_links/:weblinkID'
49
+ * Method: PUT
50
+ *
51
+ * @param {string} weblinkID - The Box ID of the web link being updated
52
+ * @param {Object} updates - Fields of the weblink to update
53
+ * @param {string} [updates.name] - Name for the web link. Will default to the URL if empty.
54
+ * @param {string} [updates.description] - Description of the web link. Will provide more context to users about the web link.
55
+ * @param {Function} [callback] - Passed the updated web link information if it was acquired successfully, error otherwise
56
+ * @returns {Promise<Object>} A promise resolving to the updated web link object
57
+ */
58
+ update(weblinkID: string, updates?: {
59
+ name?: string;
60
+ description?: string;
61
+ collections?: string[];
62
+ }, callback?: Function): any;
63
+ /**
64
+ * Deletes a web link and moves it to the trash
65
+ *
66
+ * API Endpoint: '/web_links/:weblinkID'
67
+ * Method: DELETE
68
+ *
69
+ * @param {string} weblinkID - The Box ID of the web link being moved to the trash
70
+ * @param {Function} [callback] - Empty body passed if successful, error otherwise
71
+ * @returns {Promise<Object>} A promise resolving to nothing
72
+ */
73
+ delete(weblinkID: string, callback?: Function): any;
74
+ /**
75
+ * Move a web link into a new parent folder.
76
+ *
77
+ * API Endpoint: '/web_links/:webLinkID'
78
+ * Method: PUT
79
+ *
80
+ * @param {string} webLinkID - The Box ID of the web link being requested
81
+ * @param {string} newParentID - The Box ID for the new parent folder. '0' to move to All Files.
82
+ * @param {Function} [callback] - Passed the updated web link information if it was acquired successfully
83
+ * @returns {Promise<Object>} A promise resolving to the updated web link object
84
+ */
85
+ move(webLinkID: string, newParentID: string, callback?: Function): any;
86
+ /**
87
+ * Copy a web link into a new, different folder
88
+ *
89
+ * API Endpoint: '/web_links/:webLinkID/copy
90
+ * Method: POST
91
+ *
92
+ * @param {string} webLinkID - The Box ID of the web link being requested
93
+ * @param {string} newParentID - The Box ID for the new parent folder. '0' to copy to All Files.
94
+ * @param {Object} [options] - Optional parameters for the copy operation, can be left null in most cases
95
+ * @param {string} [options.name] - A new name to use if there is an identically-named item in the new parent folder
96
+ * @param {Function} [callback] - passed the new web link info if call was successful
97
+ * @returns {Promise<Object>} A promise resolving to the new web link object
98
+ */
99
+ copy(webLinkID: string, newParentID: string, options?: {
100
+ name?: string;
101
+ }, callback?: Function): any;
102
+ /**
103
+ * Add a web link to a given collection
104
+ *
105
+ * API Endpoint: '/web_links/:webLinkID'
106
+ * Method: PUT
107
+ *
108
+ * @param {string} webLinkID - The web link to add to the collection
109
+ * @param {string} collectionID - The collection to add the web link to
110
+ * @param {Function} [callback] - Passed the updated web link if successful, error otherwise
111
+ * @returns {Promise<Object>} A promise resolving to the updated web link object
112
+ */
113
+ addToCollection(webLinkID: string, collectionID: string, callback?: Function): any;
114
+ /**
115
+ * Remove a web link from a given collection
116
+ *
117
+ * API Endpoint: '/web_links/:webLinkID'
118
+ * Method: PUT
119
+ *
120
+ * @param {string} webLinkID - The web link to remove from the collection
121
+ * @param {string} collectionID - The collection to remove the web link from
122
+ * @param {Function} [callback] - Passed the updated web link if successful, error otherwise
123
+ * @returns {Promise<Object>} A promise resolving to the updated web link object
124
+ */
125
+ removeFromCollection(webLinkID: string, collectionID: string, callback?: Function): any;
126
+ }
127
+ export = WebLinks;
@@ -1,23 +1,18 @@
1
+ "use strict";
1
2
  /**
2
3
  * @fileoverview Manager for the Web Links Resource
3
4
  */
4
-
5
- 'use strict';
6
-
7
- // ------------------------------------------------------------------------------
8
- // Requirements
9
- // ------------------------------------------------------------------------------
10
- var urlPath = require('../util/url-path');
11
-
5
+ var __importDefault = (this && this.__importDefault) || function (mod) {
6
+ return (mod && mod.__esModule) ? mod : { "default": mod };
7
+ };
8
+ var url_path_1 = __importDefault(require("../util/url-path"));
12
9
  // ------------------------------------------------------------------------------
13
10
  // Private
14
11
  // ------------------------------------------------------------------------------
15
12
  var BASE_PATH = '/web_links';
16
-
17
13
  // ------------------------------------------------------------------------------
18
14
  // Public
19
15
  // ------------------------------------------------------------------------------
20
-
21
16
  /**
22
17
  * Simple manager for interacting with all 'Weblinks' endpoints and actions.
23
18
  *
@@ -25,203 +20,182 @@ var BASE_PATH = '/web_links';
25
20
  * @param {BoxClient} client - The Box API Client that is responsible for making calls to the API
26
21
  * @returns {void}
27
22
  */
28
- function WebLinks(client) {
29
- this.client = client;
30
- }
31
-
32
- /**
33
- * Creates a web link object within a given folder.
34
- *
35
- * API Endpoint: '/web_links'
36
- * Method: POST
37
- *
38
- * @param {string} url - URL you want the web link to point to. Must include http:// or https://
39
- * @param {string} parentID - The ID of the parent folder where you're creating the web link
40
- * @param {Object} [options] - Additional parameters
41
- * @param {string} [options.name] - Name for the web link. Will default to the URL if empty.
42
- * @param {string} [options.description] - Description of the web link. Will provide more context to users about the web link.
43
- * @param {Function} [callback] - Passed the new web link information if it was acquired successfully, error otherwise
44
- * @returns {Promise<Object>} A promise resolving to the created weblink object
45
- */
46
- WebLinks.prototype.create = function(url, parentID, options, callback) {
47
- var apiPath = urlPath(BASE_PATH),
48
- params = {
49
- body: {
50
- url,
51
- parent: {
52
- id: parentID
53
- }
54
- }
55
- };
56
-
57
- Object.assign(params.body, options);
58
-
59
- return this.client.wrapWithDefaultHandler(this.client.post)(apiPath, params, callback);
60
- };
61
-
62
- /**
63
- * Use to get information about the web link.
64
- *
65
- * API Endpoint: '/web_links/:weblinkID'
66
- * Method: GET
67
- *
68
- * @param {string} weblinkID - The Box ID of web link being requested
69
- * @param {Object} [options] - Additional options for the request. Can be left null in most cases.
70
- * @param {Function} [callback] - Passed the web-link information if it was acquired successfully, error otherwise
71
- * @returns {Promise<Object>} A promise resolving to the weblink object
72
- */
73
- WebLinks.prototype.get = function(weblinkID, options, callback) {
74
- var apiPath = urlPath(BASE_PATH, weblinkID),
75
- params = {
76
- qs: options
77
- };
78
-
79
- return this.client.wrapWithDefaultHandler(this.client.get)(apiPath, params, callback);
80
- };
81
-
82
- /**
83
- * Updates information for a web link.
84
- *
85
- * API Endpoint: '/web_links/:weblinkID'
86
- * Method: PUT
87
- *
88
- * @param {string} weblinkID - The Box ID of the web link being updated
89
- * @param {Object} updates - Fields of the weblink to update
90
- * @param {string} [updates.name] - Name for the web link. Will default to the URL if empty.
91
- * @param {string} [updates.description] - Description of the web link. Will provide more context to users about the web link.
92
- * @param {Function} [callback] - Passed the updated web link information if it was acquired successfully, error otherwise
93
- * @returns {Promise<Object>} A promise resolving to the updated web link object
94
- */
95
- WebLinks.prototype.update = function(weblinkID, updates, callback) {
96
- var apiPath = urlPath(BASE_PATH, weblinkID),
97
- params = {
98
- body: updates
99
- };
100
-
101
- return this.client.wrapWithDefaultHandler(this.client.put)(apiPath, params, callback);
102
- };
103
-
104
- /**
105
- * Deletes a web link and moves it to the trash
106
- *
107
- * API Endpoint: '/web_links/:weblinkID'
108
- * Method: DELETE
109
- *
110
- * @param {string} weblinkID - The Box ID of the web link being moved to the trash
111
- * @param {Function} [callback] - Empty body passed if successful, error otherwise
112
- * @returns {Promise<Object>} A promise resolving to nothing
113
- */
114
- WebLinks.prototype.delete = function(weblinkID, callback) {
115
- var apiPath = urlPath(BASE_PATH, weblinkID);
116
-
117
- return this.client.wrapWithDefaultHandler(this.client.del)(apiPath, null, callback);
118
- };
119
-
120
- /**
121
- * Move a web link into a new parent folder.
122
- *
123
- * API Endpoint: '/web_links/:webLinkID'
124
- * Method: PUT
125
- *
126
- * @param {string} webLinkID - The Box ID of the web link being requested
127
- * @param {string} newParentID - The Box ID for the new parent folder. '0' to move to All Files.
128
- * @param {Function} [callback] - Passed the updated web link information if it was acquired successfully
129
- * @returns {Promise<Object>} A promise resolving to the updated web link object
130
- */
131
- WebLinks.prototype.move = function(webLinkID, newParentID, callback) {
132
- var params = {
133
- body: {
134
- parent: {
135
- id: newParentID
136
- }
137
- }
138
- };
139
- var apiPath = urlPath(BASE_PATH, webLinkID);
140
- return this.client.wrapWithDefaultHandler(this.client.put)(apiPath, params, callback);
141
- };
142
-
143
- /**
144
- * Copy a web link into a new, different folder
145
- *
146
- * API Endpoint: '/web_links/:webLinkID/copy
147
- * Method: POST
148
- *
149
- * @param {string} webLinkID - The Box ID of the web link being requested
150
- * @param {string} newParentID - The Box ID for the new parent folder. '0' to copy to All Files.
151
- * @param {Object} [options] - Optional parameters for the copy operation, can be left null in most cases
152
- * @param {string} [options.name] - A new name to use if there is an identically-named item in the new parent folder
153
- * @param {Function} [callback] - passed the new web link info if call was successful
154
- * @returns {Promise<Object>} A promise resolving to the new web link object
155
- */
156
- WebLinks.prototype.copy = function(webLinkID, newParentID, options, callback) {
157
-
158
- options = options || {};
159
-
160
- options.parent = {
161
- id: newParentID
162
- };
163
-
164
- var params = {
165
- body: options
166
- };
167
- var apiPath = urlPath(BASE_PATH, webLinkID, '/copy');
168
- return this.client.wrapWithDefaultHandler(this.client.post)(apiPath, params, callback);
169
- };
170
-
171
- /**
172
- * Add a web link to a given collection
173
- *
174
- * API Endpoint: '/web_links/:webLinkID'
175
- * Method: PUT
176
- *
177
- * @param {string} webLinkID - The web link to add to the collection
178
- * @param {string} collectionID - The collection to add the web link to
179
- * @param {Function} [callback] - Passed the updated web link if successful, error otherwise
180
- * @returns {Promise<Object>} A promise resolving to the updated web link object
181
- */
182
- WebLinks.prototype.addToCollection = function(webLinkID, collectionID, callback) {
183
-
184
- return this.get(webLinkID, {fields: 'collections'})
185
- .then(data => {
186
-
187
- var collections = data.collections || [];
188
-
189
- // Convert to correct format
190
- collections = collections.map(c => ({id: c.id}));
191
-
192
- if (!collections.find(c => c.id === collectionID)) {
193
-
194
- collections.push({id: collectionID});
195
- }
196
-
197
- return this.update(webLinkID, {collections});
198
- })
199
- .asCallback(callback);
200
- };
201
-
202
- /**
203
- * Remove a web link from a given collection
204
- *
205
- * API Endpoint: '/web_links/:webLinkID'
206
- * Method: PUT
207
- *
208
- * @param {string} webLinkID - The web link to remove from the collection
209
- * @param {string} collectionID - The collection to remove the web link from
210
- * @param {Function} [callback] - Passed the updated web link if successful, error otherwise
211
- * @returns {Promise<Object>} A promise resolving to the updated web link object
212
- */
213
- WebLinks.prototype.removeFromCollection = function(webLinkID, collectionID, callback) {
214
-
215
- return this.get(webLinkID, {fields: 'collections'})
216
- .then(data => {
217
-
218
- var collections = data.collections || [];
219
- // Convert to correct object format and remove the specified collection
220
- collections = collections.map(c => ({id: c.id})).filter(c => c.id !== collectionID);
221
-
222
- return this.update(webLinkID, {collections});
223
- })
224
- .asCallback(callback);
225
- };
226
-
23
+ var WebLinks = /** @class */ (function () {
24
+ function WebLinks(client) {
25
+ this.client = client;
26
+ }
27
+ /**
28
+ * Creates a web link object within a given folder.
29
+ *
30
+ * API Endpoint: '/web_links'
31
+ * Method: POST
32
+ *
33
+ * @param {string} url - URL you want the web link to point to. Must include http:// or https://
34
+ * @param {string} parentID - The ID of the parent folder where you're creating the web link
35
+ * @param {Object} [options] - Additional parameters
36
+ * @param {string} [options.name] - Name for the web link. Will default to the URL if empty.
37
+ * @param {string} [options.description] - Description of the web link. Will provide more context to users about the web link.
38
+ * @param {Function} [callback] - Passed the new web link information if it was acquired successfully, error otherwise
39
+ * @returns {Promise<Object>} A promise resolving to the created weblink object
40
+ */
41
+ WebLinks.prototype.create = function (url, parentID, options, callback) {
42
+ var apiPath = url_path_1.default(BASE_PATH), params = {
43
+ body: {
44
+ url: url,
45
+ parent: {
46
+ id: parentID,
47
+ },
48
+ },
49
+ };
50
+ Object.assign(params.body, options);
51
+ return this.client.wrapWithDefaultHandler(this.client.post)(apiPath, params, callback);
52
+ };
53
+ /**
54
+ * Use to get information about the web link.
55
+ *
56
+ * API Endpoint: '/web_links/:weblinkID'
57
+ * Method: GET
58
+ *
59
+ * @param {string} weblinkID - The Box ID of web link being requested
60
+ * @param {Object} [options] - Additional options for the request. Can be left null in most cases.
61
+ * @param {Function} [callback] - Passed the web-link information if it was acquired successfully, error otherwise
62
+ * @returns {Promise<Object>} A promise resolving to the weblink object
63
+ */
64
+ WebLinks.prototype.get = function (weblinkID, options, callback) {
65
+ var apiPath = url_path_1.default(BASE_PATH, weblinkID), params = {
66
+ qs: options,
67
+ };
68
+ return this.client.wrapWithDefaultHandler(this.client.get)(apiPath, params, callback);
69
+ };
70
+ /**
71
+ * Updates information for a web link.
72
+ *
73
+ * API Endpoint: '/web_links/:weblinkID'
74
+ * Method: PUT
75
+ *
76
+ * @param {string} weblinkID - The Box ID of the web link being updated
77
+ * @param {Object} updates - Fields of the weblink to update
78
+ * @param {string} [updates.name] - Name for the web link. Will default to the URL if empty.
79
+ * @param {string} [updates.description] - Description of the web link. Will provide more context to users about the web link.
80
+ * @param {Function} [callback] - Passed the updated web link information if it was acquired successfully, error otherwise
81
+ * @returns {Promise<Object>} A promise resolving to the updated web link object
82
+ */
83
+ WebLinks.prototype.update = function (weblinkID, updates, callback) {
84
+ var apiPath = url_path_1.default(BASE_PATH, weblinkID), params = {
85
+ body: updates,
86
+ };
87
+ return this.client.wrapWithDefaultHandler(this.client.put)(apiPath, params, callback);
88
+ };
89
+ /**
90
+ * Deletes a web link and moves it to the trash
91
+ *
92
+ * API Endpoint: '/web_links/:weblinkID'
93
+ * Method: DELETE
94
+ *
95
+ * @param {string} weblinkID - The Box ID of the web link being moved to the trash
96
+ * @param {Function} [callback] - Empty body passed if successful, error otherwise
97
+ * @returns {Promise<Object>} A promise resolving to nothing
98
+ */
99
+ WebLinks.prototype.delete = function (weblinkID, callback) {
100
+ var apiPath = url_path_1.default(BASE_PATH, weblinkID);
101
+ return this.client.wrapWithDefaultHandler(this.client.del)(apiPath, null, callback);
102
+ };
103
+ /**
104
+ * Move a web link into a new parent folder.
105
+ *
106
+ * API Endpoint: '/web_links/:webLinkID'
107
+ * Method: PUT
108
+ *
109
+ * @param {string} webLinkID - The Box ID of the web link being requested
110
+ * @param {string} newParentID - The Box ID for the new parent folder. '0' to move to All Files.
111
+ * @param {Function} [callback] - Passed the updated web link information if it was acquired successfully
112
+ * @returns {Promise<Object>} A promise resolving to the updated web link object
113
+ */
114
+ WebLinks.prototype.move = function (webLinkID, newParentID, callback) {
115
+ var params = {
116
+ body: {
117
+ parent: {
118
+ id: newParentID,
119
+ },
120
+ },
121
+ };
122
+ var apiPath = url_path_1.default(BASE_PATH, webLinkID);
123
+ return this.client.wrapWithDefaultHandler(this.client.put)(apiPath, params, callback);
124
+ };
125
+ /**
126
+ * Copy a web link into a new, different folder
127
+ *
128
+ * API Endpoint: '/web_links/:webLinkID/copy
129
+ * Method: POST
130
+ *
131
+ * @param {string} webLinkID - The Box ID of the web link being requested
132
+ * @param {string} newParentID - The Box ID for the new parent folder. '0' to copy to All Files.
133
+ * @param {Object} [options] - Optional parameters for the copy operation, can be left null in most cases
134
+ * @param {string} [options.name] - A new name to use if there is an identically-named item in the new parent folder
135
+ * @param {Function} [callback] - passed the new web link info if call was successful
136
+ * @returns {Promise<Object>} A promise resolving to the new web link object
137
+ */
138
+ WebLinks.prototype.copy = function (webLinkID, newParentID, options, callback) {
139
+ options = options || {};
140
+ options.parent = {
141
+ id: newParentID,
142
+ };
143
+ var params = {
144
+ body: options,
145
+ };
146
+ var apiPath = url_path_1.default(BASE_PATH, webLinkID, '/copy');
147
+ return this.client.wrapWithDefaultHandler(this.client.post)(apiPath, params, callback);
148
+ };
149
+ /**
150
+ * Add a web link to a given collection
151
+ *
152
+ * API Endpoint: '/web_links/:webLinkID'
153
+ * Method: PUT
154
+ *
155
+ * @param {string} webLinkID - The web link to add to the collection
156
+ * @param {string} collectionID - The collection to add the web link to
157
+ * @param {Function} [callback] - Passed the updated web link if successful, error otherwise
158
+ * @returns {Promise<Object>} A promise resolving to the updated web link object
159
+ */
160
+ WebLinks.prototype.addToCollection = function (webLinkID, collectionID, callback) {
161
+ var _this = this;
162
+ return this.get(webLinkID, { fields: 'collections' })
163
+ .then(function (data /* FIXME */) {
164
+ var collections = data.collections || [];
165
+ // Convert to correct format
166
+ collections = collections.map(function (c /* FIXME */) { return ({ id: c.id }); });
167
+ if (!collections.find(function (c /* FIXME */) { return c.id === collectionID; })) {
168
+ collections.push({ id: collectionID });
169
+ }
170
+ return _this.update(webLinkID, { collections: collections });
171
+ })
172
+ .asCallback(callback);
173
+ };
174
+ /**
175
+ * Remove a web link from a given collection
176
+ *
177
+ * API Endpoint: '/web_links/:webLinkID'
178
+ * Method: PUT
179
+ *
180
+ * @param {string} webLinkID - The web link to remove from the collection
181
+ * @param {string} collectionID - The collection to remove the web link from
182
+ * @param {Function} [callback] - Passed the updated web link if successful, error otherwise
183
+ * @returns {Promise<Object>} A promise resolving to the updated web link object
184
+ */
185
+ WebLinks.prototype.removeFromCollection = function (webLinkID, collectionID, callback) {
186
+ var _this = this;
187
+ return this.get(webLinkID, { fields: 'collections' })
188
+ .then(function (data /* FIXME */) {
189
+ var collections = data.collections || [];
190
+ // Convert to correct object format and remove the specified collection
191
+ collections = collections
192
+ .map(function (c /* FIXME */) { return ({ id: c.id }); })
193
+ .filter(function (c /* FIXME */) { return c.id !== collectionID; });
194
+ return _this.update(webLinkID, { collections: collections });
195
+ })
196
+ .asCallback(callback);
197
+ };
198
+ return WebLinks;
199
+ }());
227
200
  module.exports = WebLinks;
201
+ //# sourceMappingURL=web-links.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"web-links.js","sourceRoot":"","sources":["../../src/managers/web-links.ts"],"names":[],"mappings":";AAAA;;GAEG;;;;AAOH,8DAAuC;AAEvC,iFAAiF;AACjF,UAAU;AACV,iFAAiF;AAEjF,IAAM,SAAS,GAAG,YAAY,CAAC;AAE/B,iFAAiF;AACjF,SAAS;AACT,iFAAiF;AAEjF;;;;;;GAMG;AACH;IAGC,kBAAY,MAAiB;QAC5B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACtB,CAAC;IAED;;;;;;;;;;;;;OAaG;IACH,yBAAM,GAAN,UACC,GAAW,EACX,QAAgB,EAChB,OAGC,EACD,QAAmB;QAEnB,IAAI,OAAO,GAAG,kBAAO,CAAC,SAAS,CAAC,EAC/B,MAAM,GAAG;YACR,IAAI,EAAE;gBACL,GAAG,KAAA;gBACH,MAAM,EAAE;oBACP,EAAE,EAAE,QAAQ;iBACZ;aACD;SACD,CAAC;QAEH,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;QAEpC,OAAO,IAAI,CAAC,MAAM,CAAC,sBAAsB,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAC1D,OAAO,EACP,MAAM,EACN,QAA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