slack-edge
Version:
Slack app development framework for edge functions with streamlined TypeScript support
36 lines • 1.67 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.toInstallation = toInstallation;
/**
* Converts a response from oauth.v2.access API endpoint to an installation data.
* @param oauthAccess oauth.v2.access API response data
* @returns installation data
*/
function toInstallation(oauthAccess) {
const installation = {
app_id: oauthAccess.app_id,
is_enterprise_install: oauthAccess.is_enterprise_install,
enterprise_id: oauthAccess.enterprise?.id,
team_id: oauthAccess.team?.id,
user_id: oauthAccess.authed_user?.id,
// bot token
bot_token: oauthAccess.access_token,
bot_user_id: oauthAccess.bot_user_id,
bot_scopes: oauthAccess.scope?.split(","),
bot_refresh_token: oauthAccess.refresh_token,
bot_token_expires_at: oauthAccess.expires_in ? new Date().getTime() / 1000 + oauthAccess.expires_in : undefined,
// user token
user_token: oauthAccess.authed_user?.access_token,
user_scopes: oauthAccess.authed_user?.scope?.split(","),
user_refresh_token: oauthAccess.authed_user?.refresh_token,
user_token_expires_at: oauthAccess.authed_user?.expires_in
? new Date().getTime() / 1000 + oauthAccess.authed_user?.expires_in
: undefined,
// Only when having incoming-webhooks
incoming_webhook_url: oauthAccess.incoming_webhook?.url,
incoming_webhook_channel_id: oauthAccess.incoming_webhook?.channel_id,
incoming_webhook_configuration_url: oauthAccess.incoming_webhook?.url,
};
return installation;
}
//# sourceMappingURL=installation.js.map