"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.defaultCallbackSuccess = defaultCallbackSuccess; exports.defaultCallbackFailure = defaultCallbackFailure; exports.escapeHtml = escapeHtml; var errors_1 = require("./errors"); // Default function to call when OAuth flow is successful function defaultCallbackSuccess(installation, _options, _req, res) { var redirectUrl; if (isNotOrgInstall(installation) && installation.appId !== undefined) { // redirect back to Slack native app // Changes to the workspace app was installed to, to the app home redirectUrl = "slack://app?team=".concat(installation.team.id, "&id=").concat(installation.appId); } else if (isOrgInstall(installation)) { // redirect to Slack app management dashboard redirectUrl = "".concat(installation.enterpriseUrl, "manage/organization/apps/profile/").concat(installation.appId, "/workspaces/add"); } else { // redirect back to Slack native app // does not change the workspace the slack client was last in redirectUrl = 'slack://open'; } var browserUrl = redirectUrl; if (isNotOrgInstall(installation)) { browserUrl = "https://app.slack.com/client/".concat(installation.team.id); } var htmlResponse = "\n \n \n \n \n \n

Thank you!

\n

Redirecting to the Slack App... click here. If you use the browser version of Slack, click this link instead.

\n \n "); res.writeHead(200, { 'Content-Type': 'text/html; charset=utf-8' }); res.end(htmlResponse); } // Default function to call when OAuth flow is unsuccessful function defaultCallbackFailure(error, _options, _req, res) { var httpStatus; switch (error.code) { case errors_1.ErrorCode.MissingStateError: case errors_1.ErrorCode.InvalidStateError: case errors_1.ErrorCode.MissingCodeError: httpStatus = 400; break; default: httpStatus = 500; } res.writeHead(httpStatus, { 'Content-Type': 'text/html; charset=utf-8' }); var html = "\n \n \n \n \n

Oops, Something Went Wrong!

\n

Please try again or contact the app owner (reason: ".concat(escapeHtml(error.code), ")

\n \n "); res.end(html); } // ------------------------------------------ // Internals // ------------------------------------------ // Type guard to narrow Installation type to OrgInstallation function isOrgInstall(installation) { return installation.isEnterpriseInstall || false; } function isNotOrgInstall(installation) { return !isOrgInstall(installation); } function escapeHtml(input) { if (input) { return input .replace(/&/g, '&') .replace(//g, '>') .replace(/"/g, '"') .replace(/'/g, '''); } return ''; } //# sourceMappingURL=callback-options.js.map