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
@@ -1,51 +1,35 @@
1
+ "use strict";
1
2
  /**
2
3
  * @fileoverview Manager for the Box Metadata Resource
3
4
  */
4
-
5
- 'use strict';
6
-
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"));
9
+ var merge = require('merge-options');
7
10
  // -----------------------------------------------------------------------------
8
11
  // Typedefs
9
12
  // -----------------------------------------------------------------------------
10
-
11
- /** @typedef {string} MetadataFieldType */
12
-
13
- /**
14
- * Metadata enum option
15
- * @typedef {Object} MetadataEnumOption
16
- * @property {string} key The option value
17
- */
18
-
19
13
  /**
20
- * Field definition for a metadata template
21
- * @typedef {Object} MetadataTemplateField
22
- * @property {MetadataFieldType} type The type of the field
23
- * @property {string} key The programmatic name of the field
24
- * @property {string} displayName The display name of the field
25
- * @property {MetadataEnumOption[]} [options] For enum fields, the options
14
+ * Valid metadata field types
15
+ * @readonly
16
+ * @enum {MetadataFieldType}
26
17
  */
27
-
28
- // -----------------------------------------------------------------------------
29
- // Requirements
30
- // -----------------------------------------------------------------------------
31
- var urlPath = require('../util/url-path'),
32
- merge = require('merge-options');
33
-
18
+ var MetadataFieldType;
19
+ (function (MetadataFieldType) {
20
+ MetadataFieldType["STRING"] = "string";
21
+ MetadataFieldType["ENUM"] = "enum";
22
+ MetadataFieldType["NUMBER"] = "float";
23
+ MetadataFieldType["DATE"] = "date";
24
+ MetadataFieldType["MULTI_SELECT"] = "multiSelect";
25
+ })(MetadataFieldType || (MetadataFieldType = {}));
34
26
  // -----------------------------------------------------------------------------
35
27
  // Private
36
28
  // -----------------------------------------------------------------------------
37
- var PROPERTIES_TEMPLATE = 'properties',
38
- BASE_PATH = '/metadata_templates',
39
- SCHEMA_SUBRESOURCE = 'schema',
40
- ENTERPRISE_SCOPE = 'enterprise',
41
- GLOBAL_SCOPE = 'global',
42
- CASCADE_POLICIES_PATH = '/metadata_cascade_policies',
43
- QUERY_PATH = '/metadata_queries/execute_read';
44
-
29
+ var PROPERTIES_TEMPLATE = 'properties', BASE_PATH = '/metadata_templates', SCHEMA_SUBRESOURCE = 'schema', ENTERPRISE_SCOPE = 'enterprise', GLOBAL_SCOPE = 'global', CASCADE_POLICIES_PATH = '/metadata_cascade_policies', QUERY_PATH = '/metadata_queries/execute_read';
45
30
  // -----------------------------------------------------------------------------
46
31
  // Public
47
32
  // -----------------------------------------------------------------------------
48
-
49
33
  /**
50
34
  * Simple manager for interacting with all metadata endpoints and actions.
51
35
  *
@@ -53,299 +37,252 @@ var PROPERTIES_TEMPLATE = 'properties',
53
37
  * @param {BoxClient} client - The Box API Client that is responsible for making calls to the API
54
38
  * @returns {void}
55
39
  */
56
- function Metadata(client) {
57
- this.client = client;
58
- }
59
-
60
-
61
- Metadata.prototype = {
62
-
63
- templates: {
64
- PROPERTIES: PROPERTIES_TEMPLATE
65
- },
66
-
67
- scopes: {
68
- ENTERPRISE: ENTERPRISE_SCOPE,
69
- GLOBAL: GLOBAL_SCOPE
70
- },
71
-
72
- cascadeResolution: Object.freeze({
73
- PRESERVE_EXISTING: 'none',
74
- OVERWRITE: 'overwrite'
75
- }),
76
-
77
- /**
78
- * Valid metadata field types
79
- * @readonly
80
- * @enum {MetadataFieldType}
81
- */
82
- fieldTypes: Object.freeze({
83
- STRING: 'string',
84
- ENUM: 'enum',
85
- NUMBER: 'float',
86
- DATE: 'date',
87
- MULTI_SELECT: 'multiSelect'
88
- }),
89
-
90
- /**
91
- * Retrieve the schema definition for a metadata template
92
- *
93
- * API Endpoint: '/metadata_templates/:scope/:template'
94
- * Method: GET
95
- *
96
- * @param {string} scope - The scope of the template, e.g. "enterprise"
97
- * @param {string} template - The template to retrieve
98
- * @param {Function} [callback] - Called with the template schema if successful
99
- * @returns {Promise<Object>} A promise resolving to the template schema
100
- */
101
- getTemplateSchema(scope, template, callback) {
102
-
103
- var apiPath = urlPath(BASE_PATH, scope, template, SCHEMA_SUBRESOURCE);
104
- return this.client.wrapWithDefaultHandler(this.client.get)(apiPath, null, callback);
105
- },
106
-
107
- /**
108
- * Retrieve the schema definition for a metadata template by ID
109
- *
110
- * API Endpoint: '/metadata_templates/:id'
111
- * Method: GET
112
- *
113
- * @param {string} templateID - The ID of the template to retrieve
114
- * @param {Function} [callback] - Called with the template schema if successful
115
- * @returns {Promise<Object>} A promise resolving to the template schema
116
- */
117
- getTemplateByID(templateID, callback) {
118
-
119
- var apiPath = urlPath(BASE_PATH, templateID);
120
- return this.client.wrapWithDefaultHandler(this.client.get)(apiPath, null, callback);
121
- },
122
-
123
- /**
124
- * Get all templates in a given scope
125
- *
126
- * API Endpoint: '/metadata_templates/:scope'
127
- * Method: GET
128
- *
129
- * @param {string} scope - The scope to retrieve templates for
130
- * @param {Function} [callback] - Called with an array of templates when successful
131
- * @returns {Promise<Object>} A promise resolving to the collection of templates
132
- */
133
- getTemplates(scope, callback) {
134
-
135
- var apiPath = urlPath(BASE_PATH, scope);
136
- return this.client.wrapWithDefaultHandler(this.client.get)(apiPath, null, callback);
137
- },
138
-
139
- /**
140
- * Create a new metadata template
141
- *
142
- * API Endpoint: '/metadata_templates/schema',
143
- * Method: POST
144
- *
145
- * @param {string} templateName - The name of the metadata template
146
- * @param {MetadataTemplateField[]} fields - A list of fields for the template
147
- * @param {Object} [options] - Optional parameters, can be left null in many cases
148
- * @param {string} [options.templateKey] - The programmatic key for the template
149
- * @param {boolean} [options.hidden] - Whether the template should be hidden in the UI
150
- * @param {string} [options.scope=enterprise] - The scope for the template, only 'enterprise' is supported for now
151
- * @param {Function} [callback] - Passed the template if successful, error otherwise
152
- * @returns {Promise<Object>} A promise resolving to the created template
153
- */
154
- createTemplate(templateName, fields, options, callback) {
155
-
156
- var apiPath = urlPath(BASE_PATH, SCHEMA_SUBRESOURCE),
157
- params = {
158
- body: {
159
- scope: ENTERPRISE_SCOPE,
160
- displayName: templateName,
161
- fields
162
- }
163
- };
164
-
165
- Object.assign(params.body, options);
166
-
167
- return this.client.wrapWithDefaultHandler(this.client.post)(apiPath, params, callback);
168
- },
169
-
170
- /**
171
- * Update a metadata template via one or more non-breaking operations. Each
172
- * operation is a an object descrbing one change to the template or its
173
- * fields.
174
- *
175
- * API Endpoint: '/metadata_templates/:scope/:template/schema'
176
- * Method: PUT
177
- *
178
- * @param {string} scope - The scope of the template to modify
179
- * @param {string} template - The template to modify
180
- * @param {Object[]} operations - The operations to perform
181
- * @param {Function} [callback] - Passed the updated template if successful, error otherwise
182
- * @returns {Promise<Object>} A promise resolving to the updated template
183
- * @see {@link https://developer.box.com/en/reference/put-metadata-templates-id-id-schema/}
184
- */
185
- updateTemplate(scope, template, operations, callback) {
186
-
187
- var apiPath = urlPath(BASE_PATH, scope, template, SCHEMA_SUBRESOURCE),
188
- params = {
189
- body: operations
190
- };
191
-
192
- return this.client.wrapWithDefaultHandler(this.client.put)(apiPath, params, callback);
193
- },
194
-
195
- /**
196
- * Delete a metadata template from an enterprise.
197
- *
198
- * API Endpoint: '/metadata_templates/:scope/:template/schema'
199
- * Method: DELETE
200
- *
201
- * @param {string} scope - The scope of the template to delete
202
- * @param {string} template - The template to delete
203
- * @param {Function} [callback] - Passed empty response body if successful, err otherwise
204
- * @returns {Promise<void>} A promise resolving to nothing
205
- * @see {@link https://developer.box.com/en/reference/delete-metadata-templates-id-id-schema/}
206
- */
207
- deleteTemplate(scope, template, callback) {
208
-
209
- var apiPath = urlPath(BASE_PATH, scope, template, SCHEMA_SUBRESOURCE);
210
- return this.client.wrapWithDefaultHandler(this.client.del)(apiPath, null, callback);
211
- },
212
-
213
- /**
214
- * Get the cascade policies associated with a given folder.
215
- *
216
- * API Endpoint: '/metadata_cascade_policies'
217
- * Method: GET
218
- *
219
- * @param {string} folderID The ID of the folder to get cascade policies for
220
- * @param {Object} [options] Optional parameters
221
- * @param {string} [options.owner_enterprise_id] ID of the enterprise to get policies for
222
- * @param {Function} [callback] Passed the collection of policies if successful
223
- * @returns {Promise<Object>} Promise resolving to the collection of policies
224
- */
225
- getCascadePolicies(folderID, options, callback) {
226
-
227
- var apiPath = urlPath(CASCADE_POLICIES_PATH),
228
- params = {
229
- qs: Object.assign({ folder_id: folderID }, options)
230
- };
231
-
232
- return this.client.wrapWithDefaultHandler(this.client.get)(apiPath, params, callback);
233
- },
234
-
235
- /**
236
- * Get a metadata cascade policy object by ID
237
- *
238
- * API Endpoint: '/metadata_cascade_policies/:policyID'
239
- * Method: GET
240
- *
241
- * @param {string} policyID The ID of the policy to retrieve
242
- * @param {Function} [callback] Passed the cascade policy if successful
243
- * @returns {Promise<Object>} Promise resolving to the cascade policy
244
- */
245
- getCascadePolicy(policyID, callback) {
246
-
247
- var apiPath = urlPath(CASCADE_POLICIES_PATH, policyID);
248
-
249
- return this.client.wrapWithDefaultHandler(this.client.get)(apiPath, null, callback);
250
- },
251
-
252
- /**
253
- * Add a new cascade policy to a folder/metadata template, causing the
254
- * metadata template to be applied to all items and subfolders inside the
255
- * folder.
256
- *
257
- * API Endpoint: '/metadata_cascade_policies'
258
- * Method: POST
259
- *
260
- * @param {string} scope Metadata template scope for the template to cascade
261
- * @param {string} templateKey Metadata template key for the template to cascade
262
- * @param {string} folderID The ID of the folder to cascade over
263
- * @param {Function} [callback] Passed the cascade policy if successful
264
- * @returns {Promise<Object>} Promise resolving to the cascade policy
265
- */
266
- createCascadePolicy(scope, templateKey, folderID, callback) {
267
-
268
- var apiPath = urlPath(CASCADE_POLICIES_PATH),
269
- params = {
270
- body: {
271
- folder_id: folderID,
272
- scope,
273
- templateKey
274
- }
275
- };
276
-
277
- return this.client.wrapWithDefaultHandler(this.client.post)(apiPath, params, callback);
278
- },
279
-
280
- /**
281
- * Delete the metadata cascade policy with the given ID
282
- *
283
- * API Endpoint: '/metadata_cascade_policies/:policyID'
284
- * Method: DELETE
285
- *
286
- * @param {string} policyID The ID of the policy to delete
287
- * @param {Function} [callback] Passed nothing if successful
288
- * @returns {Promise<void>} Promise resolving to nothing
289
- */
290
- deleteCascadePolicy(policyID, callback) {
291
-
292
- var apiPath = urlPath(CASCADE_POLICIES_PATH, policyID);
293
- return this.client.wrapWithDefaultHandler(this.client.del)(apiPath, null, callback);
294
- },
295
-
296
- /**
297
- * If a policy already exists on a folder, this will apply that policy to all existing files and
298
- * sub-folders within the target folder.
299
- *
300
- * API Endpoint: '/metadata_cascade_policies/:policyID/apply'
301
- * Method: POST
302
- *
303
- * @param {string} policyID The ID of the policy to delete
304
- * @param {string} resolutionMethod How to resolve conflicts, either "none" or "overwrite"
305
- * @param {Function} [callback] Passed nothing if successful
306
- * @returns {Promise<void>} Promise resolving to nothing
307
- */
308
- forceApplyCascadePolicy(policyID, resolutionMethod, callback) {
309
-
310
- var apiPath = urlPath(CASCADE_POLICIES_PATH, policyID, 'apply'),
311
- params = {
312
- body: {
313
- conflict_resolution: resolutionMethod
314
- }
315
- };
316
-
317
- return this.client.wrapWithDefaultHandler(this.client.post)(apiPath, params, callback);
318
- },
319
-
320
- /**
321
- * Query Box items by their metadata
322
- *
323
- * API Endpoint: '/metadata_queries/execute_read'
324
- * Method: POST
325
- *
326
- * @param {string} from - The template used in the query. Must be in the form scope.templateKey
327
- * @param {string} ancestorFolderId - The folder_id to which to restrain the query
328
- * @param {Object} options - Optional parameters
329
- * @param {string} [options.query] - The logical expression of the query
330
- * @param {Object} [options.query_parameters] - Required if query present. The arguments for the query
331
- * @param {string} [options.index_name] - The name of the Index to use
332
- * @param {Object} [options.order_by] - The field_key(s) to order on and the corresponding direction(s)
333
- * @param {Array} [options.fields] - An array of fields to return
334
- * @param {Function} [callback] - Passed a collection of items and their associated metadata
335
- * @returns {Promise<void>} Promise resolving to a collection of items and their associated metadata
336
- */
337
- query(from, ancestorFolderId, options, callback) {
338
- var body = {
339
- from,
340
- ancestor_folder_id: ancestorFolderId
341
- };
342
-
343
- var params = {
344
- body: merge(body, options)
345
- };
346
-
347
- return this.client.wrapWithDefaultHandler(this.client.post)(QUERY_PATH, params, callback);
348
- }
40
+ var Metadata = /** @class */ (function () {
41
+ function Metadata(client) {
42
+ this.client = client;
43
+ }
44
+ /**
45
+ * Retrieve the schema definition for a metadata template
46
+ *
47
+ * API Endpoint: '/metadata_templates/:scope/:template'
48
+ * Method: GET
49
+ *
50
+ * @param {string} scope - The scope of the template, e.g. "enterprise"
51
+ * @param {string} template - The template to retrieve
52
+ * @param {Function} [callback] - Called with the template schema if successful
53
+ * @returns {Promise<Object>} A promise resolving to the template schema
54
+ */
55
+ Metadata.prototype.getTemplateSchema = function (scope, template, callback) {
56
+ var apiPath = url_path_1.default(BASE_PATH, scope, template, SCHEMA_SUBRESOURCE);
57
+ return this.client.wrapWithDefaultHandler(this.client.get)(apiPath, null, callback);
58
+ };
59
+ /**
60
+ * Retrieve the schema definition for a metadata template by ID
61
+ *
62
+ * API Endpoint: '/metadata_templates/:id'
63
+ * Method: GET
64
+ *
65
+ * @param {string} templateID - The ID of the template to retrieve
66
+ * @param {Function} [callback] - Called with the template schema if successful
67
+ * @returns {Promise<Object>} A promise resolving to the template schema
68
+ */
69
+ Metadata.prototype.getTemplateByID = function (templateID, callback) {
70
+ var apiPath = url_path_1.default(BASE_PATH, templateID);
71
+ return this.client.wrapWithDefaultHandler(this.client.get)(apiPath, null, callback);
72
+ };
73
+ /**
74
+ * Get all templates in a given scope
75
+ *
76
+ * API Endpoint: '/metadata_templates/:scope'
77
+ * Method: GET
78
+ *
79
+ * @param {string} scope - The scope to retrieve templates for
80
+ * @param {Function} [callback] - Called with an array of templates when successful
81
+ * @returns {Promise<Object>} A promise resolving to the collection of templates
82
+ */
83
+ Metadata.prototype.getTemplates = function (scope, callback) {
84
+ var apiPath = url_path_1.default(BASE_PATH, scope);
85
+ return this.client.wrapWithDefaultHandler(this.client.get)(apiPath, null, callback);
86
+ };
87
+ /**
88
+ * Create a new metadata template
89
+ *
90
+ * API Endpoint: '/metadata_templates/schema',
91
+ * Method: POST
92
+ *
93
+ * @param {string} templateName - The name of the metadata template
94
+ * @param {MetadataTemplateField[]} fields - A list of fields for the template
95
+ * @param {Object} [options] - Optional parameters, can be left null in many cases
96
+ * @param {string} [options.templateKey] - The programmatic key for the template
97
+ * @param {boolean} [options.hidden] - Whether the template should be hidden in the UI
98
+ * @param {string} [options.scope=enterprise] - The scope for the template, only 'enterprise' is supported for now
99
+ * @param {boolean} [options.copyInstanceOnItemCopy] - Whether to include the metadata when a file or folder is copied
100
+ * @param {Function} [callback] - Passed the template if successful, error otherwise
101
+ * @returns {Promise<Object>} A promise resolving to the created template
102
+ */
103
+ Metadata.prototype.createTemplate = function (templateName, fields, options, callback) {
104
+ var apiPath = url_path_1.default(BASE_PATH, SCHEMA_SUBRESOURCE), params = {
105
+ body: {
106
+ scope: ENTERPRISE_SCOPE,
107
+ displayName: templateName,
108
+ fields: fields,
109
+ },
110
+ };
111
+ Object.assign(params.body, options);
112
+ return this.client.wrapWithDefaultHandler(this.client.post)(apiPath, params, callback);
113
+ };
114
+ /**
115
+ * Update a metadata template via one or more non-breaking operations. Each
116
+ * operation is a an object descrbing one change to the template or its
117
+ * fields.
118
+ *
119
+ * API Endpoint: '/metadata_templates/:scope/:template/schema'
120
+ * Method: PUT
121
+ *
122
+ * @param {string} scope - The scope of the template to modify
123
+ * @param {string} template - The template to modify
124
+ * @param {Object[]} operations - The operations to perform
125
+ * @param {Function} [callback] - Passed the updated template if successful, error otherwise
126
+ * @returns {Promise<Object>} A promise resolving to the updated template
127
+ * @see {@link https://developer.box.com/en/reference/put-metadata-templates-id-id-schema/}
128
+ */
129
+ Metadata.prototype.updateTemplate = function (scope, template, operations, callback) {
130
+ var apiPath = url_path_1.default(BASE_PATH, scope, template, SCHEMA_SUBRESOURCE), params = {
131
+ body: operations,
132
+ };
133
+ return this.client.wrapWithDefaultHandler(this.client.put)(apiPath, params, callback);
134
+ };
135
+ /**
136
+ * Delete a metadata template from an enterprise.
137
+ *
138
+ * API Endpoint: '/metadata_templates/:scope/:template/schema'
139
+ * Method: DELETE
140
+ *
141
+ * @param {string} scope - The scope of the template to delete
142
+ * @param {string} template - The template to delete
143
+ * @param {Function} [callback] - Passed empty response body if successful, err otherwise
144
+ * @returns {Promise<void>} A promise resolving to nothing
145
+ * @see {@link https://developer.box.com/en/reference/delete-metadata-templates-id-id-schema/}
146
+ */
147
+ Metadata.prototype.deleteTemplate = function (scope, template, callback) {
148
+ var apiPath = url_path_1.default(BASE_PATH, scope, template, SCHEMA_SUBRESOURCE);
149
+ return this.client.wrapWithDefaultHandler(this.client.del)(apiPath, null, callback);
150
+ };
151
+ /**
152
+ * Get the cascade policies associated with a given folder.
153
+ *
154
+ * API Endpoint: '/metadata_cascade_policies'
155
+ * Method: GET
156
+ *
157
+ * @param {string} folderID The ID of the folder to get cascade policies for
158
+ * @param {Object} [options] Optional parameters
159
+ * @param {string} [options.owner_enterprise_id] ID of the enterprise to get policies for
160
+ * @param {Function} [callback] Passed the collection of policies if successful
161
+ * @returns {Promise<Object>} Promise resolving to the collection of policies
162
+ */
163
+ Metadata.prototype.getCascadePolicies = function (folderID, options, callback) {
164
+ var apiPath = url_path_1.default(CASCADE_POLICIES_PATH), params = {
165
+ qs: Object.assign({ folder_id: folderID }, options),
166
+ };
167
+ return this.client.wrapWithDefaultHandler(this.client.get)(apiPath, params, callback);
168
+ };
169
+ /**
170
+ * Get a metadata cascade policy object by ID
171
+ *
172
+ * API Endpoint: '/metadata_cascade_policies/:policyID'
173
+ * Method: GET
174
+ *
175
+ * @param {string} policyID The ID of the policy to retrieve
176
+ * @param {Function} [callback] Passed the cascade policy if successful
177
+ * @returns {Promise<Object>} Promise resolving to the cascade policy
178
+ */
179
+ Metadata.prototype.getCascadePolicy = function (policyID, callback) {
180
+ var apiPath = url_path_1.default(CASCADE_POLICIES_PATH, policyID);
181
+ return this.client.wrapWithDefaultHandler(this.client.get)(apiPath, null, callback);
182
+ };
183
+ /**
184
+ * Add a new cascade policy to a folder/metadata template, causing the
185
+ * metadata template to be applied to all items and subfolders inside the
186
+ * folder.
187
+ *
188
+ * API Endpoint: '/metadata_cascade_policies'
189
+ * Method: POST
190
+ *
191
+ * @param {string} scope Metadata template scope for the template to cascade
192
+ * @param {string} templateKey Metadata template key for the template to cascade
193
+ * @param {string} folderID The ID of the folder to cascade over
194
+ * @param {Function} [callback] Passed the cascade policy if successful
195
+ * @returns {Promise<Object>} Promise resolving to the cascade policy
196
+ */
197
+ Metadata.prototype.createCascadePolicy = function (scope, templateKey, folderID, callback) {
198
+ var apiPath = url_path_1.default(CASCADE_POLICIES_PATH), params = {
199
+ body: {
200
+ folder_id: folderID,
201
+ scope: scope,
202
+ templateKey: templateKey,
203
+ },
204
+ };
205
+ return this.client.wrapWithDefaultHandler(this.client.post)(apiPath, params, callback);
206
+ };
207
+ /**
208
+ * Delete the metadata cascade policy with the given ID
209
+ *
210
+ * API Endpoint: '/metadata_cascade_policies/:policyID'
211
+ * Method: DELETE
212
+ *
213
+ * @param {string} policyID The ID of the policy to delete
214
+ * @param {Function} [callback] Passed nothing if successful
215
+ * @returns {Promise<void>} Promise resolving to nothing
216
+ */
217
+ Metadata.prototype.deleteCascadePolicy = function (policyID, callback) {
218
+ var apiPath = url_path_1.default(CASCADE_POLICIES_PATH, policyID);
219
+ return this.client.wrapWithDefaultHandler(this.client.del)(apiPath, null, callback);
220
+ };
221
+ /**
222
+ * If a policy already exists on a folder, this will apply that policy to all existing files and
223
+ * sub-folders within the target folder.
224
+ *
225
+ * API Endpoint: '/metadata_cascade_policies/:policyID/apply'
226
+ * Method: POST
227
+ *
228
+ * @param {string} policyID The ID of the policy to delete
229
+ * @param {string} resolutionMethod How to resolve conflicts, either "none" or "overwrite"
230
+ * @param {Function} [callback] Passed nothing if successful
231
+ * @returns {Promise<void>} Promise resolving to nothing
232
+ */
233
+ Metadata.prototype.forceApplyCascadePolicy = function (policyID, resolutionMethod, callback) {
234
+ var apiPath = url_path_1.default(CASCADE_POLICIES_PATH, policyID, 'apply'), params = {
235
+ body: {
236
+ conflict_resolution: resolutionMethod,
237
+ },
238
+ };
239
+ return this.client.wrapWithDefaultHandler(this.client.post)(apiPath, params, callback);
240
+ };
241
+ /**
242
+ * Query Box items by their metadata
243
+ *
244
+ * API Endpoint: '/metadata_queries/execute_read'
245
+ * Method: POST
246
+ *
247
+ * @param {string} from - The template used in the query. Must be in the form scope.templateKey
248
+ * @param {string} ancestorFolderId - The folder_id to which to restrain the query
249
+ * @param {Object} [options] - Optional parameters
250
+ * @param {string} [options.query] - The logical expression of the query
251
+ * @param {Object} [options.query_parameters] - Required if query present. The arguments for the query
252
+ * @param {string} [options.index_name] - The name of the Index to use
253
+ * @param {Object} [options.order_by] - The field_key(s) to order on and the corresponding direction(s)
254
+ * @param {Array} [options.fields] - An array of fields to return
255
+ * @param {Function} [callback] - Passed a collection of items and their associated metadata
256
+ * @returns {Promise<void>} Promise resolving to a collection of items and their associated metadata
257
+ */
258
+ Metadata.prototype.query = function (from, ancestorFolderId, options, callback) {
259
+ var body = {
260
+ from: from,
261
+ ancestor_folder_id: ancestorFolderId,
262
+ };
263
+ var params = {
264
+ body: merge(body, options),
265
+ };
266
+ return this.client.wrapWithDefaultHandler(this.client.post)(QUERY_PATH, params, callback);
267
+ };
268
+ return Metadata;
269
+ }());
270
+ Metadata.prototype.templates = {
271
+ PROPERTIES: PROPERTIES_TEMPLATE,
272
+ };
273
+ Metadata.prototype.scopes = {
274
+ ENTERPRISE: ENTERPRISE_SCOPE,
275
+ GLOBAL: GLOBAL_SCOPE,
349
276
  };
350
-
277
+ Metadata.prototype.cascadeResolution = Object.freeze({
278
+ PRESERVE_EXISTING: 'none',
279
+ OVERWRITE: 'overwrite',
280
+ });
281
+ /**
282
+ * Valid metadata field types
283
+ * @readonly
284
+ * @enum {MetadataFieldType}
285
+ */
286
+ Metadata.prototype.fieldTypes = MetadataFieldType;
351
287
  module.exports = Metadata;
288
+ //# sourceMappingURL=metadata.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"metadata.js","sourceRoot":"","s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