@rocket.chat/apps-engine
Advanced tools
Comparing version 0.5.0 to 0.5.1
{ | ||
"name": "@rocket.chat/apps-engine", | ||
"version": "0.5.0", | ||
"version": "0.5.1", | ||
"description": "The engine code for the Rocket.Chat Apps which manages, runs, translates, coordinates and all of that.", | ||
@@ -48,3 +48,3 @@ "main": "index.js", | ||
"dependencies": { | ||
"@rocket.chat/apps-ts-definition": "^0.9.1", | ||
"@rocket.chat/apps-ts-definition": "^0.9.2", | ||
"adm-zip": "^0.4.7", | ||
@@ -51,0 +51,0 @@ "lodash": "^4.17.5", |
@@ -275,5 +275,8 @@ "use strict"; | ||
this.accessorManager.purifyApp(storageItem.id); | ||
if (isManual) { | ||
rl.setStatus(AppStatus_1.AppStatus.MANUALLY_DISABLED); | ||
} | ||
if (!isManual) return [3 /*break*/, 7]; | ||
return [4 /*yield*/, rl.setStatus(AppStatus_1.AppStatus.MANUALLY_DISABLED)]; | ||
case 6: | ||
_a.sent(); | ||
_a.label = 7; | ||
case 7: | ||
// This is async, but we don't care since it only updates in the database | ||
@@ -291,3 +294,3 @@ // and it should not mutate any properties we care about | ||
return __awaiter(this, void 0, void 0, function () { | ||
var result, created, app; | ||
var result, created, app, e_2; | ||
return __generator(this, function (_a) { | ||
@@ -315,21 +318,25 @@ switch (_a.label) { | ||
this.apps.set(app.getID(), app); | ||
// Let everyone know that the App has been added | ||
try { | ||
this.bridges.getAppActivationBridge().appAdded(app); | ||
} | ||
catch (e) { | ||
// If an error occurs during this, oh well. | ||
} | ||
if (!enable) return [3 /*break*/, 4]; | ||
// Start up the app | ||
return [4 /*yield*/, this.runStartUpProcess(created, app, false)]; | ||
_a.label = 3; | ||
case 3: | ||
// Start up the app | ||
_a.trys.push([3, 5, , 6]); | ||
return [4 /*yield*/, this.bridges.getAppActivationBridge().appAdded(app)]; | ||
case 4: | ||
_a.sent(); | ||
return [3 /*break*/, 6]; | ||
case 4: return [4 /*yield*/, this.initializeApp(created, app, true)]; | ||
case 5: | ||
e_2 = _a.sent(); | ||
return [3 /*break*/, 6]; | ||
case 6: | ||
if (!enable) return [3 /*break*/, 8]; | ||
// Start up the app | ||
return [4 /*yield*/, this.runStartUpProcess(created, app, false)]; | ||
case 7: | ||
// Start up the app | ||
_a.sent(); | ||
_a.label = 6; | ||
case 6: return [2 /*return*/, app]; | ||
return [3 /*break*/, 10]; | ||
case 8: return [4 /*yield*/, this.initializeApp(created, app, true)]; | ||
case 9: | ||
_a.sent(); | ||
_a.label = 10; | ||
case 10: return [2 /*return*/, app]; | ||
} | ||
@@ -341,3 +348,3 @@ }); | ||
return __awaiter(this, void 0, void 0, function () { | ||
var app; | ||
var app, e_3; | ||
return __generator(this, function (_a) { | ||
@@ -358,9 +365,13 @@ switch (_a.label) { | ||
_a.sent(); | ||
// Let everyone know that the App has been removed | ||
try { | ||
this.bridges.getAppActivationBridge().appRemoved(app); | ||
} | ||
catch (e) { | ||
// If an error occurs during this, oh well. | ||
} | ||
_a.label = 5; | ||
case 5: | ||
_a.trys.push([5, 7, , 8]); | ||
return [4 /*yield*/, this.bridges.getAppActivationBridge().appRemoved(app)]; | ||
case 6: | ||
_a.sent(); | ||
return [3 /*break*/, 8]; | ||
case 7: | ||
e_3 = _a.sent(); | ||
return [3 /*break*/, 8]; | ||
case 8: | ||
this.apps.delete(app.getID()); | ||
@@ -374,3 +385,3 @@ return [2 /*return*/, app]; | ||
return __awaiter(this, void 0, void 0, function () { | ||
var result, old, e_2, stored, app; | ||
var result, old, e_4, stored, app, e_5; | ||
return __generator(this, function (_a) { | ||
@@ -395,3 +406,3 @@ switch (_a.label) { | ||
case 5: | ||
e_2 = _a.sent(); | ||
e_4 = _a.sent(); | ||
return [3 /*break*/, 6]; | ||
@@ -419,10 +430,13 @@ case 6: return [4 /*yield*/, this.storage.update({ | ||
_a.sent(); | ||
// Let everyone know that the App has been updated | ||
try { | ||
this.bridges.getAppActivationBridge().appUpdated(app); | ||
} | ||
catch (e) { | ||
// If an error occurs during this, oh well. | ||
} | ||
return [2 /*return*/, app]; | ||
_a.label = 9; | ||
case 9: | ||
_a.trys.push([9, 11, , 12]); | ||
return [4 /*yield*/, this.bridges.getAppActivationBridge().appUpdated(app)]; | ||
case 10: | ||
_a.sent(); | ||
return [3 /*break*/, 12]; | ||
case 11: | ||
e_5 = _a.sent(); | ||
return [3 /*break*/, 12]; | ||
case 12: return [2 /*return*/, app]; | ||
} | ||
@@ -502,6 +516,8 @@ }); | ||
_a.sent(); | ||
if (AppStatus_1.AppStatusUtils.isEnabled(rl.getPreviousStatus())) { | ||
this.enableApp(item, rl, false, rl.getPreviousStatus() === AppStatus_1.AppStatus.MANUALLY_ENABLED); | ||
} | ||
return [2 /*return*/, this.apps.get(item.id)]; | ||
if (!AppStatus_1.AppStatusUtils.isEnabled(rl.getPreviousStatus())) return [3 /*break*/, 4]; | ||
return [4 /*yield*/, this.enableApp(item, rl, false, rl.getPreviousStatus() === AppStatus_1.AppStatus.MANUALLY_ENABLED)]; | ||
case 3: | ||
_a.sent(); | ||
_a.label = 4; | ||
case 4: return [2 /*return*/, this.apps.get(item.id)]; | ||
} | ||
@@ -517,10 +533,12 @@ }); | ||
case 0: | ||
if (app.getStatus() !== AppStatus_1.AppStatus.INITIALIZED) { | ||
isInitialized = this.initializeApp(storageItem, app, true); | ||
if (!isInitialized) { | ||
return [2 /*return*/, false]; | ||
} | ||
if (!(app.getStatus() !== AppStatus_1.AppStatus.INITIALIZED)) return [3 /*break*/, 2]; | ||
return [4 /*yield*/, this.initializeApp(storageItem, app, true)]; | ||
case 1: | ||
isInitialized = _a.sent(); | ||
if (!isInitialized) { | ||
return [2 /*return*/, false]; | ||
} | ||
return [4 /*yield*/, this.enableApp(storageItem, app, true, isManual)]; | ||
case 1: | ||
_a.label = 2; | ||
case 2: return [4 /*yield*/, this.enableApp(storageItem, app, true, isManual)]; | ||
case 3: | ||
isEnabled = _a.sent(); | ||
@@ -538,3 +556,3 @@ if (!isEnabled) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var result, configExtend, envRead, e_3; | ||
var result, configExtend, envRead, e_6; | ||
return __generator(this, function (_a) { | ||
@@ -547,3 +565,3 @@ switch (_a.label) { | ||
case 1: | ||
_a.trys.push([1, 3, , 4]); | ||
_a.trys.push([1, 4, , 6]); | ||
return [4 /*yield*/, app.call(metadata_1.AppMethod.INITIALIZE, configExtend, envRead)]; | ||
@@ -553,15 +571,19 @@ case 2: | ||
result = true; | ||
app.setStatus(AppStatus_1.AppStatus.INITIALIZED); | ||
return [3 /*break*/, 4]; | ||
return [4 /*yield*/, app.setStatus(AppStatus_1.AppStatus.INITIALIZED)]; | ||
case 3: | ||
e_3 = _a.sent(); | ||
if (e_3.name === 'NotEnoughMethodArgumentsError') { | ||
_a.sent(); | ||
return [3 /*break*/, 6]; | ||
case 4: | ||
e_6 = _a.sent(); | ||
if (e_6.name === 'NotEnoughMethodArgumentsError') { | ||
console.warn('Please report the following error:'); | ||
} | ||
console.error(e_3); | ||
console.error(e_6); | ||
this.commandManager.unregisterCommands(storageItem.id); | ||
result = false; | ||
app.setStatus(AppStatus_1.AppStatus.ERROR_DISABLED); | ||
return [3 /*break*/, 4]; | ||
case 4: | ||
return [4 /*yield*/, app.setStatus(AppStatus_1.AppStatus.ERROR_DISABLED)]; | ||
case 5: | ||
_a.sent(); | ||
return [3 /*break*/, 6]; | ||
case 6: | ||
if (saveToDb) { | ||
@@ -581,22 +603,26 @@ // This is async, but we don't care since it only updates in the database | ||
return __awaiter(this, void 0, void 0, function () { | ||
var enable, e_4; | ||
var enable, e_7; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
_a.trys.push([0, 2, , 3]); | ||
_a.trys.push([0, 3, , 5]); | ||
return [4 /*yield*/, app.call(metadata_1.AppMethod.ONENABLE, this.getAccessorManager().getEnvironmentRead(storageItem.id), this.getAccessorManager().getConfigurationModify(storageItem.id))]; | ||
case 1: | ||
enable = (_a.sent()); | ||
app.setStatus(isManual ? AppStatus_1.AppStatus.MANUALLY_ENABLED : AppStatus_1.AppStatus.AUTO_ENABLED); | ||
return [3 /*break*/, 3]; | ||
return [4 /*yield*/, app.setStatus(isManual ? AppStatus_1.AppStatus.MANUALLY_ENABLED : AppStatus_1.AppStatus.AUTO_ENABLED)]; | ||
case 2: | ||
e_4 = _a.sent(); | ||
_a.sent(); | ||
return [3 /*break*/, 5]; | ||
case 3: | ||
e_7 = _a.sent(); | ||
enable = false; | ||
if (e_4.name === 'NotEnoughMethodArgumentsError') { | ||
if (e_7.name === 'NotEnoughMethodArgumentsError') { | ||
console.warn('Please report the following error:'); | ||
} | ||
console.error(e_4); | ||
app.setStatus(AppStatus_1.AppStatus.ERROR_DISABLED); | ||
return [3 /*break*/, 3]; | ||
case 3: | ||
console.error(e_7); | ||
return [4 /*yield*/, app.setStatus(AppStatus_1.AppStatus.ERROR_DISABLED)]; | ||
case 4: | ||
_a.sent(); | ||
return [3 /*break*/, 5]; | ||
case 5: | ||
if (enable) { | ||
@@ -603,0 +629,0 @@ this.commandManager.registerCommands(app.getID()); |
import { AppStatus } from '@rocket.chat/apps-ts-definition/AppStatus'; | ||
import { ProxiedApp } from '../ProxiedApp'; | ||
export interface IAppActivationBridge { | ||
appAdded(app: ProxiedApp): void; | ||
appUpdated(app: ProxiedApp): void; | ||
appRemoved(app: ProxiedApp): void; | ||
appStatusChanged(app: ProxiedApp, status: AppStatus): void; | ||
appAdded(app: ProxiedApp): Promise<void>; | ||
appUpdated(app: ProxiedApp): Promise<void>; | ||
appRemoved(app: ProxiedApp): Promise<void>; | ||
appStatusChanged(app: ProxiedApp, status: AppStatus): Promise<void>; | ||
} |
@@ -30,3 +30,3 @@ /// <reference types="node" /> | ||
getStatus(): AppStatus; | ||
setStatus(status: AppStatus): void; | ||
setStatus(status: AppStatus): Promise<void>; | ||
getName(): string; | ||
@@ -33,0 +33,0 @@ getNameSlug(): string; |
@@ -104,3 +104,3 @@ "use strict"; | ||
_a.trys.push([1, 3, , 4]); | ||
return [4 /*yield*/, this.runInContext("Promise.resolve().then(() => app." + method + ".apply(app, args))", this.makeContext({ app: this.app, args: args }))]; | ||
return [4 /*yield*/, this.runInContext("Promise.resolve(args).then((args) => app." + method + ".apply(app, args))", this.makeContext({ app: this.app, args: args }))]; | ||
case 2: | ||
@@ -127,4 +127,15 @@ // tslint:disable-next-line:max-line-length | ||
ProxiedApp.prototype.setStatus = function (status) { | ||
this.call(metadata_1.AppMethod.SETSTATUS, status); | ||
this.manager.getBridges().getAppActivationBridge().appStatusChanged(this, this.getStatus()); | ||
return __awaiter(this, void 0, void 0, function () { | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, this.call(metadata_1.AppMethod.SETSTATUS, status)]; | ||
case 1: | ||
_a.sent(); | ||
return [4 /*yield*/, this.manager.getBridges().getAppActivationBridge().appStatusChanged(this, this.getStatus())]; | ||
case 2: | ||
_a.sent(); | ||
return [2 /*return*/]; | ||
} | ||
}); | ||
}); | ||
}; | ||
@@ -131,0 +142,0 @@ ProxiedApp.prototype.getName = function () { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
455444
4953