@rocket.chat/apps-engine
Advanced tools
Comparing version 0.4.13 to 0.5.0
{ | ||
"name": "@rocket.chat/apps-engine", | ||
"version": "0.4.13", | ||
"version": "0.5.0", | ||
"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.8.0", | ||
"@rocket.chat/apps-ts-definition": "^0.9.1", | ||
"adm-zip": "^0.4.7", | ||
@@ -51,0 +51,0 @@ "lodash": "^4.17.5", |
@@ -7,5 +7,5 @@ import { IEnvironmentalVariableBridge } from '../bridges'; | ||
constructor(bridge: IEnvironmentalVariableBridge, appId: string); | ||
getValueByName(envVarName: string): string; | ||
isReadable(envVarName: string): boolean; | ||
isSet(envVarName: string): boolean; | ||
getValueByName(envVarName: string): Promise<string>; | ||
isReadable(envVarName: string): Promise<boolean>; | ||
isSet(envVarName: string): Promise<boolean>; | ||
} |
@@ -10,7 +10,7 @@ import { IHttp, IHttpExtend, IHttpRequest, IHttpResponse } from '@rocket.chat/apps-ts-definition/accessors'; | ||
constructor(accessManager: AppAccessorManager, bridges: AppBridges, httpExtender: IHttpExtend, appId: string); | ||
get(url: string, options?: IHttpRequest): IHttpResponse; | ||
put(url: string, options?: IHttpRequest): IHttpResponse; | ||
post(url: string, options?: IHttpRequest): IHttpResponse; | ||
del(url: string, options?: IHttpRequest): IHttpResponse; | ||
get(url: string, options?: IHttpRequest): Promise<IHttpResponse>; | ||
put(url: string, options?: IHttpRequest): Promise<IHttpResponse>; | ||
post(url: string, options?: IHttpRequest): Promise<IHttpResponse>; | ||
del(url: string, options?: IHttpRequest): Promise<IHttpResponse>; | ||
private _processHandler(url, method, options?); | ||
} |
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
var __generator = (this && this.__generator) || function (thisArg, body) { | ||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; | ||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; | ||
function verb(n) { return function (v) { return step([n, v]); }; } | ||
function step(op) { | ||
if (f) throw new TypeError("Generator is already executing."); | ||
while (_) try { | ||
if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t; | ||
if (y = 0, t) op = [0, t.value]; | ||
switch (op[0]) { | ||
case 0: case 1: t = op; break; | ||
case 4: _.label++; return { value: op[1], done: false }; | ||
case 5: _.label++; y = op[1]; op = [0]; continue; | ||
case 7: op = _.ops.pop(); _.trys.pop(); continue; | ||
default: | ||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } | ||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } | ||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } | ||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } | ||
if (t[2]) _.ops.pop(); | ||
_.trys.pop(); continue; | ||
} | ||
op = body.call(thisArg, _); | ||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } | ||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; | ||
} | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -24,34 +59,44 @@ var accessors_1 = require("@rocket.chat/apps-ts-definition/accessors"); | ||
Http.prototype._processHandler = function (url, method, options) { | ||
var request = options || {}; | ||
if (typeof request.headers === 'undefined') { | ||
request.headers = {}; | ||
} | ||
this.httpExtender.getDefaultHeaders().forEach(function (value, key) { | ||
if (typeof request.headers[key] !== 'string') { | ||
request.headers[key] = value; | ||
} | ||
return __awaiter(this, void 0, void 0, function () { | ||
var request, reader, persis, response; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
request = options || {}; | ||
if (typeof request.headers === 'undefined') { | ||
request.headers = {}; | ||
} | ||
this.httpExtender.getDefaultHeaders().forEach(function (value, key) { | ||
if (typeof request.headers[key] !== 'string') { | ||
request.headers[key] = value; | ||
} | ||
}); | ||
if (typeof request.params === 'undefined') { | ||
request.params = {}; | ||
} | ||
this.httpExtender.getDefaultParams().forEach(function (value, key) { | ||
if (typeof request.params[key] !== 'string') { | ||
request.params[key] = value; | ||
} | ||
}); | ||
reader = this.accessManager.getReader(this.appId); | ||
persis = this.accessManager.getPersistence(this.appId); | ||
this.httpExtender.getPreRequestHandlers().forEach(function (handler) { | ||
request = handler.executePreHttpRequest(url, request, reader, persis); | ||
}); | ||
return [4 /*yield*/, this.bridges.getHttpBridge().call({ | ||
appId: this.appId, | ||
method: method, | ||
url: url, | ||
request: request, | ||
})]; | ||
case 1: | ||
response = _a.sent(); | ||
this.httpExtender.getPreResponseHandlers().forEach(function (handler) { | ||
response = handler.executePreHttpResponse(response, reader, persis); | ||
}); | ||
return [2 /*return*/, response]; | ||
} | ||
}); | ||
}); | ||
if (typeof request.params === 'undefined') { | ||
request.params = {}; | ||
} | ||
this.httpExtender.getDefaultParams().forEach(function (value, key) { | ||
if (typeof request.params[key] !== 'string') { | ||
request.params[key] = value; | ||
} | ||
}); | ||
var reader = this.accessManager.getReader(this.appId); | ||
var persis = this.accessManager.getPersistence(this.appId); | ||
this.httpExtender.getPreRequestHandlers().forEach(function (handler) { | ||
request = handler.executePreHttpRequest(url, request, reader, persis); | ||
}); | ||
var response = this.bridges.getHttpBridge().call({ | ||
appId: this.appId, | ||
method: method, | ||
url: url, | ||
request: request, | ||
}); | ||
this.httpExtender.getPreResponseHandlers().forEach(function (handler) { | ||
response = handler.executePreHttpResponse(response, reader, persis); | ||
}); | ||
return response; | ||
}; | ||
@@ -58,0 +103,0 @@ return Http; |
@@ -10,5 +10,5 @@ import { IMessageBridge } from '../bridges/IMessageBridge'; | ||
constructor(messageBridge: IMessageBridge, appId: string); | ||
getById(id: string): IMessage; | ||
getSenderUser(messageId: string): IUser; | ||
getRoom(messageId: string): IRoom; | ||
getById(id: string): Promise<IMessage>; | ||
getSenderUser(messageId: string): Promise<IUser>; | ||
getRoom(messageId: string): Promise<IRoom>; | ||
} |
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
var __generator = (this && this.__generator) || function (thisArg, body) { | ||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; | ||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; | ||
function verb(n) { return function (v) { return step([n, v]); }; } | ||
function step(op) { | ||
if (f) throw new TypeError("Generator is already executing."); | ||
while (_) try { | ||
if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t; | ||
if (y = 0, t) op = [0, t.value]; | ||
switch (op[0]) { | ||
case 0: case 1: t = op; break; | ||
case 4: _.label++; return { value: op[1], done: false }; | ||
case 5: _.label++; y = op[1]; op = [0]; continue; | ||
case 7: op = _.ops.pop(); _.trys.pop(); continue; | ||
default: | ||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } | ||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } | ||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } | ||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } | ||
if (t[2]) _.ops.pop(); | ||
_.trys.pop(); continue; | ||
} | ||
op = body.call(thisArg, _); | ||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } | ||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; | ||
} | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -12,14 +47,32 @@ var MessageRead = (function () { | ||
MessageRead.prototype.getSenderUser = function (messageId) { | ||
var msg = this.messageBridge.getById(messageId, this.appId); | ||
if (!msg) { | ||
return undefined; | ||
} | ||
return msg.sender; | ||
return __awaiter(this, void 0, void 0, function () { | ||
var msg; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, this.messageBridge.getById(messageId, this.appId)]; | ||
case 1: | ||
msg = _a.sent(); | ||
if (!msg) { | ||
return [2 /*return*/, undefined]; | ||
} | ||
return [2 /*return*/, msg.sender]; | ||
} | ||
}); | ||
}); | ||
}; | ||
MessageRead.prototype.getRoom = function (messageId) { | ||
var msg = this.messageBridge.getById(messageId, this.appId); | ||
if (!msg) { | ||
return undefined; | ||
} | ||
return msg.room; | ||
return __awaiter(this, void 0, void 0, function () { | ||
var msg; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, this.messageBridge.getById(messageId, this.appId)]; | ||
case 1: | ||
msg = _a.sent(); | ||
if (!msg) { | ||
return [2 /*return*/, undefined]; | ||
} | ||
return [2 /*return*/, msg.room]; | ||
} | ||
}); | ||
}); | ||
}; | ||
@@ -26,0 +79,0 @@ return MessageRead; |
@@ -11,5 +11,5 @@ import { IMessageBuilder, IModifyCreator, IRoomBuilder } from '@rocket.chat/apps-ts-definition/accessors'; | ||
startRoom(data?: IRoom): IRoomBuilder; | ||
finish(builder: IMessageBuilder | IRoomBuilder): string; | ||
finish(builder: IMessageBuilder | IRoomBuilder): Promise<string>; | ||
private _finishMessage(builder); | ||
private _finishRoom(builder); | ||
} |
@@ -8,5 +8,5 @@ import { IMessageExtender, IModifyExtender, IRoomExtender } from '@rocket.chat/apps-ts-definition/accessors'; | ||
constructor(bridges: AppBridges, appId: string); | ||
extendMessage(messageId: string, updater: IUser): IMessageExtender; | ||
extendRoom(roomId: string, updater: IUser): IRoomExtender; | ||
finish(extender: IMessageExtender | IRoomExtender): void; | ||
extendMessage(messageId: string, updater: IUser): Promise<IMessageExtender>; | ||
extendRoom(roomId: string, updater: IUser): Promise<IRoomExtender>; | ||
finish(extender: IMessageExtender | IRoomExtender): Promise<void>; | ||
} |
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
var __generator = (this && this.__generator) || function (thisArg, body) { | ||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; | ||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; | ||
function verb(n) { return function (v) { return step([n, v]); }; } | ||
function step(op) { | ||
if (f) throw new TypeError("Generator is already executing."); | ||
while (_) try { | ||
if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t; | ||
if (y = 0, t) op = [0, t.value]; | ||
switch (op[0]) { | ||
case 0: case 1: t = op; break; | ||
case 4: _.label++; return { value: op[1], done: false }; | ||
case 5: _.label++; y = op[1]; op = [0]; continue; | ||
case 7: op = _.ops.pop(); _.trys.pop(); continue; | ||
default: | ||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } | ||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } | ||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } | ||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } | ||
if (t[2]) _.ops.pop(); | ||
_.trys.pop(); continue; | ||
} | ||
op = body.call(thisArg, _); | ||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } | ||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; | ||
} | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -12,11 +47,29 @@ var metadata_1 = require("@rocket.chat/apps-ts-definition/metadata"); | ||
ModifyExtender.prototype.extendMessage = function (messageId, updater) { | ||
var msg = this.bridges.getMessageBridge().getById(messageId, this.appId); | ||
msg.editor = updater; | ||
msg.editedAt = new Date(); | ||
return new MessageExtender_1.MessageExtender(msg); | ||
return __awaiter(this, void 0, void 0, function () { | ||
var msg; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, this.bridges.getMessageBridge().getById(messageId, this.appId)]; | ||
case 1: | ||
msg = _a.sent(); | ||
msg.editor = updater; | ||
msg.editedAt = new Date(); | ||
return [2 /*return*/, new MessageExtender_1.MessageExtender(msg)]; | ||
} | ||
}); | ||
}); | ||
}; | ||
ModifyExtender.prototype.extendRoom = function (roomId, updater) { | ||
var room = this.bridges.getRoomBridge().getById(roomId, this.appId); | ||
room.updatedAt = new Date(); | ||
return new RoomExtender_1.RoomExtender(room); | ||
return __awaiter(this, void 0, void 0, function () { | ||
var room; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, this.bridges.getRoomBridge().getById(roomId, this.appId)]; | ||
case 1: | ||
room = _a.sent(); | ||
room.updatedAt = new Date(); | ||
return [2 /*return*/, new RoomExtender_1.RoomExtender(room)]; | ||
} | ||
}); | ||
}); | ||
}; | ||
@@ -23,0 +76,0 @@ ModifyExtender.prototype.finish = function (extender) { |
@@ -8,7 +8,7 @@ import { IMessageBuilder, IModifyUpdater, IRoomBuilder } from '@rocket.chat/apps-ts-definition/accessors'; | ||
constructor(bridges: AppBridges, appId: string); | ||
message(messageId: string, updater: IUser): IMessageBuilder; | ||
room(roomId: string, updater: IUser): IRoomBuilder; | ||
finish(builder: IMessageBuilder | IRoomBuilder): void; | ||
message(messageId: string, updater: IUser): Promise<IMessageBuilder>; | ||
room(roomId: string, updater: IUser): Promise<IRoomBuilder>; | ||
finish(builder: IMessageBuilder | IRoomBuilder): Promise<void>; | ||
private _finishMessage(builder); | ||
private _finishRoom(builder); | ||
} |
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
var __generator = (this && this.__generator) || function (thisArg, body) { | ||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; | ||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; | ||
function verb(n) { return function (v) { return step([n, v]); }; } | ||
function step(op) { | ||
if (f) throw new TypeError("Generator is already executing."); | ||
while (_) try { | ||
if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t; | ||
if (y = 0, t) op = [0, t.value]; | ||
switch (op[0]) { | ||
case 0: case 1: t = op; break; | ||
case 4: _.label++; return { value: op[1], done: false }; | ||
case 5: _.label++; y = op[1]; op = [0]; continue; | ||
case 7: op = _.ops.pop(); _.trys.pop(); continue; | ||
default: | ||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } | ||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } | ||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } | ||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } | ||
if (t[2]) _.ops.pop(); | ||
_.trys.pop(); continue; | ||
} | ||
op = body.call(thisArg, _); | ||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } | ||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; | ||
} | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -12,8 +47,26 @@ var metadata_1 = require("@rocket.chat/apps-ts-definition/metadata"); | ||
ModifyUpdater.prototype.message = function (messageId, updater) { | ||
var msg = this.bridges.getMessageBridge().getById(messageId, this.appId); | ||
return new MessageBuilder_1.MessageBuilder(msg); | ||
return __awaiter(this, void 0, void 0, function () { | ||
var msg; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, this.bridges.getMessageBridge().getById(messageId, this.appId)]; | ||
case 1: | ||
msg = _a.sent(); | ||
return [2 /*return*/, new MessageBuilder_1.MessageBuilder(msg)]; | ||
} | ||
}); | ||
}); | ||
}; | ||
ModifyUpdater.prototype.room = function (roomId, updater) { | ||
var room = this.bridges.getRoomBridge().getById(roomId, this.appId); | ||
return new RoomBuilder_1.RoomBuilder(room); | ||
return __awaiter(this, void 0, void 0, function () { | ||
var room; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, this.bridges.getRoomBridge().getById(roomId, this.appId)]; | ||
case 1: | ||
room = _a.sent(); | ||
return [2 /*return*/, new RoomBuilder_1.RoomBuilder(room)]; | ||
} | ||
}); | ||
}); | ||
}; | ||
@@ -20,0 +73,0 @@ ModifyUpdater.prototype.finish = function (builder) { |
@@ -10,5 +10,5 @@ import { IMessageBuilder, INotifier } from '@rocket.chat/apps-ts-definition/accessors'; | ||
constructor(bridges: AppBridges, appId: string); | ||
notifyUser(user: IUser, message: IMessage): void; | ||
notifyRoom(room: IRoom, message: IMessage): void; | ||
notifyUser(user: IUser, message: IMessage): Promise<void>; | ||
notifyRoom(room: IRoom, message: IMessage): Promise<void>; | ||
getMessageBuilder(): IMessageBuilder; | ||
} |
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
var __generator = (this && this.__generator) || function (thisArg, body) { | ||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; | ||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; | ||
function verb(n) { return function (v) { return step([n, v]); }; } | ||
function step(op) { | ||
if (f) throw new TypeError("Generator is already executing."); | ||
while (_) try { | ||
if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t; | ||
if (y = 0, t) op = [0, t.value]; | ||
switch (op[0]) { | ||
case 0: case 1: t = op; break; | ||
case 4: _.label++; return { value: op[1], done: false }; | ||
case 5: _.label++; y = op[1]; op = [0]; continue; | ||
case 7: op = _.ops.pop(); _.trys.pop(); continue; | ||
default: | ||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } | ||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } | ||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } | ||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } | ||
if (t[2]) _.ops.pop(); | ||
_.trys.pop(); continue; | ||
} | ||
op = body.call(thisArg, _); | ||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } | ||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; | ||
} | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -10,6 +45,24 @@ var MessageBuilder_1 = require("./MessageBuilder"); | ||
Notifier.prototype.notifyUser = function (user, message) { | ||
this.bridges.getMessageBridge().notifyUser(user, message, this.appId); | ||
return __awaiter(this, void 0, void 0, function () { | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, this.bridges.getMessageBridge().notifyUser(user, message, this.appId)]; | ||
case 1: | ||
_a.sent(); | ||
return [2 /*return*/]; | ||
} | ||
}); | ||
}); | ||
}; | ||
Notifier.prototype.notifyRoom = function (room, message) { | ||
this.bridges.getMessageBridge().notifyRoom(room, message, this.appId); | ||
return __awaiter(this, void 0, void 0, function () { | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, this.bridges.getMessageBridge().notifyRoom(room, message, this.appId)]; | ||
case 1: | ||
_a.sent(); | ||
return [2 /*return*/]; | ||
} | ||
}); | ||
}); | ||
}; | ||
@@ -16,0 +69,0 @@ Notifier.prototype.getMessageBuilder = function () { |
@@ -8,9 +8,9 @@ import { IPersistence } from '@rocket.chat/apps-ts-definition/accessors'; | ||
constructor(persistBridge: IPersistenceBridge, appId: string); | ||
create(data: any): string; | ||
createWithAssociation(data: object, association: RocketChatAssociationRecord): string; | ||
createWithAssociations(data: object, associations: Array<RocketChatAssociationRecord>): string; | ||
update(id: string, data: object, upsert?: boolean): string; | ||
remove(id: string): object; | ||
removeByAssociation(association: RocketChatAssociationRecord): Array<object>; | ||
removeByAssociations(associations: Array<RocketChatAssociationRecord>): Array<object>; | ||
create(data: any): Promise<string>; | ||
createWithAssociation(data: object, association: RocketChatAssociationRecord): Promise<string>; | ||
createWithAssociations(data: object, associations: Array<RocketChatAssociationRecord>): Promise<string>; | ||
update(id: string, data: object, upsert?: boolean): Promise<string>; | ||
remove(id: string): Promise<object>; | ||
removeByAssociation(association: RocketChatAssociationRecord): Promise<Array<object>>; | ||
removeByAssociations(associations: Array<RocketChatAssociationRecord>): Promise<Array<object>>; | ||
} |
@@ -8,5 +8,5 @@ import { IPersistenceRead } from '@rocket.chat/apps-ts-definition/accessors'; | ||
constructor(persistBridge: IPersistenceBridge, appId: string); | ||
read(id: string): object; | ||
readByAssociation(association: RocketChatAssociationRecord): Array<object>; | ||
readByAssociations(associations: Array<RocketChatAssociationRecord>): Array<object>; | ||
read(id: string): Promise<object>; | ||
readByAssociation(association: RocketChatAssociationRecord): Promise<Array<object>>; | ||
readByAssociations(associations: Array<RocketChatAssociationRecord>): Promise<Array<object>>; | ||
} |
@@ -10,6 +10,6 @@ import { IIterator, IRoomRead } from '@rocket.chat/apps-ts-definition/accessors'; | ||
constructor(roomBridge: IRoomBridge, appId: string); | ||
getById(id: string): IRoom; | ||
getByName(name: string): IRoom; | ||
getMessages(roomId: string): IIterator<IMessage>; | ||
getMembers(roomId: string): IIterator<IUser>; | ||
getById(id: string): Promise<IRoom>; | ||
getByName(name: string): Promise<IRoom>; | ||
getMessages(roomId: string): Promise<IIterator<IMessage>>; | ||
getMembers(roomId: string): Promise<IIterator<IUser>>; | ||
} |
import { IServerSettingBridge } from '../bridges/IServerSettingBridge'; | ||
import { IServerSettingRead } from '@rocket.chat/apps-ts-definition/accessors'; | ||
import { IIterator, IServerSettingRead } from '@rocket.chat/apps-ts-definition/accessors'; | ||
import { ISetting } from '@rocket.chat/apps-ts-definition/settings'; | ||
@@ -8,6 +8,6 @@ export declare class ServerSettingRead implements IServerSettingRead { | ||
constructor(settingBridge: IServerSettingBridge, appId: string); | ||
getOneById(id: string): ISetting; | ||
getValueById(id: string): any; | ||
getAll(): Array<ISetting>; | ||
isReadableById(id: string): boolean; | ||
getOneById(id: string): Promise<ISetting>; | ||
getValueById(id: string): Promise<any>; | ||
getAll(): Promise<IIterator<ISetting>>; | ||
isReadableById(id: string): Promise<boolean>; | ||
} |
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
var __generator = (this && this.__generator) || function (thisArg, body) { | ||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; | ||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; | ||
function verb(n) { return function (v) { return step([n, v]); }; } | ||
function step(op) { | ||
if (f) throw new TypeError("Generator is already executing."); | ||
while (_) try { | ||
if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t; | ||
if (y = 0, t) op = [0, t.value]; | ||
switch (op[0]) { | ||
case 0: case 1: t = op; break; | ||
case 4: _.label++; return { value: op[1], done: false }; | ||
case 5: _.label++; y = op[1]; op = [0]; continue; | ||
case 7: op = _.ops.pop(); _.trys.pop(); continue; | ||
default: | ||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } | ||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } | ||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } | ||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } | ||
if (t[2]) _.ops.pop(); | ||
_.trys.pop(); continue; | ||
} | ||
op = body.call(thisArg, _); | ||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } | ||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; | ||
} | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -12,10 +47,20 @@ var ServerSettingRead = (function () { | ||
ServerSettingRead.prototype.getValueById = function (id) { | ||
var set = this.settingBridge.getOneById(id, this.appId); | ||
if (typeof set === 'undefined') { | ||
throw new Error("No Server Setting found, or it is unaccessible, by the id of \"" + id + "\"."); | ||
} | ||
return set.value || set.packageValue; | ||
return __awaiter(this, void 0, void 0, function () { | ||
var set; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, this.settingBridge.getOneById(id, this.appId)]; | ||
case 1: | ||
set = _a.sent(); | ||
if (typeof set === 'undefined') { | ||
throw new Error("No Server Setting found, or it is unaccessible, by the id of \"" + id + "\"."); | ||
} | ||
return [2 /*return*/, set.value || set.packageValue]; | ||
} | ||
}); | ||
}); | ||
}; | ||
ServerSettingRead.prototype.getAll = function () { | ||
return this.settingBridge.getAll(this.appId); | ||
throw new Error('Method not implemented.'); | ||
// return this.settingBridge.getAll(this.appId); | ||
}; | ||
@@ -22,0 +67,0 @@ ServerSettingRead.prototype.isReadableById = function (id) { |
@@ -8,5 +8,5 @@ import { IServerSettingBridge } from '../bridges/IServerSettingBridge'; | ||
constructor(bridge: IServerSettingBridge, appId: string); | ||
hideGroup(name: string): void; | ||
hideSetting(id: string): void; | ||
modifySetting(setting: ISetting): void; | ||
hideGroup(name: string): Promise<void>; | ||
hideSetting(id: string): Promise<void>; | ||
modifySetting(setting: ISetting): Promise<void>; | ||
} |
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
var __generator = (this && this.__generator) || function (thisArg, body) { | ||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; | ||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; | ||
function verb(n) { return function (v) { return step([n, v]); }; } | ||
function step(op) { | ||
if (f) throw new TypeError("Generator is already executing."); | ||
while (_) try { | ||
if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t; | ||
if (y = 0, t) op = [0, t.value]; | ||
switch (op[0]) { | ||
case 0: case 1: t = op; break; | ||
case 4: _.label++; return { value: op[1], done: false }; | ||
case 5: _.label++; y = op[1]; op = [0]; continue; | ||
case 7: op = _.ops.pop(); _.trys.pop(); continue; | ||
default: | ||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } | ||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } | ||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } | ||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } | ||
if (t[2]) _.ops.pop(); | ||
_.trys.pop(); continue; | ||
} | ||
op = body.call(thisArg, _); | ||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } | ||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; | ||
} | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -9,9 +44,36 @@ var ServerSettingsModify = (function () { | ||
ServerSettingsModify.prototype.hideGroup = function (name) { | ||
this.bridge.hideGroup(name, this.appId); | ||
return __awaiter(this, void 0, void 0, function () { | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, this.bridge.hideGroup(name, this.appId)]; | ||
case 1: | ||
_a.sent(); | ||
return [2 /*return*/]; | ||
} | ||
}); | ||
}); | ||
}; | ||
ServerSettingsModify.prototype.hideSetting = function (id) { | ||
this.bridge.hideSetting(id, this.appId); | ||
return __awaiter(this, void 0, void 0, function () { | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, this.bridge.hideSetting(id, this.appId)]; | ||
case 1: | ||
_a.sent(); | ||
return [2 /*return*/]; | ||
} | ||
}); | ||
}); | ||
}; | ||
ServerSettingsModify.prototype.modifySetting = function (setting) { | ||
this.bridge.updateOne(setting, this.appId); | ||
return __awaiter(this, void 0, void 0, function () { | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, this.bridge.updateOne(setting, this.appId)]; | ||
case 1: | ||
_a.sent(); | ||
return [2 /*return*/]; | ||
} | ||
}); | ||
}); | ||
}; | ||
@@ -18,0 +80,0 @@ return ServerSettingsModify; |
@@ -7,4 +7,4 @@ import { ProxiedApp } from '../ProxiedApp'; | ||
constructor(app: ProxiedApp); | ||
getById(id: string): ISetting; | ||
getValueById(id: string): any; | ||
getById(id: string): Promise<ISetting>; | ||
getValueById(id: string): Promise<any>; | ||
} |
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
var __generator = (this && this.__generator) || function (thisArg, body) { | ||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; | ||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; | ||
function verb(n) { return function (v) { return step([n, v]); }; } | ||
function step(op) { | ||
if (f) throw new TypeError("Generator is already executing."); | ||
while (_) try { | ||
if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t; | ||
if (y = 0, t) op = [0, t.value]; | ||
switch (op[0]) { | ||
case 0: case 1: t = op; break; | ||
case 4: _.label++; return { value: op[1], done: false }; | ||
case 5: _.label++; y = op[1]; op = [0]; continue; | ||
case 7: op = _.ops.pop(); _.trys.pop(); continue; | ||
default: | ||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } | ||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } | ||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } | ||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } | ||
if (t[2]) _.ops.pop(); | ||
_.trys.pop(); continue; | ||
} | ||
op = body.call(thisArg, _); | ||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } | ||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; | ||
} | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -8,10 +43,19 @@ var SettingRead = (function () { | ||
SettingRead.prototype.getById = function (id) { | ||
return this.app.getStorageItem().settings[id]; | ||
return Promise.resolve(this.app.getStorageItem().settings[id]); | ||
}; | ||
SettingRead.prototype.getValueById = function (id) { | ||
var set = this.getById(id); | ||
if (typeof set === 'undefined') { | ||
throw new Error("Setting \"" + id + "\" does not exist."); | ||
} | ||
return set.value || set.packageValue; | ||
return __awaiter(this, void 0, void 0, function () { | ||
var set; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, this.getById(id)]; | ||
case 1: | ||
set = _a.sent(); | ||
if (typeof set === 'undefined') { | ||
throw new Error("Setting \"" + id + "\" does not exist."); | ||
} | ||
return [2 /*return*/, set.value || set.packageValue]; | ||
} | ||
}); | ||
}); | ||
}; | ||
@@ -18,0 +62,0 @@ return SettingRead; |
@@ -7,3 +7,3 @@ import { ProxiedApp } from '../ProxiedApp'; | ||
constructor(app: ProxiedApp); | ||
provideSetting(setting: ISetting): void; | ||
provideSetting(setting: ISetting): Promise<void>; | ||
} |
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
var __generator = (this && this.__generator) || function (thisArg, body) { | ||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; | ||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; | ||
function verb(n) { return function (v) { return step([n, v]); }; } | ||
function step(op) { | ||
if (f) throw new TypeError("Generator is already executing."); | ||
while (_) try { | ||
if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t; | ||
if (y = 0, t) op = [0, t.value]; | ||
switch (op[0]) { | ||
case 0: case 1: t = op; break; | ||
case 4: _.label++; return { value: op[1], done: false }; | ||
case 5: _.label++; y = op[1]; op = [0]; continue; | ||
case 7: op = _.ops.pop(); _.trys.pop(); continue; | ||
default: | ||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } | ||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } | ||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } | ||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } | ||
if (t[2]) _.ops.pop(); | ||
_.trys.pop(); continue; | ||
} | ||
op = body.call(thisArg, _); | ||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } | ||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; | ||
} | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -8,13 +43,24 @@ var SettingsExtend = (function () { | ||
SettingsExtend.prototype.provideSetting = function (setting) { | ||
if (this.app.getStorageItem().settings[setting.id]) { | ||
var old = this.app.getStorageItem().settings[setting.id]; | ||
setting.createdAt = old.createdAt; | ||
setting.updatedAt = new Date(); | ||
setting.value = old.value; | ||
this.app.getStorageItem().settings[setting.id] = setting; | ||
return; | ||
} | ||
setting.createdAt = new Date(); | ||
setting.updatedAt = new Date(); | ||
this.app.getStorageItem().settings[setting.id] = setting; | ||
return __awaiter(this, void 0, void 0, function () { | ||
var old; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
if (!this.app.getStorageItem().settings[setting.id]) return [3 /*break*/, 2]; | ||
return [4 /*yield*/, Promise.resolve(this.app.getStorageItem().settings[setting.id])]; | ||
case 1: | ||
old = _a.sent(); | ||
setting.createdAt = old.createdAt; | ||
setting.updatedAt = new Date(); | ||
setting.value = old.value; | ||
this.app.getStorageItem().settings[setting.id] = setting; | ||
return [2 /*return*/]; | ||
case 2: | ||
setting.createdAt = new Date(); | ||
setting.updatedAt = new Date(); | ||
this.app.getStorageItem().settings[setting.id] = setting; | ||
return [2 /*return*/]; | ||
} | ||
}); | ||
}); | ||
}; | ||
@@ -21,0 +67,0 @@ return SettingsExtend; |
@@ -8,3 +8,3 @@ import { AppSlashCommandManager } from '../managers/AppSlashCommandManager'; | ||
constructor(manager: AppSlashCommandManager, appId: string); | ||
provideSlashCommand(slashCommand: ISlashCommand): void; | ||
provideSlashCommand(slashCommand: ISlashCommand): Promise<void>; | ||
} |
@@ -9,3 +9,3 @@ "use strict"; | ||
SlashCommandsExtend.prototype.provideSlashCommand = function (slashCommand) { | ||
this.manager.addCommand(this.appId, slashCommand); | ||
return Promise.resolve(this.manager.addCommand(this.appId, slashCommand)); | ||
}; | ||
@@ -12,0 +12,0 @@ return SlashCommandsExtend; |
@@ -8,5 +8,5 @@ import { AppSlashCommandManager } from '../managers'; | ||
constructor(manager: AppSlashCommandManager, appId: string); | ||
modifySlashCommand(slashCommand: ISlashCommand): void; | ||
disableSlashCommand(command: string): void; | ||
enableSlashCommand(command: string): void; | ||
modifySlashCommand(slashCommand: ISlashCommand): Promise<void>; | ||
disableSlashCommand(command: string): Promise<void>; | ||
enableSlashCommand(command: string): Promise<void>; | ||
} |
@@ -9,9 +9,9 @@ "use strict"; | ||
SlashCommandsModify.prototype.modifySlashCommand = function (slashCommand) { | ||
this.manager.modifyCommand(this.appId, slashCommand); | ||
return Promise.resolve(this.manager.modifyCommand(this.appId, slashCommand)); | ||
}; | ||
SlashCommandsModify.prototype.disableSlashCommand = function (command) { | ||
this.manager.disableCommand(this.appId, command); | ||
return Promise.resolve(this.manager.disableCommand(this.appId, command)); | ||
}; | ||
SlashCommandsModify.prototype.enableSlashCommand = function (command) { | ||
this.manager.enableCommand(this.appId, command); | ||
return Promise.resolve(this.manager.enableCommand(this.appId, command)); | ||
}; | ||
@@ -18,0 +18,0 @@ return SlashCommandsModify; |
@@ -8,4 +8,4 @@ import { IUserRead } from '@rocket.chat/apps-ts-definition/accessors'; | ||
constructor(userBridge: IUserBridge, appId: string); | ||
getById(id: string): IUser; | ||
getByUsername(username: string): IUser; | ||
getById(id: string): Promise<IUser>; | ||
getByUsername(username: string): Promise<IUser>; | ||
} |
@@ -139,9 +139,22 @@ "use strict"; | ||
// Let's initialize them | ||
this.apps.forEach(function (rl) { return _this.initializeApp(items.get(rl.getID()), rl, true); }); | ||
this.apps.forEach(function (rl) { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, this.initializeApp(items.get(rl.getID()), rl, true)]; | ||
case 1: return [2 /*return*/, _a.sent()]; | ||
} | ||
}); }); }); | ||
// Now let's enable the apps which were once enabled | ||
this.apps.forEach(function (rl) { | ||
if (AppStatus_1.AppStatusUtils.isEnabled(rl.getPreviousStatus())) { | ||
_this.enableApp(items.get(rl.getID()), rl, true, rl.getPreviousStatus() === AppStatus_1.AppStatus.MANUALLY_ENABLED); | ||
} | ||
}); | ||
this.apps.forEach(function (rl) { return __awaiter(_this, void 0, void 0, function () { | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
if (!AppStatus_1.AppStatusUtils.isEnabled(rl.getPreviousStatus())) return [3 /*break*/, 2]; | ||
return [4 /*yield*/, this.enableApp(items.get(rl.getID()), rl, true, rl.getPreviousStatus() === AppStatus_1.AppStatus.MANUALLY_ENABLED)]; | ||
case 1: | ||
_a.sent(); | ||
_a.label = 2; | ||
case 2: return [2 /*return*/]; | ||
} | ||
}); | ||
}); }); | ||
this.isLoaded = true; | ||
@@ -214,7 +227,9 @@ return [2 /*return*/, Array.from(this.apps.values())]; | ||
} | ||
isSetup = this.runStartUpProcess(storageItem, rl, true); | ||
return [4 /*yield*/, this.runStartUpProcess(storageItem, rl, true)]; | ||
case 2: | ||
isSetup = _a.sent(); | ||
if (isSetup) { | ||
storageItem.status = rl.getStatus(); | ||
// This is async, but we don't care since it only updates in the database | ||
// and it should not mutate any properties we care about | ||
storageItem.status = rl.getStatus(); | ||
this.storage.update(storageItem); | ||
@@ -230,3 +245,3 @@ } | ||
return __awaiter(this, void 0, void 0, function () { | ||
var rl, storageItem; | ||
var rl, storageItem, e_1; | ||
return __generator(this, function (_a) { | ||
@@ -248,8 +263,14 @@ switch (_a.label) { | ||
} | ||
try { | ||
rl.call(metadata_1.AppMethod.ONDISABLE, this.accessorManager.getConfigurationModify(storageItem.id)); | ||
} | ||
catch (e) { | ||
console.warn('Error while disabling:', e); | ||
} | ||
_a.label = 2; | ||
case 2: | ||
_a.trys.push([2, 4, , 5]); | ||
return [4 /*yield*/, rl.call(metadata_1.AppMethod.ONDISABLE, this.accessorManager.getConfigurationModify(storageItem.id))]; | ||
case 3: | ||
_a.sent(); | ||
return [3 /*break*/, 5]; | ||
case 4: | ||
e_1 = _a.sent(); | ||
console.warn('Error while disabling:', e_1); | ||
return [3 /*break*/, 5]; | ||
case 5: | ||
this.listenerManager.unregisterListeners(rl); | ||
@@ -303,12 +324,14 @@ this.commandManager.unregisterCommands(storageItem.id); | ||
} | ||
// Should enable === true, then we go through the entire start up process | ||
// Otherwise, we only initialize it. | ||
if (enable) { | ||
// Start up the app | ||
this.runStartUpProcess(created, app, false); | ||
} | ||
else { | ||
this.initializeApp(created, app, true); | ||
} | ||
return [2 /*return*/, app]; | ||
if (!enable) return [3 /*break*/, 4]; | ||
// Start up the app | ||
return [4 /*yield*/, this.runStartUpProcess(created, app, false)]; | ||
case 3: | ||
// Start up the app | ||
_a.sent(); | ||
return [3 /*break*/, 6]; | ||
case 4: return [4 /*yield*/, this.initializeApp(created, app, true)]; | ||
case 5: | ||
_a.sent(); | ||
_a.label = 6; | ||
case 6: return [2 /*return*/, app]; | ||
} | ||
@@ -330,7 +353,8 @@ }); | ||
_a.label = 2; | ||
case 2: | ||
this.bridges.getPersistenceBridge().purge(app.getID()); | ||
return [4 /*yield*/, this.storage.remove(app.getID())]; | ||
case 2: return [4 /*yield*/, this.bridges.getPersistenceBridge().purge(app.getID())]; | ||
case 3: | ||
_a.sent(); | ||
return [4 /*yield*/, this.storage.remove(app.getID())]; | ||
case 4: | ||
_a.sent(); | ||
// Let everyone know that the App has been removed | ||
@@ -351,3 +375,3 @@ try { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var result, old, e_1, stored, app; | ||
var result, old, e_2, stored, app; | ||
return __generator(this, function (_a) { | ||
@@ -372,3 +396,3 @@ switch (_a.label) { | ||
case 5: | ||
e_1 = _a.sent(); | ||
e_2 = _a.sent(); | ||
return [3 /*break*/, 6]; | ||
@@ -392,3 +416,6 @@ case 6: return [4 /*yield*/, this.storage.update({ | ||
// Start up the app | ||
this.runStartUpProcess(stored, app, false); | ||
return [4 /*yield*/, this.runStartUpProcess(stored, app, false)]; | ||
case 8: | ||
// Start up the app | ||
_a.sent(); | ||
// Let everyone know that the App has been updated | ||
@@ -473,3 +500,5 @@ try { | ||
rl = this.apps.get(item.id); | ||
this.initializeApp(item, rl, false); | ||
return [4 /*yield*/, this.initializeApp(item, rl, false)]; | ||
case 2: | ||
_a.sent(); | ||
if (AppStatus_1.AppStatusUtils.isEnabled(rl.getPreviousStatus())) { | ||
@@ -484,71 +513,104 @@ this.enableApp(item, rl, false, rl.getPreviousStatus() === AppStatus_1.AppStatus.MANUALLY_ENABLED); | ||
AppManager.prototype.runStartUpProcess = function (storageItem, app, isManual) { | ||
if (app.getStatus() !== AppStatus_1.AppStatus.INITIALIZED) { | ||
var isInitialized = this.initializeApp(storageItem, app, true); | ||
if (!isInitialized) { | ||
return false; | ||
} | ||
} | ||
var isEnabled = this.enableApp(storageItem, app, true, isManual); | ||
if (!isEnabled) { | ||
return false; | ||
} | ||
// TODO: Register all of the listeners | ||
return true; | ||
return __awaiter(this, void 0, void 0, function () { | ||
var isInitialized, isEnabled; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
if (app.getStatus() !== AppStatus_1.AppStatus.INITIALIZED) { | ||
isInitialized = this.initializeApp(storageItem, app, true); | ||
if (!isInitialized) { | ||
return [2 /*return*/, false]; | ||
} | ||
} | ||
return [4 /*yield*/, this.enableApp(storageItem, app, true, isManual)]; | ||
case 1: | ||
isEnabled = _a.sent(); | ||
if (!isEnabled) { | ||
return [2 /*return*/, false]; | ||
} | ||
return [2 /*return*/, true]; | ||
} | ||
}); | ||
}); | ||
}; | ||
AppManager.prototype.initializeApp = function (storageItem, app, saveToDb) { | ||
if (saveToDb === void 0) { saveToDb = true; } | ||
var result; | ||
var configExtend = this.getAccessorManager().getConfigurationExtend(storageItem.id); | ||
var envRead = this.getAccessorManager().getEnvironmentRead(storageItem.id); | ||
try { | ||
app.call(metadata_1.AppMethod.INITIALIZE, configExtend, envRead); | ||
result = true; | ||
app.setStatus(AppStatus_1.AppStatus.INITIALIZED); | ||
} | ||
catch (e) { | ||
if (e.name === 'NotEnoughMethodArgumentsError') { | ||
console.warn('Please report the following error:'); | ||
} | ||
console.error(e); | ||
this.commandManager.unregisterCommands(storageItem.id); | ||
result = false; | ||
app.setStatus(AppStatus_1.AppStatus.ERROR_DISABLED); | ||
} | ||
if (saveToDb) { | ||
// This is async, but we don't care since it only updates in the database | ||
// and it should not mutate any properties we care about | ||
storageItem.status = app.getStatus(); | ||
this.storage.update(storageItem); | ||
} | ||
return result; | ||
return __awaiter(this, void 0, void 0, function () { | ||
var result, configExtend, envRead, e_3; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
configExtend = this.getAccessorManager().getConfigurationExtend(storageItem.id); | ||
envRead = this.getAccessorManager().getEnvironmentRead(storageItem.id); | ||
_a.label = 1; | ||
case 1: | ||
_a.trys.push([1, 3, , 4]); | ||
return [4 /*yield*/, app.call(metadata_1.AppMethod.INITIALIZE, configExtend, envRead)]; | ||
case 2: | ||
_a.sent(); | ||
result = true; | ||
app.setStatus(AppStatus_1.AppStatus.INITIALIZED); | ||
return [3 /*break*/, 4]; | ||
case 3: | ||
e_3 = _a.sent(); | ||
if (e_3.name === 'NotEnoughMethodArgumentsError') { | ||
console.warn('Please report the following error:'); | ||
} | ||
console.error(e_3); | ||
this.commandManager.unregisterCommands(storageItem.id); | ||
result = false; | ||
app.setStatus(AppStatus_1.AppStatus.ERROR_DISABLED); | ||
return [3 /*break*/, 4]; | ||
case 4: | ||
if (saveToDb) { | ||
// This is async, but we don't care since it only updates in the database | ||
// and it should not mutate any properties we care about | ||
storageItem.status = app.getStatus(); | ||
this.storage.update(storageItem); | ||
} | ||
return [2 /*return*/, result]; | ||
} | ||
}); | ||
}); | ||
}; | ||
AppManager.prototype.enableApp = function (storageItem, app, saveToDb, isManual) { | ||
if (saveToDb === void 0) { saveToDb = true; } | ||
var enable; | ||
try { | ||
enable = app.call(metadata_1.AppMethod.ONENABLE, this.getAccessorManager().getEnvironmentRead(storageItem.id), this.getAccessorManager().getConfigurationModify(storageItem.id)); | ||
app.setStatus(isManual ? AppStatus_1.AppStatus.MANUALLY_ENABLED : AppStatus_1.AppStatus.AUTO_ENABLED); | ||
} | ||
catch (e) { | ||
enable = false; | ||
if (e.name === 'NotEnoughMethodArgumentsError') { | ||
console.warn('Please report the following error:'); | ||
} | ||
console.error(e); | ||
app.setStatus(AppStatus_1.AppStatus.ERROR_DISABLED); | ||
} | ||
if (enable) { | ||
this.commandManager.registerCommands(app.getID()); | ||
this.listenerManager.registerListeners(app); | ||
} | ||
else { | ||
this.commandManager.unregisterCommands(app.getID()); | ||
} | ||
if (saveToDb) { | ||
// This is async, but we don't care since it only updates in the database | ||
// and it should not mutate any properties we care about | ||
storageItem.status = app.getStatus(); | ||
this.storage.update(storageItem); | ||
} | ||
return enable; | ||
return __awaiter(this, void 0, void 0, function () { | ||
var enable, e_4; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
_a.trys.push([0, 2, , 3]); | ||
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]; | ||
case 2: | ||
e_4 = _a.sent(); | ||
enable = false; | ||
if (e_4.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: | ||
if (enable) { | ||
this.commandManager.registerCommands(app.getID()); | ||
this.listenerManager.registerListeners(app); | ||
} | ||
else { | ||
this.commandManager.unregisterCommands(app.getID()); | ||
} | ||
if (saveToDb) { | ||
storageItem.status = app.getStatus(); | ||
// This is async, but we don't care since it only updates in the database | ||
// and it should not mutate any properties we care about | ||
this.storage.update(storageItem); | ||
} | ||
return [2 /*return*/, enable]; | ||
} | ||
}); | ||
}); | ||
}; | ||
@@ -555,0 +617,0 @@ AppManager.ENV_VAR_NAME_FOR_ENABLING = 'USE_UNRELEASED_ROCKETAPPS_FRAMEWORK'; |
export interface IEnvironmentalVariableBridge { | ||
getValueByName(envVarName: string, appId: string): string; | ||
isReadable(envVarName: string, appId: string): boolean; | ||
isSet(envVarName: string, appId: string): boolean; | ||
getValueByName(envVarName: string, appId: string): Promise<string>; | ||
isReadable(envVarName: string, appId: string): Promise<boolean>; | ||
isSet(envVarName: string, appId: string): Promise<boolean>; | ||
} |
import { IHttpRequest, IHttpResponse, RequestMethod } from '@rocket.chat/apps-ts-definition/accessors'; | ||
export interface IHttpBridge { | ||
call(info: IHttpBridgeRequestInfo): IHttpResponse; | ||
call(info: IHttpBridgeRequestInfo): Promise<IHttpResponse>; | ||
} | ||
@@ -5,0 +5,0 @@ export interface IHttpBridgeRequestInfo { |
@@ -5,7 +5,7 @@ import { IMessage } from '@rocket.chat/apps-ts-definition/messages'; | ||
export interface IMessageBridge { | ||
create(message: IMessage, appId: string): string; | ||
getById(messageId: string, appId: string): IMessage; | ||
update(message: IMessage, appId: string): void; | ||
notifyUser(user: IUser, message: IMessage, appId: string): void; | ||
notifyRoom(room: IRoom, message: IMessage, appId: string): void; | ||
create(message: IMessage, appId: string): Promise<string>; | ||
getById(messageId: string, appId: string): Promise<IMessage>; | ||
update(message: IMessage, appId: string): Promise<void>; | ||
notifyUser(user: IUser, message: IMessage, appId: string): Promise<void>; | ||
notifyRoom(room: IRoom, message: IMessage, appId: string): Promise<void>; | ||
} |
@@ -8,3 +8,3 @@ import { RocketChatAssociationRecord } from '@rocket.chat/apps-ts-definition/metadata'; | ||
*/ | ||
purge(appId: string): void; | ||
purge(appId: string): Promise<void>; | ||
/** | ||
@@ -17,3 +17,3 @@ * Creates a new persistant record with the provided data attached. | ||
*/ | ||
create(data: any, appId: string): string; | ||
create(data: any, appId: string): Promise<string>; | ||
/** | ||
@@ -28,3 +28,3 @@ * Creates a new record in the App's persistent storage with the data being | ||
*/ | ||
createWithAssociations(data: object, associations: Array<RocketChatAssociationRecord>, appId: string): string; | ||
createWithAssociations(data: object, associations: Array<RocketChatAssociationRecord>, appId: string): Promise<string>; | ||
/** | ||
@@ -37,3 +37,3 @@ * Retrieves from the persistent storage the record by the id provided. | ||
*/ | ||
readById(id: string, appId: string): object; | ||
readById(id: string, appId: string): Promise<object>; | ||
/** | ||
@@ -46,3 +46,3 @@ * Retrieves the data which is associated with the provided records. | ||
*/ | ||
readByAssociations(associations: Array<RocketChatAssociationRecord>, appId: string): Array<object>; | ||
readByAssociations(associations: Array<RocketChatAssociationRecord>, appId: string): Promise<Array<object>>; | ||
/** | ||
@@ -55,3 +55,3 @@ * Removes the record which matches the provided id. | ||
*/ | ||
remove(id: string, appId: string): object; | ||
remove(id: string, appId: string): Promise<object>; | ||
/** | ||
@@ -64,3 +64,3 @@ * Removes any data which has been associated with the provided records. | ||
*/ | ||
removeByAssociations(associations: Array<RocketChatAssociationRecord>, appId: string): Array<object>; | ||
removeByAssociations(associations: Array<RocketChatAssociationRecord>, appId: string): Promise<Array<object>>; | ||
/** | ||
@@ -75,3 +75,3 @@ * Updates the record in the database, with the option of creating a new one if it doesn't exist. | ||
*/ | ||
update(id: string, data: object, upsert: boolean, appId: string): string; | ||
update(id: string, data: object, upsert: boolean, appId: string): Promise<string>; | ||
} |
import { IRoom } from '@rocket.chat/apps-ts-definition/rooms'; | ||
export interface IRoomBridge { | ||
create(room: IRoom, appId: string): string; | ||
getById(roomId: string, appId: string): IRoom; | ||
getByName(roomName: string, appId: string): IRoom; | ||
update(room: IRoom, appId: string): void; | ||
create(room: IRoom, appId: string): Promise<string>; | ||
getById(roomId: string, appId: string): Promise<IRoom>; | ||
getByName(roomName: string, appId: string): Promise<IRoom>; | ||
update(room: IRoom, appId: string): Promise<void>; | ||
} |
import { ISetting } from '@rocket.chat/apps-ts-definition/settings'; | ||
export interface IServerSettingBridge { | ||
getAll(appId: string): Array<ISetting>; | ||
getOneById(id: string, appId: string): ISetting; | ||
hideGroup(name: string, appId: string): void; | ||
hideSetting(id: string, appId: string): void; | ||
isReadableById(id: string, appId: string): boolean; | ||
updateOne(setting: ISetting, appId: string): void; | ||
getAll(appId: string): Promise<Array<ISetting>>; | ||
getOneById(id: string, appId: string): Promise<ISetting>; | ||
hideGroup(name: string, appId: string): Promise<void>; | ||
hideSetting(id: string, appId: string): Promise<void>; | ||
isReadableById(id: string, appId: string): Promise<boolean>; | ||
updateOne(setting: ISetting, appId: string): Promise<void>; | ||
} |
import { IUser } from '@rocket.chat/apps-ts-definition/users'; | ||
export interface IUserBridge { | ||
getById(id: string, appId: string): IUser; | ||
getByUsername(username: string, appId: string): IUser; | ||
getById(id: string, appId: string): Promise<IUser>; | ||
getByUsername(username: string, appId: string): Promise<IUser>; | ||
} |
@@ -15,3 +15,3 @@ import { AppManager } from '../AppManager'; | ||
getListeners(int: AppInterface): Array<ProxiedApp>; | ||
executeListener(int: AppInterface, data: IMessage | IRoom | IUser): void | boolean | IMessage | IRoom | IUser; | ||
executeListener(int: AppInterface, data: IMessage | IRoom | IUser): Promise<void | boolean | IMessage | IRoom | IUser>; | ||
private executePreMessageSentPrevent(data); | ||
@@ -18,0 +18,0 @@ private executePreMessageSentExtend(data); |
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
var __generator = (this && this.__generator) || function (thisArg, body) { | ||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; | ||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; | ||
function verb(n) { return function (v) { return step([n, v]); }; } | ||
function step(op) { | ||
if (f) throw new TypeError("Generator is already executing."); | ||
while (_) try { | ||
if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t; | ||
if (y = 0, t) op = [0, t.value]; | ||
switch (op[0]) { | ||
case 0: case 1: t = op; break; | ||
case 4: _.label++; return { value: op[1], done: false }; | ||
case 5: _.label++; y = op[1]; op = [0]; continue; | ||
case 7: op = _.ops.pop(); _.trys.pop(); continue; | ||
default: | ||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } | ||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } | ||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } | ||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } | ||
if (t[2]) _.ops.pop(); | ||
_.trys.pop(); continue; | ||
} | ||
op = body.call(thisArg, _); | ||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } | ||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; | ||
} | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -42,157 +77,308 @@ var accessors_1 = require("../accessors"); | ||
AppListenerManger.prototype.executeListener = function (int, data) { | ||
switch (int) { | ||
case compiler_1.AppInterface.IPreMessageSentPrevent: | ||
return this.executePreMessageSentPrevent(data); | ||
case compiler_1.AppInterface.IPreMessageSentExtend: | ||
return this.executePreMessageSentExtend(data); | ||
case compiler_1.AppInterface.IPreMessageSentModify: | ||
return this.executePreMessageSentModify(data); | ||
case compiler_1.AppInterface.IPostMessageSent: | ||
this.executePostMessageSent(data); | ||
return; | ||
case compiler_1.AppInterface.IPreRoomCreatePrevent: | ||
return this.executePreRoomCreatePrevent(data); | ||
case compiler_1.AppInterface.IPreRoomCreateExtend: | ||
return this.executePreRoomCreateExtend(data); | ||
case compiler_1.AppInterface.IPreRoomCreateModify: | ||
return this.executePreRoomCreateModify(data); | ||
case compiler_1.AppInterface.IPostRoomCreate: | ||
this.executePostRoomCreate(data); | ||
return; | ||
default: | ||
console.warn('Unimplemented (or invalid) AppInterface was just tried to execute.'); | ||
return; | ||
} | ||
return __awaiter(this, void 0, void 0, function () { | ||
return __generator(this, function (_a) { | ||
switch (int) { | ||
case compiler_1.AppInterface.IPreMessageSentPrevent: | ||
return [2 /*return*/, this.executePreMessageSentPrevent(data)]; | ||
case compiler_1.AppInterface.IPreMessageSentExtend: | ||
return [2 /*return*/, this.executePreMessageSentExtend(data)]; | ||
case compiler_1.AppInterface.IPreMessageSentModify: | ||
return [2 /*return*/, this.executePreMessageSentModify(data)]; | ||
case compiler_1.AppInterface.IPostMessageSent: | ||
this.executePostMessageSent(data); | ||
return [2 /*return*/]; | ||
case compiler_1.AppInterface.IPreRoomCreatePrevent: | ||
return [2 /*return*/, this.executePreRoomCreatePrevent(data)]; | ||
case compiler_1.AppInterface.IPreRoomCreateExtend: | ||
return [2 /*return*/, this.executePreRoomCreateExtend(data)]; | ||
case compiler_1.AppInterface.IPreRoomCreateModify: | ||
return [2 /*return*/, this.executePreRoomCreateModify(data)]; | ||
case compiler_1.AppInterface.IPostRoomCreate: | ||
this.executePostRoomCreate(data); | ||
return [2 /*return*/]; | ||
default: | ||
console.warn('Unimplemented (or invalid) AppInterface was just tried to execute.'); | ||
return [2 /*return*/]; | ||
} | ||
return [2 /*return*/]; | ||
}); | ||
}); | ||
}; | ||
AppListenerManger.prototype.executePreMessageSentPrevent = function (data) { | ||
var prevented = false; | ||
var cfMsg = Utilities_1.Utilities.deepCloneAndFreeze(data); | ||
for (var _i = 0, _a = this.listeners.get(compiler_1.AppInterface.IPreMessageSentPrevent); _i < _a.length; _i++) { | ||
var appId = _a[_i]; | ||
var app = this.manager.getOneById(appId); | ||
var continueOn = true; | ||
if (app.hasMethod(metadata_1.AppMethod.CHECKPREMESSAGESENTPREVENT)) { | ||
continueOn = app.call(metadata_1.AppMethod.CHECKPREMESSAGESENTPREVENT, cfMsg, this.am.getReader(appId), this.am.getHttp(appId)); | ||
} | ||
if (continueOn && app.hasMethod(metadata_1.AppMethod.EXECUTEPREMESSAGESENTPREVENT)) { | ||
prevented = app.call(metadata_1.AppMethod.EXECUTEPREMESSAGESENTPREVENT, cfMsg, this.am.getReader(appId), this.am.getHttp(appId), this.am.getPersistence(appId)); | ||
if (prevented) { | ||
return prevented; | ||
return __awaiter(this, void 0, void 0, function () { | ||
var prevented, cfMsg, _i, _a, appId, app, continueOn; | ||
return __generator(this, function (_b) { | ||
switch (_b.label) { | ||
case 0: | ||
prevented = false; | ||
cfMsg = Utilities_1.Utilities.deepCloneAndFreeze(data); | ||
_i = 0, _a = this.listeners.get(compiler_1.AppInterface.IPreMessageSentPrevent); | ||
_b.label = 1; | ||
case 1: | ||
if (!(_i < _a.length)) return [3 /*break*/, 6]; | ||
appId = _a[_i]; | ||
app = this.manager.getOneById(appId); | ||
continueOn = true; | ||
if (!app.hasMethod(metadata_1.AppMethod.CHECKPREMESSAGESENTPREVENT)) return [3 /*break*/, 3]; | ||
return [4 /*yield*/, app.call(metadata_1.AppMethod.CHECKPREMESSAGESENTPREVENT, cfMsg, this.am.getReader(appId), this.am.getHttp(appId))]; | ||
case 2: | ||
continueOn = (_b.sent()); | ||
_b.label = 3; | ||
case 3: | ||
if (!(continueOn && app.hasMethod(metadata_1.AppMethod.EXECUTEPREMESSAGESENTPREVENT))) return [3 /*break*/, 5]; | ||
return [4 /*yield*/, app.call(metadata_1.AppMethod.EXECUTEPREMESSAGESENTPREVENT, cfMsg, this.am.getReader(appId), this.am.getHttp(appId), this.am.getPersistence(appId))]; | ||
case 4: | ||
prevented = (_b.sent()); | ||
if (prevented) { | ||
return [2 /*return*/, prevented]; | ||
} | ||
_b.label = 5; | ||
case 5: | ||
_i++; | ||
return [3 /*break*/, 1]; | ||
case 6: return [2 /*return*/, prevented]; | ||
} | ||
} | ||
} | ||
return prevented; | ||
}); | ||
}); | ||
}; | ||
AppListenerManger.prototype.executePreMessageSentExtend = function (data) { | ||
var msg = data; | ||
var cfMsg = Utilities_1.Utilities.deepCloneAndFreeze(msg); | ||
for (var _i = 0, _a = this.listeners.get(compiler_1.AppInterface.IPreMessageSentExtend); _i < _a.length; _i++) { | ||
var appId = _a[_i]; | ||
var app = this.manager.getOneById(appId); | ||
var continueOn = true; | ||
if (app.hasMethod(metadata_1.AppMethod.CHECKPREMESSAGESENTEXTEND)) { | ||
continueOn = app.call(metadata_1.AppMethod.CHECKPREMESSAGESENTEXTEND, cfMsg, this.am.getReader(appId), this.am.getHttp(appId)); | ||
} | ||
if (continueOn && app.hasMethod(metadata_1.AppMethod.EXECUTEPREMESSAGESENTEXTEND)) { | ||
app.call(metadata_1.AppMethod.EXECUTEPREMESSAGESENTEXTEND, cfMsg, new accessors_1.MessageExtender(msg), // This mutates the passed in object | ||
this.am.getReader(appId), this.am.getHttp(appId), this.am.getPersistence(appId)); | ||
} | ||
} | ||
return msg; | ||
return __awaiter(this, void 0, void 0, function () { | ||
var msg, cfMsg, _i, _a, appId, app, continueOn; | ||
return __generator(this, function (_b) { | ||
switch (_b.label) { | ||
case 0: | ||
msg = data; | ||
cfMsg = Utilities_1.Utilities.deepCloneAndFreeze(msg); | ||
_i = 0, _a = this.listeners.get(compiler_1.AppInterface.IPreMessageSentExtend); | ||
_b.label = 1; | ||
case 1: | ||
if (!(_i < _a.length)) return [3 /*break*/, 6]; | ||
appId = _a[_i]; | ||
app = this.manager.getOneById(appId); | ||
continueOn = true; | ||
if (!app.hasMethod(metadata_1.AppMethod.CHECKPREMESSAGESENTEXTEND)) return [3 /*break*/, 3]; | ||
return [4 /*yield*/, app.call(metadata_1.AppMethod.CHECKPREMESSAGESENTEXTEND, cfMsg, this.am.getReader(appId), this.am.getHttp(appId))]; | ||
case 2: | ||
continueOn = (_b.sent()); | ||
_b.label = 3; | ||
case 3: | ||
if (!(continueOn && app.hasMethod(metadata_1.AppMethod.EXECUTEPREMESSAGESENTEXTEND))) return [3 /*break*/, 5]; | ||
return [4 /*yield*/, app.call(metadata_1.AppMethod.EXECUTEPREMESSAGESENTEXTEND, cfMsg, new accessors_1.MessageExtender(msg), // This mutates the passed in object | ||
this.am.getReader(appId), this.am.getHttp(appId), this.am.getPersistence(appId))]; | ||
case 4: | ||
_b.sent(); | ||
_b.label = 5; | ||
case 5: | ||
_i++; | ||
return [3 /*break*/, 1]; | ||
case 6: return [2 /*return*/, msg]; | ||
} | ||
}); | ||
}); | ||
}; | ||
AppListenerManger.prototype.executePreMessageSentModify = function (data) { | ||
var msg = data; | ||
var cfMsg = Utilities_1.Utilities.deepCloneAndFreeze(msg); | ||
for (var _i = 0, _a = this.listeners.get(compiler_1.AppInterface.IPreMessageSentModify); _i < _a.length; _i++) { | ||
var appId = _a[_i]; | ||
var app = this.manager.getOneById(appId); | ||
var continueOn = true; | ||
if (app.hasMethod(metadata_1.AppMethod.CHECKPREMESSAGESENTMODIFY)) { | ||
continueOn = app.call(metadata_1.AppMethod.CHECKPREMESSAGESENTMODIFY, cfMsg, this.am.getReader(appId), this.am.getHttp(appId)); | ||
} | ||
if (continueOn && app.hasMethod(metadata_1.AppMethod.EXECUTEPREMESSAGESENTMODIFY)) { | ||
msg = app.call(metadata_1.AppMethod.EXECUTEPREMESSAGESENTMODIFY, cfMsg, new accessors_1.MessageBuilder(msg), this.am.getReader(appId), this.am.getHttp(appId), this.am.getPersistence(appId)); | ||
} | ||
} | ||
return data; | ||
return __awaiter(this, void 0, void 0, function () { | ||
var msg, cfMsg, _i, _a, appId, app, continueOn; | ||
return __generator(this, function (_b) { | ||
switch (_b.label) { | ||
case 0: | ||
msg = data; | ||
cfMsg = Utilities_1.Utilities.deepCloneAndFreeze(msg); | ||
_i = 0, _a = this.listeners.get(compiler_1.AppInterface.IPreMessageSentModify); | ||
_b.label = 1; | ||
case 1: | ||
if (!(_i < _a.length)) return [3 /*break*/, 6]; | ||
appId = _a[_i]; | ||
app = this.manager.getOneById(appId); | ||
continueOn = true; | ||
if (!app.hasMethod(metadata_1.AppMethod.CHECKPREMESSAGESENTMODIFY)) return [3 /*break*/, 3]; | ||
return [4 /*yield*/, app.call(metadata_1.AppMethod.CHECKPREMESSAGESENTMODIFY, cfMsg, this.am.getReader(appId), this.am.getHttp(appId))]; | ||
case 2: | ||
continueOn = (_b.sent()); | ||
_b.label = 3; | ||
case 3: | ||
if (!(continueOn && app.hasMethod(metadata_1.AppMethod.EXECUTEPREMESSAGESENTMODIFY))) return [3 /*break*/, 5]; | ||
return [4 /*yield*/, app.call(metadata_1.AppMethod.EXECUTEPREMESSAGESENTMODIFY, cfMsg, new accessors_1.MessageBuilder(msg), this.am.getReader(appId), this.am.getHttp(appId), this.am.getPersistence(appId))]; | ||
case 4: | ||
msg = (_b.sent()); | ||
_b.label = 5; | ||
case 5: | ||
_i++; | ||
return [3 /*break*/, 1]; | ||
case 6: return [2 /*return*/, data]; | ||
} | ||
}); | ||
}); | ||
}; | ||
AppListenerManger.prototype.executePostMessageSent = function (data) { | ||
var cfMsg = Utilities_1.Utilities.deepCloneAndFreeze(data); | ||
for (var _i = 0, _a = this.listeners.get(compiler_1.AppInterface.IPostMessageSent); _i < _a.length; _i++) { | ||
var appId = _a[_i]; | ||
var app = this.manager.getOneById(appId); | ||
var continueOn = true; | ||
if (app.hasMethod(metadata_1.AppMethod.CHECKPOSTMESSAGESENT)) { | ||
continueOn = app.call(metadata_1.AppMethod.CHECKPOSTMESSAGESENT, cfMsg, this.am.getReader(appId), this.am.getHttp(appId)); | ||
} | ||
if (continueOn && app.hasMethod(metadata_1.AppMethod.EXECUTEPOSTMESSAGESENT)) { | ||
app.call(metadata_1.AppMethod.EXECUTEPOSTMESSAGESENT, cfMsg, this.am.getReader(appId), this.am.getHttp(appId), this.am.getPersistence(appId)); | ||
} | ||
} | ||
return __awaiter(this, void 0, void 0, function () { | ||
var cfMsg, _i, _a, appId, app, continueOn; | ||
return __generator(this, function (_b) { | ||
switch (_b.label) { | ||
case 0: | ||
cfMsg = Utilities_1.Utilities.deepCloneAndFreeze(data); | ||
_i = 0, _a = this.listeners.get(compiler_1.AppInterface.IPostMessageSent); | ||
_b.label = 1; | ||
case 1: | ||
if (!(_i < _a.length)) return [3 /*break*/, 6]; | ||
appId = _a[_i]; | ||
app = this.manager.getOneById(appId); | ||
continueOn = true; | ||
if (!app.hasMethod(metadata_1.AppMethod.CHECKPOSTMESSAGESENT)) return [3 /*break*/, 3]; | ||
return [4 /*yield*/, app.call(metadata_1.AppMethod.CHECKPOSTMESSAGESENT, cfMsg, this.am.getReader(appId), this.am.getHttp(appId))]; | ||
case 2: | ||
continueOn = (_b.sent()); | ||
_b.label = 3; | ||
case 3: | ||
if (!(continueOn && app.hasMethod(metadata_1.AppMethod.EXECUTEPOSTMESSAGESENT))) return [3 /*break*/, 5]; | ||
return [4 /*yield*/, app.call(metadata_1.AppMethod.EXECUTEPOSTMESSAGESENT, cfMsg, this.am.getReader(appId), this.am.getHttp(appId), this.am.getPersistence(appId))]; | ||
case 4: | ||
_b.sent(); | ||
_b.label = 5; | ||
case 5: | ||
_i++; | ||
return [3 /*break*/, 1]; | ||
case 6: return [2 /*return*/]; | ||
} | ||
}); | ||
}); | ||
}; | ||
AppListenerManger.prototype.executePreRoomCreatePrevent = function (data) { | ||
var cfRoom = Utilities_1.Utilities.deepCloneAndFreeze(data); | ||
var prevented = false; | ||
for (var _i = 0, _a = this.listeners.get(compiler_1.AppInterface.IPreRoomCreatePrevent); _i < _a.length; _i++) { | ||
var appId = _a[_i]; | ||
var app = this.manager.getOneById(appId); | ||
var continueOn = true; | ||
if (app.hasMethod(metadata_1.AppMethod.CHECKPREROOMCREATEPREVENT)) { | ||
continueOn = app.call(metadata_1.AppMethod.CHECKPREROOMCREATEPREVENT, cfRoom, this.am.getReader(appId), this.am.getHttp(appId)); | ||
} | ||
if (continueOn && app.hasMethod(metadata_1.AppMethod.EXECUTEPREROOMCREATEPREVENT)) { | ||
prevented = app.call(metadata_1.AppMethod.EXECUTEPREROOMCREATEPREVENT, cfRoom, this.am.getReader(appId), this.am.getHttp(appId), this.am.getPersistence(appId)); | ||
if (prevented) { | ||
return prevented; | ||
return __awaiter(this, void 0, void 0, function () { | ||
var cfRoom, prevented, _i, _a, appId, app, continueOn; | ||
return __generator(this, function (_b) { | ||
switch (_b.label) { | ||
case 0: | ||
cfRoom = Utilities_1.Utilities.deepCloneAndFreeze(data); | ||
prevented = false; | ||
_i = 0, _a = this.listeners.get(compiler_1.AppInterface.IPreRoomCreatePrevent); | ||
_b.label = 1; | ||
case 1: | ||
if (!(_i < _a.length)) return [3 /*break*/, 6]; | ||
appId = _a[_i]; | ||
app = this.manager.getOneById(appId); | ||
continueOn = true; | ||
if (!app.hasMethod(metadata_1.AppMethod.CHECKPREROOMCREATEPREVENT)) return [3 /*break*/, 3]; | ||
return [4 /*yield*/, app.call(metadata_1.AppMethod.CHECKPREROOMCREATEPREVENT, cfRoom, this.am.getReader(appId), this.am.getHttp(appId))]; | ||
case 2: | ||
continueOn = (_b.sent()); | ||
_b.label = 3; | ||
case 3: | ||
if (!(continueOn && app.hasMethod(metadata_1.AppMethod.EXECUTEPREROOMCREATEPREVENT))) return [3 /*break*/, 5]; | ||
return [4 /*yield*/, app.call(metadata_1.AppMethod.EXECUTEPREROOMCREATEPREVENT, cfRoom, this.am.getReader(appId), this.am.getHttp(appId), this.am.getPersistence(appId))]; | ||
case 4: | ||
prevented = (_b.sent()); | ||
if (prevented) { | ||
return [2 /*return*/, prevented]; | ||
} | ||
_b.label = 5; | ||
case 5: | ||
_i++; | ||
return [3 /*break*/, 1]; | ||
case 6: return [2 /*return*/, prevented]; | ||
} | ||
} | ||
} | ||
return prevented; | ||
}); | ||
}); | ||
}; | ||
AppListenerManger.prototype.executePreRoomCreateExtend = function (data) { | ||
var room = data; | ||
var cfRoom = Utilities_1.Utilities.deepCloneAndFreeze(room); | ||
for (var _i = 0, _a = this.listeners.get(compiler_1.AppInterface.IPreRoomCreateExtend); _i < _a.length; _i++) { | ||
var appId = _a[_i]; | ||
var app = this.manager.getOneById(appId); | ||
var continueOn = true; | ||
if (app.hasMethod(metadata_1.AppMethod.CHECKPREROOMCREATEEXTEND)) { | ||
continueOn = app.call(metadata_1.AppMethod.CHECKPREROOMCREATEEXTEND, cfRoom, this.am.getReader(appId), this.am.getHttp(appId)); | ||
} | ||
if (continueOn && app.hasMethod(metadata_1.AppMethod.EXECUTEPREROOMCREATEEXTEND)) { | ||
app.call(metadata_1.AppMethod.EXECUTEPREROOMCREATEEXTEND, cfRoom, new accessors_1.RoomExtender(room), // This mutates the passed in object | ||
this.am.getReader(appId), this.am.getHttp(appId), this.am.getPersistence(appId)); | ||
} | ||
} | ||
return data; | ||
return __awaiter(this, void 0, void 0, function () { | ||
var room, cfRoom, _i, _a, appId, app, continueOn; | ||
return __generator(this, function (_b) { | ||
switch (_b.label) { | ||
case 0: | ||
room = data; | ||
cfRoom = Utilities_1.Utilities.deepCloneAndFreeze(room); | ||
_i = 0, _a = this.listeners.get(compiler_1.AppInterface.IPreRoomCreateExtend); | ||
_b.label = 1; | ||
case 1: | ||
if (!(_i < _a.length)) return [3 /*break*/, 6]; | ||
appId = _a[_i]; | ||
app = this.manager.getOneById(appId); | ||
continueOn = true; | ||
if (!app.hasMethod(metadata_1.AppMethod.CHECKPREROOMCREATEEXTEND)) return [3 /*break*/, 3]; | ||
return [4 /*yield*/, app.call(metadata_1.AppMethod.CHECKPREROOMCREATEEXTEND, cfRoom, this.am.getReader(appId), this.am.getHttp(appId))]; | ||
case 2: | ||
continueOn = (_b.sent()); | ||
_b.label = 3; | ||
case 3: | ||
if (!(continueOn && app.hasMethod(metadata_1.AppMethod.EXECUTEPREROOMCREATEEXTEND))) return [3 /*break*/, 5]; | ||
return [4 /*yield*/, app.call(metadata_1.AppMethod.EXECUTEPREROOMCREATEEXTEND, cfRoom, new accessors_1.RoomExtender(room), // This mutates the passed in object | ||
this.am.getReader(appId), this.am.getHttp(appId), this.am.getPersistence(appId))]; | ||
case 4: | ||
_b.sent(); | ||
_b.label = 5; | ||
case 5: | ||
_i++; | ||
return [3 /*break*/, 1]; | ||
case 6: return [2 /*return*/, data]; | ||
} | ||
}); | ||
}); | ||
}; | ||
AppListenerManger.prototype.executePreRoomCreateModify = function (data) { | ||
var room = data; | ||
var cfRoom = Utilities_1.Utilities.deepCloneAndFreeze(room); | ||
for (var _i = 0, _a = this.listeners.get(compiler_1.AppInterface.IPreRoomCreateModify); _i < _a.length; _i++) { | ||
var appId = _a[_i]; | ||
var app = this.manager.getOneById(appId); | ||
var continueOn = true; | ||
if (app.hasMethod(metadata_1.AppMethod.CHECKPREROOMCREATEMODIFY)) { | ||
continueOn = app.call(metadata_1.AppMethod.CHECKPREROOMCREATEMODIFY, cfRoom, this.am.getReader(appId), this.am.getHttp(appId)); | ||
} | ||
if (continueOn && app.hasMethod(metadata_1.AppMethod.EXECUTEPREROOMCREATEMODIFY)) { | ||
room = app.call(metadata_1.AppMethod.EXECUTEPREROOMCREATEMODIFY, cfRoom, new accessors_1.RoomBuilder(room), this.am.getReader(appId), this.am.getHttp(appId), this.am.getPersistence(appId)); | ||
} | ||
} | ||
return data; | ||
return __awaiter(this, void 0, void 0, function () { | ||
var room, cfRoom, _i, _a, appId, app, continueOn; | ||
return __generator(this, function (_b) { | ||
switch (_b.label) { | ||
case 0: | ||
room = data; | ||
cfRoom = Utilities_1.Utilities.deepCloneAndFreeze(room); | ||
_i = 0, _a = this.listeners.get(compiler_1.AppInterface.IPreRoomCreateModify); | ||
_b.label = 1; | ||
case 1: | ||
if (!(_i < _a.length)) return [3 /*break*/, 6]; | ||
appId = _a[_i]; | ||
app = this.manager.getOneById(appId); | ||
continueOn = true; | ||
if (!app.hasMethod(metadata_1.AppMethod.CHECKPREROOMCREATEMODIFY)) return [3 /*break*/, 3]; | ||
return [4 /*yield*/, app.call(metadata_1.AppMethod.CHECKPREROOMCREATEMODIFY, cfRoom, this.am.getReader(appId), this.am.getHttp(appId))]; | ||
case 2: | ||
continueOn = (_b.sent()); | ||
_b.label = 3; | ||
case 3: | ||
if (!(continueOn && app.hasMethod(metadata_1.AppMethod.EXECUTEPREROOMCREATEMODIFY))) return [3 /*break*/, 5]; | ||
return [4 /*yield*/, app.call(metadata_1.AppMethod.EXECUTEPREROOMCREATEMODIFY, cfRoom, new accessors_1.RoomBuilder(room), this.am.getReader(appId), this.am.getHttp(appId), this.am.getPersistence(appId))]; | ||
case 4: | ||
room = (_b.sent()); | ||
_b.label = 5; | ||
case 5: | ||
_i++; | ||
return [3 /*break*/, 1]; | ||
case 6: return [2 /*return*/, data]; | ||
} | ||
}); | ||
}); | ||
}; | ||
AppListenerManger.prototype.executePostRoomCreate = function (data) { | ||
var cfRoom = Utilities_1.Utilities.deepCloneAndFreeze(data); | ||
for (var _i = 0, _a = this.listeners.get(compiler_1.AppInterface.IPostRoomCreate); _i < _a.length; _i++) { | ||
var appId = _a[_i]; | ||
var app = this.manager.getOneById(appId); | ||
var continueOn = true; | ||
if (app.hasMethod(metadata_1.AppMethod.CHECKPOSTROOMCREATE)) { | ||
continueOn = app.call(metadata_1.AppMethod.CHECKPOSTROOMCREATE, cfRoom, this.am.getReader(appId), this.am.getHttp(appId)); | ||
} | ||
if (continueOn && app.hasMethod(metadata_1.AppMethod.EXECUTEPOSTROOMCREATE)) { | ||
app.call(metadata_1.AppMethod.EXECUTEPOSTROOMCREATE, cfRoom, this.am.getReader(appId), this.am.getHttp(appId), this.am.getPersistence(appId)); | ||
} | ||
} | ||
return __awaiter(this, void 0, void 0, function () { | ||
var cfRoom, _i, _a, appId, app, continueOn; | ||
return __generator(this, function (_b) { | ||
switch (_b.label) { | ||
case 0: | ||
cfRoom = Utilities_1.Utilities.deepCloneAndFreeze(data); | ||
_i = 0, _a = this.listeners.get(compiler_1.AppInterface.IPostRoomCreate); | ||
_b.label = 1; | ||
case 1: | ||
if (!(_i < _a.length)) return [3 /*break*/, 6]; | ||
appId = _a[_i]; | ||
app = this.manager.getOneById(appId); | ||
continueOn = true; | ||
if (!app.hasMethod(metadata_1.AppMethod.CHECKPOSTROOMCREATE)) return [3 /*break*/, 3]; | ||
return [4 /*yield*/, app.call(metadata_1.AppMethod.CHECKPOSTROOMCREATE, cfRoom, this.am.getReader(appId), this.am.getHttp(appId))]; | ||
case 2: | ||
continueOn = (_b.sent()); | ||
_b.label = 3; | ||
case 3: | ||
if (!(continueOn && app.hasMethod(metadata_1.AppMethod.EXECUTEPOSTROOMCREATE))) return [3 /*break*/, 5]; | ||
return [4 /*yield*/, app.call(metadata_1.AppMethod.EXECUTEPOSTROOMCREATE, cfRoom, this.am.getReader(appId), this.am.getHttp(appId), this.am.getPersistence(appId))]; | ||
case 4: | ||
_b.sent(); | ||
_b.label = 5; | ||
case 5: | ||
_i++; | ||
return [3 /*break*/, 1]; | ||
case 6: return [2 /*return*/]; | ||
} | ||
}); | ||
}); | ||
}; | ||
@@ -199,0 +385,0 @@ return AppListenerManger; |
@@ -28,3 +28,3 @@ /// <reference types="node" /> | ||
runInContext(codeToRun: string, context: vm.Context): any; | ||
call(method: AppMethod, ...args: Array<any>): any; | ||
call(method: AppMethod, ...args: Array<any>): Promise<any>; | ||
getStatus(): AppStatus; | ||
@@ -31,0 +31,0 @@ setStatus(status: AppStatus): void; |
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
var __generator = (this && this.__generator) || function (thisArg, body) { | ||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; | ||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; | ||
function verb(n) { return function (v) { return step([n, v]); }; } | ||
function step(op) { | ||
if (f) throw new TypeError("Generator is already executing."); | ||
while (_) try { | ||
if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t; | ||
if (y = 0, t) op = [0, t.value]; | ||
switch (op[0]) { | ||
case 0: case 1: t = op; break; | ||
case 4: _.label++; return { value: op[1], done: false }; | ||
case 5: _.label++; y = op[1]; op = [0]; continue; | ||
case 7: op = _.ops.pop(); _.trys.pop(); continue; | ||
default: | ||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } | ||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } | ||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } | ||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } | ||
if (t[2]) _.ops.pop(); | ||
_.trys.pop(); continue; | ||
} | ||
op = body.call(thisArg, _); | ||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } | ||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; | ||
} | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -51,24 +86,37 @@ var metadata_1 = require("@rocket.chat/apps-ts-definition/metadata"); | ||
} | ||
if (typeof this.app[method] !== 'function') { | ||
throw new Error("The App " + this.app.getName() + " (" + this.app.getID() | ||
+ (" does not have the method: \"" + method + "\"")); | ||
} | ||
// tslint:disable-next-line | ||
var methodDeclartion = this.app[method]; | ||
if (args.length < methodDeclartion.length) { | ||
throw new errors_1.NotEnoughMethodArgumentsError(method, methodDeclartion.length, args.length); | ||
} | ||
var logger = this.setupLogger(method); | ||
logger.debug(method + " is being called..."); | ||
var result; | ||
try { | ||
result = this.runInContext("app." + method + ".apply(app, args)", this.makeContext({ app: this.app, args: args })); | ||
logger.debug(method + " was successfully called!", result); | ||
} | ||
catch (e) { | ||
logger.error(e); | ||
logger.debug(method + " was unsuccessful."); | ||
} | ||
this.manager.getLogStorage().storeEntries(this.getID(), logger); | ||
return result; | ||
return __awaiter(this, void 0, void 0, function () { | ||
var methodDeclartion, logger, result, e_1; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
if (typeof this.app[method] !== 'function') { | ||
throw new Error("The App " + this.app.getName() + " (" + this.app.getID() | ||
+ (" does not have the method: \"" + method + "\"")); | ||
} | ||
methodDeclartion = this.app[method]; | ||
if (args.length < methodDeclartion.length) { | ||
throw new errors_1.NotEnoughMethodArgumentsError(method, methodDeclartion.length, args.length); | ||
} | ||
logger = this.setupLogger(method); | ||
logger.debug(method + " is being called..."); | ||
_a.label = 1; | ||
case 1: | ||
_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 }))]; | ||
case 2: | ||
// tslint:disable-next-line:max-line-length | ||
result = (_a.sent()); | ||
logger.debug(method + " was successfully called!", result); | ||
return [3 /*break*/, 4]; | ||
case 3: | ||
e_1 = _a.sent(); | ||
logger.error(e_1); | ||
logger.debug(method + " was unsuccessful."); | ||
return [3 /*break*/, 4]; | ||
case 4: | ||
this.manager.getLogStorage().storeEntries(this.getID(), logger); | ||
return [2 /*return*/, result]; | ||
} | ||
}); | ||
}); | ||
}; | ||
@@ -75,0 +123,0 @@ ProxiedApp.prototype.getStatus = function () { |
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
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
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
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
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
453809
4916
+ Added@rocket.chat/apps-ts-definition@0.9.13(transitive)
- Removed@rocket.chat/apps-ts-definition@0.8.0(transitive)