@slack/bolt 3.11.3 → 4.0.0-nextGen.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (109) hide show
  1. package/README.md +5 -2
  2. package/dist/App.d.ts +57 -27
  3. package/dist/App.d.ts.map +1 -1
  4. package/dist/App.js +138 -48
  5. package/dist/App.js.map +1 -1
  6. package/dist/Manifest.d.ts +5 -0
  7. package/dist/Manifest.d.ts.map +1 -0
  8. package/dist/Manifest.js +16 -0
  9. package/dist/Manifest.js.map +1 -0
  10. package/dist/SlackFunction-utils.d.ts +4 -0
  11. package/dist/SlackFunction-utils.d.ts.map +1 -0
  12. package/dist/SlackFunction-utils.js +27 -0
  13. package/dist/SlackFunction-utils.js.map +1 -0
  14. package/dist/SlackFunction.d.ts +181 -0
  15. package/dist/SlackFunction.d.ts.map +1 -0
  16. package/dist/SlackFunction.js +418 -0
  17. package/dist/SlackFunction.js.map +1 -0
  18. package/dist/Subscription.d.ts +61 -0
  19. package/dist/Subscription.d.ts.map +1 -0
  20. package/dist/Subscription.js +169 -0
  21. package/dist/Subscription.js.map +1 -0
  22. package/dist/cli/get-hooks.d.ts +2 -0
  23. package/dist/cli/get-hooks.d.ts.map +1 -0
  24. package/dist/cli/get-hooks.js +18 -0
  25. package/dist/cli/get-hooks.js.map +1 -0
  26. package/dist/cli/get-manifest.d.ts +3 -0
  27. package/dist/cli/get-manifest.d.ts.map +1 -0
  28. package/dist/cli/get-manifest.js +16 -0
  29. package/dist/cli/get-manifest.js.map +1 -0
  30. package/dist/cli/hook-utils/manifest.d.ts +7 -0
  31. package/dist/cli/hook-utils/manifest.d.ts.map +1 -0
  32. package/dist/cli/hook-utils/manifest.js +104 -0
  33. package/dist/cli/hook-utils/manifest.js.map +1 -0
  34. package/dist/cli/hook-utils/manifest.spec.d.ts +2 -0
  35. package/dist/cli/hook-utils/manifest.spec.d.ts.map +1 -0
  36. package/dist/cli/hook-utils/manifest.spec.js +75 -0
  37. package/dist/cli/hook-utils/manifest.spec.js.map +1 -0
  38. package/dist/cli/run.d.ts +2 -0
  39. package/dist/cli/run.d.ts.map +1 -0
  40. package/dist/cli/run.js +37 -0
  41. package/dist/cli/run.js.map +1 -0
  42. package/dist/cli/start.d.ts +3 -0
  43. package/dist/cli/start.d.ts.map +1 -0
  44. package/dist/cli/start.js +40 -0
  45. package/dist/cli/start.js.map +1 -0
  46. package/dist/errors.d.ts +13 -1
  47. package/dist/errors.d.ts.map +1 -1
  48. package/dist/errors.js +25 -1
  49. package/dist/errors.js.map +1 -1
  50. package/dist/helpers.d.ts +2 -1
  51. package/dist/helpers.d.ts.map +1 -1
  52. package/dist/helpers.js +8 -0
  53. package/dist/helpers.js.map +1 -1
  54. package/dist/index.d.ts +2 -0
  55. package/dist/index.d.ts.map +1 -1
  56. package/dist/index.js +2 -0
  57. package/dist/index.js.map +1 -1
  58. package/dist/middleware/builtin.d.ts.map +1 -1
  59. package/dist/middleware/builtin.js +0 -1
  60. package/dist/middleware/builtin.js.map +1 -1
  61. package/dist/middleware/process.d.ts.map +1 -1
  62. package/dist/middleware/process.js.map +1 -1
  63. package/dist/receivers/ExpressReceiver.d.ts +1 -1
  64. package/dist/receivers/ExpressReceiver.js +2 -1
  65. package/dist/receivers/ExpressReceiver.js.map +1 -1
  66. package/dist/receivers/HTTPModuleFunctions.d.ts.map +1 -1
  67. package/dist/receivers/HTTPModuleFunctions.js +2 -1
  68. package/dist/receivers/HTTPModuleFunctions.js.map +1 -1
  69. package/dist/receivers/HTTPReceiver.js +4 -4
  70. package/dist/receivers/HTTPReceiver.js.map +1 -1
  71. package/dist/receivers/SocketModeFunctions.js +2 -1
  72. package/dist/receivers/SocketModeFunctions.js.map +1 -1
  73. package/dist/receivers/SocketModeReceiver.js.map +1 -1
  74. package/dist/receivers/render-html-for-install-path.js +1 -1
  75. package/dist/receivers/verify-request.d.ts +2 -2
  76. package/dist/receivers/verify-request.d.ts.map +1 -1
  77. package/dist/receivers/verify-request.js +6 -5
  78. package/dist/receivers/verify-request.js.map +1 -1
  79. package/dist/types/actions/block-action.d.ts +4 -3
  80. package/dist/types/actions/block-action.d.ts.map +1 -1
  81. package/dist/types/actions/dialog-action.d.ts +4 -0
  82. package/dist/types/actions/dialog-action.d.ts.map +1 -1
  83. package/dist/types/events/base-events.d.ts +32 -2
  84. package/dist/types/events/base-events.d.ts.map +1 -1
  85. package/dist/types/events/base-events.js.map +1 -1
  86. package/dist/types/events/message-events.d.ts +37 -1
  87. package/dist/types/events/message-events.d.ts.map +1 -1
  88. package/dist/types/functions/index.d.ts +26 -0
  89. package/dist/types/functions/index.d.ts.map +1 -0
  90. package/dist/types/functions/index.js +3 -0
  91. package/dist/types/functions/index.js.map +1 -0
  92. package/dist/types/index.d.ts +1 -0
  93. package/dist/types/index.d.ts.map +1 -1
  94. package/dist/types/index.js +1 -0
  95. package/dist/types/index.js.map +1 -1
  96. package/dist/types/middleware.d.ts +25 -5
  97. package/dist/types/middleware.d.ts.map +1 -1
  98. package/dist/types/middleware.js.map +1 -1
  99. package/dist/types/subscription/index.d.ts +80 -0
  100. package/dist/types/subscription/index.d.ts.map +1 -0
  101. package/dist/types/subscription/index.js +3 -0
  102. package/dist/types/subscription/index.js.map +1 -0
  103. package/dist/types/view/index.d.ts +6 -5
  104. package/dist/types/view/index.d.ts.map +1 -1
  105. package/package.json +16 -5
  106. package/src/cli/get-hooks.js +16 -0
  107. package/src/cli/get-manifest.js +16 -0
  108. package/src/cli/hook-utils/manifest.js +114 -0
  109. package/src/cli/start.js +43 -0
@@ -0,0 +1,418 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.hasHandler = exports.findMatchingManifestDefinition = exports.hasMatchingManifestDefinition = exports.hasCallbackId = exports.errorIfInvalidConstraintKeys = exports.validate = exports.passConstraint = exports.isFunctionInteractivityEvent = exports.isFunctionExecutedEvent = exports.SlackFunction = exports.manifestUtil = void 0;
7
+ const util_1 = __importDefault(require("util"));
8
+ const logger_1 = require("@slack/logger");
9
+ const errors_1 = require("./errors");
10
+ // eslint-disable-next-line
11
+ exports.manifestUtil = require('./cli/hook-utils/manifest');
12
+ /**
13
+ * *SlackFunction*
14
+ *
15
+ * Configure a SlackFunction's callbackId,
16
+ * and any expected inputs and outputs
17
+ * in your project's manifest file (json or js).
18
+ *
19
+ * Use this class to declare your handling logic:
20
+ *
21
+ * Example:
22
+ * ```
23
+ * const myFunc = new SlackFunction('fn_callback_id', () => {});
24
+ * ```
25
+ * You can also declare
26
+ * optional handlers for `block_action` and `view` events
27
+ * related to your function.
28
+ *
29
+ * Example:
30
+ * ```
31
+ * myFunc.action('action_id', () => {})
32
+ * .view('view_callback_id', () => {});
33
+ * ```
34
+ * Note: This is not equivalent to app.action() or app.view()
35
+ *
36
+ * *Completing your function*
37
+ *
38
+ * Call the supplied utility `complete` when your function is
39
+ * done executing. This tells Slack it can proceed
40
+ * with any next steps in any workflow this function might
41
+ * be included in.
42
+ *
43
+ * Supply outputs or an error or nothing when your
44
+ * function is done. Note, your outputs should match what you
45
+ * have defined in your in your manifest.
46
+ *
47
+ * Example:
48
+ * ```
49
+ * const myFunc = new SlackFunction('fn_callback_id', ({ complete }) => {
50
+ * // do my work here
51
+ *
52
+ * complete() // or
53
+ * complete({ outputs: {} }); // or
54
+ * complete({ error: "error details here" });
55
+ * });
56
+ * ```
57
+ *
58
+ * Call `complete()` from your main handler or
59
+ * an interactivity handler. Note, once a function is
60
+ * completed (either with outputs or an error), interactions
61
+ * from views generated in the course of function execution
62
+ * will no longer trigger associated handlers, so remember to clean those up.
63
+ * */
64
+ class SlackFunction {
65
+ constructor(callbackId, handler) {
66
+ this.runHandler = async (args) => {
67
+ this.logger.debug('🚀 Executing my main handler:', this.handler);
68
+ try {
69
+ const handlerArgs = this.prepareFnArgs(args);
70
+ await this.handler(handlerArgs);
71
+ }
72
+ catch (err) {
73
+ this.logger.error('⚠️ Something went wrong executing:', this.handler, '\n⚠️ Error Details:', err);
74
+ }
75
+ };
76
+ this.runInteractivityHandlers = async (args) => {
77
+ const jobs = [];
78
+ for (let i = 0; i < this.interactivityHandlers.length; i += 1) {
79
+ const { constraints, handler } = this.interactivityHandlers[i];
80
+ if (passInteractivityConstraints(constraints, args)) {
81
+ const handlerArgs = this.prepareFnArgs(args);
82
+ // helpful logging
83
+ this.logger.debug('🚀 Executing my interactive handler:', handler);
84
+ this.logger.debug('🚀 Registered with constraints:', constraints);
85
+ jobs.push(handler(handlerArgs));
86
+ }
87
+ }
88
+ return new Promise((resolve, reject) => {
89
+ Promise.all(jobs).then((_) => resolve()).catch((error) => {
90
+ const msg = `⚠️ A SlackFunction handler promise rejected. Error details: ${error}`;
91
+ const err = new errors_1.SlackFunctionExecutionError(msg);
92
+ reject(err);
93
+ });
94
+ });
95
+ };
96
+ validate(callbackId, handler);
97
+ this.callbackId = callbackId;
98
+ this.handler = handler;
99
+ this.interactivityHandlers = [];
100
+ // set an initial default logging
101
+ const logger = new logger_1.ConsoleLogger();
102
+ logger.setName(`SlackFunction: [${this.callbackId}]`);
103
+ logger.setLevel(logger_1.LogLevel.DEBUG);
104
+ this.logger = logger;
105
+ }
106
+ /**
107
+ * Attach a block_actions interactivity handler to your SlackFunction
108
+ *
109
+ * ```
110
+ * Example:
111
+ * const actionHandler = async () => {};
112
+ * const actionHandler1 = async () => {};
113
+ * myFunc.action("id", actionHandler).action("id1", actionHandler1);
114
+ * ```
115
+ *
116
+ * @param actionIdOrConstraints Provide an action_id string
117
+ * corresponding to the value supplied in your blocks or a
118
+ * constraint object of type ActionConstraints<SlackAction>
119
+ *
120
+ * ```
121
+ * Example:
122
+ * myFunc.action({ type: "action_submission" });
123
+ * myFunc.action({ action_id: "id" }, actionHandler);
124
+ * ```
125
+ * @param handler Provide a handler function
126
+ * @returns SlackFunction instance
127
+ */
128
+ action(actionIdOrConstraints, handler) {
129
+ // normalize constraints
130
+ const constraints = (typeof actionIdOrConstraints === 'string' ||
131
+ util_1.default.types.isRegExp(actionIdOrConstraints)) ?
132
+ { action_id: actionIdOrConstraints } :
133
+ actionIdOrConstraints;
134
+ // declare our valid constraints keys
135
+ const validConstraintsKeys = ['action_id', 'block_id', 'callback_id', 'type'];
136
+ // cast to string array for convenience
137
+ const validConstraintsKeysAsStrings = validConstraintsKeys;
138
+ errorIfInvalidConstraintKeys(constraints, validConstraintsKeysAsStrings, handler);
139
+ this.interactivityHandlers.push({ constraints, handler });
140
+ return this;
141
+ }
142
+ /**
143
+ * Attach a view_submission or view_closed interactivity handler
144
+ * to your SlackFunction
145
+ *
146
+ * ```
147
+ * Example:
148
+ * const viewHandler = async () => {};
149
+ * const viewHandler1 = async () => {};
150
+ * myFunc.view("id", viewHandler).view("id1", viewHandler1)
151
+ * ```
152
+ *
153
+ * @param callbackIdOrConstraints Provide a `callback_id` string
154
+ * a constraint object of type ViewConstraints
155
+ *
156
+ * ```
157
+ * Example:
158
+ * myFunc.view({ type: "view_submission" });
159
+ * myFunc.view({ callback_id: "id", }, viewHandler)
160
+ * ```
161
+ *
162
+ * @param handler Provide a handler function
163
+ * @returns SlackFunction instance
164
+ */
165
+ view(callbackIdOrConstraints, handler) {
166
+ // normalize constraints
167
+ const constraints = (typeof callbackIdOrConstraints === 'string' ||
168
+ util_1.default.types.isRegExp(callbackIdOrConstraints)) ?
169
+ { callback_id: callbackIdOrConstraints, type: 'view_submission' } :
170
+ callbackIdOrConstraints;
171
+ // declare our valid constraints keys
172
+ const validConstraintsKeys = ['callback_id', 'type'];
173
+ // cast to string array for convenience
174
+ const validConstraintsKeysAsStrings = validConstraintsKeys;
175
+ errorIfInvalidConstraintKeys(constraints, validConstraintsKeysAsStrings, handler);
176
+ this.interactivityHandlers.push({ constraints, handler });
177
+ return this;
178
+ }
179
+ matchesFuncConstraints(args) {
180
+ if ('function' in args.payload) {
181
+ return this.callbackId === args.payload.function.callback_id;
182
+ }
183
+ return false;
184
+ }
185
+ /**
186
+ * Returns a a single middleware to global
187
+ * middleware chain. Responsible for returning
188
+ * handlers required for either function execution
189
+ * or function interactivity event handlering to
190
+ * the global event processing chain.
191
+ */
192
+ getMiddleware() {
193
+ return (args) => {
194
+ // handle function executed event
195
+ if ((isFunctionExecutedEvent(args) && this.matchesFuncConstraints(args))) {
196
+ return this.runHandler(args);
197
+ }
198
+ // handle function interactivity events
199
+ if (isFunctionInteractivityEvent(args)) {
200
+ return this.runInteractivityHandlers(args);
201
+ }
202
+ // call the next middleware in the global middleware chain
203
+ return args.next();
204
+ };
205
+ }
206
+ /**
207
+ * Ensure that SlackFunction `complete()` utility callback is provided
208
+ * as args to all function and interactivity handlers registered on
209
+ * SlackFunction instance
210
+ * @param args middleware arguments
211
+ */
212
+ prepareFnArgs(args) {
213
+ var _a;
214
+ const { next: _next, ...subArgs } = args;
215
+ // eslint-disable-next-line
216
+ const preparedArgs = { ...subArgs };
217
+ // ensure all handlers have complete utility
218
+ preparedArgs.complete = (_a = preparedArgs.complete) !== null && _a !== void 0 ? _a : this.createComplete(preparedArgs);
219
+ return preparedArgs;
220
+ }
221
+ /**
222
+ * Creates a `complete()` utility function
223
+ *
224
+ * @param args
225
+ * @returns A `complete()` utility callback
226
+ * which can be accessed from any SlackFunction
227
+ * handler and used to to complete your SlackFunction.
228
+ *
229
+ * ```
230
+ * Example:
231
+ * const handler = async ({ complete }) => { complete() };
232
+ * const myFunc = new SlackFunction("id", handler);
233
+ * ```
234
+ */
235
+ // eslint-disable-next-line
236
+ createComplete(args) {
237
+ const { payload, body, client } = args;
238
+ // gets the function execution id from a function executed event
239
+ let { function_execution_id } = payload;
240
+ // gets the function execution id from the function data in a function interactivity event
241
+ if (function_execution_id === undefined && body !== undefined && 'function_data' in body) {
242
+ function_execution_id = body.function_data.execution_id;
243
+ }
244
+ // if stil undefined, error
245
+ if (function_execution_id === undefined) {
246
+ const msg = '⚠️ Cannot generate required complete utility without a function_execution_id';
247
+ throw new errors_1.SlackFunctionCompleteError(msg);
248
+ }
249
+ // return the utility callback
250
+ return ({ outputs, error } = {}) => {
251
+ // Slack API requires functions complete with either outputs or error, not both
252
+ if (outputs && error) {
253
+ throw new errors_1.SlackFunctionCompleteError('⚠️ Cannot complete with outputs and error message supplied');
254
+ }
255
+ // if user has supplied outputs OR has supplied neither outputs nor error
256
+ if (outputs !== undefined || (outputs === undefined && error === undefined)) {
257
+ // helpful logging
258
+ this.logger.debug('🚀 Attempting to complete with outputs:', outputs);
259
+ return client.apiCall('functions.completeSuccess', {
260
+ outputs: outputs !== null && outputs !== void 0 ? outputs : {},
261
+ function_execution_id,
262
+ });
263
+ }
264
+ if (error !== undefined) {
265
+ this.logger.debug('🚀 Attempting to complete with error:', error);
266
+ return client.apiCall('functions.completeError', {
267
+ error,
268
+ function_execution_id,
269
+ });
270
+ }
271
+ return null;
272
+ };
273
+ }
274
+ }
275
+ exports.SlackFunction = SlackFunction;
276
+ /* Event handling validation */
277
+ function isFunctionExecutedEvent(args) {
278
+ if (args.payload === undefined || args.payload === null) {
279
+ return false;
280
+ }
281
+ return (args.payload.type === 'function_executed');
282
+ }
283
+ exports.isFunctionExecutedEvent = isFunctionExecutedEvent;
284
+ function isFunctionInteractivityEvent(args) {
285
+ const allowedInteractivityTypes = [
286
+ 'block_actions', 'view_submission', 'view_closed'
287
+ ];
288
+ if (args.body === undefined || args.body === null)
289
+ return false;
290
+ return (allowedInteractivityTypes.includes(args.body.type) &&
291
+ ('function_data' in args.body));
292
+ }
293
+ exports.isFunctionInteractivityEvent = isFunctionInteractivityEvent;
294
+ function passInteractivityConstraints(constraints, args) {
295
+ const { payload, body } = args;
296
+ if (!passConstraint('type', constraints, body))
297
+ return false;
298
+ if (!passConstraint('block_id', constraints, payload))
299
+ return false;
300
+ if (!passConstraint('action_id', constraints, payload))
301
+ return false;
302
+ if ('callback_id' in constraints) {
303
+ if ('view' in body) {
304
+ if (!passConstraint('callback_id', constraints, body.view))
305
+ return false;
306
+ }
307
+ else {
308
+ return false;
309
+ }
310
+ }
311
+ return true;
312
+ }
313
+ function passConstraint(constraintKey, constraints,
314
+ // eslint-disable-next-line
315
+ payload) {
316
+ let regExpMatches;
317
+ let pass = true;
318
+ // user provided constraint key, e.g. action_id
319
+ if (constraintKey in constraints) {
320
+ // event payload contains constraint key
321
+ if (constraintKey in payload) {
322
+ // eslint-disable-next-line
323
+ // @ts-ignore - we ensure constraintKey exists in constraints above
324
+ const constraintVal = constraints[constraintKey];
325
+ if (typeof constraintVal === 'string') {
326
+ if (constraintVal !== payload[constraintKey]) {
327
+ pass = false;
328
+ }
329
+ }
330
+ else {
331
+ // treat constraintKey as regular expression and check payload for matches
332
+ regExpMatches = payload[constraintKey].match(constraintVal);
333
+ if (regExpMatches === null) {
334
+ pass = false;
335
+ }
336
+ }
337
+ }
338
+ else {
339
+ // user provided constraint, but payload doesn't contain key value
340
+ pass = false;
341
+ }
342
+ }
343
+ return pass;
344
+ }
345
+ exports.passConstraint = passConstraint;
346
+ // all tests to run
347
+ const validations = [hasCallbackId, hasMatchingManifestDefinition, hasHandler];
348
+ /* Initialization validators */
349
+ function validate(callbackId, handler) {
350
+ validations.forEach((test) => {
351
+ const res = test(callbackId, handler);
352
+ if (!res.pass) {
353
+ throw new errors_1.SlackFunctionInitializationError(res.msg);
354
+ }
355
+ });
356
+ }
357
+ exports.validate = validate;
358
+ function errorIfInvalidConstraintKeys(constraints, validKeys, handler) {
359
+ const invalidKeys = Object.keys(constraints).filter((key) => !validKeys.includes(key));
360
+ if (invalidKeys.length > 0) {
361
+ const msg = `⚠️ You supplied invalid constraints: ${invalidKeys} for handler: ${handler}`;
362
+ throw new errors_1.SlackFunctionInitializationError(msg);
363
+ }
364
+ }
365
+ exports.errorIfInvalidConstraintKeys = errorIfInvalidConstraintKeys;
366
+ function hasCallbackId(callbackId, _) {
367
+ const res = { pass: true, msg: '' };
368
+ if (callbackId === undefined ||
369
+ typeof callbackId !== 'string' ||
370
+ callbackId === '') {
371
+ res.pass = false;
372
+ res.msg = 'SlackFunction expects a callback_id string as its first argument';
373
+ }
374
+ return res;
375
+ }
376
+ exports.hasCallbackId = hasCallbackId;
377
+ function hasMatchingManifestDefinition(callbackId, _) {
378
+ const res = { pass: true, msg: '' };
379
+ const { matchFound, fnKeys } = findMatchingManifestDefinition(callbackId);
380
+ if (!matchFound) {
381
+ res.pass = false;
382
+ res.msg = `Provided SlackFunction callback_id: "${callbackId}" does not have a matching manifest ` +
383
+ 'definition. Please check your manifest file.\n' +
384
+ `Definitions we were able to find: ${fnKeys}`;
385
+ }
386
+ return res;
387
+ }
388
+ exports.hasMatchingManifestDefinition = hasMatchingManifestDefinition;
389
+ function findMatchingManifestDefinition(callbackId) {
390
+ const result = { matchFound: false, fnKeys: [] };
391
+ // call the hook to get the manifest
392
+ const manifest = exports.manifestUtil.getManifestData(process.cwd());
393
+ // manifest file must exist in the project
394
+ if (!('functions' in manifest)) {
395
+ const msg = '⚠️ Could not find functions in your project manifest.';
396
+ throw new errors_1.SlackFunctionInitializationError(msg);
397
+ }
398
+ try {
399
+ // set the keys
400
+ result.fnKeys = Object.keys(manifest.functions);
401
+ result.matchFound = result.fnKeys.includes(callbackId);
402
+ }
403
+ catch (error) {
404
+ throw new errors_1.SlackFunctionInitializationError('Something went wrong when trying to read your manifest function definitions');
405
+ }
406
+ return result;
407
+ }
408
+ exports.findMatchingManifestDefinition = findMatchingManifestDefinition;
409
+ function hasHandler(_, handler) {
410
+ const res = { pass: true, msg: '' };
411
+ if (handler === undefined) {
412
+ res.pass = false;
413
+ res.msg = 'You must provide a SlackFunction handler';
414
+ }
415
+ return res;
416
+ }
417
+ exports.hasHandler = hasHandler;
418
+ //# sourceMappingURL=SlackFunction.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SlackFunction.js","sourceRoot":"","sources":["../src/SlackFunction.ts"],"names":[],"mappings":";;;;;;AAAA,gDAAwB;AACxB,0CAAgE;AAiBhE,qCAIkB;AAElB,2BAA2B;AACd,QAAA,YA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MAAM,IAAI,yCAAgC,CAAC,GAAG,CAAC,CAAC;KACjD;IAED,IAAI;QACF,eAAe;QACf,MAAM,CAAC,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC;QAChD,MAAM,CAAC,UAAU,GAAG,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC;KACxD;IAAC,OAAO,KAAK,EAAE;QACd,MAAM,IAAI,yCAAgC,CAAC,6EAA6E,CAAC,CAAC;KAC3H;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAnBD,wEAmBC;AAED,SAAgB,UAAU,CAAC,CAAS,EAAE,OAA6C;IACjF,MAAM,GAAG,GAA0B,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,EAAE,EAAE,CAAC;IAC3D,IAAI,OAAO,KAAK,SAAS,EAAE;QACzB,GAAG,CAAC,IAAI,GAAG,KAAK,CAAC;QACjB,GAAG,CAAC,GAAG,GAAG,0CAA0C,CAAC;KACtD;IACD,OAAO,GAAG,CAAC;AACb,CAAC;AAPD,gCAOC"}
@@ -0,0 +1,61 @@
1
+ import { Middleware, AnyMiddlewareArgs, AllMiddlewareArgs } from './types';
2
+ import { SubscriptionOnCreateMiddleware, SubscriptionOnConfigureMiddleware, SubscriptionOnDeletedMiddleware, SlackSubscriptionMiddlewareArgs, SubConfigureFn } from './types/subscription';
3
+ export interface SubscriptionOptions {
4
+ onCreate: SubscriptionOnCreateMiddleware | SubscriptionOnCreateMiddleware[];
5
+ onConfigure: SubscriptionOnConfigureMiddleware | SubscriptionOnConfigureMiddleware[];
6
+ onDeleted?: SubscriptionOnDeletedMiddleware | SubscriptionOnDeletedMiddleware[];
7
+ }
8
+ declare type AllSubscriptionMiddlewareArgs<T extends SlackSubscriptionMiddlewareArgs = SlackSubscriptionMiddlewareArgs> = T & AllMiddlewareArgs;
9
+ export declare type SubscriptionMiddleware = SubscriptionOnCreateMiddleware[] | SubscriptionOnConfigureMiddleware[] | SubscriptionOnDeletedMiddleware[] | [];
10
+ export declare const VALID_NOTIFICATION_SUBSCRIPTION_INTERACTION_TYPES: string[];
11
+ /**
12
+ * Subscription describes a collection of named middlewares
13
+ * for handling notification subscription related interaction
14
+ * payloads.
15
+ * */
16
+ export declare class Subscription {
17
+ /**
18
+ * @description The unique resource id for this Subscription.
19
+ * */
20
+ private id;
21
+ /** Middleware to process :: 'notification_subscription_create_requested'
22
+ * interaction payload
23
+ * */
24
+ private onCreate;
25
+ /** Middleware to process :: 'notification_subscription_configure_requested'
26
+ * interaction payload
27
+ * */
28
+ private onConfigure;
29
+ /** Middleware to process :: 'notification_subscription_deleted' interaction
30
+ * payload
31
+ * */
32
+ private onDeleted;
33
+ constructor(id: string, options: SubscriptionOptions);
34
+ getMiddleware(): Middleware<AnyMiddlewareArgs>;
35
+ /**
36
+ * `matchesConstraints()` implements any required constraints
37
+ * on notification subscription interaction payloads.
38
+ * */
39
+ private matchesConstraints;
40
+ private process;
41
+ private getSubMiddleware;
42
+ }
43
+ export declare function validate(id: string, options: SubscriptionOptions): void;
44
+ export declare function isSubscriptionInteraction(args: AnyMiddlewareArgs): args is AllSubscriptionMiddlewareArgs;
45
+ /**
46
+ * `processSubMiddleware()` processes subscription interaction payload with the
47
+ * middleware supplied by the user.
48
+ * */
49
+ export declare function processSubMiddleware(args: AllSubscriptionMiddlewareArgs, origMiddleware: SubscriptionMiddleware): Promise<void>;
50
+ /**
51
+ * `prepareSubArgs()` prepares the arguments for the specific middlewares
52
+ * adding specific arguments for utilities
53
+ * */
54
+ export declare function prepareSubArgs(args: AllMiddlewareArgs): AllSubscriptionMiddlewareArgs;
55
+ /**
56
+ * Utility which returns a fxn which can be used to
57
+ * open a configure view for configuring a Slack subscription
58
+ * */
59
+ export declare function createConfigure(args: any): SubConfigureFn;
60
+ export {};
61
+ //# sourceMappingURL=Subscription.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Subscription.d.ts","sourceRoot":"","sources":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AA6B,CAGxG;AAED;;;KAGK;AACL,wBAAsB,oBAAoB,CACxC,IAAI,EAAE,6BAA6B,EACnC,cAAc,EAAE,sBAAsB,GACrC,OAAO,CAAC,IAAI,CAAC,CAiBf;AACD;;;KAGK;AACL,wBAAgB,cAAc,CAAC,IAAI,EAAE,iBAAiB,GAAG,6BAA6B,CAcrF;AAED;;;KAGK;AACL,wBAAgB,eAAe,CAAC,IAAI,EAAE,GAAG,GAAG,cAAc,CAUzD"}
@@ -0,0 +1,169 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createConfigure = exports.prepareSubArgs = exports.processSubMiddleware = exports.isSubscriptionInteraction = exports.validate = exports.Subscription = exports.VALID_NOTIFICATION_SUBSCRIPTION_INTERACTION_TYPES = void 0;
4
+ /* Constants */
5
+ exports.VALID_NOTIFICATION_SUBSCRIPTION_INTERACTION_TYPES = [
6
+ 'notification_subscription_create_requested',
7
+ 'notification_subscription_configure_requested',
8
+ 'notification_subscription_deleted',
9
+ ];
10
+ /**
11
+ * Subscription describes a collection of named middlewares
12
+ * for handling notification subscription related interaction
13
+ * payloads.
14
+ * */
15
+ class Subscription {
16
+ constructor(id, options) {
17
+ /** Middleware to process :: 'notification_subscription_deleted' interaction
18
+ * payload
19
+ * */
20
+ this.onDeleted = [];
21
+ this.process = async (args) => {
22
+ const { payload } = args;
23
+ const subArgs = prepareSubArgs(args);
24
+ const subMiddleware = this.getSubMiddleware(payload);
25
+ return processSubMiddleware(subArgs, subMiddleware);
26
+ };
27
+ this.getSubMiddleware = (payload) => {
28
+ switch (payload.type) {
29
+ case 'notification_subscription_create_requested':
30
+ return this.onCreate;
31
+ case 'notification_subscription_configure_requested':
32
+ return this.onConfigure;
33
+ case 'notification_subscription_deleted':
34
+ return this.onDeleted;
35
+ default:
36
+ return [];
37
+ }
38
+ };
39
+ validate(id, options);
40
+ const { onCreate, onConfigure, onDeleted } = options;
41
+ this.id = id;
42
+ this.onCreate = Array.isArray(onCreate) ? onCreate : [onCreate];
43
+ this.onConfigure = Array.isArray(onConfigure) ? onConfigure : [onConfigure];
44
+ if (onDeleted !== undefined) {
45
+ this.onDeleted = Array.isArray(onDeleted) ? onDeleted : [onDeleted];
46
+ }
47
+ }
48
+ /* Utilities */
49
+ getMiddleware() {
50
+ return async (args) => {
51
+ if (isSubscriptionInteraction(args) && this.matchesConstraints(args)) {
52
+ return this.process(args);
53
+ }
54
+ return args.next();
55
+ };
56
+ }
57
+ /**
58
+ * `matchesConstraints()` implements any required constraints
59
+ * on notification subscription interaction payloads.
60
+ * */
61
+ matchesConstraints(args) {
62
+ // TODO :: implement constraint matching against custom action_id
63
+ // when supported
64
+ // If a custom action_id is provided, it should match the id of the Subscription
65
+ // in order for proper middlewares to be invoked.
66
+ return typeof this.id === 'string' && typeof args.payload.action_id === 'string';
67
+ }
68
+ }
69
+ exports.Subscription = Subscription;
70
+ /* Utilities */
71
+ function validate(id, options) {
72
+ // id must be a string
73
+ if (typeof id !== 'string') {
74
+ throw new Error('Subscription id must be a string');
75
+ }
76
+ // Check user has supplied minimal required middleware
77
+ const requiredKeys = ['onCreate', 'onConfigure'];
78
+ const missingKeys = requiredKeys.filter((key) => !(key in options));
79
+ if (missingKeys.length > 0) {
80
+ throw new Error(`Subscription handling options provided are missing required keys: ${missingKeys.join(', ')}`);
81
+ }
82
+ // Check user has supplied valid middleware
83
+ const currentKeys = Object.keys(options);
84
+ currentKeys.forEach((fnKey) => {
85
+ // must be non-falsy value
86
+ if (!options[fnKey]) {
87
+ throw new Error(`You must supply a middleware for ${fnKey}`);
88
+ }
89
+ // must be either a fn or array
90
+ if (typeof options[fnKey] !== 'function' && !Array.isArray(options[fnKey])) {
91
+ throw new Error(`Subscription handling option ${fnKey} must be a function or an array of functions`);
92
+ }
93
+ // arrays must contain middleware functions
94
+ if (Array.isArray(options[fnKey])) {
95
+ const array = options[fnKey];
96
+ array.forEach((middleware) => {
97
+ if (typeof middleware !== 'function') {
98
+ throw new Error('Subscription handling option(s) supplied as arrays must contain only functions');
99
+ }
100
+ });
101
+ }
102
+ });
103
+ }
104
+ exports.validate = validate;
105
+ function isSubscriptionInteraction(args) {
106
+ return exports.VALID_NOTIFICATION_SUBSCRIPTION_INTERACTION_TYPES
107
+ .includes(args.payload.type);
108
+ }
109
+ exports.isSubscriptionInteraction = isSubscriptionInteraction;
110
+ /**
111
+ * `processSubMiddleware()` processes subscription interaction payload with the
112
+ * middleware supplied by the user.
113
+ * */
114
+ async function processSubMiddleware(args, origMiddleware) {
115
+ // Copy the array so modifications don't affect the original
116
+ const middlewares = [...origMiddleware];
117
+ // Don't process the last item in the array, it shouldn't get a next fn
118
+ let lastCalledMiddlewareIndex = -1;
119
+ // recursively call each middleware in array
120
+ const invokeMiddleware = async (toCallMiddlewareIndex) => {
121
+ if (lastCalledMiddlewareIndex < middlewares.length - 1) {
122
+ lastCalledMiddlewareIndex = toCallMiddlewareIndex;
123
+ // invoke middleware
124
+ await middlewares[toCallMiddlewareIndex]({
125
+ ...args,
126
+ });
127
+ invokeMiddleware(toCallMiddlewareIndex + 1);
128
+ }
129
+ };
130
+ invokeMiddleware(0);
131
+ }
132
+ exports.processSubMiddleware = processSubMiddleware;
133
+ /**
134
+ * `prepareSubArgs()` prepares the arguments for the specific middlewares
135
+ * adding specific arguments for utilities
136
+ * */
137
+ function prepareSubArgs(args) {
138
+ const { next: _next, ...subArgs } = args;
139
+ const preparedArgs = { ...subArgs };
140
+ switch (preparedArgs.payload.type) {
141
+ case 'notification_subscription_create_requested':
142
+ preparedArgs.configure = createConfigure(preparedArgs);
143
+ break;
144
+ case 'notification_subscription_configure_requested':
145
+ preparedArgs.configure = createConfigure(preparedArgs);
146
+ break;
147
+ default:
148
+ break;
149
+ }
150
+ return preparedArgs;
151
+ }
152
+ exports.prepareSubArgs = prepareSubArgs;
153
+ /**
154
+ * Utility which returns a fxn which can be used to
155
+ * open a configure view for configuring a Slack subscription
156
+ * */
157
+ function createConfigure(args) {
158
+ const { payload } = args;
159
+ const trigger_id = payload.notification_subscription_action_trigger_id;
160
+ const { client, context } = args;
161
+ const token = context.botToken !== undefined ? context.botToken : context.userToken;
162
+ return (view) => client.views.open({
163
+ token,
164
+ trigger_id,
165
+ view,
166
+ });
167
+ }
168
+ exports.createConfigure = createConfigure;
169
+ //# sourceMappingURL=Subscription.js.map