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