@dereekb/trello 13.38.0 → 13.40.0

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.
@@ -1,1170 +0,0 @@
1
- 'use strict';
2
-
3
- var common = require('@nestjs/common');
4
- var trello = require('@dereekb/trello');
5
- var config = require('@nestjs/config');
6
- var util = require('@dereekb/util');
7
- var nestjs = require('@dereekb/nestjs');
8
- var node_crypto = require('node:crypto');
9
-
10
- function _type_of(obj) {
11
- "@swc/helpers - typeof";
12
- return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
13
- }
14
- function __decorate(decorators, target, key, desc) {
15
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
16
- if ((typeof Reflect === "undefined" ? "undefined" : _type_of(Reflect)) === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
17
- else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
18
- return c > 3 && r && Object.defineProperty(target, key, r), r;
19
- }
20
- function __param(paramIndex, decorator) {
21
- return function(target, key) {
22
- decorator(target, key, paramIndex);
23
- };
24
- }
25
- typeof SuppressedError === "function" ? SuppressedError : function(error, suppressed, message) {
26
- var e = new Error(message);
27
- return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
28
- };
29
-
30
- function _class_call_check$5(instance, Constructor) {
31
- if (!(instance instanceof Constructor)) {
32
- throw new TypeError("Cannot call a class as a function");
33
- }
34
- }
35
- function _defineProperties$4(target, props) {
36
- for(var i = 0; i < props.length; i++){
37
- var descriptor = props[i];
38
- descriptor.enumerable = descriptor.enumerable || false;
39
- descriptor.configurable = true;
40
- if ("value" in descriptor) descriptor.writable = true;
41
- Object.defineProperty(target, descriptor.key, descriptor);
42
- }
43
- }
44
- function _create_class$4(Constructor, protoProps, staticProps) {
45
- if (staticProps) _defineProperties$4(Constructor, staticProps);
46
- return Constructor;
47
- }
48
- function _define_property$5(obj, key, value) {
49
- if (key in obj) {
50
- Object.defineProperty(obj, key, {
51
- value: value,
52
- enumerable: true,
53
- configurable: true,
54
- writable: true
55
- });
56
- } else {
57
- obj[key] = value;
58
- }
59
- return obj;
60
- }
61
- var TRELLO_API_KEY_ENV_VAR = 'TRELLO_API_KEY';
62
- var TRELLO_API_TOKEN_ENV_VAR = 'TRELLO_API_TOKEN';
63
- /**
64
- * Configuration for TrelloApi.
65
- */ var TrelloServiceConfig = /*#__PURE__*/ function() {
66
- function TrelloServiceConfig() {
67
- _class_call_check$5(this, TrelloServiceConfig);
68
- _define_property$5(this, "trello", void 0);
69
- _define_property$5(this, "factoryConfig", void 0);
70
- }
71
- _create_class$4(TrelloServiceConfig, null, [
72
- {
73
- key: "assertValidConfig",
74
- value: function assertValidConfig(config) {
75
- if (!config.trello.apiKey) {
76
- throw new Error('No Trello API key specified.');
77
- }
78
- if (!config.trello.apiToken) {
79
- throw new Error('No Trello API token specified.');
80
- }
81
- }
82
- }
83
- ]);
84
- return TrelloServiceConfig;
85
- }
86
- ();
87
-
88
- function _class_call_check$4(instance, Constructor) {
89
- if (!(instance instanceof Constructor)) {
90
- throw new TypeError("Cannot call a class as a function");
91
- }
92
- }
93
- function _defineProperties$3(target, props) {
94
- for(var i = 0; i < props.length; i++){
95
- var descriptor = props[i];
96
- descriptor.enumerable = descriptor.enumerable || false;
97
- descriptor.configurable = true;
98
- if ("value" in descriptor) descriptor.writable = true;
99
- Object.defineProperty(target, descriptor.key, descriptor);
100
- }
101
- }
102
- function _create_class$3(Constructor, protoProps, staticProps) {
103
- if (protoProps) _defineProperties$3(Constructor.prototype, protoProps);
104
- return Constructor;
105
- }
106
- function _define_property$4(obj, key, value) {
107
- if (key in obj) {
108
- Object.defineProperty(obj, key, {
109
- value: value,
110
- enumerable: true,
111
- configurable: true,
112
- writable: true
113
- });
114
- } else {
115
- obj[key] = value;
116
- }
117
- return obj;
118
- }
119
- exports.TrelloApi = /*#__PURE__*/ function() {
120
- function TrelloApi(config) {
121
- _class_call_check$4(this, TrelloApi);
122
- _define_property$4(this, "config", void 0);
123
- _define_property$4(this, "trello", void 0);
124
- this.config = config;
125
- this.trello = trello.trelloFactory(config.factoryConfig)(config.trello);
126
- }
127
- _create_class$3(TrelloApi, [
128
- {
129
- key: "trelloContext",
130
- get: function get() {
131
- return this.trello.trelloContext;
132
- }
133
- },
134
- {
135
- key: "trelloRateLimiter",
136
- get: function get() {
137
- return this.trello.trelloContext.trelloRateLimiter;
138
- }
139
- },
140
- {
141
- key: "getBoard",
142
- get: // MARK: Boards
143
- function get() {
144
- return trello.getBoard(this.trelloContext);
145
- }
146
- },
147
- {
148
- key: "createBoard",
149
- get: function get() {
150
- return trello.createBoard(this.trelloContext);
151
- }
152
- },
153
- {
154
- key: "updateBoard",
155
- get: function get() {
156
- return trello.updateBoard(this.trelloContext);
157
- }
158
- },
159
- {
160
- key: "deleteBoard",
161
- get: function get() {
162
- return trello.deleteBoard(this.trelloContext);
163
- }
164
- },
165
- {
166
- key: "listBoardLists",
167
- get: function get() {
168
- return trello.listBoardLists(this.trelloContext);
169
- }
170
- },
171
- {
172
- key: "listBoardCards",
173
- get: function get() {
174
- return trello.listBoardCards(this.trelloContext);
175
- }
176
- },
177
- {
178
- key: "listBoardMembers",
179
- get: function get() {
180
- return trello.listBoardMembers(this.trelloContext);
181
- }
182
- },
183
- {
184
- key: "listBoardLabels",
185
- get: function get() {
186
- return trello.listBoardLabels(this.trelloContext);
187
- }
188
- },
189
- {
190
- key: "getList",
191
- get: // MARK: Lists
192
- function get() {
193
- return trello.getList(this.trelloContext);
194
- }
195
- },
196
- {
197
- key: "createList",
198
- get: function get() {
199
- return trello.createList(this.trelloContext);
200
- }
201
- },
202
- {
203
- key: "updateList",
204
- get: function get() {
205
- return trello.updateList(this.trelloContext);
206
- }
207
- },
208
- {
209
- key: "listCardsInList",
210
- get: function get() {
211
- return trello.listCardsInList(this.trelloContext);
212
- }
213
- },
214
- {
215
- key: "getCard",
216
- get: // MARK: Cards
217
- function get() {
218
- return trello.getCard(this.trelloContext);
219
- }
220
- },
221
- {
222
- key: "createCard",
223
- get: function get() {
224
- return trello.createCard(this.trelloContext);
225
- }
226
- },
227
- {
228
- key: "updateCard",
229
- get: function get() {
230
- return trello.updateCard(this.trelloContext);
231
- }
232
- },
233
- {
234
- key: "deleteCard",
235
- get: function get() {
236
- return trello.deleteCard(this.trelloContext);
237
- }
238
- },
239
- {
240
- key: "addCommentToCard",
241
- get: function get() {
242
- return trello.addCommentToCard(this.trelloContext);
243
- }
244
- },
245
- {
246
- key: "addMemberToCard",
247
- get: function get() {
248
- return trello.addMemberToCard(this.trelloContext);
249
- }
250
- },
251
- {
252
- key: "addLabelToCard",
253
- get: function get() {
254
- return trello.addLabelToCard(this.trelloContext);
255
- }
256
- },
257
- {
258
- key: "listCardActions",
259
- get: function get() {
260
- return trello.listCardActions(this.trelloContext);
261
- }
262
- },
263
- {
264
- key: "listCardAttachments",
265
- get: // MARK: Card Attachments
266
- function get() {
267
- return trello.listCardAttachments(this.trelloContext);
268
- }
269
- },
270
- {
271
- key: "getCardAttachment",
272
- get: function get() {
273
- return trello.getCardAttachment(this.trelloContext);
274
- }
275
- },
276
- {
277
- key: "addAttachmentToCard",
278
- get: function get() {
279
- return trello.addAttachmentToCard(this.trelloContext);
280
- }
281
- },
282
- {
283
- key: "deleteAttachmentFromCard",
284
- get: function get() {
285
- return trello.deleteAttachmentFromCard(this.trelloContext);
286
- }
287
- },
288
- {
289
- key: "downloadCardAttachment",
290
- get: function get() {
291
- return trello.downloadCardAttachment(this.trelloContext);
292
- }
293
- },
294
- {
295
- key: "getMember",
296
- get: // MARK: Members
297
- function get() {
298
- return trello.getMember(this.trelloContext);
299
- }
300
- },
301
- {
302
- key: "getMe",
303
- get: function get() {
304
- return trello.getMe(this.trelloContext);
305
- }
306
- },
307
- {
308
- key: "createWebhook",
309
- get: // MARK: Webhooks
310
- function get() {
311
- return trello.createWebhook(this.trelloContext);
312
- }
313
- },
314
- {
315
- key: "getWebhook",
316
- get: function get() {
317
- return trello.getWebhook(this.trelloContext);
318
- }
319
- },
320
- {
321
- key: "updateWebhook",
322
- get: function get() {
323
- return trello.updateWebhook(this.trelloContext);
324
- }
325
- },
326
- {
327
- key: "deleteWebhook",
328
- get: function get() {
329
- return trello.deleteWebhook(this.trelloContext);
330
- }
331
- },
332
- {
333
- key: "listWebhooksForToken",
334
- get: function get() {
335
- return trello.listWebhooksForToken(this.trelloContext);
336
- }
337
- }
338
- ]);
339
- return TrelloApi;
340
- }();
341
- exports.TrelloApi = __decorate([
342
- common.Injectable(),
343
- __param(0, common.Inject(TrelloServiceConfig))
344
- ], exports.TrelloApi);
345
-
346
- function _array_like_to_array(arr, len) {
347
- if (len == null || len > arr.length) len = arr.length;
348
- for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
349
- return arr2;
350
- }
351
- function _array_without_holes(arr) {
352
- if (Array.isArray(arr)) return _array_like_to_array(arr);
353
- }
354
- function _iterable_to_array(iter) {
355
- if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
356
- }
357
- function _non_iterable_spread() {
358
- throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
359
- }
360
- function _to_consumable_array(arr) {
361
- return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
362
- }
363
- function _unsupported_iterable_to_array(o, minLen) {
364
- if (!o) return;
365
- if (typeof o === "string") return _array_like_to_array(o, minLen);
366
- var n = Object.prototype.toString.call(o).slice(8, -1);
367
- if (n === "Object" && o.constructor) n = o.constructor.name;
368
- if (n === "Map" || n === "Set") return Array.from(n);
369
- if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
370
- }
371
- /**
372
- * Default factory function for creating TrelloServiceConfig from ConfigService.
373
- *
374
- * Reads `TRELLO_API_KEY` and `TRELLO_API_TOKEN` from the environment.
375
- *
376
- * @param configService - The NestJS ConfigService.
377
- * @returns A validated TrelloServiceConfig.
378
- */ function trelloServiceConfigFactory(configService) {
379
- var config = {
380
- trello: {
381
- apiKey: configService.get(TRELLO_API_KEY_ENV_VAR),
382
- apiToken: configService.get(TRELLO_API_TOKEN_ENV_VAR)
383
- }
384
- };
385
- TrelloServiceConfig.assertValidConfig(config);
386
- return config;
387
- }
388
- /**
389
- * Convenience function used to generate ModuleMetadata for an app's TrelloModule.
390
- *
391
- * @param config - Optional additional module metadata overrides.
392
- * @returns Module metadata for the Trello module.
393
- */ function appTrelloModuleMetadata(config$1) {
394
- var _ref = config$1 !== null && config$1 !== void 0 ? config$1 : {}, imports = _ref.imports, exports$1 = _ref.exports, providers = _ref.providers;
395
- return {
396
- imports: [
397
- config.ConfigModule
398
- ].concat(_to_consumable_array(imports !== null && imports !== void 0 ? imports : [])),
399
- exports: [
400
- exports.TrelloApi
401
- ].concat(_to_consumable_array(exports$1 !== null && exports$1 !== void 0 ? exports$1 : [])),
402
- providers: [
403
- {
404
- provide: TrelloServiceConfig,
405
- inject: [
406
- config.ConfigService
407
- ],
408
- useFactory: trelloServiceConfigFactory
409
- },
410
- exports.TrelloApi
411
- ].concat(_to_consumable_array(providers !== null && providers !== void 0 ? providers : []))
412
- };
413
- }
414
-
415
- function _define_property$3(obj, key, value) {
416
- if (key in obj) {
417
- Object.defineProperty(obj, key, {
418
- value: value,
419
- enumerable: true,
420
- configurable: true,
421
- writable: true
422
- });
423
- } else {
424
- obj[key] = value;
425
- }
426
- return obj;
427
- }
428
- function _object_spread(target) {
429
- for(var i = 1; i < arguments.length; i++){
430
- var source = arguments[i] != null ? arguments[i] : {};
431
- var ownKeys = Object.keys(source);
432
- if (typeof Object.getOwnPropertySymbols === "function") {
433
- ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
434
- return Object.getOwnPropertyDescriptor(source, sym).enumerable;
435
- }));
436
- }
437
- ownKeys.forEach(function(key) {
438
- _define_property$3(target, key, source[key]);
439
- });
440
- }
441
- return target;
442
- }
443
- function ownKeys(object, enumerableOnly) {
444
- var keys = Object.keys(object);
445
- if (Object.getOwnPropertySymbols) {
446
- var symbols = Object.getOwnPropertySymbols(object);
447
- keys.push.apply(keys, symbols);
448
- }
449
- return keys;
450
- }
451
- function _object_spread_props(target, source) {
452
- source = source != null ? source : {};
453
- if (Object.getOwnPropertyDescriptors) {
454
- Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
455
- } else {
456
- ownKeys(Object(source)).forEach(function(key) {
457
- Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
458
- });
459
- }
460
- return target;
461
- }
462
- /**
463
- * Action type emitted when a new card is created.
464
- */ var TRELLO_WEBHOOK_CREATE_CARD_ACTION_TYPE = 'createCard';
465
- /**
466
- * Action type emitted when a card is updated.
467
- */ var TRELLO_WEBHOOK_UPDATE_CARD_ACTION_TYPE = 'updateCard';
468
- /**
469
- * Action type emitted when a card is deleted.
470
- */ var TRELLO_WEBHOOK_DELETE_CARD_ACTION_TYPE = 'deleteCard';
471
- /**
472
- * Action type emitted when a comment is added to a card.
473
- */ var TRELLO_WEBHOOK_COMMENT_CARD_ACTION_TYPE = 'commentCard';
474
- /**
475
- * Action type emitted when a member is added to a card.
476
- */ var TRELLO_WEBHOOK_ADD_MEMBER_TO_CARD_ACTION_TYPE = 'addMemberToCard';
477
- /**
478
- * Action type emitted when a member is removed from a card.
479
- */ var TRELLO_WEBHOOK_REMOVE_MEMBER_FROM_CARD_ACTION_TYPE = 'removeMemberFromCard';
480
- /**
481
- * Action type emitted when a board is updated.
482
- */ var TRELLO_WEBHOOK_UPDATE_BOARD_ACTION_TYPE = 'updateBoard';
483
- /**
484
- * Re-narrows an UntypedTrelloWebhookEvent's payload to the given action data type.
485
- *
486
- * @param event - The untyped event.
487
- * @returns A typed view over the same event.
488
- */ function trelloWebhookEvent(event) {
489
- return {
490
- action: event.action,
491
- model: event.model,
492
- webhook: event.webhook
493
- };
494
- }
495
- var trelloEventHandlerFactory = util.handlerFactory(function(x) {
496
- return x.action.type;
497
- });
498
- var trelloEventHandlerConfigurerFactory = util.handlerConfigurerFactory({
499
- configurerForAccessor: function configurerForAccessor(accessor) {
500
- var fnWithKey = util.handlerMappedSetFunctionFactory(accessor, trelloWebhookEvent);
501
- var configurer = _object_spread_props(_object_spread({}, accessor), {
502
- handleCreateCard: fnWithKey(TRELLO_WEBHOOK_CREATE_CARD_ACTION_TYPE),
503
- handleUpdateCard: fnWithKey(TRELLO_WEBHOOK_UPDATE_CARD_ACTION_TYPE),
504
- handleDeleteCard: fnWithKey(TRELLO_WEBHOOK_DELETE_CARD_ACTION_TYPE),
505
- handleCommentCard: fnWithKey(TRELLO_WEBHOOK_COMMENT_CARD_ACTION_TYPE),
506
- handleAddMemberToCard: fnWithKey(TRELLO_WEBHOOK_ADD_MEMBER_TO_CARD_ACTION_TYPE),
507
- handleRemoveMemberFromCard: fnWithKey(TRELLO_WEBHOOK_REMOVE_MEMBER_FROM_CARD_ACTION_TYPE),
508
- handleUpdateBoard: fnWithKey(TRELLO_WEBHOOK_UPDATE_BOARD_ACTION_TYPE)
509
- });
510
- return configurer;
511
- }
512
- });
513
-
514
- function _class_call_check$3(instance, Constructor) {
515
- if (!(instance instanceof Constructor)) {
516
- throw new TypeError("Cannot call a class as a function");
517
- }
518
- }
519
- function _defineProperties$2(target, props) {
520
- for(var i = 0; i < props.length; i++){
521
- var descriptor = props[i];
522
- descriptor.enumerable = descriptor.enumerable || false;
523
- descriptor.configurable = true;
524
- if ("value" in descriptor) descriptor.writable = true;
525
- Object.defineProperty(target, descriptor.key, descriptor);
526
- }
527
- }
528
- function _create_class$2(Constructor, protoProps, staticProps) {
529
- if (staticProps) _defineProperties$2(Constructor, staticProps);
530
- return Constructor;
531
- }
532
- function _define_property$2(obj, key, value) {
533
- if (key in obj) {
534
- Object.defineProperty(obj, key, {
535
- value: value,
536
- enumerable: true,
537
- configurable: true,
538
- writable: true
539
- });
540
- } else {
541
- obj[key] = value;
542
- }
543
- return obj;
544
- }
545
- var TRELLO_APP_SECRET_ENV_VAR = 'TRELLO_APP_SECRET';
546
- var TRELLO_WEBHOOK_CALLBACK_URL_ENV_VAR = 'TRELLO_WEBHOOK_CALLBACK_URL';
547
- /**
548
- * Configuration for {@link TrelloWebhookService}.
549
- */ var TrelloWebhookServiceConfig = /*#__PURE__*/ function() {
550
- function TrelloWebhookServiceConfig() {
551
- _class_call_check$3(this, TrelloWebhookServiceConfig);
552
- _define_property$2(this, "webhookConfig", void 0);
553
- }
554
- _create_class$2(TrelloWebhookServiceConfig, null, [
555
- {
556
- key: "assertValidConfig",
557
- value: function assertValidConfig(config) {
558
- if (!config.webhookConfig.appSecret) {
559
- throw new Error('No Trello app secret specified.');
560
- }
561
- if (!config.webhookConfig.callbackUrl) {
562
- throw new Error('No Trello webhook callback URL specified.');
563
- }
564
- }
565
- }
566
- ]);
567
- return TrelloWebhookServiceConfig;
568
- }
569
- ();
570
-
571
- /**
572
- * Computes the expected `X-Trello-Webhook` value for the given body + callback URL.
573
- *
574
- * Exported for testability.
575
- *
576
- * @param appSecret - The Trello app secret.
577
- * @param rawBody - The raw request body bytes.
578
- * @param callbackUrl - The exact callback URL configured for this webhook.
579
- * @returns The expected base64 signature value.
580
- */ function trelloWebhookExpectedSignature(appSecret, rawBody, callbackUrl) {
581
- var hmac = node_crypto.createHmac('sha1', appSecret);
582
- hmac.update(rawBody);
583
- hmac.update(callbackUrl);
584
- return hmac.digest('base64');
585
- }
586
- /**
587
- * Verifies a Trello webhook event header.
588
- *
589
- * @param config - The verifier configuration.
590
- * @returns Verifies a Trello webhook event.
591
- *
592
- * @see https://developer.atlassian.com/cloud/trello/guides/rest-api/webhooks/#webhook-signatures
593
- */ function trelloWebhookEventVerifier(config) {
594
- var appSecret = config.appSecret, callbackUrl = config.callbackUrl;
595
- return function(request, rawBody) {
596
- var headerValue = request.headers['x-trello-webhook'];
597
- var signature;
598
- if (typeof headerValue === 'string') {
599
- signature = headerValue;
600
- } else if (Array.isArray(headerValue)) {
601
- signature = headerValue[0];
602
- }
603
- var valid = false;
604
- if (signature) {
605
- var expected = trelloWebhookExpectedSignature(appSecret, rawBody, callbackUrl);
606
- var expectedBuffer = Buffer.from(expected);
607
- var signatureBuffer = Buffer.from(signature);
608
- valid = expectedBuffer.length === signatureBuffer.length && node_crypto.timingSafeEqual(expectedBuffer, signatureBuffer);
609
- }
610
- var event;
611
- var result;
612
- if (valid) {
613
- try {
614
- event = JSON.parse(rawBody.toString('utf8'));
615
- result = {
616
- valid: valid,
617
- event: event
618
- };
619
- } catch (unused) {
620
- result = {
621
- valid: false
622
- };
623
- }
624
- } else {
625
- result = {
626
- valid: valid,
627
- event: event
628
- };
629
- }
630
- return result;
631
- };
632
- }
633
-
634
- function asyncGeneratorStep$1(gen, resolve, reject, _next, _throw, key, arg) {
635
- try {
636
- var info = gen[key](arg);
637
- var value = info.value;
638
- } catch (error) {
639
- reject(error);
640
- return;
641
- }
642
- if (info.done) {
643
- resolve(value);
644
- } else {
645
- Promise.resolve(value).then(_next, _throw);
646
- }
647
- }
648
- function _async_to_generator$1(fn) {
649
- return function() {
650
- var self = this, args = arguments;
651
- return new Promise(function(resolve, reject) {
652
- var gen = fn.apply(self, args);
653
- function _next(value) {
654
- asyncGeneratorStep$1(gen, resolve, reject, _next, _throw, "next", value);
655
- }
656
- function _throw(err) {
657
- asyncGeneratorStep$1(gen, resolve, reject, _next, _throw, "throw", err);
658
- }
659
- _next(undefined);
660
- });
661
- };
662
- }
663
- function _class_call_check$2(instance, Constructor) {
664
- if (!(instance instanceof Constructor)) {
665
- throw new TypeError("Cannot call a class as a function");
666
- }
667
- }
668
- function _defineProperties$1(target, props) {
669
- for(var i = 0; i < props.length; i++){
670
- var descriptor = props[i];
671
- descriptor.enumerable = descriptor.enumerable || false;
672
- descriptor.configurable = true;
673
- if ("value" in descriptor) descriptor.writable = true;
674
- Object.defineProperty(target, descriptor.key, descriptor);
675
- }
676
- }
677
- function _create_class$1(Constructor, protoProps, staticProps) {
678
- if (protoProps) _defineProperties$1(Constructor.prototype, protoProps);
679
- return Constructor;
680
- }
681
- function _define_property$1(obj, key, value) {
682
- if (key in obj) {
683
- Object.defineProperty(obj, key, {
684
- value: value,
685
- enumerable: true,
686
- configurable: true,
687
- writable: true
688
- });
689
- } else {
690
- obj[key] = value;
691
- }
692
- return obj;
693
- }
694
- function _ts_generator$1(thisArg, body) {
695
- var f, y, t, _ = {
696
- label: 0,
697
- sent: function() {
698
- if (t[0] & 1) throw t[1];
699
- return t[1];
700
- },
701
- trys: [],
702
- ops: []
703
- }, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype), d = Object.defineProperty;
704
- return d(g, "next", {
705
- value: verb(0)
706
- }), d(g, "throw", {
707
- value: verb(1)
708
- }), d(g, "return", {
709
- value: verb(2)
710
- }), typeof Symbol === "function" && d(g, Symbol.iterator, {
711
- value: function() {
712
- return this;
713
- }
714
- }), g;
715
- function verb(n) {
716
- return function(v) {
717
- return step([
718
- n,
719
- v
720
- ]);
721
- };
722
- }
723
- function step(op) {
724
- if (f) throw new TypeError("Generator is already executing.");
725
- while(g && (g = 0, op[0] && (_ = 0)), _)try {
726
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
727
- if (y = 0, t) op = [
728
- op[0] & 2,
729
- t.value
730
- ];
731
- switch(op[0]){
732
- case 0:
733
- case 1:
734
- t = op;
735
- break;
736
- case 4:
737
- _.label++;
738
- return {
739
- value: op[1],
740
- done: false
741
- };
742
- case 5:
743
- _.label++;
744
- y = op[1];
745
- op = [
746
- 0
747
- ];
748
- continue;
749
- case 7:
750
- op = _.ops.pop();
751
- _.trys.pop();
752
- continue;
753
- default:
754
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
755
- _ = 0;
756
- continue;
757
- }
758
- if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
759
- _.label = op[1];
760
- break;
761
- }
762
- if (op[0] === 6 && _.label < t[1]) {
763
- _.label = t[1];
764
- t = op;
765
- break;
766
- }
767
- if (t && _.label < t[2]) {
768
- _.label = t[2];
769
- _.ops.push(op);
770
- break;
771
- }
772
- if (t[2]) _.ops.pop();
773
- _.trys.pop();
774
- continue;
775
- }
776
- op = body.call(thisArg, _);
777
- } catch (e) {
778
- op = [
779
- 6,
780
- e
781
- ];
782
- y = 0;
783
- } finally{
784
- f = t = 0;
785
- }
786
- if (op[0] & 5) throw op[1];
787
- return {
788
- value: op[0] ? op[1] : void 0,
789
- done: true
790
- };
791
- }
792
- }
793
- /**
794
- * Service that processes Trello webhook events.
795
- *
796
- * Verifies the signature, then dispatches verified events through a {@link Handler}
797
- * configured via {@link TrelloEventHandlerConfigurer}.
798
- */ exports.TrelloWebhookService = /*#__PURE__*/ function() {
799
- function TrelloWebhookService(config) {
800
- _class_call_check$2(this, TrelloWebhookService);
801
- _define_property$1(this, "logger", new common.Logger('TrelloWebhookService'));
802
- _define_property$1(this, "_verifier", void 0);
803
- _define_property$1(this, "handler", trelloEventHandlerFactory());
804
- _define_property$1(this, "configure", trelloEventHandlerConfigurerFactory(this.handler));
805
- this._verifier = trelloWebhookEventVerifier({
806
- appSecret: config.webhookConfig.appSecret,
807
- callbackUrl: config.webhookConfig.callbackUrl
808
- });
809
- }
810
- _create_class$1(TrelloWebhookService, [
811
- {
812
- key: "updateForWebhook",
813
- value: function updateForWebhook(req, rawBody) {
814
- return _async_to_generator$1(function() {
815
- var _this__verifier, valid, event, handled;
816
- return _ts_generator$1(this, function(_state) {
817
- switch(_state.label){
818
- case 0:
819
- _this__verifier = this._verifier(req, rawBody), valid = _this__verifier.valid, event = _this__verifier.event;
820
- handled = false;
821
- if (!!valid) return [
822
- 3,
823
- 1
824
- ];
825
- this.logger.warn('Received invalid Trello webhook event');
826
- return [
827
- 3,
828
- 3
829
- ];
830
- case 1:
831
- if (!event) return [
832
- 3,
833
- 3
834
- ];
835
- return [
836
- 4,
837
- this.updateForTrelloEvent(event)
838
- ];
839
- case 2:
840
- handled = _state.sent();
841
- _state.label = 3;
842
- case 3:
843
- return [
844
- 2,
845
- {
846
- valid: valid,
847
- handled: handled,
848
- event: event
849
- }
850
- ];
851
- }
852
- });
853
- }).call(this);
854
- }
855
- },
856
- {
857
- key: "updateForTrelloEvent",
858
- value: function updateForTrelloEvent(event) {
859
- return _async_to_generator$1(function() {
860
- var handled;
861
- return _ts_generator$1(this, function(_state) {
862
- switch(_state.label){
863
- case 0:
864
- return [
865
- 4,
866
- this.handler(event)
867
- ];
868
- case 1:
869
- handled = _state.sent();
870
- if (!handled) {
871
- this.logger.warn("Unhandled Trello webhook action type: ".concat(event.action.type));
872
- }
873
- return [
874
- 2,
875
- handled
876
- ];
877
- }
878
- });
879
- }).call(this);
880
- }
881
- }
882
- ]);
883
- return TrelloWebhookService;
884
- }();
885
- exports.TrelloWebhookService = __decorate([
886
- common.Injectable(),
887
- __param(0, common.Inject(TrelloWebhookServiceConfig))
888
- ], exports.TrelloWebhookService);
889
-
890
- function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
891
- try {
892
- var info = gen[key](arg);
893
- var value = info.value;
894
- } catch (error) {
895
- reject(error);
896
- return;
897
- }
898
- if (info.done) {
899
- resolve(value);
900
- } else {
901
- Promise.resolve(value).then(_next, _throw);
902
- }
903
- }
904
- function _async_to_generator(fn) {
905
- return function() {
906
- var self = this, args = arguments;
907
- return new Promise(function(resolve, reject) {
908
- var gen = fn.apply(self, args);
909
- function _next(value) {
910
- asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
911
- }
912
- function _throw(err) {
913
- asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
914
- }
915
- _next(undefined);
916
- });
917
- };
918
- }
919
- function _class_call_check$1(instance, Constructor) {
920
- if (!(instance instanceof Constructor)) {
921
- throw new TypeError("Cannot call a class as a function");
922
- }
923
- }
924
- function _defineProperties(target, props) {
925
- for(var i = 0; i < props.length; i++){
926
- var descriptor = props[i];
927
- descriptor.enumerable = descriptor.enumerable || false;
928
- descriptor.configurable = true;
929
- if ("value" in descriptor) descriptor.writable = true;
930
- Object.defineProperty(target, descriptor.key, descriptor);
931
- }
932
- }
933
- function _create_class(Constructor, protoProps, staticProps) {
934
- if (protoProps) _defineProperties(Constructor.prototype, protoProps);
935
- return Constructor;
936
- }
937
- function _define_property(obj, key, value) {
938
- if (key in obj) {
939
- Object.defineProperty(obj, key, {
940
- value: value,
941
- enumerable: true,
942
- configurable: true,
943
- writable: true
944
- });
945
- } else {
946
- obj[key] = value;
947
- }
948
- return obj;
949
- }
950
- function _ts_generator(thisArg, body) {
951
- var f, y, t, _ = {
952
- label: 0,
953
- sent: function() {
954
- if (t[0] & 1) throw t[1];
955
- return t[1];
956
- },
957
- trys: [],
958
- ops: []
959
- }, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype), d = Object.defineProperty;
960
- return d(g, "next", {
961
- value: verb(0)
962
- }), d(g, "throw", {
963
- value: verb(1)
964
- }), d(g, "return", {
965
- value: verb(2)
966
- }), typeof Symbol === "function" && d(g, Symbol.iterator, {
967
- value: function() {
968
- return this;
969
- }
970
- }), g;
971
- function verb(n) {
972
- return function(v) {
973
- return step([
974
- n,
975
- v
976
- ]);
977
- };
978
- }
979
- function step(op) {
980
- if (f) throw new TypeError("Generator is already executing.");
981
- while(g && (g = 0, op[0] && (_ = 0)), _)try {
982
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
983
- if (y = 0, t) op = [
984
- op[0] & 2,
985
- t.value
986
- ];
987
- switch(op[0]){
988
- case 0:
989
- case 1:
990
- t = op;
991
- break;
992
- case 4:
993
- _.label++;
994
- return {
995
- value: op[1],
996
- done: false
997
- };
998
- case 5:
999
- _.label++;
1000
- y = op[1];
1001
- op = [
1002
- 0
1003
- ];
1004
- continue;
1005
- case 7:
1006
- op = _.ops.pop();
1007
- _.trys.pop();
1008
- continue;
1009
- default:
1010
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
1011
- _ = 0;
1012
- continue;
1013
- }
1014
- if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
1015
- _.label = op[1];
1016
- break;
1017
- }
1018
- if (op[0] === 6 && _.label < t[1]) {
1019
- _.label = t[1];
1020
- t = op;
1021
- break;
1022
- }
1023
- if (t && _.label < t[2]) {
1024
- _.label = t[2];
1025
- _.ops.push(op);
1026
- break;
1027
- }
1028
- if (t[2]) _.ops.pop();
1029
- _.trys.pop();
1030
- continue;
1031
- }
1032
- op = body.call(thisArg, _);
1033
- } catch (e) {
1034
- op = [
1035
- 6,
1036
- e
1037
- ];
1038
- y = 0;
1039
- } finally{
1040
- f = t = 0;
1041
- }
1042
- if (op[0] & 5) throw op[1];
1043
- return {
1044
- value: op[0] ? op[1] : void 0,
1045
- done: true
1046
- };
1047
- }
1048
- }
1049
- exports.TrelloWebhookController = /*#__PURE__*/ function() {
1050
- function TrelloWebhookController(trelloWebhookService) {
1051
- _class_call_check$1(this, TrelloWebhookController);
1052
- _define_property(this, "trelloWebhookService", void 0);
1053
- this.trelloWebhookService = trelloWebhookService;
1054
- }
1055
- _create_class(TrelloWebhookController, [
1056
- {
1057
- /**
1058
- * Endpoint Trello pings with HEAD during webhook registration. Must return 200.
1059
- */ key: "handleTrelloWebhookHead",
1060
- value: function handleTrelloWebhookHead() {
1061
- // Empty body, 200 status.
1062
- }
1063
- },
1064
- {
1065
- key: "handleTrelloWebhook",
1066
- value: function handleTrelloWebhook(req, rawBody) {
1067
- return _async_to_generator(function() {
1068
- return _ts_generator(this, function(_state) {
1069
- switch(_state.label){
1070
- case 0:
1071
- return [
1072
- 4,
1073
- this.trelloWebhookService.updateForWebhook(req, rawBody)
1074
- ];
1075
- case 1:
1076
- _state.sent();
1077
- return [
1078
- 2
1079
- ];
1080
- }
1081
- });
1082
- }).call(this);
1083
- }
1084
- }
1085
- ]);
1086
- return TrelloWebhookController;
1087
- }();
1088
- __decorate([
1089
- common.Head()
1090
- ], exports.TrelloWebhookController.prototype, "handleTrelloWebhookHead", null);
1091
- __decorate([
1092
- common.Post(),
1093
- __param(0, common.Req()),
1094
- __param(1, nestjs.RawBody())
1095
- ], exports.TrelloWebhookController.prototype, "handleTrelloWebhook", null);
1096
- exports.TrelloWebhookController = __decorate([
1097
- common.Controller('/webhook/trello'),
1098
- __param(0, common.Inject(exports.TrelloWebhookService))
1099
- ], exports.TrelloWebhookController);
1100
-
1101
- function _class_call_check(instance, Constructor) {
1102
- if (!(instance instanceof Constructor)) {
1103
- throw new TypeError("Cannot call a class as a function");
1104
- }
1105
- }
1106
- /**
1107
- * Factory function that creates TrelloWebhookServiceConfig from NestJS ConfigService.
1108
- *
1109
- * Reads `TRELLO_APP_SECRET` and `TRELLO_WEBHOOK_CALLBACK_URL` from the environment.
1110
- *
1111
- * @param configService - The NestJS ConfigService.
1112
- * @returns A validated TrelloWebhookServiceConfig.
1113
- */ function trelloWebhookServiceConfigFactory(configService) {
1114
- var config = {
1115
- webhookConfig: {
1116
- appSecret: configService.get(TRELLO_APP_SECRET_ENV_VAR),
1117
- callbackUrl: configService.get(TRELLO_WEBHOOK_CALLBACK_URL_ENV_VAR)
1118
- }
1119
- };
1120
- TrelloWebhookServiceConfig.assertValidConfig(config);
1121
- return config;
1122
- }
1123
- exports.TrelloWebhookModule = function TrelloWebhookModule() {
1124
- _class_call_check(this, TrelloWebhookModule);
1125
- };
1126
- exports.TrelloWebhookModule = __decorate([
1127
- common.Module({
1128
- imports: [
1129
- config.ConfigModule
1130
- ],
1131
- controllers: [
1132
- exports.TrelloWebhookController
1133
- ],
1134
- exports: [
1135
- exports.TrelloWebhookService
1136
- ],
1137
- providers: [
1138
- {
1139
- provide: TrelloWebhookServiceConfig,
1140
- inject: [
1141
- config.ConfigService
1142
- ],
1143
- useFactory: trelloWebhookServiceConfigFactory
1144
- },
1145
- exports.TrelloWebhookService
1146
- ]
1147
- })
1148
- ], exports.TrelloWebhookModule);
1149
-
1150
- exports.TRELLO_API_KEY_ENV_VAR = TRELLO_API_KEY_ENV_VAR;
1151
- exports.TRELLO_API_TOKEN_ENV_VAR = TRELLO_API_TOKEN_ENV_VAR;
1152
- exports.TRELLO_APP_SECRET_ENV_VAR = TRELLO_APP_SECRET_ENV_VAR;
1153
- exports.TRELLO_WEBHOOK_ADD_MEMBER_TO_CARD_ACTION_TYPE = TRELLO_WEBHOOK_ADD_MEMBER_TO_CARD_ACTION_TYPE;
1154
- exports.TRELLO_WEBHOOK_CALLBACK_URL_ENV_VAR = TRELLO_WEBHOOK_CALLBACK_URL_ENV_VAR;
1155
- exports.TRELLO_WEBHOOK_COMMENT_CARD_ACTION_TYPE = TRELLO_WEBHOOK_COMMENT_CARD_ACTION_TYPE;
1156
- exports.TRELLO_WEBHOOK_CREATE_CARD_ACTION_TYPE = TRELLO_WEBHOOK_CREATE_CARD_ACTION_TYPE;
1157
- exports.TRELLO_WEBHOOK_DELETE_CARD_ACTION_TYPE = TRELLO_WEBHOOK_DELETE_CARD_ACTION_TYPE;
1158
- exports.TRELLO_WEBHOOK_REMOVE_MEMBER_FROM_CARD_ACTION_TYPE = TRELLO_WEBHOOK_REMOVE_MEMBER_FROM_CARD_ACTION_TYPE;
1159
- exports.TRELLO_WEBHOOK_UPDATE_BOARD_ACTION_TYPE = TRELLO_WEBHOOK_UPDATE_BOARD_ACTION_TYPE;
1160
- exports.TRELLO_WEBHOOK_UPDATE_CARD_ACTION_TYPE = TRELLO_WEBHOOK_UPDATE_CARD_ACTION_TYPE;
1161
- exports.TrelloServiceConfig = TrelloServiceConfig;
1162
- exports.TrelloWebhookServiceConfig = TrelloWebhookServiceConfig;
1163
- exports.appTrelloModuleMetadata = appTrelloModuleMetadata;
1164
- exports.trelloEventHandlerConfigurerFactory = trelloEventHandlerConfigurerFactory;
1165
- exports.trelloEventHandlerFactory = trelloEventHandlerFactory;
1166
- exports.trelloServiceConfigFactory = trelloServiceConfigFactory;
1167
- exports.trelloWebhookEvent = trelloWebhookEvent;
1168
- exports.trelloWebhookEventVerifier = trelloWebhookEventVerifier;
1169
- exports.trelloWebhookExpectedSignature = trelloWebhookExpectedSignature;
1170
- exports.trelloWebhookServiceConfigFactory = trelloWebhookServiceConfigFactory;