UNPKG

slack-edge

Version:

Slack app development framework for edge functions with streamlined TypeScript support

38 lines 1.57 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.singleTeamAuthorize = void 0; const errors_1 = require("../errors"); const slack_web_api_client_1 = require("slack-web-api-client"); /** * Authorize function for an app tha is installed only into a single workspace. * @param req request from Slack * @returns valid AuthorizeResult object */ const singleTeamAuthorize = async (req) => { // This authorize function supports only the bot token for a workspace const botToken = req.env.SLACK_BOT_TOKEN; const client = new slack_web_api_client_1.SlackAPIClient(botToken); try { const response = await client.auth.test(); const scopes = response.headers.get("x-oauth-scopes") ?? ""; return { botToken, enterpriseId: response.enterprise_id, teamId: response.team_id, team: response.team, url: response.url, botId: response.bot_id, botUserId: response.user_id, userId: response.user_id, user: response.user, botScopes: scopes.split(","), userToken: undefined, // As mentioned above, user tokens are not supported in this module userScopes: undefined, // As mentioned above, user tokens are not supported in this module }; } catch (e) { throw new errors_1.AuthorizeError(`Failed to call auth.test API due to ${e.message}`); } }; exports.singleTeamAuthorize = singleTeamAuthorize; //# sourceMappingURL=single-team-authorize.js.map