@dereekb/zoom 13.0.0 → 13.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.cjs.default.js +1 -0
- package/index.cjs.js +476 -525
- package/index.cjs.mjs +2 -0
- package/index.esm.js +476 -525
- package/nestjs/index.cjs.default.js +1 -0
- package/nestjs/index.cjs.js +487 -452
- package/nestjs/index.cjs.mjs +2 -0
- package/nestjs/index.esm.js +487 -452
- package/nestjs/package.json +20 -15
- package/package.json +21 -24
package/index.cjs.js
CHANGED
|
@@ -1,10 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
require('core-js/modules/es.json.stringify.js');
|
|
4
3
|
var fetch = require('@dereekb/util/fetch');
|
|
5
|
-
require('core-js/modules/es.set.difference.v2.js');
|
|
6
|
-
require('core-js/modules/es.set.symmetric-difference.v2.js');
|
|
7
|
-
require('core-js/modules/es.set.union.v2.js');
|
|
8
4
|
var util = require('@dereekb/util');
|
|
9
5
|
var makeError = require('make-error');
|
|
10
6
|
|
|
@@ -17,23 +13,17 @@ var makeError = require('make-error');
|
|
|
17
13
|
* @returns
|
|
18
14
|
*/
|
|
19
15
|
function mapToZoomPageResult(dataTypeKey) {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
next_page_token,
|
|
31
|
-
page_count,
|
|
32
|
-
page_number,
|
|
33
|
-
page_size,
|
|
34
|
-
total_records
|
|
16
|
+
return (data) => {
|
|
17
|
+
const { next_page_token, page_count, page_number, page_size, total_records } = data;
|
|
18
|
+
return {
|
|
19
|
+
data: data[dataTypeKey],
|
|
20
|
+
next_page_token,
|
|
21
|
+
page_count,
|
|
22
|
+
page_number,
|
|
23
|
+
page_size,
|
|
24
|
+
total_records
|
|
25
|
+
};
|
|
35
26
|
};
|
|
36
|
-
};
|
|
37
27
|
}
|
|
38
28
|
/**
|
|
39
29
|
* Creates a FetchPageFactory using the input ZoomFetchPageFetchFunction.
|
|
@@ -43,23 +33,19 @@ function mapToZoomPageResult(dataTypeKey) {
|
|
|
43
33
|
* @returns
|
|
44
34
|
*/
|
|
45
35
|
function zoomFetchPageFactory(fetch$1, defaults) {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
page_size: options.maxItemsPerPage ?? input.page_size
|
|
60
|
-
};
|
|
61
|
-
}
|
|
62
|
-
});
|
|
36
|
+
return fetch.fetchPageFactory({
|
|
37
|
+
...defaults,
|
|
38
|
+
fetch: fetch$1,
|
|
39
|
+
readFetchPageResultInfo: function (result) {
|
|
40
|
+
return {
|
|
41
|
+
nextPageCursor: result.next_page_token,
|
|
42
|
+
hasNext: Boolean(result.next_page_token) // has more when a non-empty next_page_token is returned
|
|
43
|
+
};
|
|
44
|
+
},
|
|
45
|
+
buildInputForNextPage: function (pageResult, input, options) {
|
|
46
|
+
return { ...input, next_page_token: pageResult.nextPageCursor, page_size: options.maxItemsPerPage ?? input.page_size };
|
|
47
|
+
}
|
|
48
|
+
});
|
|
63
49
|
}
|
|
64
50
|
|
|
65
51
|
/**
|
|
@@ -70,26 +56,26 @@ const ZOOM_SUCCESS_CODE = 'SUCCESS';
|
|
|
70
56
|
* Zoom Server Error
|
|
71
57
|
*/
|
|
72
58
|
class ZoomServerError extends makeError.BaseError {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
59
|
+
error;
|
|
60
|
+
get code() {
|
|
61
|
+
return this.error.code;
|
|
62
|
+
}
|
|
63
|
+
constructor(error) {
|
|
64
|
+
super(error.message);
|
|
65
|
+
this.error = error;
|
|
66
|
+
}
|
|
81
67
|
}
|
|
82
68
|
/**
|
|
83
69
|
* Zoom Server Error that includes the FetchResponseError
|
|
84
70
|
*/
|
|
85
71
|
class ZoomServerFetchResponseError extends ZoomServerError {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
72
|
+
data;
|
|
73
|
+
responseError;
|
|
74
|
+
constructor(data, responseError) {
|
|
75
|
+
super(data);
|
|
76
|
+
this.data = data;
|
|
77
|
+
this.responseError = responseError;
|
|
78
|
+
}
|
|
93
79
|
}
|
|
94
80
|
/**
|
|
95
81
|
* Creates a logZoomServerErrorFunction that logs the error to console.
|
|
@@ -98,22 +84,17 @@ class ZoomServerFetchResponseError extends ZoomServerError {
|
|
|
98
84
|
* @returns
|
|
99
85
|
*/
|
|
100
86
|
function logZoomServerErrorFunction(zoomApiNamePrefix) {
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
}
|
|
112
|
-
console.log(`${zoomApiNamePrefix}Error(name:${error.name}): `, {
|
|
113
|
-
error
|
|
114
|
-
});
|
|
115
|
-
}
|
|
116
|
-
};
|
|
87
|
+
return (error) => {
|
|
88
|
+
if (error instanceof ZoomServerFetchResponseError) {
|
|
89
|
+
console.log(`${zoomApiNamePrefix}Error(${error.responseError.response.status}): `, { error, errorData: error.data });
|
|
90
|
+
}
|
|
91
|
+
else if (error instanceof ZoomServerError) {
|
|
92
|
+
console.log(`${zoomApiNamePrefix}Error(code:${error.code}): `, { error });
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
console.log(`${zoomApiNamePrefix}Error(name:${error.name}): `, { error });
|
|
96
|
+
}
|
|
97
|
+
};
|
|
117
98
|
}
|
|
118
99
|
/**
|
|
119
100
|
* Wraps a ConfiguredFetch to support handling errors returned by fetch.
|
|
@@ -122,22 +103,23 @@ function logZoomServerErrorFunction(zoomApiNamePrefix) {
|
|
|
122
103
|
* @returns
|
|
123
104
|
*/
|
|
124
105
|
function handleZoomErrorFetchFactory(parseZoomError, defaultLogError) {
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
106
|
+
return (fetch$1, logError = defaultLogError) => {
|
|
107
|
+
return async (x, y) => {
|
|
108
|
+
try {
|
|
109
|
+
return await fetch$1(x, y); // await to catch thrown errors
|
|
110
|
+
}
|
|
111
|
+
catch (e) {
|
|
112
|
+
if (e instanceof fetch.FetchResponseError) {
|
|
113
|
+
const error = await parseZoomError(e);
|
|
114
|
+
if (error) {
|
|
115
|
+
logError(error); // log before throwing.
|
|
116
|
+
throw error;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
throw e;
|
|
120
|
+
}
|
|
121
|
+
};
|
|
139
122
|
};
|
|
140
|
-
};
|
|
141
123
|
}
|
|
142
124
|
// MARK: Parsed Errors
|
|
143
125
|
/**
|
|
@@ -156,34 +138,27 @@ const ZOOM_RATE_LIMIT_RETRY_AFTER_HEADER = 'Retry-After';
|
|
|
156
138
|
const DEFAULT_ZOOM_API_RATE_LIMIT = 2;
|
|
157
139
|
const DEFAULT_ZOOM_API_RATE_LIMIT_RESET_PERIOD = util.MS_IN_SECOND;
|
|
158
140
|
function zoomRateLimitHeaderDetails(headers) {
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
retryAfter,
|
|
176
|
-
retryAfterAt,
|
|
177
|
-
category,
|
|
178
|
-
type
|
|
179
|
-
};
|
|
180
|
-
}
|
|
181
|
-
return result;
|
|
141
|
+
const limitHeader = headers.get(ZOOM_RATE_LIMIT_LIMIT_HEADER);
|
|
142
|
+
const remainingHeader = headers.get(ZOOM_RATE_LIMIT_REMAINING_HEADER);
|
|
143
|
+
const retryAfterHeader = headers.get(ZOOM_RATE_LIMIT_RETRY_AFTER_HEADER);
|
|
144
|
+
const categoryHeader = headers.get(ZOOM_RATE_LIMIT_CATEGORY_HEADER);
|
|
145
|
+
const typeHeader = headers.get(ZOOM_RATE_LIMIT_TYPE_HEADER);
|
|
146
|
+
let result = null;
|
|
147
|
+
if (categoryHeader != null && typeHeader != null) {
|
|
148
|
+
const category = categoryHeader;
|
|
149
|
+
const type = typeHeader;
|
|
150
|
+
const limit = limitHeader ? Number(limitHeader) : undefined;
|
|
151
|
+
const remaining = remainingHeader ? Number(remainingHeader) : undefined;
|
|
152
|
+
const retryAfter = retryAfterHeader ? Number(retryAfterHeader) : undefined;
|
|
153
|
+
const retryAfterAt = retryAfterHeader ? new Date(retryAfterHeader) : undefined;
|
|
154
|
+
result = { limit, remaining, retryAfter, retryAfterAt, category, type };
|
|
155
|
+
}
|
|
156
|
+
return result;
|
|
182
157
|
}
|
|
183
158
|
class ZoomTooManyRequestsError extends ZoomServerFetchResponseError {
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
159
|
+
get headerDetails() {
|
|
160
|
+
return zoomRateLimitHeaderDetails(this.responseError.response.headers);
|
|
161
|
+
}
|
|
187
162
|
}
|
|
188
163
|
/**
|
|
189
164
|
* Function that parses/transforms a ZoomServerErrorData into a general ZoomServerError or other known error type.
|
|
@@ -193,22 +168,23 @@ class ZoomTooManyRequestsError extends ZoomServerFetchResponseError {
|
|
|
193
168
|
* @returns
|
|
194
169
|
*/
|
|
195
170
|
function parseZoomServerErrorData(zoomServerError, responseError) {
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
} else if (zoomServerError) {
|
|
205
|
-
switch (zoomServerError.code) {
|
|
206
|
-
default:
|
|
207
|
-
result = new ZoomServerFetchResponseError(zoomServerError, responseError);
|
|
208
|
-
break;
|
|
171
|
+
let result;
|
|
172
|
+
if (responseError.response.status === ZOOM_TOO_MANY_REQUESTS_HTTP_STATUS_CODE) {
|
|
173
|
+
result = new ZoomTooManyRequestsError(zoomServerError, responseError);
|
|
174
|
+
console.warn('ZoomTooManyRequestsError', {
|
|
175
|
+
result,
|
|
176
|
+
responseError,
|
|
177
|
+
headerDetails: result.headerDetails
|
|
178
|
+
});
|
|
209
179
|
}
|
|
210
|
-
|
|
211
|
-
|
|
180
|
+
else if (zoomServerError) {
|
|
181
|
+
switch (zoomServerError.code) {
|
|
182
|
+
default:
|
|
183
|
+
result = new ZoomServerFetchResponseError(zoomServerError, responseError);
|
|
184
|
+
break;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
return result;
|
|
212
188
|
}
|
|
213
189
|
/**
|
|
214
190
|
* Returns a pre-configured MakeUrlSearchParamsOptions that omits the silenceError key.
|
|
@@ -216,84 +192,80 @@ function parseZoomServerErrorData(zoomServerError, responseError) {
|
|
|
216
192
|
* If other options are input, it merges those two options together and adds silenceError to the omitted keys.
|
|
217
193
|
*/
|
|
218
194
|
function omitSilenceZoomErrorKeys(options) {
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
omitKeys
|
|
222
|
-
}]);
|
|
195
|
+
const omitKeys = ['silenceError'];
|
|
196
|
+
return fetch.mergeMakeUrlSearchParamsOptions([options, { omitKeys }]);
|
|
223
197
|
}
|
|
224
198
|
function silenceZoomErrorWithCodesFunction(codes, returnFn) {
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
199
|
+
const codesSet = new Set(util.asArray(codes));
|
|
200
|
+
return (silence) => {
|
|
201
|
+
return (reason) => {
|
|
202
|
+
if (silence !== false && reason instanceof ZoomServerFetchResponseError) {
|
|
203
|
+
if (codesSet.has(reason.code)) {
|
|
204
|
+
return returnFn?.(reason);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
throw reason;
|
|
208
|
+
};
|
|
234
209
|
};
|
|
235
|
-
};
|
|
236
210
|
}
|
|
237
211
|
|
|
238
212
|
/**
|
|
239
213
|
* https://developers.zoom.us/docs/api/rest/reference/zoom-api/methods/#operation/meeting
|
|
240
214
|
*/
|
|
241
215
|
function getMeeting(context) {
|
|
242
|
-
|
|
216
|
+
return (input) => context.fetchJson(`/meetings/${input.meetingId}`, 'GET');
|
|
243
217
|
}
|
|
244
218
|
/**
|
|
245
219
|
* https://developers.zoom.us/docs/api/rest/reference/zoom-api/methods/#operation/meetings
|
|
246
220
|
*/
|
|
247
221
|
function listMeetingsForUser(context) {
|
|
248
|
-
|
|
222
|
+
return (input) => context.fetchJson(`/users/${input.user}/meetings`, 'GET').then(mapToZoomPageResult('meetings'));
|
|
249
223
|
}
|
|
250
224
|
function listMeetingsForUserPageFactory(context) {
|
|
251
|
-
|
|
225
|
+
return zoomFetchPageFactory(listMeetingsForUser(context));
|
|
252
226
|
}
|
|
253
227
|
/**
|
|
254
228
|
* https://developers.zoom.us/docs/api/meetings/#tag/meetings/POST/users/{userId}/meetings
|
|
255
229
|
*/
|
|
256
230
|
function createMeetingForUser(context) {
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
231
|
+
return (input) => {
|
|
232
|
+
return context.fetchJson(`/users/${input.user}/meetings`, {
|
|
233
|
+
method: 'POST',
|
|
234
|
+
body: JSON.stringify(input.template)
|
|
235
|
+
});
|
|
236
|
+
};
|
|
263
237
|
}
|
|
264
238
|
/**
|
|
265
239
|
* https://developers.zoom.us/docs/api/meetings/#tag/meetings/PUT/meetings/{meetingId}
|
|
266
240
|
*/
|
|
267
241
|
function updateMeeting(context) {
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
body: JSON.stringify(input.template)
|
|
273
|
-
});
|
|
242
|
+
return (input) => context.fetchJson(`/meetings/${input.meetingId}?${fetch.makeUrlSearchParams({ occurrence_id: input.occurrence_id })}`, {
|
|
243
|
+
method: 'PATCH',
|
|
244
|
+
body: JSON.stringify(input.template)
|
|
245
|
+
});
|
|
274
246
|
}
|
|
275
247
|
const DELETE_MEETING_DOES_NOT_EXIST_ERROR_CODE = 3001;
|
|
276
248
|
/**
|
|
277
249
|
* https://developers.zoom.us/docs/api/meetings/#tag/meetings/DELETE/meetings/{meetingId}
|
|
278
250
|
*/
|
|
279
251
|
function deleteMeeting(context) {
|
|
280
|
-
|
|
281
|
-
|
|
252
|
+
const silenceDoesNotExistError = silenceZoomErrorWithCodesFunction(DELETE_MEETING_DOES_NOT_EXIST_ERROR_CODE);
|
|
253
|
+
return (input) => context.fetchJson(`/meetings/${input.meetingId}?${fetch.makeUrlSearchParams(input, omitSilenceZoomErrorKeys())}`, 'DELETE').catch(silenceDoesNotExistError(input.silenceError));
|
|
282
254
|
}
|
|
283
255
|
/**
|
|
284
256
|
* https://developers.zoom.us/docs/api/meetings/#tag/meetings/GET/past_meetings/{meetingId}
|
|
285
257
|
*/
|
|
286
258
|
function getPastMeeting(context) {
|
|
287
|
-
|
|
259
|
+
return (input) => context.fetchJson(`/past_meetings/${input.meetingId}`, 'GET');
|
|
288
260
|
}
|
|
289
261
|
/**
|
|
290
262
|
* https://developers.zoom.us/docs/api/meetings/#tag/meetings/GET/past_meetings/{meetingId}/participants
|
|
291
263
|
*/
|
|
292
264
|
function getPastMeetingParticipants(context) {
|
|
293
|
-
|
|
265
|
+
return (input) => context.fetchJson(`/past_meetings/${input.meetingId}/participants`, 'GET').then(mapToZoomPageResult('participants'));
|
|
294
266
|
}
|
|
295
267
|
function getPastMeetingParticipantsPageFactory(context) {
|
|
296
|
-
|
|
268
|
+
return zoomFetchPageFactory(getPastMeetingParticipants(context));
|
|
297
269
|
}
|
|
298
270
|
|
|
299
271
|
/**
|
|
@@ -307,66 +279,66 @@ function getPastMeetingParticipantsPageFactory(context) {
|
|
|
307
279
|
*/
|
|
308
280
|
exports.ZoomMeetingType = void 0;
|
|
309
281
|
(function (ZoomMeetingType) {
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
282
|
+
ZoomMeetingType[ZoomMeetingType["INSTANT"] = 1] = "INSTANT";
|
|
283
|
+
ZoomMeetingType[ZoomMeetingType["SCHEDULED"] = 2] = "SCHEDULED";
|
|
284
|
+
ZoomMeetingType[ZoomMeetingType["RECURRING_NO_FIXED_TIME"] = 3] = "RECURRING_NO_FIXED_TIME";
|
|
285
|
+
ZoomMeetingType[ZoomMeetingType["PMI"] = 4] = "PMI";
|
|
286
|
+
ZoomMeetingType[ZoomMeetingType["RECURRING_FIXED_TIME"] = 8] = "RECURRING_FIXED_TIME";
|
|
287
|
+
ZoomMeetingType[ZoomMeetingType["SCREEN_SHARE_ONLY"] = 10] = "SCREEN_SHARE_ONLY";
|
|
316
288
|
})(exports.ZoomMeetingType || (exports.ZoomMeetingType = {}));
|
|
317
289
|
exports.ZoomRecurrenceType = void 0;
|
|
318
290
|
(function (ZoomRecurrenceType) {
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
291
|
+
ZoomRecurrenceType[ZoomRecurrenceType["DAILY"] = 1] = "DAILY";
|
|
292
|
+
ZoomRecurrenceType[ZoomRecurrenceType["WEEKLY"] = 2] = "WEEKLY";
|
|
293
|
+
ZoomRecurrenceType[ZoomRecurrenceType["MONTHLY"] = 3] = "MONTHLY";
|
|
322
294
|
})(exports.ZoomRecurrenceType || (exports.ZoomRecurrenceType = {}));
|
|
323
295
|
exports.ZoomMonthlyWeek = void 0;
|
|
324
296
|
(function (ZoomMonthlyWeek) {
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
297
|
+
ZoomMonthlyWeek[ZoomMonthlyWeek["LAST_WEEK"] = -1] = "LAST_WEEK";
|
|
298
|
+
ZoomMonthlyWeek[ZoomMonthlyWeek["FIRST_WEEK"] = 1] = "FIRST_WEEK";
|
|
299
|
+
ZoomMonthlyWeek[ZoomMonthlyWeek["SECOND_WEEK"] = 2] = "SECOND_WEEK";
|
|
300
|
+
ZoomMonthlyWeek[ZoomMonthlyWeek["THIRD_WEEK"] = 3] = "THIRD_WEEK";
|
|
301
|
+
ZoomMonthlyWeek[ZoomMonthlyWeek["FOURTH_WEEK"] = 4] = "FOURTH_WEEK";
|
|
330
302
|
})(exports.ZoomMonthlyWeek || (exports.ZoomMonthlyWeek = {}));
|
|
331
303
|
exports.ZoomMonthlyWeekDay = void 0;
|
|
332
304
|
(function (ZoomMonthlyWeekDay) {
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
305
|
+
ZoomMonthlyWeekDay[ZoomMonthlyWeekDay["SUNDAY"] = 1] = "SUNDAY";
|
|
306
|
+
ZoomMonthlyWeekDay[ZoomMonthlyWeekDay["MONDAY"] = 2] = "MONDAY";
|
|
307
|
+
ZoomMonthlyWeekDay[ZoomMonthlyWeekDay["TUESDAY"] = 3] = "TUESDAY";
|
|
308
|
+
ZoomMonthlyWeekDay[ZoomMonthlyWeekDay["WEDNESDAY"] = 4] = "WEDNESDAY";
|
|
309
|
+
ZoomMonthlyWeekDay[ZoomMonthlyWeekDay["THURSDAY"] = 5] = "THURSDAY";
|
|
310
|
+
ZoomMonthlyWeekDay[ZoomMonthlyWeekDay["FRIDAY"] = 6] = "FRIDAY";
|
|
311
|
+
ZoomMonthlyWeekDay[ZoomMonthlyWeekDay["SATURDAY"] = 7] = "SATURDAY";
|
|
340
312
|
})(exports.ZoomMonthlyWeekDay || (exports.ZoomMonthlyWeekDay = {}));
|
|
341
313
|
exports.ZoomApprovalType = void 0;
|
|
342
314
|
(function (ZoomApprovalType) {
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
315
|
+
/**
|
|
316
|
+
* Automatically approve.
|
|
317
|
+
*/
|
|
318
|
+
ZoomApprovalType[ZoomApprovalType["AUTOMATICALLY_APPROVE"] = 0] = "AUTOMATICALLY_APPROVE";
|
|
319
|
+
/**
|
|
320
|
+
* Manually approve.
|
|
321
|
+
*/
|
|
322
|
+
ZoomApprovalType[ZoomApprovalType["MANUALLY_APPROVE"] = 1] = "MANUALLY_APPROVE";
|
|
323
|
+
/**
|
|
324
|
+
* No registration required.
|
|
325
|
+
*/
|
|
326
|
+
ZoomApprovalType[ZoomApprovalType["NO_REGISTRATION_REQUIRED"] = 2] = "NO_REGISTRATION_REQUIRED";
|
|
355
327
|
})(exports.ZoomApprovalType || (exports.ZoomApprovalType = {}));
|
|
356
328
|
exports.ZoomRegistrationType = void 0;
|
|
357
329
|
(function (ZoomRegistrationType) {
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
330
|
+
/**
|
|
331
|
+
* Attendees register once and can attend any meeting occurrence.
|
|
332
|
+
*/
|
|
333
|
+
ZoomRegistrationType[ZoomRegistrationType["REGISTER_ONCE_ATTEND_ANY"] = 1] = "REGISTER_ONCE_ATTEND_ANY";
|
|
334
|
+
/**
|
|
335
|
+
* Attendees must register for each meeting occurrence.
|
|
336
|
+
*/
|
|
337
|
+
ZoomRegistrationType[ZoomRegistrationType["REGISTER_FOR_EACH_OCCURRENCE"] = 2] = "REGISTER_FOR_EACH_OCCURRENCE";
|
|
338
|
+
/**
|
|
339
|
+
* Attendees register once and can select one or more meeting occurrences to attend.
|
|
340
|
+
*/
|
|
341
|
+
ZoomRegistrationType[ZoomRegistrationType["REGISTER_ONCE_CHOOSE_OCCURRENCES"] = 3] = "REGISTER_ONCE_CHOOSE_OCCURRENCES";
|
|
370
342
|
})(exports.ZoomRegistrationType || (exports.ZoomRegistrationType = {}));
|
|
371
343
|
|
|
372
344
|
/**
|
|
@@ -376,7 +348,7 @@ exports.ZoomRegistrationType = void 0;
|
|
|
376
348
|
* @returns
|
|
377
349
|
*/
|
|
378
350
|
function getUser(context) {
|
|
379
|
-
|
|
351
|
+
return (input) => context.fetchJson(`/users/${input.userId}`, 'GET');
|
|
380
352
|
}
|
|
381
353
|
/**
|
|
382
354
|
* https://developers.zoom.us/docs/api/users/#tag/users/GET/users
|
|
@@ -385,40 +357,40 @@ function getUser(context) {
|
|
|
385
357
|
* @returns
|
|
386
358
|
*/
|
|
387
359
|
function listUsers(context) {
|
|
388
|
-
|
|
360
|
+
return (input) => context.fetchJson(`/users?${fetch.makeUrlSearchParams(input)}`, 'GET').then(mapToZoomPageResult('users'));
|
|
389
361
|
}
|
|
390
362
|
function listUsersPageFactory(context) {
|
|
391
|
-
|
|
363
|
+
return zoomFetchPageFactory(listUsers(context));
|
|
392
364
|
}
|
|
393
365
|
|
|
394
366
|
exports.ZoomUserType = void 0;
|
|
395
367
|
(function (ZoomUserType) {
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
368
|
+
ZoomUserType[ZoomUserType["Basic"] = 1] = "Basic";
|
|
369
|
+
ZoomUserType[ZoomUserType["Licensed"] = 2] = "Licensed";
|
|
370
|
+
ZoomUserType[ZoomUserType["Unassigned"] = 4] = "Unassigned";
|
|
371
|
+
ZoomUserType[ZoomUserType["None"] = 99] = "None";
|
|
400
372
|
})(exports.ZoomUserType || (exports.ZoomUserType = {}));
|
|
401
373
|
|
|
402
374
|
// MARK: Parser
|
|
403
375
|
const logZoomErrorToConsole = logZoomServerErrorFunction('Zoom');
|
|
404
376
|
async function parseZoomApiError(responseError) {
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
377
|
+
const data = await responseError.response.json().catch((x) => undefined);
|
|
378
|
+
let result;
|
|
379
|
+
if (data) {
|
|
380
|
+
result = parseZoomApiServerErrorResponseData(data, responseError);
|
|
381
|
+
}
|
|
382
|
+
return result;
|
|
411
383
|
}
|
|
412
384
|
function parseZoomApiServerErrorResponseData(zoomServerError, responseError) {
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
385
|
+
let result;
|
|
386
|
+
if (zoomServerError) {
|
|
387
|
+
switch (zoomServerError.code) {
|
|
388
|
+
default:
|
|
389
|
+
result = parseZoomServerErrorData(zoomServerError, responseError);
|
|
390
|
+
break;
|
|
391
|
+
}
|
|
419
392
|
}
|
|
420
|
-
|
|
421
|
-
return result;
|
|
393
|
+
return result;
|
|
422
394
|
}
|
|
423
395
|
const handleZoomErrorFetch = handleZoomErrorFetchFactory(parseZoomApiError, logZoomErrorToConsole);
|
|
424
396
|
|
|
@@ -431,46 +403,46 @@ const ZOOM_ACCOUNTS_INVALID_GRANT_ERROR_CODE = 'invalid_grant';
|
|
|
431
403
|
* Thrown if the call to the Zoom API creating an access token using a refresh token fails.
|
|
432
404
|
*/
|
|
433
405
|
class ZoomOAuthAccessTokenError extends fetch.FetchRequestFactoryError {
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
406
|
+
errorCode;
|
|
407
|
+
constructor(errorCode) {
|
|
408
|
+
super(`ZoomOAuthAccessTokenError: ${errorCode}`);
|
|
409
|
+
this.errorCode = errorCode;
|
|
410
|
+
}
|
|
439
411
|
}
|
|
440
412
|
/**
|
|
441
413
|
* Thrown if a valid ZoomAccessToken cannot be retrieved successfully.
|
|
442
414
|
*/
|
|
443
415
|
class ZoomOAuthAuthFailureError extends fetch.FetchRequestFactoryError {
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
416
|
+
reason;
|
|
417
|
+
constructor(reason) {
|
|
418
|
+
super(`Failed to retrieve proper authentication for the API call. Reason: ${reason}`);
|
|
419
|
+
this.reason = reason;
|
|
420
|
+
}
|
|
449
421
|
}
|
|
450
422
|
const logZoomOAuthErrorToConsole = logZoomServerErrorFunction('ZoomOAuth');
|
|
451
423
|
async function parseZoomOAuthError(responseError) {
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
424
|
+
const data = await responseError.response.json().catch((x) => undefined);
|
|
425
|
+
let result;
|
|
426
|
+
if (data) {
|
|
427
|
+
result = parseZoomOAuthServerErrorResponseData(data, responseError);
|
|
428
|
+
}
|
|
429
|
+
return result;
|
|
458
430
|
}
|
|
459
431
|
function parseZoomOAuthServerErrorResponseData(zoomServerError, responseError) {
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
432
|
+
let result;
|
|
433
|
+
if (zoomServerError) {
|
|
434
|
+
const potentialErrorStringCode = zoomServerError.error;
|
|
435
|
+
const errorCode = potentialErrorStringCode ?? zoomServerError.code;
|
|
436
|
+
switch (errorCode) {
|
|
437
|
+
case ZOOM_ACCOUNTS_INVALID_GRANT_ERROR_CODE:
|
|
438
|
+
result = new ZoomOAuthAccessTokenError(errorCode);
|
|
439
|
+
break;
|
|
440
|
+
default:
|
|
441
|
+
result = parseZoomServerErrorData(zoomServerError, responseError);
|
|
442
|
+
break;
|
|
443
|
+
}
|
|
471
444
|
}
|
|
472
|
-
|
|
473
|
-
return result;
|
|
445
|
+
return result;
|
|
474
446
|
}
|
|
475
447
|
const handleZoomOAuthErrorFetch = handleZoomErrorFetchFactory(parseZoomOAuthError, logZoomOAuthErrorToConsole);
|
|
476
448
|
|
|
@@ -478,76 +450,72 @@ const handleZoomOAuthErrorFetch = handleZoomErrorFetchFactory(parseZoomOAuthErro
|
|
|
478
450
|
* Generates a new ZoomAccessTokenStringFactory.
|
|
479
451
|
*/
|
|
480
452
|
function zoomAccessTokenStringFactory(zoomAccessTokenFactory) {
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
453
|
+
return async () => {
|
|
454
|
+
const token = await zoomAccessTokenFactory();
|
|
455
|
+
if (!token?.accessToken) {
|
|
456
|
+
throw new ZoomOAuthAuthFailureError();
|
|
457
|
+
}
|
|
458
|
+
return token.accessToken;
|
|
459
|
+
};
|
|
488
460
|
}
|
|
489
461
|
|
|
490
|
-
const DEFAULT_ZOOM_RATE_LIMITED_TOO_MANY_REQUETS_LOG_FUNCTION = headers => {
|
|
491
|
-
|
|
462
|
+
const DEFAULT_ZOOM_RATE_LIMITED_TOO_MANY_REQUETS_LOG_FUNCTION = (headers) => {
|
|
463
|
+
console.warn(`zoomRateLimitedFetchHandler(): Too many requests made. The limit is ${headers.limit} requests per reset period. RetryAt is set for ${headers.retryAfterAt}.`);
|
|
492
464
|
};
|
|
493
465
|
function zoomRateLimitedFetchHandler(config) {
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
466
|
+
const onTooManyRequests = config?.onTooManyRequests !== false ? (config?.onTooManyRequests ?? DEFAULT_ZOOM_RATE_LIMITED_TOO_MANY_REQUETS_LOG_FUNCTION) : undefined;
|
|
467
|
+
const defaultLimit = config?.maxRateLimit ?? DEFAULT_ZOOM_API_RATE_LIMIT;
|
|
468
|
+
const defaultResetPeriod = config?.resetPeriod ?? DEFAULT_ZOOM_API_RATE_LIMIT_RESET_PERIOD;
|
|
469
|
+
function configForLimit(limit, resetAt) {
|
|
470
|
+
return {
|
|
471
|
+
limit: defaultLimit,
|
|
472
|
+
startLimitAt: 2,
|
|
473
|
+
cooldownRate: 1,
|
|
474
|
+
exponentRate: 1.2,
|
|
475
|
+
maxWaitTime: util.MS_IN_SECOND * 5,
|
|
476
|
+
resetPeriod: defaultResetPeriod,
|
|
477
|
+
resetAt
|
|
478
|
+
};
|
|
479
|
+
}
|
|
480
|
+
const defaultConfig = configForLimit();
|
|
481
|
+
const rateLimiter = util.resetPeriodPromiseRateLimiter(defaultConfig);
|
|
482
|
+
return fetch.rateLimitedFetchHandler({
|
|
483
|
+
rateLimiter,
|
|
484
|
+
updateWithResponse: function (response, fetchResponseError) {
|
|
485
|
+
const hasLimitHeader = response.headers.has(ZOOM_RATE_LIMIT_REMAINING_HEADER);
|
|
486
|
+
let shouldRetry = false;
|
|
487
|
+
// let enabled = false; // rate limiter should not be turned off
|
|
488
|
+
if (hasLimitHeader) {
|
|
489
|
+
const headerDetails = zoomRateLimitHeaderDetails(response.headers);
|
|
490
|
+
if (headerDetails) {
|
|
491
|
+
const { type, limit, retryAfterAt, remaining } = headerDetails;
|
|
492
|
+
if (response.status === ZOOM_TOO_MANY_REQUESTS_HTTP_STATUS_CODE) {
|
|
493
|
+
// For simple query-per-second rate limits, just schedule a retry
|
|
494
|
+
if (type === 'QPS') {
|
|
495
|
+
shouldRetry = true;
|
|
496
|
+
try {
|
|
497
|
+
onTooManyRequests?.(headerDetails, response, fetchResponseError);
|
|
498
|
+
}
|
|
499
|
+
catch (e) { }
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
// NOTE: typically it seems like these headers are not available usually.
|
|
503
|
+
// There is a daily limit for message requests
|
|
504
|
+
if (limit != null && retryAfterAt != null && remaining != null) {
|
|
505
|
+
if (limit !== defaultLimit) {
|
|
506
|
+
const newConfig = configForLimit(limit, retryAfterAt);
|
|
507
|
+
rateLimiter.setConfig(newConfig, false);
|
|
508
|
+
}
|
|
509
|
+
rateLimiter.setRemainingLimit(remaining);
|
|
510
|
+
rateLimiter.setNextResetAt(retryAfterAt);
|
|
511
|
+
// enabled = true;
|
|
512
|
+
}
|
|
513
|
+
}
|
|
540
514
|
}
|
|
541
|
-
rateLimiter.
|
|
542
|
-
|
|
543
|
-
// enabled = true;
|
|
544
|
-
}
|
|
515
|
+
// rateLimiter.setEnabled(enabled);
|
|
516
|
+
return shouldRetry;
|
|
545
517
|
}
|
|
546
|
-
|
|
547
|
-
// rateLimiter.setEnabled(enabled);
|
|
548
|
-
return shouldRetry;
|
|
549
|
-
}
|
|
550
|
-
});
|
|
518
|
+
});
|
|
551
519
|
}
|
|
552
520
|
|
|
553
521
|
/**
|
|
@@ -556,76 +524,69 @@ function zoomRateLimitedFetchHandler(config) {
|
|
|
556
524
|
const ZOOM_API_URL = 'https://api.zoom.us/v2';
|
|
557
525
|
|
|
558
526
|
function zoomFactory(factoryConfig) {
|
|
559
|
-
|
|
560
|
-
oauthContext
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
config,
|
|
622
|
-
zoomRateLimiter: fetchHandler._rateLimiter
|
|
623
|
-
};
|
|
624
|
-
const zoom = {
|
|
625
|
-
zoomServerContext: zoomContext
|
|
527
|
+
const { oauthContext } = factoryConfig;
|
|
528
|
+
const serverAccessTokenStringFactory = zoomAccessTokenStringFactory(oauthContext.loadAccessToken);
|
|
529
|
+
const fetchHandler = zoomRateLimitedFetchHandler(factoryConfig.rateLimiterConfig);
|
|
530
|
+
const { logZoomServerErrorFunction, fetchFactory = (input) => fetch.fetchApiFetchService.makeFetch({
|
|
531
|
+
baseUrl: ZOOM_API_URL,
|
|
532
|
+
baseRequest: async () => ({
|
|
533
|
+
headers: {
|
|
534
|
+
'Content-Type': 'application/json',
|
|
535
|
+
Authorization: `Bearer ${await input.zoomAccessTokenStringFactory()}`
|
|
536
|
+
}
|
|
537
|
+
}),
|
|
538
|
+
fetchHandler,
|
|
539
|
+
timeout: 20 * 1000, // 20 second timeout
|
|
540
|
+
requireOkResponse: true, // enforce ok response
|
|
541
|
+
useTimeout: true // use timeout
|
|
542
|
+
}) } = factoryConfig;
|
|
543
|
+
return (config) => {
|
|
544
|
+
const baseFetch = fetchFactory({
|
|
545
|
+
zoomAccessTokenStringFactory: serverAccessTokenStringFactory
|
|
546
|
+
});
|
|
547
|
+
const serverFetch = handleZoomErrorFetch(baseFetch, logZoomServerErrorFunction);
|
|
548
|
+
const serverFetchJson = fetch.fetchJsonFunction(serverFetch, {
|
|
549
|
+
handleFetchJsonParseErrorFunction: fetch.returnNullHandleFetchJsonParseErrorFunction
|
|
550
|
+
});
|
|
551
|
+
// MARK: Make User Context
|
|
552
|
+
const makeUserContext = (input) => {
|
|
553
|
+
const userAccessTokenFactory = oauthContext.makeUserAccessTokenFactory({
|
|
554
|
+
refreshToken: input.refreshToken,
|
|
555
|
+
userAccessTokenCache: input.accessTokenCache
|
|
556
|
+
});
|
|
557
|
+
const userAccessTokenStringFactory = zoomAccessTokenStringFactory(userAccessTokenFactory);
|
|
558
|
+
const userFetch = fetchFactory({
|
|
559
|
+
zoomAccessTokenStringFactory: userAccessTokenStringFactory
|
|
560
|
+
});
|
|
561
|
+
const userFetchJson = fetch.fetchJsonFunction(userFetch, {
|
|
562
|
+
handleFetchJsonParseErrorFunction: fetch.returnNullHandleFetchJsonParseErrorFunction
|
|
563
|
+
});
|
|
564
|
+
const result = {
|
|
565
|
+
zoomServerContext: zoomContext,
|
|
566
|
+
type: 'user',
|
|
567
|
+
fetch: userFetch,
|
|
568
|
+
fetchJson: userFetchJson,
|
|
569
|
+
userFetch,
|
|
570
|
+
userFetchJson,
|
|
571
|
+
zoomRateLimiter: fetchHandler._rateLimiter
|
|
572
|
+
};
|
|
573
|
+
return result;
|
|
574
|
+
};
|
|
575
|
+
const zoomContext = {
|
|
576
|
+
type: 'server',
|
|
577
|
+
fetch: serverFetch,
|
|
578
|
+
fetchJson: serverFetchJson,
|
|
579
|
+
serverFetch,
|
|
580
|
+
serverFetchJson,
|
|
581
|
+
makeUserContext,
|
|
582
|
+
config,
|
|
583
|
+
zoomRateLimiter: fetchHandler._rateLimiter
|
|
584
|
+
};
|
|
585
|
+
const zoom = {
|
|
586
|
+
zoomServerContext: zoomContext
|
|
587
|
+
};
|
|
588
|
+
return zoom;
|
|
626
589
|
};
|
|
627
|
-
return zoom;
|
|
628
|
-
};
|
|
629
590
|
}
|
|
630
591
|
|
|
631
592
|
/**
|
|
@@ -635,9 +596,9 @@ function zoomFactory(factoryConfig) {
|
|
|
635
596
|
* @returns
|
|
636
597
|
*/
|
|
637
598
|
function serverAccessToken(context) {
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
599
|
+
return (input) => {
|
|
600
|
+
return context.fetchJson(`/token?grant_type=account_credentials&account_id=${input?.accountId ?? context.config.accountId}`, zoomOAuthApiFetchJsonInput(context, input));
|
|
601
|
+
};
|
|
641
602
|
}
|
|
642
603
|
/**
|
|
643
604
|
* Retrieves a new AccessToken for a user using their refresh token.
|
|
@@ -646,27 +607,27 @@ function serverAccessToken(context) {
|
|
|
646
607
|
* @returns
|
|
647
608
|
*/
|
|
648
609
|
function userAccessToken(context) {
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
610
|
+
return (input) => {
|
|
611
|
+
const refreshToken = input.refreshToken;
|
|
612
|
+
return context.fetchJson(`/token?grant_type=refresh_token&refresh_token=${refreshToken}`, zoomOAuthApiFetchJsonInput(context, input));
|
|
613
|
+
};
|
|
653
614
|
}
|
|
654
615
|
function zoomOAuthApiFetchJsonInput(context, input) {
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
616
|
+
const clientId = input?.client?.clientId ?? context.config.clientId;
|
|
617
|
+
const clientSecret = input?.client?.clientSecret ?? context.config.clientSecret;
|
|
618
|
+
const fetchJsonInput = {
|
|
619
|
+
headers: {
|
|
620
|
+
Authorization: zoomOAuthServerBasicAuthorizationHeaderValue({
|
|
621
|
+
clientId,
|
|
622
|
+
clientSecret
|
|
623
|
+
})
|
|
624
|
+
},
|
|
625
|
+
method: 'POST'
|
|
626
|
+
};
|
|
627
|
+
return fetchJsonInput;
|
|
667
628
|
}
|
|
668
629
|
function zoomOAuthServerBasicAuthorizationHeaderValue(input) {
|
|
669
|
-
|
|
630
|
+
return `Basic ${Buffer.from(`${input.clientId}:${input.clientSecret}`).toString('base64')}`;
|
|
670
631
|
}
|
|
671
632
|
|
|
672
633
|
/**
|
|
@@ -675,85 +636,77 @@ function zoomOAuthServerBasicAuthorizationHeaderValue(input) {
|
|
|
675
636
|
const ZOOM_OAUTH_API_URL = 'https://zoom.us/oauth';
|
|
676
637
|
|
|
677
638
|
function zoomOAuthFactory(factoryConfig) {
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
639
|
+
const fetchHandler = zoomRateLimitedFetchHandler();
|
|
640
|
+
const { logZoomServerErrorFunction, fetchFactory = (_) => fetch.fetchApiFetchService.makeFetch({
|
|
641
|
+
baseUrl: ZOOM_OAUTH_API_URL,
|
|
642
|
+
baseRequest: {
|
|
643
|
+
headers: {
|
|
644
|
+
'Content-Type': 'application/json'
|
|
645
|
+
}
|
|
646
|
+
},
|
|
647
|
+
fetchHandler,
|
|
648
|
+
timeout: 20 * 1000, // 20 second timeout
|
|
649
|
+
requireOkResponse: true, // enforce ok response
|
|
650
|
+
useTimeout: true // use timeout
|
|
651
|
+
}) } = factoryConfig;
|
|
652
|
+
return (config) => {
|
|
653
|
+
if (!config.clientId) {
|
|
654
|
+
throw new Error('ZoomOAuthConfig missing clientId.');
|
|
686
655
|
}
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
return zoomOAuthZoomAccessTokenFactory({
|
|
741
|
-
tokenRefresher: userTokenRefresher,
|
|
742
|
-
accessTokenCache: input.userAccessTokenCache
|
|
743
|
-
});
|
|
744
|
-
};
|
|
745
|
-
const oauthContext = {
|
|
746
|
-
fetch: fetch$1,
|
|
747
|
-
fetchJson,
|
|
748
|
-
loadAccessToken,
|
|
749
|
-
makeUserAccessTokenFactory,
|
|
750
|
-
config
|
|
751
|
-
};
|
|
752
|
-
const zoomOAuth = {
|
|
753
|
-
oauthContext
|
|
656
|
+
else if (!config.clientSecret) {
|
|
657
|
+
throw new Error('ZoomOAuthConfig missing clientSecret.');
|
|
658
|
+
}
|
|
659
|
+
else if (!config.accountId) {
|
|
660
|
+
throw new Error('ZoomOAuthConfig missing accountId.');
|
|
661
|
+
}
|
|
662
|
+
const baseFetch = fetchFactory();
|
|
663
|
+
const fetch$1 = handleZoomOAuthErrorFetch(baseFetch, logZoomServerErrorFunction);
|
|
664
|
+
const fetchJson = fetch.fetchJsonFunction(fetch$1, {
|
|
665
|
+
handleFetchJsonParseErrorFunction: fetch.returnNullHandleFetchJsonParseErrorFunction
|
|
666
|
+
});
|
|
667
|
+
function accessTokenFromTokenResponse(result) {
|
|
668
|
+
const createdAt = new Date().getTime();
|
|
669
|
+
const { access_token, api_url, scope, expires_in } = result;
|
|
670
|
+
const accessToken = {
|
|
671
|
+
accessToken: access_token,
|
|
672
|
+
apiDomain: api_url,
|
|
673
|
+
expiresIn: expires_in,
|
|
674
|
+
expiresAt: new Date(createdAt + expires_in * util.MS_IN_SECOND),
|
|
675
|
+
scope
|
|
676
|
+
};
|
|
677
|
+
return accessToken;
|
|
678
|
+
}
|
|
679
|
+
const tokenRefresher = async () => {
|
|
680
|
+
const accessToken = await serverAccessToken(oauthContext)();
|
|
681
|
+
return accessTokenFromTokenResponse(accessToken);
|
|
682
|
+
};
|
|
683
|
+
const loadAccessToken = zoomOAuthZoomAccessTokenFactory({
|
|
684
|
+
tokenRefresher,
|
|
685
|
+
accessTokenCache: config.accessTokenCache
|
|
686
|
+
});
|
|
687
|
+
// User Access Token
|
|
688
|
+
const makeUserAccessTokenFactory = (input) => {
|
|
689
|
+
const userTokenRefresher = async () => {
|
|
690
|
+
const accessToken = await userAccessToken(oauthContext)(input);
|
|
691
|
+
return accessTokenFromTokenResponse(accessToken);
|
|
692
|
+
};
|
|
693
|
+
return zoomOAuthZoomAccessTokenFactory({
|
|
694
|
+
tokenRefresher: userTokenRefresher,
|
|
695
|
+
accessTokenCache: input.userAccessTokenCache
|
|
696
|
+
});
|
|
697
|
+
};
|
|
698
|
+
const oauthContext = {
|
|
699
|
+
fetch: fetch$1,
|
|
700
|
+
fetchJson,
|
|
701
|
+
loadAccessToken,
|
|
702
|
+
makeUserAccessTokenFactory,
|
|
703
|
+
config
|
|
704
|
+
};
|
|
705
|
+
const zoomOAuth = {
|
|
706
|
+
oauthContext
|
|
707
|
+
};
|
|
708
|
+
return zoomOAuth;
|
|
754
709
|
};
|
|
755
|
-
return zoomOAuth;
|
|
756
|
-
};
|
|
757
710
|
}
|
|
758
711
|
/**
|
|
759
712
|
* Creates a ZoomOAuthZoomAccessTokenFactoryConfig
|
|
@@ -762,49 +715,47 @@ function zoomOAuthFactory(factoryConfig) {
|
|
|
762
715
|
* @returns
|
|
763
716
|
*/
|
|
764
717
|
function zoomOAuthZoomAccessTokenFactory(config) {
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
const cachedToken = await accessTokenCache?.loadCachedToken();
|
|
779
|
-
if (cachedToken) {
|
|
780
|
-
currentToken = cachedToken;
|
|
781
|
-
}
|
|
782
|
-
}
|
|
783
|
-
// check expiration
|
|
784
|
-
if (currentToken != null) {
|
|
785
|
-
const isExpired = new Date().getTime() + tokenExpirationBuffer >= currentToken.expiresAt.getTime();
|
|
786
|
-
if (isExpired) {
|
|
787
|
-
currentToken = null;
|
|
788
|
-
}
|
|
789
|
-
}
|
|
790
|
-
// load from source
|
|
791
|
-
if (!currentToken) {
|
|
792
|
-
try {
|
|
793
|
-
currentToken = await tokenRefresher();
|
|
794
|
-
} catch (e) {
|
|
795
|
-
console.error(`zoomOAuthZoomAccessTokenFactory(): Failed retrieving new token from tokenRefresher: `, e);
|
|
796
|
-
throw new ZoomOAuthAuthFailureError('Token Refresh Failed');
|
|
797
|
-
}
|
|
798
|
-
if (currentToken) {
|
|
799
|
-
try {
|
|
800
|
-
await accessTokenCache?.updateCachedToken(currentToken);
|
|
801
|
-
} catch (e) {
|
|
802
|
-
// do nothing
|
|
718
|
+
const { tokenRefresher, accessTokenCache, tokenExpirationBuffer: inputTokenExpirationBuffer } = config;
|
|
719
|
+
const tokenExpirationBuffer = inputTokenExpirationBuffer ?? util.MS_IN_MINUTE;
|
|
720
|
+
/**
|
|
721
|
+
* Caches the token internally here until it expires.
|
|
722
|
+
*/
|
|
723
|
+
let currentToken = null;
|
|
724
|
+
return async () => {
|
|
725
|
+
// load from cache
|
|
726
|
+
if (!currentToken) {
|
|
727
|
+
const cachedToken = await accessTokenCache?.loadCachedToken();
|
|
728
|
+
if (cachedToken) {
|
|
729
|
+
currentToken = cachedToken;
|
|
730
|
+
}
|
|
803
731
|
}
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
732
|
+
// check expiration
|
|
733
|
+
if (currentToken != null) {
|
|
734
|
+
const isExpired = new Date().getTime() + tokenExpirationBuffer >= currentToken.expiresAt.getTime();
|
|
735
|
+
if (isExpired) {
|
|
736
|
+
currentToken = null;
|
|
737
|
+
}
|
|
738
|
+
}
|
|
739
|
+
// load from source
|
|
740
|
+
if (!currentToken) {
|
|
741
|
+
try {
|
|
742
|
+
currentToken = await tokenRefresher();
|
|
743
|
+
}
|
|
744
|
+
catch (e) {
|
|
745
|
+
console.error(`zoomOAuthZoomAccessTokenFactory(): Failed retrieving new token from tokenRefresher: `, e);
|
|
746
|
+
throw new ZoomOAuthAuthFailureError('Token Refresh Failed');
|
|
747
|
+
}
|
|
748
|
+
if (currentToken) {
|
|
749
|
+
try {
|
|
750
|
+
await accessTokenCache?.updateCachedToken(currentToken);
|
|
751
|
+
}
|
|
752
|
+
catch (e) {
|
|
753
|
+
// do nothing
|
|
754
|
+
}
|
|
755
|
+
}
|
|
756
|
+
}
|
|
757
|
+
return currentToken;
|
|
758
|
+
};
|
|
808
759
|
}
|
|
809
760
|
|
|
810
761
|
exports.DEFAULT_ZOOM_API_RATE_LIMIT = DEFAULT_ZOOM_API_RATE_LIMIT;
|