slack-edge
Version:
Slack app development framework for edge functions with streamlined TypeScript support
119 lines • 5.59 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.renderDefaultOAuthStartPage = renderDefaultOAuthStartPage;
exports.renderSimpleCSSOAuthStartPage = renderSimpleCSSOAuthStartPage;
exports.renderDefaultOAuthErrorPage = renderDefaultOAuthErrorPage;
exports.renderSimpleCSSOAuthErrorPage = renderSimpleCSSOAuthErrorPage;
exports.renderDefaultOAuthCompletionPage = renderDefaultOAuthCompletionPage;
exports.renderSimpleCSSOAuthCompletionPage = renderSimpleCSSOAuthCompletionPage;
const escape_html_1 = require("./escape-html");
/**
* Generates an HTML data for the /slack/install page.
* @param url the URL to start the OAuth flow
* @returns HTML data
*/
// deno-lint-ignore require-await
async function renderDefaultOAuthStartPage({ url, immediateRedirect }) {
const meta = immediateRedirect ? `<meta http-equiv="refresh" content="2;url=${(0, escape_html_1.escapeHtml)(url)}'" />` : "";
return ("<html>" +
"<head>" +
meta +
"<title>Redirecting to Slack ...</title>" +
"</head>" +
'<body>Redirecting to the Slack OAuth page ... Click <a href="' +
(0, escape_html_1.escapeHtml)(url) +
'">here</a> to continue.</body>' +
"</html>");
}
// deno-lint-ignore require-await
async function renderSimpleCSSOAuthStartPage({ url, immediateRedirect }) {
const meta = immediateRedirect ? `<meta http-equiv="refresh" content="2;url=${(0, escape_html_1.escapeHtml)(url)}'" />` : "";
return `<html>
<head>
${meta}
<title>Redirecting to Slack ...</title>
<link rel="stylesheet" href="https://cdn.simplecss.org/simple.min.css">
</head>
<body>
<main>
<h2>Installing Slack App</h2>
<p>Redirecting to the Slack OAuth page ... Click <a href="${(0, escape_html_1.escapeHtml)(url)}">here</a> to continue.</p>
</main>
</body>
</html>`;
}
/**
* Generates an HTML data indicating an error for the /slack/oauth_redirect page.
* @param installPath the path to start the OAuth flow again
* @param reason the error reason code
* @returns HTML data
*/
// deno-lint-ignore require-await
async function renderDefaultOAuthErrorPage({ installPath, reason }) {
return ('<html><head><style>body {{ padding: 10px 15px; font-family: verdana; text-align: center; }}</style></head><body><h2>Oops, Something Went Wrong!</h2><p>Please try again from <a href="' +
(0, escape_html_1.escapeHtml)(installPath) +
'">here</a> or contact the app owner (reason: ' +
(0, escape_html_1.escapeHtml)(reason.message) +
")</p></body></html>");
}
// deno-lint-ignore require-await
async function renderSimpleCSSOAuthErrorPage({ installPath, reason }) {
return `<html>
<head>
<link rel="stylesheet" href="https://cdn.simplecss.org/simple.min.css">
</head>
<body>
<main>
<h2>Oops, Something Went Wrong!</h2>
<p>Please try again from <a href="${(0, escape_html_1.escapeHtml)(installPath)}">here</a> or contact the app owner (reason: ${(0, escape_html_1.escapeHtml)(reason.message)})</p>
</main>
</body>
</html>`;
}
/**
* Generates an HTML data indicating app installation successfully completed for the /slack/oauth_redirect page.
* @param appId the app's ID
* @param teamId workspace ID to head to
* @param isEnterpriseInstall org-wide installation or not
* @param enterpriseUrl the management console URL for Enterprise Grid admins
* @param installation installation data
* @param authTestResponse auth.test API response
* @returns HTML data
*/
// deno-lint-ignore require-await
async function renderDefaultOAuthCompletionPage({ appId, teamId, isEnterpriseInstall, enterpriseUrl, }) {
let url = `slack://app?team=${teamId}&id=${appId}`;
if (isEnterpriseInstall && enterpriseUrl !== undefined) {
url = `${enterpriseUrl}manage/organization/apps/profile/${appId}/workspaces/add`;
}
const browserUrl = `https://app.slack.com/client/${teamId}`;
return ('<html><head><meta http-equiv="refresh" content="0; URL=' +
(0, escape_html_1.escapeHtml)(url) +
'"><style>body {{ padding: 10px 15px; font-family: verdana; text-align: center; }}</style></head><body><h2>Thank you!</h2><p>Redirecting to the Slack App... click <a href="' +
(0, escape_html_1.escapeHtml)(url) +
'">here</a>. If you use the browser version of Slack, click <a href="' +
(0, escape_html_1.escapeHtml)(browserUrl) +
'" target="_blank">this link</a> instead.</p></body></html>');
}
// deno-lint-ignore require-await
async function renderSimpleCSSOAuthCompletionPage({ appId, teamId, isEnterpriseInstall, enterpriseUrl, }) {
let url = `slack://app?team=${teamId}&id=${appId}`;
if (isEnterpriseInstall && enterpriseUrl !== undefined) {
url = `${enterpriseUrl}manage/organization/apps/profile/${appId}/workspaces/add`;
}
const browserUrl = `https://app.slack.com/client/${teamId}`;
return `<html>
<head>
<meta http-equiv="refresh" content="0; URL=${(0, escape_html_1.escapeHtml)(url)}">
<link rel="stylesheet" href="https://cdn.simplecss.org/simple.min.css">
</head>
<body>
<main>
<h2>Thank you!</h2>
<p>Redirecting to the Slack App... click <a href="${(0, escape_html_1.escapeHtml)(url)}">here</a>.
If you use the browser version of Slack, click <a href="${(0, escape_html_1.escapeHtml)(browserUrl)}" target="_blank">this link</a> instead.</p>
</main>
</body>
</html>`;
}
//# sourceMappingURL=oauth-page-renderer.js.map