@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.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
- return data => {
21
- const {
22
- next_page_token,
23
- page_count,
24
- page_number,
25
- page_size,
26
- total_records
27
- } = data;
28
- return {
29
- data: data[dataTypeKey],
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
- return fetch.fetchPageFactory({
47
- ...defaults,
48
- fetch: fetch$1,
49
- readFetchPageResultInfo: function (result) {
50
- return {
51
- nextPageCursor: result.next_page_token,
52
- hasNext: Boolean(result.next_page_token) // has more when a non-empty next_page_token is returned
53
- };
54
- },
55
- buildInputForNextPage: function (pageResult, input, options) {
56
- return {
57
- ...input,
58
- next_page_token: pageResult.nextPageCursor,
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
- get code() {
74
- return this.error.code;
75
- }
76
- constructor(error) {
77
- super(error.message);
78
- this.error = void 0;
79
- this.error = error;
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
- constructor(data, responseError) {
87
- super(data);
88
- this.data = void 0;
89
- this.responseError = void 0;
90
- this.data = data;
91
- this.responseError = responseError;
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
- return error => {
102
- if (error instanceof ZoomServerFetchResponseError) {
103
- console.log(`${zoomApiNamePrefix}Error(${error.responseError.response.status}): `, {
104
- error,
105
- errorData: error.data
106
- });
107
- } else if (error instanceof ZoomServerError) {
108
- console.log(`${zoomApiNamePrefix}Error(code:${error.code}): `, {
109
- error
110
- });
111
- } else {
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
- return (fetch$1, logError = defaultLogError) => {
126
- return async (x, y) => {
127
- try {
128
- return await fetch$1(x, y); // await to catch thrown errors
129
- } catch (e) {
130
- if (e instanceof fetch.FetchResponseError) {
131
- const error = await parseZoomError(e);
132
- if (error) {
133
- logError(error); // log before throwing.
134
- throw error;
135
- }
136
- }
137
- throw e;
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
- const limitHeader = headers.get(ZOOM_RATE_LIMIT_LIMIT_HEADER);
160
- const remainingHeader = headers.get(ZOOM_RATE_LIMIT_REMAINING_HEADER);
161
- const retryAfterHeader = headers.get(ZOOM_RATE_LIMIT_RETRY_AFTER_HEADER);
162
- const categoryHeader = headers.get(ZOOM_RATE_LIMIT_CATEGORY_HEADER);
163
- const typeHeader = headers.get(ZOOM_RATE_LIMIT_TYPE_HEADER);
164
- let result = null;
165
- if (categoryHeader != null && typeHeader != null) {
166
- const category = categoryHeader;
167
- const type = typeHeader;
168
- const limit = limitHeader ? Number(limitHeader) : undefined;
169
- const remaining = remainingHeader ? Number(remainingHeader) : undefined;
170
- const retryAfter = retryAfterHeader ? Number(retryAfterHeader) : undefined;
171
- const retryAfterAt = retryAfterHeader ? new Date(retryAfterHeader) : undefined;
172
- result = {
173
- limit,
174
- remaining,
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
- get headerDetails() {
185
- return zoomRateLimitHeaderDetails(this.responseError.response.headers);
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
- let result;
197
- if (responseError.response.status === ZOOM_TOO_MANY_REQUESTS_HTTP_STATUS_CODE) {
198
- result = new ZoomTooManyRequestsError(zoomServerError, responseError);
199
- console.warn('ZoomTooManyRequestsError', {
200
- result,
201
- responseError,
202
- headerDetails: result.headerDetails
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
- return result;
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
- const omitKeys = ['silenceError'];
220
- return fetch.mergeMakeUrlSearchParamsOptions([options, {
221
- omitKeys
222
- }]);
195
+ const omitKeys = ['silenceError'];
196
+ return fetch.mergeMakeUrlSearchParamsOptions([options, { omitKeys }]);
223
197
  }
224
198
  function silenceZoomErrorWithCodesFunction(codes, returnFn) {
225
- const codesSet = new Set(util.asArray(codes));
226
- return silence => {
227
- return reason => {
228
- if (silence !== false && reason instanceof ZoomServerFetchResponseError) {
229
- if (codesSet.has(reason.code)) {
230
- return returnFn?.(reason);
231
- }
232
- }
233
- throw reason;
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
- return input => context.fetchJson(`/meetings/${input.meetingId}`, 'GET');
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
- return input => context.fetchJson(`/users/${input.user}/meetings`, 'GET').then(mapToZoomPageResult('meetings'));
222
+ return (input) => context.fetchJson(`/users/${input.user}/meetings`, 'GET').then(mapToZoomPageResult('meetings'));
249
223
  }
250
224
  function listMeetingsForUserPageFactory(context) {
251
- return zoomFetchPageFactory(listMeetingsForUser(context));
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
- return input => {
258
- return context.fetchJson(`/users/${input.user}/meetings`, {
259
- method: 'POST',
260
- body: JSON.stringify(input.template)
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
- return input => context.fetchJson(`/meetings/${input.meetingId}?${fetch.makeUrlSearchParams({
269
- occurrence_id: input.occurrence_id
270
- })}`, {
271
- method: 'PATCH',
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
- const silenceDoesNotExistError = silenceZoomErrorWithCodesFunction(DELETE_MEETING_DOES_NOT_EXIST_ERROR_CODE);
281
- return input => context.fetchJson(`/meetings/${input.meetingId}?${fetch.makeUrlSearchParams(input, omitSilenceZoomErrorKeys())}`, 'DELETE').catch(silenceDoesNotExistError(input.silenceError));
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
- return input => context.fetchJson(`/past_meetings/${input.meetingId}`, 'GET');
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
- return input => context.fetchJson(`/past_meetings/${input.meetingId}/participants`, 'GET').then(mapToZoomPageResult('participants'));
265
+ return (input) => context.fetchJson(`/past_meetings/${input.meetingId}/participants`, 'GET').then(mapToZoomPageResult('participants'));
294
266
  }
295
267
  function getPastMeetingParticipantsPageFactory(context) {
296
- return zoomFetchPageFactory(getPastMeetingParticipants(context));
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
- ZoomMeetingType[ZoomMeetingType["INSTANT"] = 1] = "INSTANT";
311
- ZoomMeetingType[ZoomMeetingType["SCHEDULED"] = 2] = "SCHEDULED";
312
- ZoomMeetingType[ZoomMeetingType["RECURRING_NO_FIXED_TIME"] = 3] = "RECURRING_NO_FIXED_TIME";
313
- ZoomMeetingType[ZoomMeetingType["PMI"] = 4] = "PMI";
314
- ZoomMeetingType[ZoomMeetingType["RECURRING_FIXED_TIME"] = 8] = "RECURRING_FIXED_TIME";
315
- ZoomMeetingType[ZoomMeetingType["SCREEN_SHARE_ONLY"] = 10] = "SCREEN_SHARE_ONLY";
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
- ZoomRecurrenceType[ZoomRecurrenceType["DAILY"] = 1] = "DAILY";
320
- ZoomRecurrenceType[ZoomRecurrenceType["WEEKLY"] = 2] = "WEEKLY";
321
- ZoomRecurrenceType[ZoomRecurrenceType["MONTHLY"] = 3] = "MONTHLY";
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
- ZoomMonthlyWeek[ZoomMonthlyWeek["LAST_WEEK"] = -1] = "LAST_WEEK";
326
- ZoomMonthlyWeek[ZoomMonthlyWeek["FIRST_WEEK"] = 1] = "FIRST_WEEK";
327
- ZoomMonthlyWeek[ZoomMonthlyWeek["SECOND_WEEK"] = 2] = "SECOND_WEEK";
328
- ZoomMonthlyWeek[ZoomMonthlyWeek["THIRD_WEEK"] = 3] = "THIRD_WEEK";
329
- ZoomMonthlyWeek[ZoomMonthlyWeek["FOURTH_WEEK"] = 4] = "FOURTH_WEEK";
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
- ZoomMonthlyWeekDay[ZoomMonthlyWeekDay["SUNDAY"] = 1] = "SUNDAY";
334
- ZoomMonthlyWeekDay[ZoomMonthlyWeekDay["MONDAY"] = 2] = "MONDAY";
335
- ZoomMonthlyWeekDay[ZoomMonthlyWeekDay["TUESDAY"] = 3] = "TUESDAY";
336
- ZoomMonthlyWeekDay[ZoomMonthlyWeekDay["WEDNESDAY"] = 4] = "WEDNESDAY";
337
- ZoomMonthlyWeekDay[ZoomMonthlyWeekDay["THURSDAY"] = 5] = "THURSDAY";
338
- ZoomMonthlyWeekDay[ZoomMonthlyWeekDay["FRIDAY"] = 6] = "FRIDAY";
339
- ZoomMonthlyWeekDay[ZoomMonthlyWeekDay["SATURDAY"] = 7] = "SATURDAY";
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
- * Automatically approve.
345
- */
346
- ZoomApprovalType[ZoomApprovalType["AUTOMATICALLY_APPROVE"] = 0] = "AUTOMATICALLY_APPROVE";
347
- /**
348
- * Manually approve.
349
- */
350
- ZoomApprovalType[ZoomApprovalType["MANUALLY_APPROVE"] = 1] = "MANUALLY_APPROVE";
351
- /**
352
- * No registration required.
353
- */
354
- ZoomApprovalType[ZoomApprovalType["NO_REGISTRATION_REQUIRED"] = 2] = "NO_REGISTRATION_REQUIRED";
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
- * Attendees register once and can attend any meeting occurrence.
360
- */
361
- ZoomRegistrationType[ZoomRegistrationType["REGISTER_ONCE_ATTEND_ANY"] = 1] = "REGISTER_ONCE_ATTEND_ANY";
362
- /**
363
- * Attendees must register for each meeting occurrence.
364
- */
365
- ZoomRegistrationType[ZoomRegistrationType["REGISTER_FOR_EACH_OCCURRENCE"] = 2] = "REGISTER_FOR_EACH_OCCURRENCE";
366
- /**
367
- * Attendees register once and can select one or more meeting occurrences to attend.
368
- */
369
- ZoomRegistrationType[ZoomRegistrationType["REGISTER_ONCE_CHOOSE_OCCURRENCES"] = 3] = "REGISTER_ONCE_CHOOSE_OCCURRENCES";
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
- return input => context.fetchJson(`/users/${input.userId}`, 'GET');
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
- return input => context.fetchJson(`/users?${fetch.makeUrlSearchParams(input)}`, 'GET').then(mapToZoomPageResult('users'));
360
+ return (input) => context.fetchJson(`/users?${fetch.makeUrlSearchParams(input)}`, 'GET').then(mapToZoomPageResult('users'));
389
361
  }
390
362
  function listUsersPageFactory(context) {
391
- return zoomFetchPageFactory(listUsers(context));
363
+ return zoomFetchPageFactory(listUsers(context));
392
364
  }
393
365
 
394
366
  exports.ZoomUserType = void 0;
395
367
  (function (ZoomUserType) {
396
- ZoomUserType[ZoomUserType["Basic"] = 1] = "Basic";
397
- ZoomUserType[ZoomUserType["Licensed"] = 2] = "Licensed";
398
- ZoomUserType[ZoomUserType["Unassigned"] = 4] = "Unassigned";
399
- ZoomUserType[ZoomUserType["None"] = 99] = "None";
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
- const data = await responseError.response.json().catch(x => undefined);
406
- let result;
407
- if (data) {
408
- result = parseZoomApiServerErrorResponseData(data, responseError);
409
- }
410
- return result;
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
- let result;
414
- if (zoomServerError) {
415
- switch (zoomServerError.code) {
416
- default:
417
- result = parseZoomServerErrorData(zoomServerError, responseError);
418
- break;
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
- constructor(errorCode) {
435
- super(`ZoomOAuthAccessTokenError: ${errorCode}`);
436
- this.errorCode = void 0;
437
- this.errorCode = errorCode;
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
- constructor(reason) {
445
- super(`Failed to retrieve proper authentication for the API call. Reason: ${reason}`);
446
- this.reason = void 0;
447
- this.reason = reason;
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
- const data = await responseError.response.json().catch(x => undefined);
453
- let result;
454
- if (data) {
455
- result = parseZoomOAuthServerErrorResponseData(data, responseError);
456
- }
457
- return result;
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
- let result;
461
- if (zoomServerError) {
462
- const potentialErrorStringCode = zoomServerError.error;
463
- const errorCode = potentialErrorStringCode ?? zoomServerError.code;
464
- switch (errorCode) {
465
- case ZOOM_ACCOUNTS_INVALID_GRANT_ERROR_CODE:
466
- result = new ZoomOAuthAccessTokenError(errorCode);
467
- break;
468
- default:
469
- result = parseZoomServerErrorData(zoomServerError, responseError);
470
- break;
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
- return async () => {
482
- const token = await zoomAccessTokenFactory();
483
- if (!token?.accessToken) {
484
- throw new ZoomOAuthAuthFailureError();
485
- }
486
- return token.accessToken;
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
- console.warn(`zoomRateLimitedFetchHandler(): Too many requests made. The limit is ${headers.limit} requests per reset period. RetryAt is set for ${headers.retryAfterAt}.`);
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
- const onTooManyRequests = config?.onTooManyRequests !== false ? config?.onTooManyRequests ?? DEFAULT_ZOOM_RATE_LIMITED_TOO_MANY_REQUETS_LOG_FUNCTION : undefined;
495
- const defaultLimit = config?.maxRateLimit ?? DEFAULT_ZOOM_API_RATE_LIMIT;
496
- const defaultResetPeriod = config?.resetPeriod ?? DEFAULT_ZOOM_API_RATE_LIMIT_RESET_PERIOD;
497
- function configForLimit(limit, resetAt) {
498
- return {
499
- limit: defaultLimit,
500
- startLimitAt: 2,
501
- cooldownRate: 1,
502
- exponentRate: 1.2,
503
- maxWaitTime: util.MS_IN_SECOND * 5,
504
- resetPeriod: defaultResetPeriod,
505
- resetAt
506
- };
507
- }
508
- const defaultConfig = configForLimit();
509
- const rateLimiter = util.resetPeriodPromiseRateLimiter(defaultConfig);
510
- return fetch.rateLimitedFetchHandler({
511
- rateLimiter,
512
- updateWithResponse: function (response, fetchResponseError) {
513
- const hasLimitHeader = response.headers.has(ZOOM_RATE_LIMIT_REMAINING_HEADER);
514
- let shouldRetry = false;
515
- // let enabled = false; // rate limiter should not be turned off
516
- if (hasLimitHeader) {
517
- const headerDetails = zoomRateLimitHeaderDetails(response.headers);
518
- if (headerDetails) {
519
- const {
520
- type,
521
- limit,
522
- retryAfterAt,
523
- remaining
524
- } = headerDetails;
525
- if (response.status === ZOOM_TOO_MANY_REQUESTS_HTTP_STATUS_CODE) {
526
- // For simple query-per-second rate limits, just schedule a retry
527
- if (type === 'QPS') {
528
- shouldRetry = true;
529
- try {
530
- onTooManyRequests?.(headerDetails, response, fetchResponseError);
531
- } catch (e) {}
532
- }
533
- }
534
- // NOTE: typically it seems like these headers are not available usually.
535
- // There is a daily limit for message requests
536
- if (limit != null && retryAfterAt != null && remaining != null) {
537
- if (limit !== defaultLimit) {
538
- const newConfig = configForLimit(limit, retryAfterAt);
539
- rateLimiter.setConfig(newConfig, false);
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.setRemainingLimit(remaining);
542
- rateLimiter.setNextResetAt(retryAfterAt);
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
- const {
560
- oauthContext
561
- } = factoryConfig;
562
- const serverAccessTokenStringFactory = zoomAccessTokenStringFactory(oauthContext.loadAccessToken);
563
- const fetchHandler = zoomRateLimitedFetchHandler(factoryConfig.rateLimiterConfig);
564
- const {
565
- logZoomServerErrorFunction,
566
- fetchFactory = input => fetch.fetchApiFetchService.makeFetch({
567
- baseUrl: ZOOM_API_URL,
568
- baseRequest: async () => ({
569
- headers: {
570
- 'Content-Type': 'application/json',
571
- Authorization: `Bearer ${await input.zoomAccessTokenStringFactory()}`
572
- }
573
- }),
574
- fetchHandler,
575
- timeout: 20 * 1000,
576
- // 20 second timeout
577
- requireOkResponse: true,
578
- // enforce ok response
579
- useTimeout: true // use timeout
580
- })
581
- } = factoryConfig;
582
- return config => {
583
- const baseFetch = fetchFactory({
584
- zoomAccessTokenStringFactory: serverAccessTokenStringFactory
585
- });
586
- const serverFetch = handleZoomErrorFetch(baseFetch, logZoomServerErrorFunction);
587
- const serverFetchJson = fetch.fetchJsonFunction(serverFetch, {
588
- handleFetchJsonParseErrorFunction: fetch.returnNullHandleFetchJsonParseErrorFunction
589
- });
590
- // MARK: Make User Context
591
- const makeUserContext = input => {
592
- const userAccessTokenFactory = oauthContext.makeUserAccessTokenFactory({
593
- refreshToken: input.refreshToken,
594
- userAccessTokenCache: input.accessTokenCache
595
- });
596
- const userAccessTokenStringFactory = zoomAccessTokenStringFactory(userAccessTokenFactory);
597
- const userFetch = fetchFactory({
598
- zoomAccessTokenStringFactory: userAccessTokenStringFactory
599
- });
600
- const userFetchJson = fetch.fetchJsonFunction(userFetch, {
601
- handleFetchJsonParseErrorFunction: fetch.returnNullHandleFetchJsonParseErrorFunction
602
- });
603
- const result = {
604
- zoomServerContext: zoomContext,
605
- type: 'user',
606
- fetch: userFetch,
607
- fetchJson: userFetchJson,
608
- userFetch,
609
- userFetchJson,
610
- zoomRateLimiter: fetchHandler._rateLimiter
611
- };
612
- return result;
613
- };
614
- const zoomContext = {
615
- type: 'server',
616
- fetch: serverFetch,
617
- fetchJson: serverFetchJson,
618
- serverFetch,
619
- serverFetchJson,
620
- makeUserContext,
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
- return input => {
639
- return context.fetchJson(`/token?grant_type=account_credentials&account_id=${input?.accountId ?? context.config.accountId}`, zoomOAuthApiFetchJsonInput(context, input));
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
- return input => {
650
- const refreshToken = input.refreshToken;
651
- return context.fetchJson(`/token?grant_type=refresh_token&refresh_token=${refreshToken}`, zoomOAuthApiFetchJsonInput(context, input));
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
- const clientId = input?.client?.clientId ?? context.config.clientId;
656
- const clientSecret = input?.client?.clientSecret ?? context.config.clientSecret;
657
- const fetchJsonInput = {
658
- headers: {
659
- Authorization: zoomOAuthServerBasicAuthorizationHeaderValue({
660
- clientId,
661
- clientSecret
662
- })
663
- },
664
- method: 'POST'
665
- };
666
- return fetchJsonInput;
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
- return `Basic ${Buffer.from(`${input.clientId}:${input.clientSecret}`).toString('base64')}`;
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
- const fetchHandler = zoomRateLimitedFetchHandler();
679
- const {
680
- logZoomServerErrorFunction,
681
- fetchFactory = _ => fetch.fetchApiFetchService.makeFetch({
682
- baseUrl: ZOOM_OAUTH_API_URL,
683
- baseRequest: {
684
- headers: {
685
- 'Content-Type': 'application/json'
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
- fetchHandler,
689
- timeout: 20 * 1000,
690
- // 20 second timeout
691
- requireOkResponse: true,
692
- // enforce ok response
693
- useTimeout: true // use timeout
694
- })
695
- } = factoryConfig;
696
- return config => {
697
- if (!config.clientId) {
698
- throw new Error('ZoomOAuthConfig missing clientId.');
699
- } else if (!config.clientSecret) {
700
- throw new Error('ZoomOAuthConfig missing clientSecret.');
701
- } else if (!config.accountId) {
702
- throw new Error('ZoomOAuthConfig missing accountId.');
703
- }
704
- const baseFetch = fetchFactory();
705
- const fetch$1 = handleZoomOAuthErrorFetch(baseFetch, logZoomServerErrorFunction);
706
- const fetchJson = fetch.fetchJsonFunction(fetch$1, {
707
- handleFetchJsonParseErrorFunction: fetch.returnNullHandleFetchJsonParseErrorFunction
708
- });
709
- function accessTokenFromTokenResponse(result) {
710
- const createdAt = new Date().getTime();
711
- const {
712
- access_token,
713
- api_url,
714
- scope,
715
- expires_in
716
- } = result;
717
- const accessToken = {
718
- accessToken: access_token,
719
- apiDomain: api_url,
720
- expiresIn: expires_in,
721
- expiresAt: new Date(createdAt + expires_in * util.MS_IN_SECOND),
722
- scope
723
- };
724
- return accessToken;
725
- }
726
- const tokenRefresher = async () => {
727
- const accessToken = await serverAccessToken(oauthContext)();
728
- return accessTokenFromTokenResponse(accessToken);
729
- };
730
- const loadAccessToken = zoomOAuthZoomAccessTokenFactory({
731
- tokenRefresher,
732
- accessTokenCache: config.accessTokenCache
733
- });
734
- // User Access Token
735
- const makeUserAccessTokenFactory = input => {
736
- const userTokenRefresher = async () => {
737
- const accessToken = await userAccessToken(oauthContext)(input);
738
- return accessTokenFromTokenResponse(accessToken);
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
- const {
766
- tokenRefresher,
767
- accessTokenCache,
768
- tokenExpirationBuffer: inputTokenExpirationBuffer
769
- } = config;
770
- const tokenExpirationBuffer = inputTokenExpirationBuffer ?? util.MS_IN_MINUTE;
771
- /**
772
- * Caches the token internally here until it expires.
773
- */
774
- let currentToken = null;
775
- return async () => {
776
- // load from cache
777
- if (!currentToken) {
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
- return currentToken;
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;