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 @@
1
+ {"version":3,"file":"chunked-uploader.js","sourceRoot":"","sources":["../src/chunked-uploader.ts"],"names":[],"mappings":";AAAA;;GAEG;;;;;;;;;;;;;;;;;;;AAEH,qCAAmC;AAoEnC,gFAAgF;AAChF,eAAe;AACf,gFAAgF;AAEhF,iCAAsC;AACtC,iCAAoD;AACpD,kDAA4B;AAG5B,gFAAgF;AAChF,UAAU;AACV,gFAAgF;AAEhF,IAAM,eAAe,GAAG,MAAM,CAAC,MAAM,CAAC;IACrC,WAAW,EAAE,CAAC;IACd,aAAa,EAAE,IAAI;CACnB,CAAC,CAAC;AAEH;;;;GAIG;AACH;IAAoB,yBAAY;IAY/B;;;;;;;;;OASG;IACH,eACC,MAAiB,EACjB,SAAiB,EACjB,KAAsB,EACtB,MAAc,EACd,SAAiB,EACjB,OAA+B;QANhC,YAQC,iBAAO,SAYP;QAVA,KAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,KAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,KAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,KAAI,CAAC,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC;QAC3B,KAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,KAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,KAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,KAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,KAAI,CAAC,KAAK,GAAG,IAAI,CAAC;QAClB,KAAI,CAAC,QAAQ,GAAG,KAAK,CAAC;;IACvB,CAAC;IAED;;;OAGG;IACH,uBAAO,GAAP;QACC,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC;IACvB,CAAC;IAED;;;;;OAKG;IACH,sBAAM,GAAN;QAAA,iBAiCC;QAhCA,IAAI,CAAC,M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AAC;QAC3C,IAAI,CAAC,UAAU,GAAG,KAAK,CAAC;QACxB,IAAI,OAAO,GAAG,MAAM,CAAC,MAAM,CAC1B;YACC,KAAK,EAAE,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,UAAC,CAAC,IAAK,OAAA,CAAC,CAAC,OAAO,EAAE,EAAX,CAAW,CAAC;SAC3C,EACD,IAAI,CAAC,QAAQ,CAAC,cAAc,CAC5B,CAAC;QACF,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,mBAAmB,CAAC,IAAI,CAAC,UAAU,EAAE,IAAI,EAAE,OAAO,EAAE,UACtE,GAAQ,CAAC,WAAW,EACpB,IAAS,CAAC,WAAW;YAErB,wFAAwF;YACxF,kCAAkC;YAClC,IAAI,GAAG,EAAE;gBACR,KAAI,CAAC,IAAI,CAAC,OAAO,EAAE;oBAClB,aAAa,EAAE,KAAI,CAAC,kBAAkB;oBACtC,KAAK,EAAE,GAAG;iBACV,CAAC,CAAC;gBACH,KAAI,CAAC,OAAQ,CAAC,GAAG,CAAC,CAAC;gBACnB,OAAO;aACP;YAED,KAAI,CAAC,IAAI,CAAC,gBAAgB,EAAE,IAAI,CAAC,CAAC;YAClC,KAAI,CAAC,QAAS,CAAC,IAAI,CAAC,CAAC;QACtB,CAAC,CAAC,CAAC;IACJ,CAAC;IACF,sBAAC;AAAD,CAAC,AA1OD,CAA8B,qBAAY,GA0OzC;AAED,iBAAS,eAAe,CAAC"}
@@ -0,0 +1,82 @@
1
+ /**
2
+ * @fileoverview Enterprise event stream backed by the enterprise events API
3
+ */
4
+ /// <reference types="node" />
5
+ import { Readable } from 'stream';
6
+ import BoxClient from './box-client';
7
+ declare type Options = {
8
+ streamPosition?: string;
9
+ startDate?: string;
10
+ endDate?: string;
11
+ eventTypeFilter?: EventType[];
12
+ pollingInterval?: number;
13
+ chunkSize?: number;
14
+ };
15
+ declare type EventType = string;
16
+ /**
17
+ * Stream of Box enterprise events.
18
+ *
19
+ * By default, the stream starts from the current time.
20
+ * Pass 'startDate' to start from a specific time.
21
+ * Pass 'streamPosition' to start from a previous stream position, or '0' for all available past events (~1 year).
22
+ * Once the stream catches up to the current time, it will begin polling every 'pollingInterval' seconds.
23
+ * If 'pollingInterval' = 0, then the stream will end when it catches up to the current time (no polling).
24
+ *
25
+ * @param {BoxClient} client - The client to use to get events
26
+ * @param {Object} [options] - Options
27
+ * @param {string} [options.streamPosition] - The stream position to start from (pass '0' for all past events)
28
+ * @param {string} [options.startDate] - The date to start from
29
+ * @param {string} [options.endDate] - The date to end at
30
+ * @param {EventType[]} [options.eventTypeFilter] - Array of event types to return
31
+ * @param {int} [options.pollingInterval=60] - Polling interval (in seconds). Pass 0 for no polling.
32
+ * @param {int} [options.chunkSize=500] - Number of events to fetch per call (max = 500)
33
+ * @constructor
34
+ * @extends Readable
35
+ */
36
+ declare class EnterpriseEventStream extends Readable {
37
+ _client: BoxClient;
38
+ _options: Options & Required<Pick<Options, 'pollingInterval' | 'chunkSize'>>;
39
+ _streamPosition?: string;
40
+ constructor(client: BoxClient, options?: Options);
41
+ /**
42
+ * @returns {?number} - Returns null if no events have been fetched from Box yet.
43
+ */
44
+ getStreamPosition(): string | undefined;
45
+ /**
46
+ * Get the stream state.
47
+ *
48
+ * @returns {Object} - The stream state
49
+ */
50
+ getStreamState(): {
51
+ streamPosition: string | undefined;
52
+ startDate: string | undefined;
53
+ endDate: string | undefined;
54
+ eventTypeFilter: string[] | undefined;
55
+ };
56
+ /**
57
+ * Set the stream state.
58
+ *
59
+ * @param {Object} state - The stream state
60
+ * @returns {void}
61
+ */
62
+ setStreamState(state: Pick<Options, 'streamPosition' | 'startDate' | 'endDate' | 'eventTypeFilter'>): void;
63
+ /**
64
+ * Fetch the next chunk of events
65
+ *
66
+ * If there are no events, poll until events are available.
67
+ * If an error occurs, emit the error but continuing polling as usual.
68
+ * @param {Function} callback - Passed the array of events
69
+ * @returns {void}
70
+ * @private
71
+ */
72
+ fetchEvents(callback: Function): void;
73
+ /**
74
+ * Implementation of the stream-internal read function. This is called
75
+ * by the stream whenever it needs more data, and will not be called again
76
+ * until data is pushed into the stream.
77
+ * @returns {void}
78
+ * @private
79
+ */
80
+ _read(): void;
81
+ }
82
+ export = EnterpriseEventStream;
@@ -1,28 +1,36 @@
1
+ "use strict";
1
2
  /**
2
3
  * @fileoverview Enterprise event stream backed by the enterprise events API
3
4
  */
4
-
5
- 'use strict';
6
-
5
+ var __extends = (this && this.__extends) || (function () {
6
+ var extendStatics = function (d, b) {
7
+ extendStatics = Object.setPrototypeOf ||
8
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
9
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
10
+ return extendStatics(d, b);
11
+ };
12
+ return function (d, b) {
13
+ if (typeof b !== "function" && b !== null)
14
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
15
+ extendStatics(d, b);
16
+ function __() { this.constructor = d; }
17
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
18
+ };
19
+ })();
7
20
  // ------------------------------------------------------------------------------
8
21
  // Requirements
9
22
  // ------------------------------------------------------------------------------
10
-
11
- const Readable = require('stream').Readable,
12
- util = require('util');
13
-
23
+ var stream_1 = require("stream");
14
24
  // ------------------------------------------------------------------------------
15
25
  // Private
16
26
  // ------------------------------------------------------------------------------
17
-
18
- const DEFAULT_OPTIONS = Object.freeze({
19
- pollingInterval: 60, // seconds
20
- chunkSize: 500
21
-
22
- });// ------------------------------------------------------------------------------
27
+ var DEFAULT_OPTIONS = Object.freeze({
28
+ pollingInterval: 60,
29
+ chunkSize: 500,
30
+ });
31
+ // ------------------------------------------------------------------------------
23
32
  // Public
24
33
  // ------------------------------------------------------------------------------
25
-
26
34
  /**
27
35
  * Stream of Box enterprise events.
28
36
  *
@@ -43,193 +51,171 @@ const DEFAULT_OPTIONS = Object.freeze({
43
51
  * @constructor
44
52
  * @extends Readable
45
53
  */
46
- function EnterpriseEventStream(client, options) {
47
-
48
- Readable.call(this, {
49
- objectMode: true
50
- });
51
-
52
- /**
53
- * @var {BoxClient} - The client for making API calls
54
- * @private
55
- */
56
- this._client = client;
57
-
58
- /**
59
- * @var {Object} - Options
60
- * @private
61
- */
62
- this._options = Object.assign({}, DEFAULT_OPTIONS, options);
63
-
64
- // Handle the case where the caller passes streamPosition = 0 instead of streamPosition = '0'.
65
- if (!this._options.startDate && !this._options.streamPosition && this._options.streamPosition !== 0) {
66
- // If neither startDate nor streamPosition is specified, start from the current time.
67
- this._options.startDate = new Date().toISOString()
68
- .replace(/\.000Z$/, '-00:00');
69
- }
70
-
71
- /**
72
- * @var {?string} - The current stream position
73
- * @private
74
- */
75
- this._streamPosition = this._options.streamPosition;
76
- }
77
-
78
- util.inherits(EnterpriseEventStream, Readable);
79
-
80
- /**
81
- * @returns {?string} - Returns null if no events have been fetched from Box yet.
82
- */
83
- EnterpriseEventStream.prototype.getStreamPosition = function() {
84
- return this._streamPosition;
85
- };
86
-
87
- /**
88
- * Get the stream state.
89
- *
90
- * @returns {Object} - The stream state
91
- */
92
- EnterpriseEventStream.prototype.getStreamState = function() {
93
- // We need to return both streamPosition and startDate, since streamPosition will be null until
94
- // the first set of events is returned from Box.
95
- return {
96
- streamPosition: this._streamPosition,
97
- startDate: this._options.startDate,
98
- endDate: this._options.endDate,
99
- eventTypeFilter: this._options.eventTypeFilter
100
- };
101
- };
102
-
103
- /**
104
- * Set the stream state.
105
- *
106
- * @param {Object} state - The stream state
107
- * @returns {void}
108
- */
109
- EnterpriseEventStream.prototype.setStreamState = function(state) {
110
- // We need to set both streamPosition and startDate, since streamPosition will be null until
111
- // the first set of events is returned from Box.
112
- this._streamPosition = state.streamPosition;
113
- this._options.startDate = state.startDate;
114
- this._options.endDate = state.endDate;
115
- this._options.eventTypeFilter = state.eventTypeFilter;
116
- };
117
-
118
- /**
119
- * Fetch the next chunk of events
120
- *
121
- * If there are no events, poll until events are available.
122
- * If an error occurs, emit the error but continuing polling as usual.
123
- * @param {Function} callback - Passed the array of events
124
- * @returns {void}
125
- * @private
126
- */
127
- EnterpriseEventStream.prototype.fetchEvents = function(callback) {
128
- const self = this,
129
- params = {
130
- stream_type: 'admin_logs'
131
- };
132
-
133
- // Use the current stream position.
134
- // Handle the case where the caller passes streamPosition === 0 instead of streamPosition === '0'.
135
- if (this._streamPosition || this._streamPosition === 0) {
136
- params.stream_position = this._streamPosition;
137
- }
138
-
139
- if (this._options.startDate) {
140
- params.created_after = this._options.startDate;
141
- }
142
-
143
- if (this._options.endDate) {
144
- params.created_before = this._options.endDate;
145
- }
146
-
147
- if (this._options.eventTypeFilter) {
148
- params.event_type = this._options.eventTypeFilter.join(',');
149
- }
150
-
151
- if (this._options.chunkSize) {
152
- params.limit = this._options.chunkSize;
153
- }
154
-
155
- this._client.events.get(params, (err, result) => {
156
- if (err) {
157
- self.emit('error', err);
158
- // If there was a "permanent" error, we would call the callback with it here.
159
- // But it's not clear which errors are truly permanent?
160
- // If Box is down or returning errors for an extended period, we still want to resume when it recovers.
161
- // So, continue polling at the regular frequency.
162
- // Don't use a shorter retry interval (to avoid DDOSing Box).
163
- }
164
-
165
- if (err || !result || !result.entries || result.entries.length === 0) {
166
- if (!self._options.pollingInterval) {
167
- // If polling is disabled, end the stream.
168
- callback();
169
- return;
170
- }
171
-
172
- // There were no events returned (or an error occurred), so schedule another poll.
173
- const delay = self._options.pollingInterval * 1000;
174
-
175
- // Stream readers can use this to flush buffered events to a downstream system.
176
- self.emit('wait', delay);
177
-
178
- setTimeout(() => {
179
- self.fetchEvents(callback);
180
- }, delay);
181
- return;
182
- }
183
-
184
- // Only update the stream position if there were events returned.
185
- // The API currently returns next_stream_position = 0 if there are no events (may be a bug?).
186
- // But we don't want to start over at the beginning in that case, so ignore it.
187
- self._streamPosition = result.next_stream_position;
188
-
189
- // Notify the reader of the new stream position.
190
- // Stream readers can respond to the 'newStreamState' event to persist the stream state.
191
- self.emit('newStreamState', self.getStreamState());
192
-
193
- callback(null, result.entries);
194
- });
195
- };
196
-
197
- /**
198
- * Implementation of the stream-internal read function. This is called
199
- * by the stream whenever it needs more data, and will not be called again
200
- * until data is pushed into the stream.
201
- * @returns {void}
202
- * @private
203
- */
204
- EnterpriseEventStream.prototype._read = function() {
205
- // Fetch the next chunk of events.
206
- const self = this;
207
-
208
- // This will poll forever until events are available.
209
- this.fetchEvents((err, events) => {
210
- if (err || !events || events.length === 0) {
211
- // Close the stream if there was a "permanent" failure or we reached the end of the events.
212
- self.push(null);
213
- return;
214
- }
215
-
216
- // Pause the stream to avoid race conditions while pushing in the new events.
217
- // Without this, _read() would be called again from inside each push(),
218
- // resulting in multiple parallel calls to fetchEvents().
219
- // See https://github.com/nodejs/node/issues/3203
220
- const wasPaused = self.isPaused();
221
- self.pause();
222
-
223
- // Push all of the events into the stream.
224
- events.forEach(event => {
225
- self.push(event);
226
- });
227
-
228
- if (!wasPaused) {
229
- // This will deliver the events and trigger the next call to _read() once they have been consumed.
230
- self.resume();
231
- }
232
- });
233
- };
234
-
54
+ var EnterpriseEventStream = /** @class */ (function (_super) {
55
+ __extends(EnterpriseEventStream, _super);
56
+ function EnterpriseEventStream(client, options) {
57
+ var _this = _super.call(this, {
58
+ objectMode: true,
59
+ }) || this;
60
+ /**
61
+ * @var {BoxClient} - The client for making API calls
62
+ * @private
63
+ */
64
+ _this._client = client;
65
+ /**
66
+ * @var {Object} - Options
67
+ * @private
68
+ */
69
+ _this._options = Object.assign({}, DEFAULT_OPTIONS, options);
70
+ // Handle the case where the caller passes streamPosition = 0 instead of streamPosition = '0'.
71
+ if (!_this._options.startDate &&
72
+ !_this._options.streamPosition &&
73
+ _this._options.streamPosition !== 0) {
74
+ // If neither startDate nor streamPosition is specified, start from the current time.
75
+ _this._options.startDate = new Date()
76
+ .toISOString()
77
+ .replace(/\.000Z$/, '-00:00');
78
+ }
79
+ /**
80
+ * @var {?string} - The current stream position
81
+ * @private
82
+ */
83
+ _this._streamPosition = _this._options.streamPosition;
84
+ return _this;
85
+ }
86
+ /**
87
+ * @returns {?number} - Returns null if no events have been fetched from Box yet.
88
+ */
89
+ EnterpriseEventStream.prototype.getStreamPosition = function () {
90
+ return this._streamPosition;
91
+ };
92
+ /**
93
+ * Get the stream state.
94
+ *
95
+ * @returns {Object} - The stream state
96
+ */
97
+ EnterpriseEventStream.prototype.getStreamState = function () {
98
+ // We need to return both streamPosition and startDate, since streamPosition will be null until
99
+ // the first set of events is returned from Box.
100
+ return {
101
+ streamPosition: this._streamPosition,
102
+ startDate: this._options.startDate,
103
+ endDate: this._options.endDate,
104
+ eventTypeFilter: this._options.eventTypeFilter,
105
+ };
106
+ };
107
+ /**
108
+ * Set the stream state.
109
+ *
110
+ * @param {Object} state - The stream state
111
+ * @returns {void}
112
+ */
113
+ EnterpriseEventStream.prototype.setStreamState = function (state) {
114
+ // We need to set both streamPosition and startDate, since streamPosition will be null until
115
+ // the first set of events is returned from Box.
116
+ this._streamPosition = state.streamPosition;
117
+ this._options.startDate = state.startDate;
118
+ this._options.endDate = state.endDate;
119
+ this._options.eventTypeFilter = state.eventTypeFilter;
120
+ };
121
+ /**
122
+ * Fetch the next chunk of events
123
+ *
124
+ * If there are no events, poll until events are available.
125
+ * If an error occurs, emit the error but continuing polling as usual.
126
+ * @param {Function} callback - Passed the array of events
127
+ * @returns {void}
128
+ * @private
129
+ */
130
+ EnterpriseEventStream.prototype.fetchEvents = function (callback) {
131
+ var self = this, params = {
132
+ stream_type: 'admin_logs',
133
+ };
134
+ // Use the current stream position.
135
+ // Handle the case where the caller passes streamPosition === 0 instead of streamPosition === '0'.
136
+ if (this._streamPosition || this._streamPosition === 0) {
137
+ params.stream_position = this._streamPosition;
138
+ }
139
+ if (this._options.startDate) {
140
+ params.created_after = this._options.startDate;
141
+ }
142
+ if (this._options.endDate) {
143
+ params.created_before = this._options.endDate;
144
+ }
145
+ if (this._options.eventTypeFilter) {
146
+ params.event_type = this._options.eventTypeFilter.join(',');
147
+ }
148
+ if (this._options.chunkSize) {
149
+ params.limit = this._options.chunkSize;
150
+ }
151
+ this._client.events.get(params, function (err /* FIXME */, result /* FIXME */) {
152
+ if (err) {
153
+ self.emit('error', err);
154
+ // If there was a "permanent" error, we would call the callback with it here.
155
+ // But it's not clear which errors are truly permanent?
156
+ // If Box is down or returning errors for an extended period, we still want to resume when it recovers.
157
+ // So, continue polling at the regular frequency.
158
+ // Don't use a shorter retry interval (to avoid DDOSing Box).
159
+ }
160
+ if (err || !result || !result.entries || result.entries.length === 0) {
161
+ if (!self._options.pollingInterval) {
162
+ // If polling is disabled, end the stream.
163
+ callback();
164
+ return;
165
+ }
166
+ // There were no events returned (or an error occurred), so schedule another poll.
167
+ var delay = self._options.pollingInterval * 1000;
168
+ // Stream readers can use this to flush buffered events to a downstream system.
169
+ self.emit('wait', delay);
170
+ setTimeout(function () {
171
+ self.fetchEvents(callback);
172
+ }, delay);
173
+ return;
174
+ }
175
+ // Only update the stream position if there were events returned.
176
+ // The API currently returns next_stream_position = 0 if there are no events (may be a bug?).
177
+ // But we don't want to start over at the beginning in that case, so ignore it.
178
+ self._streamPosition = result.next_stream_position;
179
+ // Notify the reader of the new stream position.
180
+ // Stream readers can respond to the 'newStreamState' event to persist the stream state.
181
+ self.emit('newStreamState', self.getStreamState());
182
+ callback(null, result.entries);
183
+ });
184
+ };
185
+ /**
186
+ * Implementation of the stream-internal read function. This is called
187
+ * by the stream whenever it needs more data, and will not be called again
188
+ * until data is pushed into the stream.
189
+ * @returns {void}
190
+ * @private
191
+ */
192
+ EnterpriseEventStream.prototype._read = function () {
193
+ // Fetch the next chunk of events.
194
+ var self = this;
195
+ // This will poll forever until events are available.
196
+ this.fetchEvents(function (err /* FIXME */, events /* FIXME */) {
197
+ if (err || !events || events.length === 0) {
198
+ // Close the stream if there was a "permanent" failure or we reached the end of the events.
199
+ self.push(null);
200
+ return;
201
+ }
202
+ // Pause the stream to avoid race conditions while pushing in the new events.
203
+ // Without this, _read() would be called again from inside each push(),
204
+ // resulting in multiple parallel calls to fetchEvents().
205
+ // See https://github.com/nodejs/node/issues/3203
206
+ var wasPaused = self.isPaused();
207
+ self.pause();
208
+ // Push all of the events into the stream.
209
+ events.forEach(function (event /* FIXME */) {
210
+ self.push(event);
211
+ });
212
+ if (!wasPaused) {
213
+ // This will deliver the events and trigger the next call to _read() once they have been consumed.
214
+ self.resume();
215
+ }
216
+ });
217
+ };
218
+ return EnterpriseEventStream;
219
+ }(stream_1.Readable));
235
220
  module.exports = EnterpriseEventStream;
221
+ //# sourceMappingURL=enterprise-event-stream.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"enterprise-event-stream.js","sourceRoot":"","sources":["../src/enterprise-event-stream.ts"],"names":[],"mappings":";AAAA;;GAEG;;;;;;;;;;;;;;;;AAEH,iFAAiF;AACjF,eAAe;AACf,iFAAiF;AAEjF,iCAAkC;AAkBlC,iFAAiF;AACjF,UAAU;AACV,iFAAiF;AAEjF,IAAM,eAAe,GAAG,MAAM,CAAC,MAAM,CAAC;IACrC,eAAe,EAAE,EAAE;IACnB,SAAS,EAAE,GAAG;CACd,CAAC,CAAC;AAEH,iFAAiF;AACjF,SAAS;AACT,iFAAiF;AAEjF;;;;;;;;;;;;;;;;;;;GAmBG;AACH;IAAoC,yCAAQ;IAK3C,+BAAY,MAAiB,EAAE,OAAiB;QAAhD,YACC,kBAAM;YACL,UAAU,EAAE,IAAI;SAChB,CAAC,SA+BF;QA7BA;;;WAGG;QACH,KAAI,CAAC,OAAO,GAAG,MAAM,CAAC;QAEtB;;;WAGG;QACH,KAAI,CAAC,QAAQ,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,eAAe,EAAE,OAAO,CAAC,CAAC;QAE5D,8FAA8F;QAC9F,IACC,CAAC,KAAI,CAAC,QAAQ,CAAC,SAAS;YACxB,CAAC,KAAI,CAAC,QAAQ,CAAC,cAAc;YAC5B,KAAI,CAAC,QAAQ,CAAC,cAAsB,KAAK,CAAC,EAC1C;YACD,qFAAqF;YACrF,KAAI,CAAC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AqB,CAAC"}
@@ -0,0 +1,92 @@
1
+ /**
2
+ * @fileoverview Event stream backed by the events API
3
+ */
4
+ /// <reference types="node" />
5
+ import { Readable } from 'stream';
6
+ import BoxClient from './box-client';
7
+ declare type Options = {
8
+ retryDelay: number;
9
+ deduplicationFilterSize: number;
10
+ fetchInterval: number;
11
+ };
12
+ declare type LongPollInfo = {
13
+ max_retries: number;
14
+ retry_timeout: number;
15
+ url: string;
16
+ };
17
+ /**
18
+ * Stream of Box events from a given client and point in time.
19
+ * @param {BoxClient} client The client to use to get events
20
+ * @param {string} streamPosition The point in time to start at
21
+ * @param {Object} [options] Optional parameters
22
+ * @param {int} [options.retryDelay=1000] Number of ms to wait before retrying after an error
23
+ * @param {int} [options.deduplicationFilterSize=5000] Number of IDs to track for deduplication
24
+ * @param {int} [options.fetchInterval=1000] Minimunm number of ms between calls for more events
25
+ * @constructor
26
+ * @extends Readable
27
+ */
28
+ declare class EventStream extends Readable {
29
+ _client: BoxClient;
30
+ _streamPosition: string;
31
+ _longPollInfo?: LongPollInfo;
32
+ _longPollRetries: number;
33
+ _dedupHash: Record<string, boolean>;
34
+ _rateLimiter: Promise<any>;
35
+ _options: Options;
36
+ _retryTimer?: NodeJS.Timeout | number;
37
+ constructor(client: BoxClient, streamPosition: string, options?: Partial<Options>);
38
+ /**
39
+ * Retrieve the url and params for long polling for new updates
40
+ * @returns {Promise} Promise for testing purposes
41
+ * @private
42
+ */
43
+ getLongPollInfo(): any;
44
+ /**
45
+ * Long poll for notification of new events. We do this rather than
46
+ * polling for the events directly in order to minimize the number of API
47
+ * calls necessary.
48
+ * @returns {Promise} Promise for testing pruposes
49
+ * @private
50
+ */
51
+ doLongPoll(): any;
52
+ /**
53
+ * Retries long-polling after a delay.
54
+ * Does not attempt if stream is already destroyed.
55
+ * @returns {void}
56
+ * @private
57
+ */
58
+ retryPollInfo(): void;
59
+ /**
60
+ * Fetch the latest group of events and push them into the stream
61
+ * @returns {Promise} Promise for testing purposes
62
+ * @private
63
+ */
64
+ fetchEvents(): Promise<any>;
65
+ /**
66
+ * Clean up the deduplication filter, to prevent it from growing
67
+ * too big and eating up memory. We look at the latest set of events
68
+ * returned and assume that any IDs not in that set don't need to be
69
+ * tracked for deduplication any more.
70
+ * @param {Object[]} latestEvents The latest events from the API
71
+ * @returns {void}
72
+ * @private
73
+ */
74
+ cleanupDedupFilter(latestEvents: any): void;
75
+ /**
76
+ * Implementation of the stream-internal read function. This is called
77
+ * by the stream whenever it needs more data, and will not be called again
78
+ * until data is pushed into the stream.
79
+ * @returns {void}
80
+ * @private
81
+ */
82
+ _read(): void;
83
+ /**
84
+ * Implementation of stream-internal `_destroy` function (v8.0.0 and later).
85
+ * Called by stream consumers to effectively stop polling via the public
86
+ * `destroy()`.
87
+ * @returns {void}
88
+ * @private
89
+ */
90
+ _destroy(): void;
91
+ }
92
+ export = EventStream;