Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@slack/oauth

Package Overview
Dependencies
Maintainers
12
Versions
28
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@slack/oauth - npm Package Compare versions

Comparing version 2.3.0 to 2.4.0

124

dist/index.js

@@ -155,9 +155,10 @@ "use strict";

InstallProvider.prototype.authorize = function (source) {
var _a, _b, _c, _d;
return __awaiter(this, void 0, void 0, function () {
var queryResult, authResult, currentUTCSec, tokensToRefresh, installationUpdates, refreshResponses, _i, refreshResponses_1, refreshResp, tokenType, updatedInstallation, error_1;
var _a;
return __generator(this, function (_b) {
switch (_b.label) {
var _e;
return __generator(this, function (_f) {
switch (_f.label) {
case 0:
_b.trys.push([0, 10, , 11]);
_f.trys.push([0, 10, , 11]);
queryResult = void 0;

@@ -167,31 +168,30 @@ if (!source.isEnterpriseInstall) return [3 /*break*/, 2];

case 1:
queryResult = _b.sent();
queryResult = _f.sent();
return [3 /*break*/, 4];
case 2: return [4 /*yield*/, this.installationStore.fetchInstallation(source, this.logger)];
case 3:
queryResult = _b.sent();
_b.label = 4;
queryResult = _f.sent();
_f.label = 4;
case 4:
if (queryResult === undefined) {
if (queryResult === undefined || queryResult === null) {
throw new Error('Failed fetching data from the Installation Store');
}
authResult = {};
authResult.userToken = queryResult.user.token;
if (queryResult.team !== undefined) {
if (queryResult.user) {
authResult.userToken = queryResult.user.token;
}
if ((_a = queryResult.team) === null || _a === void 0 ? void 0 : _a.id) {
authResult.teamId = queryResult.team.id;
}
else if (source.teamId !== undefined) {
else if (source === null || source === void 0 ? void 0 : source.teamId) {
/**
* since queryResult is a org installation, it won't have team.id. If one was passed in via source,
* we should add it to the authResult
* Since queryResult is a org installation, it won't have team.id.
* If one was passed in via source, we should add it to the authResult.
*/
authResult.teamId = source.teamId;
}
if (queryResult.enterprise !== undefined) {
authResult.enterpriseId = queryResult.enterprise.id;
if (((_b = queryResult === null || queryResult === void 0 ? void 0 : queryResult.enterprise) === null || _b === void 0 ? void 0 : _b.id) || (source === null || source === void 0 ? void 0 : source.enterpriseId)) {
authResult.enterpriseId = ((_c = queryResult === null || queryResult === void 0 ? void 0 : queryResult.enterprise) === null || _c === void 0 ? void 0 : _c.id) || (source === null || source === void 0 ? void 0 : source.enterpriseId);
}
else if (source.enterpriseId !== undefined) {
authResult.enterpriseId = source.enterpriseId;
}
if (queryResult.bot !== undefined) {
if (queryResult.bot) {
authResult.botToken = queryResult.bot.token;

@@ -201,3 +201,3 @@ authResult.botId = queryResult.bot.id;

// Token Rotation Enabled (Bot Token)
if (queryResult.bot.refreshToken !== undefined) {
if (queryResult.bot.refreshToken) {
authResult.botRefreshToken = queryResult.bot.refreshToken;

@@ -208,7 +208,7 @@ authResult.botTokenExpiresAt = queryResult.bot.expiresAt; // utc, seconds

// Token Rotation Enabled (User Token)
if (queryResult.user.refreshToken !== undefined) {
if ((_d = queryResult.user) === null || _d === void 0 ? void 0 : _d.refreshToken) {
authResult.userRefreshToken = queryResult.user.refreshToken;
authResult.userTokenExpiresAt = queryResult.user.expiresAt; // utc, seconds
}
if (!(authResult.botRefreshToken !== undefined || authResult.userRefreshToken !== undefined)) return [3 /*break*/, 9];
if (!(authResult.botRefreshToken || authResult.userRefreshToken)) return [3 /*break*/, 9];
currentUTCSec = Math.floor(Date.now() / 1000);

@@ -220,5 +220,5 @@ tokensToRefresh = detectExpiredOrExpiringTokens(authResult, currentUTCSec);

case 5:
refreshResponses = _b.sent();
refreshResponses = _f.sent();
_i = 0, refreshResponses_1 = refreshResponses;
_b.label = 6;
_f.label = 6;
case 6:

@@ -243,3 +243,3 @@ if (!(_i < refreshResponses_1.length)) return [3 /*break*/, 9];

installationUpdates[tokenType].expiresAt = currentUTCSec + refreshResp.expires_in;
updatedInstallation = __assign(__assign({}, installationUpdates), (_a = {}, _a[tokenType] = __assign(__assign({}, queryResult[tokenType]), installationUpdates[tokenType]), _a));
updatedInstallation = __assign(__assign({}, installationUpdates), (_e = {}, _e[tokenType] = __assign(__assign({}, queryResult[tokenType]), installationUpdates[tokenType]), _e));
// TODO: related to the above TODO comment as well

@@ -251,4 +251,4 @@ // eslint-disable-next-line no-await-in-loop

// eslint-disable-next-line no-await-in-loop
_b.sent();
_b.label = 8;
_f.sent();
_f.label = 8;
case 8:

@@ -259,3 +259,3 @@ _i++;

case 10:
error_1 = _b.sent();
error_1 = _f.sent();
throw new errors_1.AuthorizationError(error_1.message);

@@ -300,3 +300,3 @@ case 11: return [2 /*return*/];

InstallProvider.extractSearchParams = function (req) {
var searchParams = new url_1.URL(req.url, "https://" + req.headers.host).searchParams;
var searchParams = new url_1.URL(req.url, "https://".concat(req.headers.host)).searchParams;
return searchParams;

@@ -316,3 +316,3 @@ };

slackURL = new url_1.URL(this.authorizationUrl);
if (options.scopes === undefined) {
if (options.scopes === undefined || options.scopes === null) {
throw new errors_1.GenerateInstallUrlError('You must provide a scope parameter when calling generateInstallUrl');

@@ -326,3 +326,3 @@ }

}
params = new url_1.URLSearchParams("scope=" + scopes);
params = new url_1.URLSearchParams("scope=".concat(scopes));
if (!(stateVerification && this.stateStore)) return [3 /*break*/, 2];

@@ -374,7 +374,7 @@ return [4 /*yield*/, this.stateStore.generateStateParam(options, new Date())];

return __awaiter(this, void 0, void 0, function () {
var code, flowError, state, searchParams, emptyInstallOptions, client, installation, resp, v1Resp, v1Installation, authResult, botId, v2Resp, v2Installation, currentUTC, authResult, authResult, error_2;
var code, flowError, state, searchParams, emptyInstallOptions, client, installation, resp, v1Resp, v1Installation, authResult, botId, v2Resp, v2Installation, currentUTC, authResult, authResult, error_2, emptyInstallOptions;
return __generator(this, function (_b) {
switch (_b.label) {
case 0:
_b.trys.push([0, 17, , 18]);
_b.trys.push([0, 18, , 19]);
if (req.url !== undefined) {

@@ -449,3 +449,3 @@ searchParams = InstallProvider.extractSearchParams(req);

installation = v1Installation;
return [3 /*break*/, 12];
return [3 /*break*/, 13];
case 6: return [4 /*yield*/, client.oauth.v2.access({

@@ -494,9 +494,10 @@ code: code,

case 9:
if (!(v2Resp.authed_user !== undefined && v2Resp.authed_user.access_token !== undefined)) return [3 /*break*/, 11];
if (!(v2Resp.authed_user !== undefined && v2Resp.authed_user.access_token !== undefined)) return [3 /*break*/, 12];
if (!(v2Resp.is_enterprise_install && v2Installation.enterpriseUrl === undefined)) return [3 /*break*/, 11];
return [4 /*yield*/, runAuthTest(v2Resp.authed_user.access_token, this.clientOptions)];
case 10:
authResult = _b.sent();
if (v2Resp.is_enterprise_install && v2Installation.enterpriseUrl === undefined) {
v2Installation.enterpriseUrl = authResult.url;
}
v2Installation.enterpriseUrl = authResult.url;
_b.label = 11;
case 11:
// Token Rotation is Enabled

@@ -507,8 +508,8 @@ if (v2Resp.authed_user.refresh_token !== undefined && v2Resp.authed_user.expires_in !== undefined) {

}
_b.label = 11;
case 11:
_b.label = 12;
case 12:
resp = v2Resp;
installation = v2Installation;
_b.label = 12;
case 12:
_b.label = 13;
case 13:
if (resp.incoming_webhook !== undefined) {

@@ -527,12 +528,12 @@ installation.incomingWebhook = {

}
if (!installation.isEnterpriseInstall) return [3 /*break*/, 14];
if (!installation.isEnterpriseInstall) return [3 /*break*/, 15];
return [4 /*yield*/, this.installationStore.storeInstallation(installation, this.logger)];
case 13:
case 14:
_b.sent();
return [3 /*break*/, 16];
case 14: return [4 /*yield*/, this.installationStore.storeInstallation(installation, this.logger)];
case 15:
return [3 /*break*/, 17];
case 15: return [4 /*yield*/, this.installationStore.storeInstallation(installation, this.logger)];
case 16:
_b.sent();
_b.label = 16;
case 16:
_b.label = 17;
case 17:
// Call the success callback

@@ -547,6 +548,11 @@ if (options !== undefined && options.success !== undefined) {

}
return [3 /*break*/, 18];
case 17:
return [3 /*break*/, 19];
case 18:
error_2 = _b.sent();
this.logger.error(error_2);
if (!installOptions) {
emptyInstallOptions = { scopes: [] };
// eslint-disable-next-line no-param-reassign
installOptions = emptyInstallOptions;
}
// Call the failure callback

@@ -561,4 +567,4 @@ if (options !== undefined && options.failure !== undefined) {

}
return [3 /*break*/, 18];
case 18: return [2 /*return*/];
return [3 /*break*/, 19];
case 19: return [2 /*return*/];
}

@@ -577,7 +583,7 @@ });

// Changes to the workspace app was installed to, to the app home
redirectUrl = "slack://app?team=" + installation.team.id + "&id=" + installation.appId;
redirectUrl = "slack://app?team=".concat(installation.team.id, "&id=").concat(installation.appId);
}
else if (isOrgInstall(installation)) {
// redirect to Slack app management dashboard
redirectUrl = installation.enterpriseUrl + "manage/organization/apps/profile/" + installation.appId + "/workspaces/add";
redirectUrl = "".concat(installation.enterpriseUrl, "manage/organization/apps/profile/").concat(installation.appId, "/workspaces/add");
}

@@ -589,3 +595,3 @@ else {

}
var htmlResponse = "<html>\n <meta http-equiv=\"refresh\" content=\"0; URL=" + redirectUrl + "\">\n <body>\n <h1>Success! Redirecting to the Slack App...</h1>\n <button onClick=\"window.location = '" + redirectUrl + "'\">Click here to redirect</button>\n </body></html>";
var htmlResponse = "<html>\n <meta http-equiv=\"refresh\" content=\"0; URL=".concat(redirectUrl, "\">\n <body>\n <h1>Success! Redirecting to the Slack App...</h1>\n <button onClick=\"window.location = '").concat(redirectUrl, "'\">Click here to redirect</button>\n </body></html>");
res.writeHead(200, { 'Content-Type': 'text/html' });

@@ -630,3 +636,4 @@ res.end(htmlResponse);

var EXPIRY_WINDOW = 7200; // 2 hours
if (authResult.botRefreshToken !== undefined && authResult.botTokenExpiresAt !== undefined) {
if (authResult.botRefreshToken &&
(authResult.botTokenExpiresAt !== undefined && authResult.botTokenExpiresAt !== null)) {
var botTokenExpiresIn = authResult.botTokenExpiresAt - currentUTCSec;

@@ -637,3 +644,4 @@ if (botTokenExpiresIn <= EXPIRY_WINDOW) {

}
if (authResult.userRefreshToken !== undefined && authResult.userTokenExpiresAt !== undefined) {
if (authResult.userRefreshToken &&
(authResult.userTokenExpiresAt !== undefined && authResult.userTokenExpiresAt !== null)) {
var userTokenExpiresIn = authResult.userTokenExpiresAt - currentUTCSec;

@@ -640,0 +648,0 @@ if (userTokenExpiresIn <= EXPIRY_WINDOW) {

@@ -22,3 +22,3 @@ "use strict";

})();
logger.setName(name + ":" + instanceId);
logger.setName("".concat(name, ":").concat(instanceId));
if (level !== undefined) {

@@ -25,0 +25,0 @@ logger.setLevel(level);

@@ -47,4 +47,4 @@ "use strict";

function FileInstallationStore(_a) {
var _b = _a === void 0 ? {} : _a, _c = _b.baseDir, baseDir = _c === void 0 ? (0, os_1.homedir)() + "/.bolt-js-app-installation" : _c, clientId = _b.clientId, _d = _b.historicalDataEnabled, historicalDataEnabled = _d === void 0 ? true : _d;
this.baseDir = clientId !== undefined ? baseDir + "/" + clientId : baseDir;
var _b = _a === void 0 ? {} : _a, _c = _b.baseDir, baseDir = _c === void 0 ? "".concat((0, os_1.homedir)(), "/.bolt-js-app-installation") : _c, clientId = _b.clientId, _d = _b.historicalDataEnabled, historicalDataEnabled = _d === void 0 ? true : _d;
this.baseDir = clientId !== undefined ? "".concat(baseDir, "/").concat(clientId) : baseDir;
this.historicalDataEnabled = historicalDataEnabled;

@@ -60,3 +60,3 @@ }

if (logger !== undefined) {
logger.info("Storing installation in " + installationDir + " for " + JSON.stringify({ enterprise: enterprise, team: team, user: user }));
logger.info("Storing installation in ".concat(installationDir, " for ").concat(JSON.stringify({ enterprise: enterprise, team: team, user: user })));
logger.warn('FileInstallationStore is not intended for production purposes.');

@@ -67,8 +67,8 @@ }

try {
writeToFile(installationDir + "/app-latest", installationData);
writeToFile(installationDir + "/user-" + user.id + "-latest", installationData);
writeToFile("".concat(installationDir, "/app-latest"), installationData);
writeToFile("".concat(installationDir, "/user-").concat(user.id, "-latest"), installationData);
if (this.historicalDataEnabled) {
currentUTC = Date.now();
writeToFile(installationDir + "/app-" + currentUTC, installationData);
writeToFile(installationDir + "/user-" + user.id + "-" + currentUTC, installationData);
writeToFile("".concat(installationDir, "/app-").concat(currentUTC), installationData);
writeToFile("".concat(installationDir, "/user-").concat(user.id, "-").concat(currentUTC), installationData);
}

@@ -90,3 +90,3 @@ }

if (logger !== undefined) {
logger.info("Retrieving installation from " + installationDir + " with the following query: " + JSON.stringify(query));
logger.info("Retrieving installation from ".concat(installationDir, " with the following query: ").concat(JSON.stringify(query)));
}

@@ -98,3 +98,3 @@ if (isEnterpriseInstall && enterpriseId === undefined) {

try {
data = fs_1.default.readFileSync(path_1.default.resolve(installationDir + "/app-latest"));
data = fs_1.default.readFileSync(path_1.default.resolve("".concat(installationDir, "/app-latest")));
installation = JSON.parse(data.toString());

@@ -117,3 +117,3 @@ return [2 /*return*/, installation];

if (logger !== undefined) {
logger.info("Deleting installations in " + installationDir + " with the following query: " + JSON.stringify(query));
logger.info("Deleting installations in ".concat(installationDir, " with the following query: ").concat(JSON.stringify(query)));
}

@@ -126,7 +126,7 @@ filesToDelete = [];

else {
userFiles = fs_1.default.readdirSync(installationDir).filter(function (file) { return file.includes("user-" + userId + "-"); });
userFiles = fs_1.default.readdirSync(installationDir).filter(function (file) { return file.includes("user-".concat(userId, "-")); });
filesToDelete = filesToDelete.concat(userFiles);
}
try {
filesToDelete.map(function (filePath) { return deleteFile(path_1.default.resolve(installationDir + "/" + filePath)); });
filesToDelete.map(function (filePath) { return deleteFile(path_1.default.resolve("".concat(installationDir, "/").concat(filePath))); });
}

@@ -144,5 +144,5 @@ catch (err) {

if (isEnterpriseInstall === void 0) { isEnterpriseInstall = false; }
var installDir = this.baseDir + "/" + enterpriseId;
var installDir = "".concat(this.baseDir, "/").concat(enterpriseId);
if (teamId !== '' && !isEnterpriseInstall) {
installDir += (enterpriseId !== '') ? "-" + teamId : "" + teamId;
installDir += (enterpriseId !== '') ? "-".concat(teamId) : "".concat(teamId);
}

@@ -149,0 +149,0 @@ return installDir;

{
"name": "@slack/oauth",
"version": "2.3.0",
"version": "2.4.0",
"description": "Official library for interacting with Slack's Oauth endpoints",

@@ -5,0 +5,0 @@ "author": "Slack Technologies, LLC",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc