@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.
@@ -48,58 +48,59 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
48
48
  * Configuration for ZoomService
49
49
  */
50
50
  class ZoomOAuthServiceConfig {
51
- zoomOAuth;
52
- factoryConfig;
53
- static assertValidConfig(config) {
54
- const {
55
- zoomOAuth
56
- } = config;
57
- if (!zoomOAuth) {
58
- throw new Error('ZoomOAuthServiceConfig.zoomOAuth is required');
59
- } else {
60
- if (!zoomOAuth.accountId) {
61
- throw new Error('ZoomOAuthServiceConfig.zoomOAuth.accountId is required');
62
- } else if (!zoomOAuth.clientSecret) {
63
- throw new Error('ZoomOAuthServiceConfig.zoomOAuth.clientSecret is required');
64
- } else if (!zoomOAuth.clientId) {
65
- throw new Error('ZoomOAuthServiceConfig.zoomOAuth.clientId is required');
66
- }
67
- }
68
- }
51
+ zoomOAuth;
52
+ factoryConfig;
53
+ static assertValidConfig(config) {
54
+ const { zoomOAuth } = config;
55
+ if (!zoomOAuth) {
56
+ throw new Error('ZoomOAuthServiceConfig.zoomOAuth is required');
57
+ }
58
+ else {
59
+ if (!zoomOAuth.accountId) {
60
+ throw new Error('ZoomOAuthServiceConfig.zoomOAuth.accountId is required');
61
+ }
62
+ else if (!zoomOAuth.clientSecret) {
63
+ throw new Error('ZoomOAuthServiceConfig.zoomOAuth.clientSecret is required');
64
+ }
65
+ else if (!zoomOAuth.clientId) {
66
+ throw new Error('ZoomOAuthServiceConfig.zoomOAuth.clientId is required');
67
+ }
68
+ }
69
+ }
69
70
  }
70
71
  function readZoomOAuthServiceConfigFromConfigService(configService, prefix) {
71
- const prefixString = characterPrefixSuffixInstance({
72
- suffix: '_',
73
- suffixEmptyString: false
74
- }).prefixSuffixString(prefix ?? '');
75
- const accountIdKey = `${prefixString}ZOOM_ACCOUNT_ID`;
76
- const clientIdKey = `${prefixString}ZOOM_CLIENT_ID`;
77
- const clientSecretKey = `${prefixString}ZOOM_CLIENT_SECRET`;
78
- const accountId = configService.getOrThrow(accountIdKey);
79
- const clientId = configService.getOrThrow(clientIdKey);
80
- const clientSecret = configService.getOrThrow(clientSecretKey);
81
- const config = {
82
- zoomOAuth: {
83
- authEntityType: 'account',
84
- accountId,
85
- clientId,
86
- clientSecret
87
- }
88
- };
89
- ZoomOAuthServiceConfig.assertValidConfig(config);
90
- return config;
72
+ const prefixString = characterPrefixSuffixInstance({ suffix: '_', suffixEmptyString: false }).prefixSuffixString(prefix ?? '');
73
+ const accountIdKey = `${prefixString}ZOOM_ACCOUNT_ID`;
74
+ const clientIdKey = `${prefixString}ZOOM_CLIENT_ID`;
75
+ const clientSecretKey = `${prefixString}ZOOM_CLIENT_SECRET`;
76
+ const accountId = configService.getOrThrow(accountIdKey);
77
+ const clientId = configService.getOrThrow(clientIdKey);
78
+ const clientSecret = configService.getOrThrow(clientSecretKey);
79
+ const config = {
80
+ zoomOAuth: {
81
+ authEntityType: 'account',
82
+ accountId,
83
+ clientId,
84
+ clientSecret
85
+ }
86
+ };
87
+ ZoomOAuthServiceConfig.assertValidConfig(config);
88
+ return config;
91
89
  }
92
90
 
93
91
  /**
94
92
  * Service used for retrieving ZoomAccessTokenCache for Zoom services.
95
93
  */
96
- let ZoomOAuthAccessTokenCacheService = class ZoomOAuthAccessTokenCacheService {};
97
- ZoomOAuthAccessTokenCacheService = __decorate([Injectable()], ZoomOAuthAccessTokenCacheService);
94
+ let ZoomOAuthAccessTokenCacheService = class ZoomOAuthAccessTokenCacheService {
95
+ };
96
+ ZoomOAuthAccessTokenCacheService = __decorate([
97
+ Injectable()
98
+ ], ZoomOAuthAccessTokenCacheService);
98
99
  function logMergeZoomOAuthAccessTokenCacheServiceErrorFunction(failedUpdates) {
99
- console.warn(`mergeZoomOAuthAccessTokenCacheServices(): failed updating ${failedUpdates.length} caches.`);
100
- failedUpdates.forEach(([x, e], i) => {
101
- console.warn(`Cache update failure ${i + 1}: - ${e}`);
102
- });
100
+ console.warn(`mergeZoomOAuthAccessTokenCacheServices(): failed updating ${failedUpdates.length} caches.`);
101
+ failedUpdates.forEach(([x, e], i) => {
102
+ console.warn(`Cache update failure ${i + 1}: - ${e}`);
103
+ });
103
104
  }
104
105
  /**
105
106
  * Merges the input services in order to use some as a backup source.
@@ -111,54 +112,62 @@ function logMergeZoomOAuthAccessTokenCacheServiceErrorFunction(failedUpdates) {
111
112
  * @param servicesToMerge Must include atleast one service. Empty arrays will throw an error.
112
113
  */
113
114
  function mergeZoomOAuthAccessTokenCacheServices(inputServicesToMerge, logError) {
114
- const allServices = [...inputServicesToMerge];
115
- const logErrorFunction = typeof logError === 'function' ? logError : logError !== false ? logMergeZoomOAuthAccessTokenCacheServiceErrorFunction : undefined;
116
- if (allServices.length === 0) {
117
- throw new Error('mergeZoomOAuthAccessTokenCacheServices() input cannot be empty.');
118
- }
119
- const loadZoomAccessTokenCache = accessCachesForServices => {
120
- const loadCachedTokenFromFirstService = tryWithPromiseFactoriesFunction({
121
- promiseFactories: accessCachesForServices.map(x => () => x.loadCachedToken().catch(() => null).then(x => {
122
- let result = undefined;
123
- if (x && !isPast(x.expiresAt)) {
124
- result = x; // only return from cache if it is not expired
125
- }
126
- return result;
127
- })),
128
- successOnMaybe: false,
129
- throwErrors: false
130
- });
131
- const cacheForService = {
132
- loadCachedToken: function () {
133
- return loadCachedTokenFromFirstService();
134
- },
135
- updateCachedToken: async function (accessToken) {
136
- return Promise.allSettled(accessCachesForServices.map(x => x.updateCachedToken(accessToken).then(() => null).catch(e => {
137
- return [x, e];
138
- }))).then(x => {
139
- // only find the failures if we're logging
140
- if (logErrorFunction != null) {
141
- const failedUpdates = filterMaybeArrayValues(x.map(y => y.value));
142
- if (failedUpdates.length) {
143
- logErrorFunction(failedUpdates);
144
- }
145
- }
115
+ const allServices = [...inputServicesToMerge];
116
+ const logErrorFunction = typeof logError === 'function' ? logError : logError !== false ? logMergeZoomOAuthAccessTokenCacheServiceErrorFunction : undefined;
117
+ if (allServices.length === 0) {
118
+ throw new Error('mergeZoomOAuthAccessTokenCacheServices() input cannot be empty.');
119
+ }
120
+ const loadZoomAccessTokenCache = (accessCachesForServices) => {
121
+ const loadCachedTokenFromFirstService = tryWithPromiseFactoriesFunction({
122
+ promiseFactories: accessCachesForServices.map((x) => () => x
123
+ .loadCachedToken()
124
+ .catch(() => null)
125
+ .then((x) => {
126
+ let result = undefined;
127
+ if (x && !isPast(x.expiresAt)) {
128
+ result = x; // only return from cache if it is not expired
129
+ }
130
+ return result;
131
+ })),
132
+ successOnMaybe: false,
133
+ throwErrors: false
146
134
  });
147
- }
135
+ const cacheForService = {
136
+ loadCachedToken: function () {
137
+ return loadCachedTokenFromFirstService();
138
+ },
139
+ updateCachedToken: async function (accessToken) {
140
+ return Promise.allSettled(accessCachesForServices.map((x) => x
141
+ .updateCachedToken(accessToken)
142
+ .then(() => null)
143
+ .catch((e) => {
144
+ return [x, e];
145
+ }))).then((x) => {
146
+ // only find the failures if we're logging
147
+ if (logErrorFunction != null) {
148
+ const failedUpdates = filterMaybeArrayValues(x.map((y) => y.value));
149
+ if (failedUpdates.length) {
150
+ logErrorFunction(failedUpdates);
151
+ }
152
+ }
153
+ });
154
+ }
155
+ };
156
+ return cacheForService;
157
+ };
158
+ const allServiceAccessTokenCaches = allServices.map((x) => x.loadZoomAccessTokenCache());
159
+ const allServicesWithCacheForRefreshToken = allServices.filter((x) => x.cacheForRefreshToken != null);
160
+ const cacheForRefreshToken = allServiceAccessTokenCaches.length > 0
161
+ ? (refreshToken) => {
162
+ const allCaches = allServicesWithCacheForRefreshToken.map((x) => x.cacheForRefreshToken(refreshToken));
163
+ return loadZoomAccessTokenCache(allCaches);
164
+ }
165
+ : undefined;
166
+ const service = {
167
+ loadZoomAccessTokenCache: () => loadZoomAccessTokenCache(allServiceAccessTokenCaches),
168
+ cacheForRefreshToken
148
169
  };
149
- return cacheForService;
150
- };
151
- const allServiceAccessTokenCaches = allServices.map(x => x.loadZoomAccessTokenCache());
152
- const allServicesWithCacheForRefreshToken = allServices.filter(x => x.cacheForRefreshToken != null);
153
- const cacheForRefreshToken = allServiceAccessTokenCaches.length > 0 ? refreshToken => {
154
- const allCaches = allServicesWithCacheForRefreshToken.map(x => x.cacheForRefreshToken(refreshToken));
155
- return loadZoomAccessTokenCache(allCaches);
156
- } : undefined;
157
- const service = {
158
- loadZoomAccessTokenCache: () => loadZoomAccessTokenCache(allServiceAccessTokenCaches),
159
- cacheForRefreshToken
160
- };
161
- return service;
170
+ return service;
162
171
  }
163
172
  // MARK: Memory Access Token Cache
164
173
  /**
@@ -167,32 +176,28 @@ function mergeZoomOAuthAccessTokenCacheServices(inputServicesToMerge, logError)
167
176
  * @returns
168
177
  */
169
178
  function memoryZoomOAuthAccessTokenCacheService(existingToken, logAccessToConsole) {
170
- let token = existingToken;
171
- function loadZoomAccessTokenCache() {
172
- const accessTokenCache = {
173
- loadCachedToken: async function () {
174
- if (logAccessToConsole) {
175
- console.log('retrieving access token from memory: ', {
176
- token
177
- });
178
- }
179
- return token;
180
- },
181
- updateCachedToken: async function (accessToken) {
182
- token = accessToken;
183
- if (logAccessToConsole) {
184
- console.log('updating access token in memory: ', {
185
- accessToken
186
- });
187
- }
188
- }
179
+ let token = existingToken;
180
+ function loadZoomAccessTokenCache() {
181
+ const accessTokenCache = {
182
+ loadCachedToken: async function () {
183
+ if (logAccessToConsole) {
184
+ console.log('retrieving access token from memory: ', { token });
185
+ }
186
+ return token;
187
+ },
188
+ updateCachedToken: async function (accessToken) {
189
+ token = accessToken;
190
+ if (logAccessToConsole) {
191
+ console.log('updating access token in memory: ', { accessToken });
192
+ }
193
+ }
194
+ };
195
+ return accessTokenCache;
196
+ }
197
+ return {
198
+ loadZoomAccessTokenCache,
199
+ cacheForRefreshToken: () => loadZoomAccessTokenCache()
189
200
  };
190
- return accessTokenCache;
191
- }
192
- return {
193
- loadZoomAccessTokenCache,
194
- cacheForRefreshToken: () => loadZoomAccessTokenCache()
195
- };
196
201
  }
197
202
  // MARK: File System Access Token Cache
198
203
  const DEFAULT_FILE_ZOOM_ACCOUNTS_ACCESS_TOKEN_CACHE_SERVICE_PATH = '.tmp/zoom-access-tokens.json';
@@ -204,128 +209,137 @@ const DEFAULT_FILE_ZOOM_ACCOUNTS_ACCESS_TOKEN_CACHE_SERVICE_PATH = '.tmp/zoom-ac
204
209
  * @returns
205
210
  */
206
211
  function fileZoomOAuthAccessTokenCacheService(filename = DEFAULT_FILE_ZOOM_ACCOUNTS_ACCESS_TOKEN_CACHE_SERVICE_PATH, useMemoryCache = true) {
207
- let loadedToken = null;
208
- async function loadTokenFile() {
209
- let token = undefined;
210
- if (!loadedToken) {
211
- token = (await readTokenFile()) ?? {};
212
- } else {
213
- token = loadedToken;
214
- }
215
- return token;
216
- }
217
- function readTokenFile() {
218
- return new Promise(resolve => {
219
- mkdirSync(dirname(filename), {
220
- recursive: true
221
- }); // make the directory first
222
- readFile(filename, {}, (x, data) => {
223
- let result = undefined;
224
- if (!x) {
225
- try {
226
- result = JSON.parse(data.toString());
227
- if (result?.token) {
228
- result.token.expiresAt = new Date(result.token.expiresAt);
229
- }
230
- } catch (e) {
231
- console.error('Failed reading token file: ', e);
232
- }
233
- }
234
- resolve(result);
235
- });
236
- }).then(x => {
237
- // update loaded tokens
238
- if (useMemoryCache) {
239
- loadedToken = {
240
- ...loadedToken,
241
- ...x
242
- };
243
- }
244
- return x;
245
- });
246
- }
247
- async function writeTokenFile(tokens) {
248
- return new Promise((resolve, reject) => {
249
- writeFile(filename, JSON.stringify(tokens), {}, x => {
250
- if (!x) {
251
- resolve();
252
- } else {
253
- reject(x);
212
+ let loadedToken = null;
213
+ async function loadTokenFile() {
214
+ let token = undefined;
215
+ if (!loadedToken) {
216
+ token = (await readTokenFile()) ?? {};
254
217
  }
255
- });
256
- });
257
- }
258
- async function deleteTokenFile() {
259
- return new Promise((resolve, reject) => {
260
- rm(filename, x => {
261
- if (!x) {
262
- resolve();
263
- } else {
264
- reject(x);
218
+ else {
219
+ token = loadedToken;
265
220
  }
266
- });
267
- });
268
- }
269
- function loadZoomAccessTokenCache() {
270
- const accessTokenCache = {
271
- loadCachedToken: async function () {
272
- const tokens = await loadTokenFile();
273
- const token = tokens.token;
274
- // console.log('retrieving access token from file: ', { token });
275
221
  return token;
276
- },
277
- updateCachedToken: async function (accessToken) {
278
- const tokenFile = await loadTokenFile();
279
- if (tokenFile) {
280
- tokenFile.token = accessToken;
281
- }
282
- // console.log('updating access token in file: ', { accessToken });
283
- try {
284
- await writeTokenFile(tokenFile);
285
- } catch (e) {
286
- console.error('Failed updating access token in file: ', e);
287
- }
288
- }
222
+ }
223
+ function readTokenFile() {
224
+ return new Promise((resolve) => {
225
+ mkdirSync(dirname(filename), { recursive: true }); // make the directory first
226
+ readFile(filename, {}, (x, data) => {
227
+ let result = undefined;
228
+ if (!x) {
229
+ try {
230
+ result = JSON.parse(data.toString());
231
+ if (result?.token) {
232
+ result.token.expiresAt = new Date(result.token.expiresAt);
233
+ }
234
+ }
235
+ catch (e) {
236
+ console.error('Failed reading token file: ', e);
237
+ }
238
+ }
239
+ resolve(result);
240
+ });
241
+ }).then((x) => {
242
+ // update loaded tokens
243
+ if (useMemoryCache) {
244
+ loadedToken = {
245
+ ...loadedToken,
246
+ ...x
247
+ };
248
+ }
249
+ return x;
250
+ });
251
+ }
252
+ async function writeTokenFile(tokens) {
253
+ return new Promise((resolve, reject) => {
254
+ writeFile(filename, JSON.stringify(tokens), {}, (x) => {
255
+ if (!x) {
256
+ resolve();
257
+ }
258
+ else {
259
+ reject(x);
260
+ }
261
+ });
262
+ });
263
+ }
264
+ async function deleteTokenFile() {
265
+ return new Promise((resolve, reject) => {
266
+ rm(filename, (x) => {
267
+ if (!x) {
268
+ resolve();
269
+ }
270
+ else {
271
+ reject(x);
272
+ }
273
+ });
274
+ });
275
+ }
276
+ function loadZoomAccessTokenCache() {
277
+ const accessTokenCache = {
278
+ loadCachedToken: async function () {
279
+ const tokens = await loadTokenFile();
280
+ const token = tokens.token;
281
+ // console.log('retrieving access token from file: ', { token });
282
+ return token;
283
+ },
284
+ updateCachedToken: async function (accessToken) {
285
+ const tokenFile = await loadTokenFile();
286
+ if (tokenFile) {
287
+ tokenFile.token = accessToken;
288
+ }
289
+ // console.log('updating access token in file: ', { accessToken });
290
+ try {
291
+ await writeTokenFile(tokenFile);
292
+ }
293
+ catch (e) {
294
+ console.error('Failed updating access token in file: ', e);
295
+ }
296
+ }
297
+ };
298
+ return accessTokenCache;
299
+ }
300
+ return {
301
+ loadZoomAccessTokenCache,
302
+ readTokenFile,
303
+ writeTokenFile,
304
+ deleteTokenFile
289
305
  };
290
- return accessTokenCache;
291
- }
292
- return {
293
- loadZoomAccessTokenCache,
294
- readTokenFile,
295
- writeTokenFile,
296
- deleteTokenFile
297
- };
298
306
  }
299
307
 
300
308
  let ZoomOAuthApi = class ZoomOAuthApi {
301
- config;
302
- cacheService;
303
- zoomOAuth;
304
- get oauthContext() {
305
- return this.zoomOAuth.oauthContext;
306
- }
307
- constructor(config, cacheService) {
308
- this.config = config;
309
- this.cacheService = cacheService;
310
- const accessTokenCache = config.zoomOAuth.accessTokenCache ? config.zoomOAuth.accessTokenCache : cacheService.loadZoomAccessTokenCache();
311
- this.zoomOAuth = zoomOAuthFactory(config.factoryConfig ?? {})({
312
- accessTokenCache,
313
- ...config.zoomOAuth
314
- });
315
- }
316
- // MARK: Accessors
317
- get serverAccessToken() {
318
- return serverAccessToken(this.oauthContext);
319
- }
320
- get userAccessToken() {
321
- return userAccessToken(this.oauthContext);
322
- }
309
+ config;
310
+ cacheService;
311
+ zoomOAuth;
312
+ get oauthContext() {
313
+ return this.zoomOAuth.oauthContext;
314
+ }
315
+ constructor(config, cacheService) {
316
+ this.config = config;
317
+ this.cacheService = cacheService;
318
+ const accessTokenCache = config.zoomOAuth.accessTokenCache ? config.zoomOAuth.accessTokenCache : cacheService.loadZoomAccessTokenCache();
319
+ this.zoomOAuth = zoomOAuthFactory(config.factoryConfig ?? {})({
320
+ accessTokenCache,
321
+ ...config.zoomOAuth
322
+ });
323
+ }
324
+ // MARK: Accessors
325
+ get serverAccessToken() {
326
+ return serverAccessToken(this.oauthContext);
327
+ }
328
+ get userAccessToken() {
329
+ return userAccessToken(this.oauthContext);
330
+ }
323
331
  };
324
- ZoomOAuthApi = __decorate([Injectable(), __param(0, Inject(ZoomOAuthServiceConfig)), __param(1, Inject(ZoomOAuthAccessTokenCacheService)), __metadata("design:paramtypes", [ZoomOAuthServiceConfig, ZoomOAuthAccessTokenCacheService])], ZoomOAuthApi);
332
+ ZoomOAuthApi = __decorate([
333
+ Injectable(),
334
+ __param(0, Inject(ZoomOAuthServiceConfig)),
335
+ __param(1, Inject(ZoomOAuthAccessTokenCacheService)),
336
+ __metadata("design:paramtypes", [ZoomOAuthServiceConfig,
337
+ ZoomOAuthAccessTokenCacheService])
338
+ ], ZoomOAuthApi);
325
339
 
326
340
  function zoomOAuthServiceConfigFactory(configService) {
327
- const config = readZoomOAuthServiceConfigFromConfigService(configService);
328
- return config;
341
+ const config = readZoomOAuthServiceConfigFromConfigService(configService);
342
+ return config;
329
343
  }
330
344
  /**
331
345
  * Convenience function used to generate ModuleMetadata for an app's ZoomOAuthModule.
@@ -335,22 +349,21 @@ function zoomOAuthServiceConfigFactory(configService) {
335
349
  * @returns
336
350
  */
337
351
  function appZoomOAuthModuleMetadata(config) {
338
- const {
339
- dependencyModule,
340
- imports,
341
- exports: exports$1,
342
- providers
343
- } = config;
344
- const dependencyModuleImport = dependencyModule ? [dependencyModule] : [];
345
- return {
346
- imports: [ConfigModule, ...dependencyModuleImport, ...(imports ?? [])],
347
- exports: [ZoomOAuthApi, ...(exports$1 ?? [])],
348
- providers: [{
349
- provide: ZoomOAuthServiceConfig,
350
- inject: [ConfigService],
351
- useFactory: config.zoomOAuthServiceConfigFactory ?? zoomOAuthServiceConfigFactory
352
- }, ZoomOAuthApi, ...(providers ?? [])]
353
- };
352
+ const { dependencyModule, imports, exports: exports$1, providers } = config;
353
+ const dependencyModuleImport = dependencyModule ? [dependencyModule] : [];
354
+ return {
355
+ imports: [ConfigModule, ...dependencyModuleImport, ...(imports ?? [])],
356
+ exports: [ZoomOAuthApi, ...(exports$1 ?? [])],
357
+ providers: [
358
+ {
359
+ provide: ZoomOAuthServiceConfig,
360
+ inject: [ConfigService],
361
+ useFactory: config.zoomOAuthServiceConfigFactory ?? zoomOAuthServiceConfigFactory
362
+ },
363
+ ZoomOAuthApi,
364
+ ...(providers ?? [])
365
+ ]
366
+ };
354
367
  }
355
368
 
356
369
  const ZOOM_SECRET_TOKEN_ENV_VAR = 'ZOOM_SECRET_TOKEN';
@@ -358,12 +371,12 @@ const ZOOM_SECRET_TOKEN_ENV_VAR = 'ZOOM_SECRET_TOKEN';
358
371
  * Configuration for ZoomService
359
372
  */
360
373
  class ZoomWebhookServiceConfig {
361
- webhookConfig;
362
- static assertValidConfig(config) {
363
- if (!config.webhookConfig.zoomSecretToken) {
364
- throw new Error('No zoom secret token specified.');
374
+ webhookConfig;
375
+ static assertValidConfig(config) {
376
+ if (!config.webhookConfig.zoomSecretToken) {
377
+ throw new Error('No zoom secret token specified.');
378
+ }
365
379
  }
366
- }
367
380
  }
368
381
 
369
382
  // MARK: Meeting Alert
@@ -388,29 +401,29 @@ const ZOOM_WEBHOOK_MEETING_PERMANENTLY_DELETED_EVENT_TYPE = 'meeting.permanently
388
401
  * @returns
389
402
  */
390
403
  function zoomWebhookEvent(event) {
391
- return {
392
- event: event.event,
393
- event_ts: event.event_ts,
394
- payload: event.payload
395
- };
404
+ return {
405
+ event: event.event,
406
+ event_ts: event.event_ts,
407
+ payload: event.payload
408
+ };
396
409
  }
397
- const zoomEventHandlerFactory = handlerFactory(x => x.event);
410
+ const zoomEventHandlerFactory = handlerFactory((x) => x.event);
398
411
  const zoomEventHandlerConfigurerFactory = handlerConfigurerFactory({
399
- configurerForAccessor: accessor => {
400
- // eslint-disable-next-line
401
- const fnWithKey = handlerMappedSetFunctionFactory(accessor, zoomWebhookEvent);
402
- const configurer = {
403
- ...accessor,
404
- // Meetings
405
- handleMeetingCreated: fnWithKey(ZOOM_WEBHOOK_MEETING_CREATED_EVENT_TYPE),
406
- handleMeetingUpdated: fnWithKey(ZOOM_WEBHOOK_MEETING_UPDATED_EVENT_TYPE),
407
- handleMeetingDeleted: fnWithKey(ZOOM_WEBHOOK_MEETING_DELETED_EVENT_TYPE),
408
- handleMeetingStarted: fnWithKey(ZOOM_WEBHOOK_MEETING_STARTED_EVENT_TYPE),
409
- handleMeetingEnded: fnWithKey(ZOOM_WEBHOOK_MEETING_ENDED_EVENT_TYPE),
410
- handleMeetingPermanentlyDeleted: fnWithKey(ZOOM_WEBHOOK_MEETING_PERMANENTLY_DELETED_EVENT_TYPE)
411
- };
412
- return configurer;
413
- }
412
+ configurerForAccessor: (accessor) => {
413
+ // eslint-disable-next-line
414
+ const fnWithKey = handlerMappedSetFunctionFactory(accessor, zoomWebhookEvent);
415
+ const configurer = {
416
+ ...accessor,
417
+ // Meetings
418
+ handleMeetingCreated: fnWithKey(ZOOM_WEBHOOK_MEETING_CREATED_EVENT_TYPE),
419
+ handleMeetingUpdated: fnWithKey(ZOOM_WEBHOOK_MEETING_UPDATED_EVENT_TYPE),
420
+ handleMeetingDeleted: fnWithKey(ZOOM_WEBHOOK_MEETING_DELETED_EVENT_TYPE),
421
+ handleMeetingStarted: fnWithKey(ZOOM_WEBHOOK_MEETING_STARTED_EVENT_TYPE),
422
+ handleMeetingEnded: fnWithKey(ZOOM_WEBHOOK_MEETING_ENDED_EVENT_TYPE),
423
+ handleMeetingPermanentlyDeleted: fnWithKey(ZOOM_WEBHOOK_MEETING_PERMANENTLY_DELETED_EVENT_TYPE)
424
+ };
425
+ return configurer;
426
+ }
414
427
  });
415
428
 
416
429
  /**
@@ -422,18 +435,18 @@ const zoomEventHandlerConfigurerFactory = handlerConfigurerFactory({
422
435
  * @returns A function that verifies a Zoom webhook event.
423
436
  */
424
437
  function zoomWebhookEventVerifier(zoomSecretToken) {
425
- return (request, rawBody) => {
426
- const requestBodyString = String(request.body);
427
- const message = `v0:${request.headers['x-zm-request-timestamp']}:${requestBodyString}`;
428
- const hashForVerify = createHmac('sha256', zoomSecretToken).update(message).digest('hex');
429
- const signature = `v0=${hashForVerify}`;
430
- const valid = request.headers['x-zm-signature'] === signature;
431
- const result = {
432
- valid,
433
- event: JSON.parse(requestBodyString)
438
+ return (request, rawBody) => {
439
+ const requestBodyString = String(request.body);
440
+ const message = `v0:${request.headers['x-zm-request-timestamp']}:${requestBodyString}`;
441
+ const hashForVerify = createHmac('sha256', zoomSecretToken).update(message).digest('hex');
442
+ const signature = `v0=${hashForVerify}`;
443
+ const valid = request.headers['x-zm-signature'] === signature;
444
+ const result = {
445
+ valid,
446
+ event: JSON.parse(requestBodyString)
447
+ };
448
+ return result;
434
449
  };
435
- return result;
436
- };
437
450
  }
438
451
 
439
452
  const ZOOM_WEBHOOK_URL_VALIDATION_EVENT_TYPE = 'endpoint.url_validation';
@@ -445,193 +458,216 @@ const ZOOM_WEBHOOK_URL_VALIDATION_EVENT_TYPE = 'endpoint.url_validation';
445
458
  * @returns A ZoomWebhookEventValidationFunction.
446
459
  */
447
460
  function zoomWebhookEventValidationFunction(zoomSecretToken) {
448
- return event => {
449
- const {
450
- plainToken
451
- } = event.payload;
452
- if (!plainToken) {
453
- throw new Error(`The expected plaintoken value was not provided by the event's payload.`);
454
- }
455
- const encryptedToken = createHmac('sha256', zoomSecretToken).update(plainToken).digest('hex');
456
- const result = {
457
- plainToken,
458
- encryptedToken
461
+ return (event) => {
462
+ const { plainToken } = event.payload;
463
+ if (!plainToken) {
464
+ throw new Error(`The expected plaintoken value was not provided by the event's payload.`);
465
+ }
466
+ const encryptedToken = createHmac('sha256', zoomSecretToken).update(plainToken).digest('hex');
467
+ const result = {
468
+ plainToken,
469
+ encryptedToken
470
+ };
471
+ return result;
459
472
  };
460
- return result;
461
- };
462
473
  }
463
474
 
464
475
  /**
465
476
  * Service that makes system changes based on Zoom webhook events.
466
477
  */
467
478
  let ZoomWebhookService = class ZoomWebhookService {
468
- logger = new Logger('ZoomWebhookService');
469
- _verifier;
470
- _validator;
471
- handler = zoomEventHandlerFactory();
472
- configure = zoomEventHandlerConfigurerFactory(this.handler);
473
- constructor(config) {
474
- this._verifier = zoomWebhookEventVerifier(config.webhookConfig.zoomSecretToken);
475
- this._validator = zoomWebhookEventValidationFunction(config.webhookConfig.zoomSecretToken);
476
- }
477
- async updateForWebhook(req, rawBody) {
478
- const {
479
- valid,
480
- event
481
- } = this._verifier(req, rawBody);
482
- let handled = false;
483
- let validationEventResponse;
484
- if (!valid) {
485
- this.logger.warn('Received invalid zoom event: ', event);
486
- } else if (event.event === ZOOM_WEBHOOK_URL_VALIDATION_EVENT_TYPE) {
487
- validationEventResponse = this._validator(event);
488
- handled = true;
489
- } else {
490
- handled = await this.updateForZoomEvent(event);
491
- }
492
- const result = {
493
- valid,
494
- handled,
495
- event,
496
- validationEventResponse
497
- };
498
- return result;
499
- }
500
- async updateForZoomEvent(event) {
501
- const handled = await this.handler(event);
502
- if (!handled) {
503
- this.logger.warn('Received unexpected/unhandled zoom event: ', event);
504
- }
505
- return handled;
506
- }
479
+ logger = new Logger('ZoomWebhookService');
480
+ _verifier;
481
+ _validator;
482
+ handler = zoomEventHandlerFactory();
483
+ configure = zoomEventHandlerConfigurerFactory(this.handler);
484
+ constructor(config) {
485
+ this._verifier = zoomWebhookEventVerifier(config.webhookConfig.zoomSecretToken);
486
+ this._validator = zoomWebhookEventValidationFunction(config.webhookConfig.zoomSecretToken);
487
+ }
488
+ async updateForWebhook(req, rawBody) {
489
+ const { valid, event } = this._verifier(req, rawBody);
490
+ let handled = false;
491
+ let validationEventResponse;
492
+ if (!valid) {
493
+ this.logger.warn('Received invalid zoom event: ', event);
494
+ }
495
+ else if (event.event === ZOOM_WEBHOOK_URL_VALIDATION_EVENT_TYPE) {
496
+ validationEventResponse = this._validator(event);
497
+ handled = true;
498
+ }
499
+ else {
500
+ handled = await this.updateForZoomEvent(event);
501
+ }
502
+ const result = {
503
+ valid,
504
+ handled,
505
+ event,
506
+ validationEventResponse
507
+ };
508
+ return result;
509
+ }
510
+ async updateForZoomEvent(event) {
511
+ const handled = await this.handler(event);
512
+ if (!handled) {
513
+ this.logger.warn('Received unexpected/unhandled zoom event: ', event);
514
+ }
515
+ return handled;
516
+ }
507
517
  };
508
- ZoomWebhookService = __decorate([Injectable(), __param(0, Inject(ZoomWebhookServiceConfig)), __metadata("design:paramtypes", [ZoomWebhookServiceConfig])], ZoomWebhookService);
518
+ ZoomWebhookService = __decorate([
519
+ Injectable(),
520
+ __param(0, Inject(ZoomWebhookServiceConfig)),
521
+ __metadata("design:paramtypes", [ZoomWebhookServiceConfig])
522
+ ], ZoomWebhookService);
509
523
 
510
524
  let ZoomWebhookController = class ZoomWebhookController {
511
- zoomWebhookService;
512
- constructor(zoomWebhookService) {
513
- this.zoomWebhookService = zoomWebhookService;
514
- }
515
- async handleZoomWebhook(res, req, rawBody) {
516
- const {
517
- valid,
518
- validationEventResponse
519
- } = await this.zoomWebhookService.updateForWebhook(req, rawBody);
520
- const response = res.status(200); // always return a 200 status code
521
- if (valid && validationEventResponse) {
522
- response.json(validationEventResponse);
523
- } else {
524
- response.json({});
525
- }
526
- }
525
+ zoomWebhookService;
526
+ constructor(zoomWebhookService) {
527
+ this.zoomWebhookService = zoomWebhookService;
528
+ }
529
+ async handleZoomWebhook(res, req, rawBody) {
530
+ const { valid, validationEventResponse } = await this.zoomWebhookService.updateForWebhook(req, rawBody);
531
+ const response = res.status(200); // always return a 200 status code
532
+ if (valid && validationEventResponse) {
533
+ response.json(validationEventResponse);
534
+ }
535
+ else {
536
+ response.json({});
537
+ }
538
+ }
527
539
  };
528
- __decorate([Post(), __param(0, Res()), __param(1, Req()), __param(2, RawBody()), __metadata("design:type", Function), __metadata("design:paramtypes", [Object, Object, Object]), __metadata("design:returntype", Promise)], ZoomWebhookController.prototype, "handleZoomWebhook", null);
529
- ZoomWebhookController = __decorate([Controller('/webhook/zoom'), __param(0, Inject(ZoomWebhookService)), __metadata("design:paramtypes", [ZoomWebhookService])], ZoomWebhookController);
540
+ __decorate([
541
+ Post(),
542
+ __param(0, Res()),
543
+ __param(1, Req()),
544
+ __param(2, RawBody()),
545
+ __metadata("design:type", Function),
546
+ __metadata("design:paramtypes", [Object, Object, Object]),
547
+ __metadata("design:returntype", Promise)
548
+ ], ZoomWebhookController.prototype, "handleZoomWebhook", null);
549
+ ZoomWebhookController = __decorate([
550
+ Controller('/webhook/zoom'),
551
+ __param(0, Inject(ZoomWebhookService)),
552
+ __metadata("design:paramtypes", [ZoomWebhookService])
553
+ ], ZoomWebhookController);
530
554
 
531
555
  function zoomWebhookServiceConfigFactory(configService) {
532
- const config = {
533
- webhookConfig: {
534
- zoomSecretToken: configService.get(ZOOM_SECRET_TOKEN_ENV_VAR)
535
- }
536
- };
537
- ZoomWebhookServiceConfig.assertValidConfig(config);
538
- return config;
556
+ const config = {
557
+ webhookConfig: {
558
+ zoomSecretToken: configService.get(ZOOM_SECRET_TOKEN_ENV_VAR)
559
+ }
560
+ };
561
+ ZoomWebhookServiceConfig.assertValidConfig(config);
562
+ return config;
539
563
  }
540
564
  /**
541
565
  * Configures webhooks for the service.
542
566
  */
543
- let ZoomWebhookModule = class ZoomWebhookModule {};
544
- ZoomWebhookModule = __decorate([Module({
545
- imports: [ConfigModule],
546
- controllers: [ZoomWebhookController],
547
- exports: [ZoomWebhookService],
548
- providers: [{
549
- provide: ZoomWebhookServiceConfig,
550
- inject: [ConfigService],
551
- useFactory: zoomWebhookServiceConfigFactory
552
- }, ZoomWebhookService]
553
- })], ZoomWebhookModule);
567
+ let ZoomWebhookModule = class ZoomWebhookModule {
568
+ };
569
+ ZoomWebhookModule = __decorate([
570
+ Module({
571
+ imports: [ConfigModule],
572
+ controllers: [ZoomWebhookController],
573
+ exports: [ZoomWebhookService],
574
+ providers: [
575
+ {
576
+ provide: ZoomWebhookServiceConfig,
577
+ inject: [ConfigService],
578
+ useFactory: zoomWebhookServiceConfigFactory
579
+ },
580
+ ZoomWebhookService
581
+ ]
582
+ })
583
+ ], ZoomWebhookModule);
554
584
 
555
585
  /**
556
586
  * Configuration for ZoomService
557
587
  */
558
588
  class ZoomServiceConfig {
559
- zoom;
560
- factoryConfig;
561
- static assertValidConfig(config) {
562
- // TODO?
563
- }
589
+ zoom;
590
+ factoryConfig;
591
+ static assertValidConfig(config) {
592
+ // TODO?
593
+ }
564
594
  }
565
595
 
566
596
  let ZoomApi = class ZoomApi {
567
- config;
568
- zoomOAuthApi;
569
- zoom;
570
- get zoomContext() {
571
- return this.zoom.zoomServerContext;
572
- }
573
- get zoomRateLimiter() {
574
- return this.zoom.zoomServerContext.zoomRateLimiter;
575
- }
576
- constructor(config, zoomOAuthApi) {
577
- this.config = config;
578
- this.zoomOAuthApi = zoomOAuthApi;
579
- this.zoom = zoomFactory({
580
- ...config.factoryConfig,
581
- oauthContext: zoomOAuthApi.oauthContext
582
- })(config.zoom);
583
- }
584
- // MARK: Users
585
- get getUser() {
586
- return getUser(this.zoomContext);
587
- }
588
- get listUsers() {
589
- return listUsers(this.zoomContext);
590
- }
591
- get listUsersPageFactory() {
592
- return listUsersPageFactory(this.zoomContext);
593
- }
594
- // MARK: Meetings
595
- get listMeetingsForUser() {
596
- return listMeetingsForUser(this.zoomContext);
597
- }
598
- get listMeetingsForUserPageFactory() {
599
- return listMeetingsForUserPageFactory(this.zoomContext);
600
- }
601
- get createMeetingForUser() {
602
- return createMeetingForUser(this.zoomContext);
603
- }
604
- get getMeeting() {
605
- return getMeeting(this.zoomContext);
606
- }
607
- get updateMeeting() {
608
- return updateMeeting(this.zoomContext);
609
- }
610
- get deleteMeeting() {
611
- return deleteMeeting(this.zoomContext);
612
- }
613
- // MARK: Past Meetings
614
- get getPastMeeting() {
615
- return getPastMeeting(this.zoomContext);
616
- }
617
- get getPastMeetingParticipants() {
618
- return getPastMeetingParticipants(this.zoomContext);
619
- }
597
+ config;
598
+ zoomOAuthApi;
599
+ zoom;
600
+ get zoomContext() {
601
+ return this.zoom.zoomServerContext;
602
+ }
603
+ get zoomRateLimiter() {
604
+ return this.zoom.zoomServerContext.zoomRateLimiter;
605
+ }
606
+ constructor(config, zoomOAuthApi) {
607
+ this.config = config;
608
+ this.zoomOAuthApi = zoomOAuthApi;
609
+ this.zoom = zoomFactory({
610
+ ...config.factoryConfig,
611
+ oauthContext: zoomOAuthApi.oauthContext
612
+ })(config.zoom);
613
+ }
614
+ // MARK: Users
615
+ get getUser() {
616
+ return getUser(this.zoomContext);
617
+ }
618
+ get listUsers() {
619
+ return listUsers(this.zoomContext);
620
+ }
621
+ get listUsersPageFactory() {
622
+ return listUsersPageFactory(this.zoomContext);
623
+ }
624
+ // MARK: Meetings
625
+ get listMeetingsForUser() {
626
+ return listMeetingsForUser(this.zoomContext);
627
+ }
628
+ get listMeetingsForUserPageFactory() {
629
+ return listMeetingsForUserPageFactory(this.zoomContext);
630
+ }
631
+ get createMeetingForUser() {
632
+ return createMeetingForUser(this.zoomContext);
633
+ }
634
+ get getMeeting() {
635
+ return getMeeting(this.zoomContext);
636
+ }
637
+ get updateMeeting() {
638
+ return updateMeeting(this.zoomContext);
639
+ }
640
+ get deleteMeeting() {
641
+ return deleteMeeting(this.zoomContext);
642
+ }
643
+ // MARK: Past Meetings
644
+ get getPastMeeting() {
645
+ return getPastMeeting(this.zoomContext);
646
+ }
647
+ get getPastMeetingParticipants() {
648
+ return getPastMeetingParticipants(this.zoomContext);
649
+ }
620
650
  };
621
- ZoomApi = __decorate([Injectable(), __param(0, Inject(ZoomServiceConfig)), __param(1, Inject(ZoomOAuthApi)), __metadata("design:paramtypes", [ZoomServiceConfig, ZoomOAuthApi])], ZoomApi);
651
+ ZoomApi = __decorate([
652
+ Injectable(),
653
+ __param(0, Inject(ZoomServiceConfig)),
654
+ __param(1, Inject(ZoomOAuthApi)),
655
+ __metadata("design:paramtypes", [ZoomServiceConfig,
656
+ ZoomOAuthApi])
657
+ ], ZoomApi);
622
658
  class ZoomApiUserContext {
623
- constructor(refreshToken) {
624
- // TODO: ...
625
- }
659
+ constructor(refreshToken) {
660
+ // TODO: ...
661
+ }
626
662
  }
627
663
 
628
664
  // MARK: Provider Factories
629
665
  function zoomServiceConfigFactory(configService) {
630
- const config = {
631
- zoom: {}
632
- };
633
- ZoomServiceConfig.assertValidConfig(config);
634
- return config;
666
+ const config = {
667
+ zoom: {}
668
+ };
669
+ ZoomServiceConfig.assertValidConfig(config);
670
+ return config;
635
671
  }
636
672
  /**
637
673
  * Convenience function used to generate ModuleMetadata for an app's ZoomModule.
@@ -641,22 +677,21 @@ function zoomServiceConfigFactory(configService) {
641
677
  * @returns
642
678
  */
643
679
  function appZoomModuleMetadata(config) {
644
- const {
645
- dependencyModule,
646
- imports,
647
- exports: exports$1,
648
- providers
649
- } = config;
650
- const dependencyModuleImport = dependencyModule ? [dependencyModule] : [];
651
- return {
652
- imports: [ConfigModule, ...dependencyModuleImport, ...(imports ?? [])],
653
- exports: [ZoomApi, ...(exports$1 ?? [])],
654
- providers: [{
655
- provide: ZoomServiceConfig,
656
- inject: [ConfigService],
657
- useFactory: zoomServiceConfigFactory
658
- }, ZoomApi, ...(providers ?? [])]
659
- };
680
+ const { dependencyModule, imports, exports: exports$1, providers } = config;
681
+ const dependencyModuleImport = dependencyModule ? [dependencyModule] : [];
682
+ return {
683
+ imports: [ConfigModule, ...dependencyModuleImport, ...(imports ?? [])],
684
+ exports: [ZoomApi, ...(exports$1 ?? [])],
685
+ providers: [
686
+ {
687
+ provide: ZoomServiceConfig,
688
+ inject: [ConfigService],
689
+ useFactory: zoomServiceConfigFactory
690
+ },
691
+ ZoomApi,
692
+ ...(providers ?? [])
693
+ ]
694
+ };
660
695
  }
661
696
 
662
697
  export { DEFAULT_FILE_ZOOM_ACCOUNTS_ACCESS_TOKEN_CACHE_SERVICE_PATH, ZOOM_SECRET_TOKEN_ENV_VAR, ZOOM_WEBHOOK_MEETING_ALERT_EVENT_TYPE, ZOOM_WEBHOOK_MEETING_CREATED_EVENT_TYPE, ZOOM_WEBHOOK_MEETING_DELETED_EVENT_TYPE, ZOOM_WEBHOOK_MEETING_ENDED_EVENT_TYPE, ZOOM_WEBHOOK_MEETING_PERMANENTLY_DELETED_EVENT_TYPE, ZOOM_WEBHOOK_MEETING_STARTED_EVENT_TYPE, ZOOM_WEBHOOK_MEETING_UPDATED_EVENT_TYPE, ZOOM_WEBHOOK_URL_VALIDATION_EVENT_TYPE, ZoomApi, ZoomApiUserContext, ZoomOAuthAccessTokenCacheService, ZoomOAuthApi, ZoomOAuthServiceConfig, ZoomServiceConfig, ZoomWebhookController, ZoomWebhookModule, ZoomWebhookService, ZoomWebhookServiceConfig, appZoomModuleMetadata, appZoomOAuthModuleMetadata, fileZoomOAuthAccessTokenCacheService, logMergeZoomOAuthAccessTokenCacheServiceErrorFunction, memoryZoomOAuthAccessTokenCacheService, mergeZoomOAuthAccessTokenCacheServices, readZoomOAuthServiceConfigFromConfigService, zoomEventHandlerConfigurerFactory, zoomEventHandlerFactory, zoomOAuthServiceConfigFactory, zoomServiceConfigFactory, zoomWebhookEvent, zoomWebhookEventValidationFunction, zoomWebhookEventVerifier, zoomWebhookServiceConfigFactory };