@slack/bolt 3.8.0 → 3.8.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.
- package/dist/App.d.ts +212 -0
- package/dist/App.d.ts.map +1 -0
- package/dist/App.js +796 -0
- package/dist/App.js.map +1 -0
- package/dist/WorkflowStep.d.ts +106 -0
- package/dist/WorkflowStep.d.ts.map +1 -0
- package/dist/WorkflowStep.js +196 -0
- package/dist/WorkflowStep.js.map +1 -0
- package/dist/conversation-store.d.ts +31 -0
- package/dist/conversation-store.d.ts.map +1 -0
- package/dist/conversation-store.js +72 -0
- package/dist/conversation-store.js.map +1 -0
- package/dist/errors.d.ts +79 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +120 -0
- package/dist/errors.js.map +1 -0
- package/dist/helpers.d.ts +24 -0
- package/dist/helpers.d.ts.map +1 -0
- package/dist/helpers.js +100 -0
- package/dist/helpers.js.map +1 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +43 -0
- package/dist/index.js.map +1 -0
- package/dist/middleware/builtin.d.ts +52 -0
- package/dist/middleware/builtin.d.ts.map +1 -0
- package/dist/middleware/builtin.js +311 -0
- package/dist/middleware/builtin.js.map +1 -0
- package/dist/middleware/process.d.ts +5 -0
- package/dist/middleware/process.d.ts.map +1 -0
- package/dist/middleware/process.js +25 -0
- package/dist/middleware/process.js.map +1 -0
- package/dist/receivers/AwsLambdaReceiver.d.ts +53 -0
- package/dist/receivers/AwsLambdaReceiver.d.ts.map +1 -0
- package/dist/receivers/AwsLambdaReceiver.js +188 -0
- package/dist/receivers/AwsLambdaReceiver.js.map +1 -0
- package/dist/receivers/ExpressReceiver.d.ts +77 -0
- package/dist/receivers/ExpressReceiver.d.ts.map +1 -0
- package/dist/receivers/ExpressReceiver.js +445 -0
- package/dist/receivers/ExpressReceiver.js.map +1 -0
- package/dist/receivers/HTTPReceiver.d.ts +109 -0
- package/dist/receivers/HTTPReceiver.d.ts.map +1 -0
- package/dist/receivers/HTTPReceiver.js +501 -0
- package/dist/receivers/HTTPReceiver.js.map +1 -0
- package/dist/receivers/SocketModeReceiver.d.ts +61 -0
- package/dist/receivers/SocketModeReceiver.d.ts.map +1 -0
- package/dist/receivers/SocketModeReceiver.js +175 -0
- package/dist/receivers/SocketModeReceiver.js.map +1 -0
- package/dist/receivers/custom-routes.d.ts +14 -0
- package/dist/receivers/custom-routes.d.ts.map +1 -0
- package/dist/receivers/custom-routes.js +33 -0
- package/dist/receivers/custom-routes.js.map +1 -0
- package/dist/receivers/http-utils.d.ts +5 -0
- package/dist/receivers/http-utils.d.ts.map +1 -0
- package/dist/receivers/http-utils.js +35 -0
- package/dist/receivers/http-utils.js.map +1 -0
- package/dist/receivers/render-html-for-install-path.d.ts +3 -0
- package/dist/receivers/render-html-for-install-path.d.ts.map +1 -0
- package/dist/receivers/render-html-for-install-path.js +25 -0
- package/dist/receivers/render-html-for-install-path.js.map +1 -0
- package/dist/receivers/verify-redirect-opts.d.ts +7 -0
- package/dist/receivers/verify-redirect-opts.d.ts.map +1 -0
- package/dist/receivers/verify-redirect-opts.js +23 -0
- package/dist/receivers/verify-redirect-opts.js.map +1 -0
- package/dist/receivers/verify-request.d.ts +41 -0
- package/dist/receivers/verify-request.d.ts.map +1 -0
- package/dist/receivers/verify-request.js +98 -0
- package/dist/receivers/verify-request.js.map +1 -0
- package/dist/types/actions/block-action.d.ts +231 -0
- package/dist/types/actions/block-action.d.ts.map +1 -0
- package/dist/types/actions/block-action.js +3 -0
- package/dist/types/actions/block-action.js.map +1 -0
- package/dist/types/actions/dialog-action.d.ts +47 -0
- package/dist/types/actions/dialog-action.d.ts.map +1 -0
- package/dist/types/actions/dialog-action.js +3 -0
- package/dist/types/actions/dialog-action.js.map +1 -0
- package/dist/types/actions/index.d.ts +46 -0
- package/dist/types/actions/index.d.ts.map +1 -0
- package/dist/types/actions/index.js +17 -0
- package/dist/types/actions/index.js.map +1 -0
- package/dist/types/actions/interactive-message.d.ts +66 -0
- package/dist/types/actions/interactive-message.d.ts.map +1 -0
- package/dist/types/actions/interactive-message.js +3 -0
- package/dist/types/actions/interactive-message.js.map +1 -0
- package/dist/types/actions/workflow-step-edit.d.ts +49 -0
- package/dist/types/actions/workflow-step-edit.d.ts.map +1 -0
- package/dist/types/actions/workflow-step-edit.js +3 -0
- package/dist/types/actions/workflow-step-edit.js.map +1 -0
- package/dist/types/command/index.d.ts +36 -0
- package/dist/types/command/index.d.ts.map +1 -0
- package/dist/types/command/index.js +3 -0
- package/dist/types/command/index.js.map +1 -0
- package/dist/types/events/base-events.d.ts +699 -0
- package/dist/types/events/base-events.d.ts.map +1 -0
- package/dist/types/events/base-events.js +5 -0
- package/dist/types/events/base-events.js.map +1 -0
- package/dist/types/events/index.d.ts +63 -0
- package/dist/types/events/index.d.ts.map +1 -0
- package/dist/types/events/index.js +14 -0
- package/dist/types/events/index.js.map +1 -0
- package/dist/types/events/message-events.d.ts +312 -0
- package/dist/types/events/message-events.d.ts.map +1 -0
- package/dist/types/events/message-events.js +3 -0
- package/dist/types/events/message-events.js.map +1 -0
- package/dist/types/helpers.d.ts +17 -0
- package/dist/types/helpers.d.ts.map +1 -0
- package/dist/types/helpers.js +3 -0
- package/dist/types/helpers.js.map +1 -0
- package/dist/types/index.d.ts +10 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +22 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/middleware.d.ts +65 -0
- package/dist/types/middleware.d.ts.map +1 -0
- package/dist/types/middleware.js +14 -0
- package/dist/types/middleware.js.map +1 -0
- package/dist/types/options/index.d.ts +192 -0
- package/dist/types/options/index.d.ts.map +1 -0
- package/dist/types/options/index.js +3 -0
- package/dist/types/options/index.js.map +1 -0
- package/dist/types/receiver.d.ts +16 -0
- package/dist/types/receiver.d.ts.map +1 -0
- package/dist/types/receiver.js +3 -0
- package/dist/types/receiver.js.map +1 -0
- package/dist/types/shortcuts/global-shortcut.d.ts +29 -0
- package/dist/types/shortcuts/global-shortcut.d.ts.map +1 -0
- package/dist/types/shortcuts/global-shortcut.js +3 -0
- package/dist/types/shortcuts/global-shortcut.js.map +1 -0
- package/dist/types/shortcuts/index.d.ts +23 -0
- package/dist/types/shortcuts/index.d.ts.map +1 -0
- package/dist/types/shortcuts/index.js +16 -0
- package/dist/types/shortcuts/index.js.map +1 -0
- package/dist/types/shortcuts/message-shortcut.d.ts +43 -0
- package/dist/types/shortcuts/message-shortcut.d.ts.map +1 -0
- package/dist/types/shortcuts/message-shortcut.js +3 -0
- package/dist/types/shortcuts/message-shortcut.js.map +1 -0
- package/dist/types/utilities.d.ts +23 -0
- package/dist/types/utilities.d.ts.map +1 -0
- package/dist/types/utilities.js +3 -0
- package/dist/types/utilities.js.map +1 -0
- package/dist/types/view/index.d.ts +175 -0
- package/dist/types/view/index.d.ts.map +1 -0
- package/dist/types/view/index.js +3 -0
- package/dist/types/view/index.js.map +1 -0
- package/package.json +1 -1
- package/dist/package.json +0 -88
|
@@ -0,0 +1,175 @@
|
|
|
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
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
7
|
+
const socket_mode_1 = require("@slack/socket-mode");
|
|
8
|
+
const http_1 = require("http");
|
|
9
|
+
const logger_1 = require("@slack/logger");
|
|
10
|
+
const oauth_1 = require("@slack/oauth");
|
|
11
|
+
const render_html_for_install_path_1 = __importDefault(require("./render-html-for-install-path"));
|
|
12
|
+
const custom_routes_1 = require("./custom-routes");
|
|
13
|
+
const verify_redirect_opts_1 = require("./verify-redirect-opts");
|
|
14
|
+
/**
|
|
15
|
+
* Receives Events, Slash Commands, and Actions of a web socket connection
|
|
16
|
+
*/
|
|
17
|
+
class SocketModeReceiver {
|
|
18
|
+
constructor({ appToken, logger = undefined, logLevel = logger_1.LogLevel.INFO, clientId = undefined, clientSecret = undefined, stateSecret = undefined, redirectUri = undefined, installationStore = undefined, scopes = undefined, installerOptions = {}, customRoutes = [], customPropertiesExtractor = (_args) => ({}), }) {
|
|
19
|
+
var _a;
|
|
20
|
+
this.installer = undefined;
|
|
21
|
+
this.client = new socket_mode_1.SocketModeClient({
|
|
22
|
+
appToken,
|
|
23
|
+
logLevel,
|
|
24
|
+
logger,
|
|
25
|
+
clientOptions: installerOptions.clientOptions,
|
|
26
|
+
});
|
|
27
|
+
this.logger = logger !== null && logger !== void 0 ? logger : (() => {
|
|
28
|
+
const defaultLogger = new logger_1.ConsoleLogger();
|
|
29
|
+
defaultLogger.setLevel(logLevel);
|
|
30
|
+
return defaultLogger;
|
|
31
|
+
})();
|
|
32
|
+
this.routes = (0, custom_routes_1.prepareRoutes)(customRoutes);
|
|
33
|
+
// Verify redirect options if supplied, throws coded error if invalid
|
|
34
|
+
(0, verify_redirect_opts_1.verifyRedirectOpts)({ redirectUri, redirectUriPath: installerOptions.redirectUriPath });
|
|
35
|
+
if (clientId !== undefined &&
|
|
36
|
+
clientSecret !== undefined &&
|
|
37
|
+
(installerOptions.stateVerification === false || // state store not needed
|
|
38
|
+
stateSecret !== undefined ||
|
|
39
|
+
installerOptions.stateStore !== undefined) // user provided state store
|
|
40
|
+
) {
|
|
41
|
+
this.installer = new oauth_1.InstallProvider({
|
|
42
|
+
clientId,
|
|
43
|
+
clientSecret,
|
|
44
|
+
stateSecret,
|
|
45
|
+
installationStore,
|
|
46
|
+
logLevel,
|
|
47
|
+
logger,
|
|
48
|
+
stateStore: installerOptions.stateStore,
|
|
49
|
+
stateVerification: installerOptions.stateVerification,
|
|
50
|
+
authVersion: (_a = installerOptions.authVersion) !== null && _a !== void 0 ? _a : 'v2',
|
|
51
|
+
clientOptions: installerOptions.clientOptions,
|
|
52
|
+
authorizationUrl: installerOptions.authorizationUrl,
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
// Add OAuth and/or custom routes to receiver
|
|
56
|
+
if (this.installer !== undefined || customRoutes.length) {
|
|
57
|
+
// use default or passed in redirect path
|
|
58
|
+
const redirectUriPath = installerOptions.redirectUriPath === undefined ? '/slack/oauth_redirect' : installerOptions.redirectUriPath;
|
|
59
|
+
// use default or passed in installPath
|
|
60
|
+
const installPath = installerOptions.installPath === undefined ? '/slack/install' : installerOptions.installPath;
|
|
61
|
+
const directInstallEnabled = installerOptions.directInstall !== undefined && installerOptions.directInstall;
|
|
62
|
+
this.httpServerPort = installerOptions.port === undefined ? 3000 : installerOptions.port;
|
|
63
|
+
this.httpServer = (0, http_1.createServer)(async (req, res) => {
|
|
64
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
65
|
+
const method = req.method.toUpperCase();
|
|
66
|
+
// Handle OAuth-related requests
|
|
67
|
+
if (this.installer) {
|
|
68
|
+
// create install url options
|
|
69
|
+
const installUrlOptions = {
|
|
70
|
+
metadata: installerOptions.metadata,
|
|
71
|
+
scopes: scopes !== null && scopes !== void 0 ? scopes : [],
|
|
72
|
+
userScopes: installerOptions.userScopes,
|
|
73
|
+
redirectUri,
|
|
74
|
+
};
|
|
75
|
+
// Installation has been initiated
|
|
76
|
+
if (req.url && req.url.startsWith(redirectUriPath)) {
|
|
77
|
+
const { stateVerification, callbackOptions } = installerOptions;
|
|
78
|
+
if (stateVerification === false) {
|
|
79
|
+
// if stateVerification is disabled make install options available to handler
|
|
80
|
+
// since they won't be encoded in the state param of the generated url
|
|
81
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
82
|
+
await this.installer.handleCallback(req, res, callbackOptions, installUrlOptions);
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
86
|
+
await this.installer.handleCallback(req, res, callbackOptions);
|
|
87
|
+
}
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
// Visiting the installation endpoint
|
|
91
|
+
if (req.url && req.url.startsWith(installPath)) {
|
|
92
|
+
const { stateVerification, renderHtmlForInstallPath } = installerOptions;
|
|
93
|
+
try {
|
|
94
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
95
|
+
const url = await this.installer.generateInstallUrl(installUrlOptions, stateVerification);
|
|
96
|
+
if (directInstallEnabled) {
|
|
97
|
+
res.writeHead(302, { Location: url });
|
|
98
|
+
res.end('');
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
res.writeHead(200, {});
|
|
102
|
+
const renderHtml = renderHtmlForInstallPath !== undefined ?
|
|
103
|
+
renderHtmlForInstallPath :
|
|
104
|
+
render_html_for_install_path_1.default;
|
|
105
|
+
res.end(renderHtml(url));
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
catch (err) {
|
|
110
|
+
const e = err;
|
|
111
|
+
throw new Error(e);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
// Handle request for custom routes
|
|
116
|
+
if (customRoutes.length && req.url) {
|
|
117
|
+
const match = this.routes[req.url] && this.routes[req.url][method] !== undefined;
|
|
118
|
+
if (match) {
|
|
119
|
+
this.routes[req.url][method](req, res);
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
this.logger.info(`An unhandled HTTP request (${req.method}) made to ${req.url} was ignored`);
|
|
124
|
+
res.writeHead(404, {});
|
|
125
|
+
res.end();
|
|
126
|
+
});
|
|
127
|
+
this.logger.debug(`Listening for HTTP requests on port ${this.httpServerPort}`);
|
|
128
|
+
if (this.installer) {
|
|
129
|
+
this.logger.debug(`Go to http://localhost:${this.httpServerPort}${installPath} to initiate OAuth flow`);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
this.client.on('slack_event', async (args) => {
|
|
133
|
+
var _a;
|
|
134
|
+
const { ack, body, retry_num, retry_reason } = args;
|
|
135
|
+
const event = {
|
|
136
|
+
body,
|
|
137
|
+
ack,
|
|
138
|
+
retryNum: retry_num,
|
|
139
|
+
retryReason: retry_reason,
|
|
140
|
+
customProperties: customPropertiesExtractor(args),
|
|
141
|
+
};
|
|
142
|
+
await ((_a = this.app) === null || _a === void 0 ? void 0 : _a.processEvent(event));
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
init(app) {
|
|
146
|
+
this.app = app;
|
|
147
|
+
}
|
|
148
|
+
start() {
|
|
149
|
+
if (this.httpServer !== undefined) {
|
|
150
|
+
// This HTTP server is only for the OAuth flow support
|
|
151
|
+
this.httpServer.listen(this.httpServerPort);
|
|
152
|
+
}
|
|
153
|
+
// start socket mode client
|
|
154
|
+
return this.client.start();
|
|
155
|
+
}
|
|
156
|
+
stop() {
|
|
157
|
+
if (this.httpServer !== undefined) {
|
|
158
|
+
// This HTTP server is only for the OAuth flow support
|
|
159
|
+
this.httpServer.close((error) => {
|
|
160
|
+
this.logger.error(`Failed to shutdown the HTTP server for OAuth flow: ${error}`);
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
return new Promise((resolve, reject) => {
|
|
164
|
+
try {
|
|
165
|
+
this.client.disconnect();
|
|
166
|
+
resolve();
|
|
167
|
+
}
|
|
168
|
+
catch (error) {
|
|
169
|
+
reject(error);
|
|
170
|
+
}
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
exports.default = SocketModeReceiver;
|
|
175
|
+
//# sourceMappingURL=SocketModeReceiver.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SocketModeReceiver.js","sourceRoot":"","sources":["../../src/receivers/SocketModeReceiver.ts"],"names":[],"mappings":";;;;;AAAA,uDAAuD;AACvD,oDAAsD;AACtD,+BAA6E;AAC7E,0CAAgE;AAChE,wCAA2G;AAI3G,kGAA6E;AAE7E,mDAAgE;AAChE,iEAA4D;AA0C5D;;GAEG;AACH,MAAqB,kBAAkB;IAgBrC,YAAmB,E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|
+
/// <reference types="node" />
|
|
2
|
+
import { IncomingMessage, ServerResponse } from 'http';
|
|
3
|
+
export interface CustomRoute {
|
|
4
|
+
path: string;
|
|
5
|
+
method: string | string[];
|
|
6
|
+
handler: (req: IncomingMessage, res: ServerResponse) => void;
|
|
7
|
+
}
|
|
8
|
+
export interface ReceiverRoutes {
|
|
9
|
+
[url: string]: {
|
|
10
|
+
[method: string]: (req: IncomingMessage, res: ServerResponse) => void;
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
export declare function prepareRoutes(customRoutes: CustomRoute[]): ReceiverRoutes;
|
|
14
|
+
//# sourceMappingURL=custom-routes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"custom-routes.d.ts","sourceRoot":"","sources":["../../src/receivers/custom-routes.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,MAAM,CAAC;AAGvD,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IAC1B,OAAO,EAAE,CAAC,GAAG,EAAE,eAAe,EAAE,GAAG,EAAE,cAAc,KAAK,IAAI,CAAC;CAC9D;AAED,MAAM,WAAW,cAAc;IAC7B,CAAC,GAAG,EAAE,MAAM,GAAG;QACb,CAAC,MAAM,EAAE,MAAM,GAAG,CAAC,GAAG,EAAE,eAAe,EAAE,GAAG,EAAE,cAAc,KAAK,IAAI,CAAC;KACvE,CAAC;CACH;AAED,wBAAgB,aAAa,CAAC,YAAY,EAAE,WAAW,EAAE,GAAG,cAAc,CAazE"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.prepareRoutes = void 0;
|
|
4
|
+
const errors_1 = require("../errors");
|
|
5
|
+
function prepareRoutes(customRoutes) {
|
|
6
|
+
const routes = {};
|
|
7
|
+
validateCustomRoutes(customRoutes);
|
|
8
|
+
customRoutes.forEach((r) => {
|
|
9
|
+
const methodObj = Array.isArray(r.method) ?
|
|
10
|
+
r.method.reduce((o, key) => ({ ...o, [key.toUpperCase()]: r.handler }), {}) :
|
|
11
|
+
{ [r.method.toUpperCase()]: r.handler };
|
|
12
|
+
routes[r.path] = routes[r.path] ? { ...routes[r.path], ...methodObj } : methodObj;
|
|
13
|
+
});
|
|
14
|
+
return routes;
|
|
15
|
+
}
|
|
16
|
+
exports.prepareRoutes = prepareRoutes;
|
|
17
|
+
function validateCustomRoutes(customRoutes) {
|
|
18
|
+
const requiredKeys = ['path', 'method', 'handler'];
|
|
19
|
+
const missingKeys = [];
|
|
20
|
+
// Check for missing required keys
|
|
21
|
+
customRoutes.forEach((route) => {
|
|
22
|
+
requiredKeys.forEach((key) => {
|
|
23
|
+
if (route[key] === undefined && !missingKeys.includes(key)) {
|
|
24
|
+
missingKeys.push(key);
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
if (missingKeys.length > 0) {
|
|
29
|
+
const errorMsg = `One or more routes in customRoutes are missing required keys: ${missingKeys.join(', ')}`;
|
|
30
|
+
throw new errors_1.CustomRouteInitializationError(errorMsg);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=custom-routes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"custom-routes.js","sourceRoot":"","sources":["../../src/receivers/custom-routes.ts"],"names":[],"mappings":";;;AACA,sCAA2D;AAc3D,SAAgB,aAAa,CAAC,YAA2B;IACvD,MAAM,MAAM,GAAmB,EAAE,CAAC;IAElC,oBAAoB,CAAC,YAAY,CAAC,CAAC;IAEnC,YAAY,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE;QACzB,MAAM,SAAS,GAAG,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC;YACzC,CAAC,CAAC,MAA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;KACpD;AACH,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { IncomingMessage } from 'http';
|
|
3
|
+
export declare function extractRetryNum(req: IncomingMessage): number | undefined;
|
|
4
|
+
export declare function extractRetryReason(req: IncomingMessage): string | undefined;
|
|
5
|
+
//# sourceMappingURL=http-utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http-utils.d.ts","sourceRoot":"","sources":["../../src/receivers/http-utils.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,MAAM,CAAC;AAEvC,wBAAgB,eAAe,CAAC,GAAG,EAAE,eAAe,GAAG,MAAM,GAAG,SAAS,CAWxE;AAED,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,eAAe,GAAG,MAAM,GAAG,SAAS,CAY3E"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.extractRetryReason = exports.extractRetryNum = void 0;
|
|
4
|
+
function extractRetryNum(req) {
|
|
5
|
+
let retryNum;
|
|
6
|
+
const retryNumHeaderValue = req.headers['x-slack-retry-num'];
|
|
7
|
+
if (retryNumHeaderValue === undefined) {
|
|
8
|
+
retryNum = undefined;
|
|
9
|
+
}
|
|
10
|
+
else if (typeof retryNumHeaderValue === 'string') {
|
|
11
|
+
retryNum = parseInt(retryNumHeaderValue, 10);
|
|
12
|
+
}
|
|
13
|
+
else if (Array.isArray(retryNumHeaderValue) && retryNumHeaderValue.length > 0) {
|
|
14
|
+
retryNum = parseInt(retryNumHeaderValue[0], 10);
|
|
15
|
+
}
|
|
16
|
+
return retryNum;
|
|
17
|
+
}
|
|
18
|
+
exports.extractRetryNum = extractRetryNum;
|
|
19
|
+
function extractRetryReason(req) {
|
|
20
|
+
let retryReason;
|
|
21
|
+
const retryReasonHeaderValue = req.headers['x-slack-retry-reason'];
|
|
22
|
+
if (retryReasonHeaderValue === undefined) {
|
|
23
|
+
retryReason = undefined;
|
|
24
|
+
}
|
|
25
|
+
else if (typeof retryReasonHeaderValue === 'string') {
|
|
26
|
+
retryReason = retryReasonHeaderValue;
|
|
27
|
+
}
|
|
28
|
+
else if (Array.isArray(retryReasonHeaderValue) && retryReasonHeaderValue.length > 0) {
|
|
29
|
+
// eslint-disable-next-line prefer-destructuring
|
|
30
|
+
retryReason = retryReasonHeaderValue[0];
|
|
31
|
+
}
|
|
32
|
+
return retryReason;
|
|
33
|
+
}
|
|
34
|
+
exports.extractRetryReason = extractRetryReason;
|
|
35
|
+
//# sourceMappingURL=http-utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http-utils.js","sourceRoot":"","sources":["../../src/receivers/http-utils.ts"],"names":[],"mappings":";;;AAEA,SAAgB,eAAe,CAAC,GAAoB;IAClD,IAAI,QAAQ,CAAC;IACb,MAAM,mBAAmB,GAAG,GAAG,CAAC,OAAO,CAAC,mBAAmB,CAAC,CAAC;IAC7D,IAAI,mBAAmB,KAAK,SAAS,EAAE;QACrC,QAAQ,GAAG,SAAS,CAAC;KACtB;SAAM,IAAI,OAAO,mBAAmB,KAAK,QAAQ,EAAE;QAClD,QAAQ,GAAG,QAAQ,CAAC,mBAAmB,EAAE,EAAE,CAAC,CAAC;KAC9C;SAAM,IAAI,KAAK,CAAC,OAAO,CAAC,mBAAmB,CAAC,IAAI,mBAAmB,CAAC,MAAM,GAAG,CAAC,EAAE;QAC/E,QAAQ,GAAG,QAAQ,CAAC,mBAAmB,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;KACjD;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC;AAXD,0CAWC;AAED,SAAgB,kBAAkB,CAAC,GAAoB;IACrD,IAAI,WAAW,CAAC;IAChB,MAAM,sBAAsB,GAAG,GAAG,CAAC,OAAO,CAAC,sBAAsB,CAAC,CAAC;IACnE,IAAI,sBAAsB,KAAK,SAAS,EAAE;QACxC,WAAW,GAAG,SAAS,CAAC;KACzB;SAAM,IAAI,OAAO,sBAAsB,KAAK,QAAQ,EAAE;QACrD,WAAW,GAAG,sBAAsB,CAAC;KACtC;SAAM,IAAI,KAAK,CAAC,OAAO,CAAC,sBAAsB,CAAC,IAAI,sBAAsB,CAAC,MAAM,GAAG,CAAC,EAAE;QACrF,gDAAgD;QAChD,WAAW,GAAG,sBAAsB,CAAC,CAAC,CAAC,CAAC;KACzC;IACD,OAAO,WAAW,CAAC;AACrB,CAAC;AAZD,gDAYC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"render-html-for-install-path.d.ts","sourceRoot":"","sources":["../../src/receivers/render-html-for-install-path.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,OAAO,UAAU,+BAA+B,CAAC,aAAa,EAAE,MAAM,GAAG,MAAM,CAcrF;AAGD,wBAAgB,wBAAwB,CAAC,aAAa,EAAE,MAAM,GAAG,MAAM,CAEtE"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.renderHtmlForInstallPath = void 0;
|
|
4
|
+
function defaultRenderHtmlForInstallPath(addToSlackUrl) {
|
|
5
|
+
return `<html>
|
|
6
|
+
<body>
|
|
7
|
+
<a href=${addToSlackUrl}>
|
|
8
|
+
<img
|
|
9
|
+
alt="Add to Slack"
|
|
10
|
+
height="40"
|
|
11
|
+
width="139"
|
|
12
|
+
src="https://platform.slack-edge.com/img/add_to_slack.png"
|
|
13
|
+
srcset="https://platform.slack-edge.com/img/add_to_slack.png 1x, https://platform.slack-edge.com/img/add_to_slack@2x.png 2x"
|
|
14
|
+
/>
|
|
15
|
+
</a>
|
|
16
|
+
</body>
|
|
17
|
+
</html>`;
|
|
18
|
+
}
|
|
19
|
+
exports.default = defaultRenderHtmlForInstallPath;
|
|
20
|
+
// For backward-compatibility
|
|
21
|
+
function renderHtmlForInstallPath(addToSlackUrl) {
|
|
22
|
+
return defaultRenderHtmlForInstallPath(addToSlackUrl);
|
|
23
|
+
}
|
|
24
|
+
exports.renderHtmlForInstallPath = renderHtmlForInstallPath;
|
|
25
|
+
//# sourceMappingURL=render-html-for-install-path.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"render-html-for-install-path.js","sourceRoot":"","sources":["../../src/receivers/render-html-for-install-path.ts"],"names":[],"mappings":";;;AAAA,SAAwB,+BAA+B,CAAC,aAAqB;IAC3E,OAAO;;kBAES,aAAa;;;;;;;;;;YAUnB,CAAC;AACb,CAAC;AAdD,kDAcC;AAED,6BAA6B;AAC7B,SAAgB,wBAAwB,CAAC,aAAqB;IAC5D,OAAO,+BAA+B,CAAC,aAAa,CAAC,CAAC;AACxD,CAAC;AAFD,4DAEC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { HTTPReceiverOptions, HTTPReceiverInstallerOptions } from './HTTPReceiver';
|
|
2
|
+
export interface RedirectOptions {
|
|
3
|
+
redirectUri?: HTTPReceiverOptions['redirectUri'];
|
|
4
|
+
redirectUriPath?: HTTPReceiverInstallerOptions['redirectUriPath'];
|
|
5
|
+
}
|
|
6
|
+
export declare function verifyRedirectOpts({ redirectUri, redirectUriPath }: RedirectOptions): void;
|
|
7
|
+
//# sourceMappingURL=verify-redirect-opts.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"verify-redirect-opts.d.ts","sourceRoot":"","sources":["../../src/receivers/verify-redirect-opts.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,mBAAmB,EAAE,4BAA4B,EAAE,MAAM,gBAAgB,CAAC;AAEnF,MAAM,WAAW,eAAe;IAC9B,WAAW,CAAC,EAAE,mBAAmB,CAAC,aAAa,CAAC,CAAC;IACjD,eAAe,CAAC,EAAE,4BAA4B,CAAC,iBAAiB,CAAC,CAAC;CACnE;AAED,wBAAgB,kBAAkB,CAAC,EAAE,WAAW,EAAE,eAAe,EAAE,EAAE,eAAe,GAAG,IAAI,CAgB1F"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.verifyRedirectOpts = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Helper to verify redirect uri and redirect uri path exist and are consistent
|
|
6
|
+
* when supplied.
|
|
7
|
+
*/
|
|
8
|
+
const errors_1 = require("../errors");
|
|
9
|
+
function verifyRedirectOpts({ redirectUri, redirectUriPath }) {
|
|
10
|
+
// if redirectUri is supplied, redirectUriPath is required
|
|
11
|
+
if ((redirectUri && !redirectUriPath)) {
|
|
12
|
+
throw new errors_1.AppInitializationError(' You have set a redirectUri but not a matching redirectUriPath.' +
|
|
13
|
+
' Please provide this via installerOptions.redirectUriPath' +
|
|
14
|
+
' Note: These should be consistent, e.g. https://example.com/redirect and /redirect');
|
|
15
|
+
}
|
|
16
|
+
// if both redirectUri and redirectUri are supplied, they must be consistent
|
|
17
|
+
if (redirectUri && redirectUriPath && !(redirectUri === null || redirectUri === void 0 ? void 0 : redirectUri.endsWith(redirectUriPath))) {
|
|
18
|
+
throw new errors_1.AppInitializationError('redirectUri and installerOptions.redirectUriPath should be consistent' +
|
|
19
|
+
' e.g. https://example.com/redirect and /redirect');
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
exports.verifyRedirectOpts = verifyRedirectOpts;
|
|
23
|
+
//# sourceMappingURL=verify-redirect-opts.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"verify-redirect-opts.js","sourceRoot":"","sources":["../../src/receivers/verify-redirect-opts.ts"],"names":[],"mappings":";;;AAAA;;;EAGE;AACF,sCAAmD;AAQnD,SAAgB,kBAAkB,CAAC,EAAE,WAAW,EAAE,eAAe,EAAmB;IAClF,0DAA0D;IAC1D,IAAI,CAAC,WAAW,IAAI,CAAC,eAAe,CAAC,EAAE;QACrC,MAAM,IAAI,+BAAsB,CAC9B,iEAAiE;YACjE,2DAA2D;YAC3D,oFAAoF,CACrF,CAAC;KACH;IACD,4EAA4E;IAC5E,IAAI,WAAW,IAAI,eAAe,IAAI,CAAC,CAAA,WAAW,aAAX,WAAW,uBAAX,WAAW,CAAE,QAAQ,CAAC,eAAe,CAAC,CAAA,EAAE;QAC7E,MAAM,IAAI,+BAAsB,CAC9B,uEAAuE;YACvE,kDAAkD,CACnD,CAAC;KACH;AACH,CAAC;AAhBD,gDAgBC"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Functions used to verify the authenticity of incoming HTTP requests from Slack.
|
|
3
|
+
*
|
|
4
|
+
* The functions in this file are intentionally generic (don't depend on any particular web framework) and
|
|
5
|
+
* time-independent (for testing) so they can be used in a wide variety of applications. The intention is to distribute
|
|
6
|
+
* these functions in its own package.
|
|
7
|
+
*
|
|
8
|
+
* For now, there is some duplication between the contents of this file and ExpressReceiver.ts. Later, the duplication
|
|
9
|
+
* can be reduced by implementing the equivalent functionality in terms of the functions in this file.
|
|
10
|
+
*/
|
|
11
|
+
/// <reference types="node" />
|
|
12
|
+
import type { Logger } from '@slack/logger';
|
|
13
|
+
import type { IncomingMessage, ServerResponse } from 'http';
|
|
14
|
+
export interface VerifyOptions {
|
|
15
|
+
enabled?: boolean;
|
|
16
|
+
signingSecret: string;
|
|
17
|
+
nowMs?: () => number;
|
|
18
|
+
logger?: Logger;
|
|
19
|
+
}
|
|
20
|
+
export interface BufferedIncomingMessage extends IncomingMessage {
|
|
21
|
+
rawBody: Buffer;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Verify the authenticity of an incoming HTTP request from Slack and buffer the HTTP body.
|
|
25
|
+
*
|
|
26
|
+
* When verification succeeds, the returned promise is resolved. When verification fails, the returned promise is
|
|
27
|
+
* rejected with an error describing the reason. IMPORTANT: The error messages may contain sensitive information about
|
|
28
|
+
* failures, do not return the error message text to users in a production environment. It's recommended to catch all
|
|
29
|
+
* errors and return an opaque failure (HTTP status code 401, no body).
|
|
30
|
+
*
|
|
31
|
+
* Verification requires consuming `req` as a Readable stream. If the `req` was consumed before this function is called,
|
|
32
|
+
* then this function expects it to be stored as a Buffer at `req.rawBody`. This is a convention used by infrastructure
|
|
33
|
+
* platforms such as Google Cloud Platform. When the function returns, the buffered body is stored at the `req.rawBody`
|
|
34
|
+
* property for further handling.
|
|
35
|
+
*
|
|
36
|
+
* The function is designed to be curry-able for use as a standard http RequestListener, and therefore keeps `req` and
|
|
37
|
+
* `res` are the last arguments. However, the function is also async, which means when it is curried for use as a
|
|
38
|
+
* RequestListener, the caller should also capture and use the return value.
|
|
39
|
+
*/
|
|
40
|
+
export declare function verify(options: VerifyOptions, req: IncomingMessage, _res?: ServerResponse): Promise<BufferedIncomingMessage>;
|
|
41
|
+
//# sourceMappingURL=verify-request.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"verify-request.d.ts","sourceRoot":"","sources":["../../src/receivers/verify-request.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;;AAKH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,MAAM,CAAC;AAI5D,MAAM,WAAW,aAAa;IAC5B,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,aAAa,EAAE,MAAM,CAAC;IACtB,KAAK,CAAC,EAAE,MAAM,MAAM,CAAC;IACrB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,uBAAwB,SAAQ,eAAe;IAC9D,OAAO,EAAE,MAAM,CAAC;CACjB;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAsB,MAAM,CAC1B,OAAO,EAAE,aAAa,EACtB,GAAG,EAAE,eAAe,EACpB,IAAI,CAAC,EAAE,cAAc,GACpB,OAAO,CAAC,uBAAuB,CAAC,CAiDlC"}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Functions used to verify the authenticity of incoming HTTP requests from Slack.
|
|
4
|
+
*
|
|
5
|
+
* The functions in this file are intentionally generic (don't depend on any particular web framework) and
|
|
6
|
+
* time-independent (for testing) so they can be used in a wide variety of applications. The intention is to distribute
|
|
7
|
+
* these functions in its own package.
|
|
8
|
+
*
|
|
9
|
+
* For now, there is some duplication between the contents of this file and ExpressReceiver.ts. Later, the duplication
|
|
10
|
+
* can be reduced by implementing the equivalent functionality in terms of the functions in this file.
|
|
11
|
+
*/
|
|
12
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
13
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
14
|
+
};
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
exports.verify = void 0;
|
|
17
|
+
const crypto_1 = require("crypto");
|
|
18
|
+
const raw_body_1 = __importDefault(require("raw-body"));
|
|
19
|
+
const tsscmp_1 = __importDefault(require("tsscmp"));
|
|
20
|
+
const verifyErrorPrefix = 'Failed to verify authenticity';
|
|
21
|
+
/**
|
|
22
|
+
* Verify the authenticity of an incoming HTTP request from Slack and buffer the HTTP body.
|
|
23
|
+
*
|
|
24
|
+
* When verification succeeds, the returned promise is resolved. When verification fails, the returned promise is
|
|
25
|
+
* rejected with an error describing the reason. IMPORTANT: The error messages may contain sensitive information about
|
|
26
|
+
* failures, do not return the error message text to users in a production environment. It's recommended to catch all
|
|
27
|
+
* errors and return an opaque failure (HTTP status code 401, no body).
|
|
28
|
+
*
|
|
29
|
+
* Verification requires consuming `req` as a Readable stream. If the `req` was consumed before this function is called,
|
|
30
|
+
* then this function expects it to be stored as a Buffer at `req.rawBody`. This is a convention used by infrastructure
|
|
31
|
+
* platforms such as Google Cloud Platform. When the function returns, the buffered body is stored at the `req.rawBody`
|
|
32
|
+
* property for further handling.
|
|
33
|
+
*
|
|
34
|
+
* The function is designed to be curry-able for use as a standard http RequestListener, and therefore keeps `req` and
|
|
35
|
+
* `res` are the last arguments. However, the function is also async, which means when it is curried for use as a
|
|
36
|
+
* RequestListener, the caller should also capture and use the return value.
|
|
37
|
+
*/
|
|
38
|
+
async function verify(options, req, _res) {
|
|
39
|
+
var _a;
|
|
40
|
+
const { signingSecret } = options;
|
|
41
|
+
// Consume the readable stream (or use the previously consumed readable stream)
|
|
42
|
+
const bufferedReq = await bufferIncomingMessage(req);
|
|
43
|
+
if (options.enabled !== undefined && !options.enabled) {
|
|
44
|
+
// As the validation is disabled, immediately return the bufferred reuest
|
|
45
|
+
return bufferedReq;
|
|
46
|
+
}
|
|
47
|
+
// Find the relevant request headers
|
|
48
|
+
const signature = getHeader(req, 'x-slack-signature');
|
|
49
|
+
const requestTimestampSec = Number(getHeader(req, 'x-slack-request-timestamp'));
|
|
50
|
+
if (Number.isNaN(requestTimestampSec)) {
|
|
51
|
+
throw new Error(`${verifyErrorPrefix}: header x-slack-request-timestamp did not have the expected type (${requestTimestampSec})`);
|
|
52
|
+
}
|
|
53
|
+
// Calculate time-dependent values
|
|
54
|
+
const nowMsFn = (_a = options.nowMs) !== null && _a !== void 0 ? _a : (() => Date.now());
|
|
55
|
+
const nowMs = nowMsFn();
|
|
56
|
+
const fiveMinutesAgoSec = Math.floor(nowMs / 1000) - 60 * 5;
|
|
57
|
+
// Enforce verification rules
|
|
58
|
+
// Rule 1: Check staleness
|
|
59
|
+
if (requestTimestampSec < fiveMinutesAgoSec) {
|
|
60
|
+
throw new Error(`${verifyErrorPrefix}: stale`);
|
|
61
|
+
}
|
|
62
|
+
// Rule 2: Check signature
|
|
63
|
+
// Separate parts of signature
|
|
64
|
+
const [signatureVersion, signatureHash] = signature.split('=');
|
|
65
|
+
// Only handle known versions
|
|
66
|
+
if (signatureVersion !== 'v0') {
|
|
67
|
+
throw new Error(`${verifyErrorPrefix}: unknown signature version`);
|
|
68
|
+
}
|
|
69
|
+
// Compute our own signature hash
|
|
70
|
+
const hmac = (0, crypto_1.createHmac)('sha256', signingSecret);
|
|
71
|
+
hmac.update(`${signatureVersion}:${requestTimestampSec}:${bufferedReq.rawBody.toString()}`);
|
|
72
|
+
const ourSignatureHash = hmac.digest('hex');
|
|
73
|
+
if (!(0, tsscmp_1.default)(signatureHash, ourSignatureHash)) {
|
|
74
|
+
throw new Error(`${verifyErrorPrefix}: signature mismatch`);
|
|
75
|
+
}
|
|
76
|
+
// Checks have passed! Return the value that has a side effect (the buffered request)
|
|
77
|
+
return bufferedReq;
|
|
78
|
+
}
|
|
79
|
+
exports.verify = verify;
|
|
80
|
+
async function bufferIncomingMessage(req) {
|
|
81
|
+
if (isBufferedIncomingMessage(req)) {
|
|
82
|
+
return req;
|
|
83
|
+
}
|
|
84
|
+
const bufferedRequest = req;
|
|
85
|
+
bufferedRequest.rawBody = await (0, raw_body_1.default)(req);
|
|
86
|
+
return bufferedRequest;
|
|
87
|
+
}
|
|
88
|
+
function isBufferedIncomingMessage(req) {
|
|
89
|
+
return Buffer.isBuffer(req.rawBody);
|
|
90
|
+
}
|
|
91
|
+
function getHeader(req, header) {
|
|
92
|
+
const value = req.headers[header];
|
|
93
|
+
if (value === undefined || Array.isArray(value)) {
|
|
94
|
+
throw new Error(`${verifyErrorPrefix}: header ${header} did not have the expected type (${value})`);
|
|
95
|
+
}
|
|
96
|
+
return value;
|
|
97
|
+
}
|
|
98
|
+
//# sourceMappingURL=verify-request.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"verify-request.js","sourceRoot":"","sources":["../../src/receivers/verify-request.ts"],"names":[],"mappings":";AAAA;;;;;;;;;GASG;;;;;;AAEH,mCAAoC;AACpC,wDAA+B;AAC/B,oDAA4B;AAI5B,MAAM,iBAAiB,GAAG,+BAA+B,CAAC;AAa1D;;;;;;;;;;;;;;;;GAgBG;AACI,KAAK,UAAU,MAAM,CAC1B,OAAsB,EACtB,GAAoB,EACpB,IAAqB;;IAErB,MAAM,EAA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