Skip to content
This repository was archived by the owner on Nov 5, 2025. It is now read-only.

Commit e4bd643

Browse files
authored
Release 1.43.1 (#789)
2 parents 15ebf21 + 8ff3da1 commit e4bd643

File tree

13 files changed

+144
-75
lines changed

13 files changed

+144
-75
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ jspm_packages
3838
.npm
3939

4040
.deno
41+
.deno-cache
4142

4243
# Optional REPL history
4344
.node_repl_history
Lines changed: 33 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
// deno-lint-ignore-file no-explicit-any
22
import { assertEquals, assertObjectMatch } from 'https://deno.land/[email protected]/assert/mod.ts';
33
import { beforeEach, describe, it } from 'https://deno.land/[email protected]/testing/bdd.ts';
4-
import { spy } from "https://deno.land/[email protected]/testing/mock.ts";
4+
import { spy } from 'https://deno.land/[email protected]/testing/mock.ts';
55

66
import { AppObjectRegistry } from '../../AppObjectRegistry.ts';
77
import videoconfHandler from '../videoconference-handler.ts';
8-
import { assertInstanceOf } from "https://deno.land/[email protected]/assert/assert_instance_of.ts";
9-
import { JsonRpcError } from "jsonrpc-lite";
8+
import { assertInstanceOf } from 'https://deno.land/[email protected]/assert/assert_instance_of.ts';
9+
import { JsonRpcError } from 'jsonrpc-lite';
1010

1111
describe('handlers > videoconference', () => {
1212
// deno-lint-ignore no-unused-vars
@@ -16,15 +16,18 @@ describe('handlers > videoconference', () => {
1616
// deno-lint-ignore no-unused-vars
1717
const mockMethodWithTwoParam = (call: any, user: any, read: any, modify: any, http: any, persis: any): Promise<string> => Promise.resolve('ok two');
1818
// deno-lint-ignore no-unused-vars
19-
const mockMethodWithThreeParam = (call: any, user: any, options: any, read: any, modify: any, http: any, persis: any): Promise<string> => Promise.resolve('ok three');
19+
const mockMethodWithThreeParam = (call: any, user: any, options: any, read: any, modify: any, http: any, persis: any): Promise<string> =>
20+
Promise.resolve('ok three');
2021
const mockProvider = {
2122
empty: mockMethodWithoutParam,
2223
one: mockMethodWithOneParam,
2324
two: mockMethodWithTwoParam,
2425
three: mockMethodWithThreeParam,
2526
notAFunction: true,
26-
error: () => { throw new Error('Method execution error example') }
27-
}
27+
error: () => {
28+
throw new Error('Method execution error example');
29+
},
30+
};
2831

2932
beforeEach(() => {
3033
AppObjectRegistry.clear();
@@ -36,9 +39,9 @@ describe('handlers > videoconference', () => {
3639

3740
const result = await videoconfHandler('videoconference:test-provider:empty', []);
3841

39-
assertEquals(result, 'ok none')
42+
assertEquals(result, 'ok none');
4043
assertEquals(_spy.calls[0].args.length, 4);
41-
44+
4245
_spy.restore();
4346
});
4447

@@ -47,7 +50,7 @@ describe('handlers > videoconference', () => {
4750

4851
const result = await videoconfHandler('videoconference:test-provider:one', ['call']);
4952

50-
assertEquals(result, 'ok one')
53+
assertEquals(result, 'ok one');
5154
assertEquals(_spy.calls[0].args.length, 5);
5255
assertEquals(_spy.calls[0].args[0], 'call');
5356

@@ -59,7 +62,7 @@ describe('handlers > videoconference', () => {
5962

6063
const result = await videoconfHandler('videoconference:test-provider:two', ['call', 'user']);
6164

62-
assertEquals(result, 'ok two')
65+
assertEquals(result, 'ok two');
6366
assertEquals(_spy.calls[0].args.length, 6);
6467
assertEquals(_spy.calls[0].args[0], 'call');
6568
assertEquals(_spy.calls[0].args[1], 'user');
@@ -72,7 +75,7 @@ describe('handlers > videoconference', () => {
7275

7376
const result = await videoconfHandler('videoconference:test-provider:three', ['call', 'user', 'options']);
7477

75-
assertEquals(result, 'ok three')
78+
assertEquals(result, 'ok three');
7679
assertEquals(_spy.calls[0].args.length, 7);
7780
assertEquals(_spy.calls[0].args[0], 'call');
7881
assertEquals(_spy.calls[0].args[1], 'user');
@@ -84,34 +87,36 @@ describe('handlers > videoconference', () => {
8487
it('correctly handles an error on execution of a videoconf method', async () => {
8588
const result = await videoconfHandler('videoconference:test-provider:error', []);
8689

87-
assertInstanceOf(result, JsonRpcError)
90+
assertInstanceOf(result, JsonRpcError);
8891
assertObjectMatch(result, {
8992
message: 'Method execution error example',
90-
code: -32000
91-
})
92-
})
93+
code: -32000,
94+
});
95+
});
9396

9497
it('correctly handles an error when provider is not found', async () => {
95-
const providerName = 'error-provider'
98+
const providerName = 'error-provider';
9699
const result = await videoconfHandler(`videoconference:${providerName}:method`, []);
97100

98-
assertInstanceOf(result, JsonRpcError)
101+
assertInstanceOf(result, JsonRpcError);
99102
assertObjectMatch(result, {
100103
message: `Provider ${providerName} not found`,
101-
code: -32000
102-
})
103-
})
104+
code: -32000,
105+
});
106+
});
104107

105108
it('correctly handles an error if method is not a function of provider', async () => {
106-
const methodName = 'notAFunction'
107-
const providerName = 'test-provider'
109+
const methodName = 'notAFunction';
110+
const providerName = 'test-provider';
108111
const result = await videoconfHandler(`videoconference:${providerName}:${methodName}`, []);
109112

110-
assertInstanceOf(result, JsonRpcError)
113+
assertInstanceOf(result, JsonRpcError);
111114
assertObjectMatch(result, {
112-
message: `Method ${methodName} not found on provider ${providerName}`,
113-
code: -32000
114-
})
115-
})
116-
115+
message: 'Method not found',
116+
code: -32601,
117+
data: {
118+
message: `Method ${methodName} not found on provider ${providerName}`,
119+
},
120+
});
121+
});
117122
});

deno-runtime/handlers/videoconference-handler.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ export default async function videoConferenceHandler(call: string, params: unkno
1818
const method = provider[methodName as keyof IVideoConfProvider];
1919

2020
if (typeof method !== 'function') {
21-
return new JsonRpcError(`Method ${methodName} not found on provider ${providerName}`, -32000);
21+
return JsonRpcError.methodNotFound({
22+
message: `Method ${methodName} not found on provider ${providerName}`,
23+
});
2224
}
2325

2426
const [videoconf, user, options] = params as Array<unknown>;

deno-runtime/lib/accessors/mod.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ export class AppAccessors {
7171
params,
7272
})
7373
.then((response) => response.result)
74-
.catch((err) => err.error);
74+
.catch((err) => { throw new Error(err.error) });
7575
},
7676
},
7777
) as T;

deno-runtime/lib/accessors/modify/ModifyCreator.ts

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ const { RocketChatAssociationModel } = require('@rocket.chat/apps-engine/definit
3434
};
3535

3636
export class ModifyCreator implements IModifyCreator {
37-
constructor(private readonly senderFn: typeof Messenger.sendRequest) {}
37+
constructor(private readonly senderFn: typeof Messenger.sendRequest) { }
3838

3939
getLivechatCreator(): ILivechatCreator {
4040
return new Proxy(
@@ -56,7 +56,9 @@ export class ModifyCreator implements IModifyCreator {
5656
params,
5757
})
5858
.then((response) => response.result)
59-
.catch((err) => err.error);
59+
.catch((err) => {
60+
throw new Error(err.error);
61+
});
6062
},
6163
},
6264
) as ILivechatCreator;
@@ -68,15 +70,17 @@ export class ModifyCreator implements IModifyCreator {
6870
{
6971
get:
7072
(_target: unknown, prop: string) =>
71-
(...params: unknown[]) =>
72-
prop === 'toJSON'
73-
? {}
74-
: this.senderFn({
75-
method: `accessor:getModifier:getCreator:getUploadCreator:${prop}`,
76-
params,
77-
})
78-
.then((response) => response.result)
79-
.catch((err) => err.error),
73+
(...params: unknown[]) =>
74+
prop === 'toJSON'
75+
? {}
76+
: this.senderFn({
77+
method: `accessor:getModifier:getCreator:getUploadCreator:${prop}`,
78+
params,
79+
})
80+
.then((response) => response.result)
81+
.catch((err) => {
82+
throw new Error(err.error);
83+
}),
8084
},
8185
) as IUploadCreator;
8286
}

deno-runtime/lib/accessors/modify/ModifyUpdater.ts

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -26,23 +26,25 @@ const { RocketChatAssociationModel } = require('@rocket.chat/apps-engine/definit
2626
};
2727

2828
export class ModifyUpdater implements IModifyUpdater {
29-
constructor(private readonly senderFn: typeof Messenger.sendRequest) {}
29+
constructor(private readonly senderFn: typeof Messenger.sendRequest) { }
3030

3131
public getLivechatUpdater(): ILivechatUpdater {
3232
return new Proxy(
3333
{ __kind: 'getLivechatUpdater' },
3434
{
3535
get:
3636
(_target: unknown, prop: string) =>
37-
(...params: unknown[]) =>
38-
prop === 'toJSON'
39-
? {}
40-
: this.senderFn({
41-
method: `accessor:getModifier:getUpdater:getLivechatUpdater:${prop}`,
42-
params,
43-
})
44-
.then((response) => response.result)
45-
.catch((err) => err.error),
37+
(...params: unknown[]) =>
38+
prop === 'toJSON'
39+
? {}
40+
: this.senderFn({
41+
method: `accessor:getModifier:getUpdater:getLivechatUpdater:${prop}`,
42+
params,
43+
})
44+
.then((response) => response.result)
45+
.catch((err) => {
46+
throw new Error(err.error);
47+
}),
4648
},
4749
) as ILivechatUpdater;
4850
}
@@ -53,15 +55,17 @@ export class ModifyUpdater implements IModifyUpdater {
5355
{
5456
get:
5557
(_target: unknown, prop: string) =>
56-
(...params: unknown[]) =>
57-
prop === 'toJSON'
58-
? {}
59-
: this.senderFn({
60-
method: `accessor:getModifier:getUpdater:getUserUpdater:${prop}`,
61-
params,
62-
})
63-
.then((response) => response.result)
64-
.catch((err) => err.error),
58+
(...params: unknown[]) =>
59+
prop === 'toJSON'
60+
? {}
61+
: this.senderFn({
62+
method: `accessor:getModifier:getUpdater:getUserUpdater:${prop}`,
63+
params,
64+
})
65+
.then((response) => response.result)
66+
.catch((err) => {
67+
throw new Error(err.error);
68+
}),
6569
},
6670
) as IUserUpdater;
6771
}

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@rocket.chat/apps-engine",
3-
"version": "1.43.0",
3+
"version": "1.43.1",
44
"description": "The engine code for the Rocket.Chat Apps which manages, runs, translates, coordinates and all of that.",
55
"main": "index",
66
"typings": "index",
@@ -19,7 +19,7 @@
1919
"test:node": "NODE_ENV=test ts-node ./tests/runner.ts",
2020
"test:deno": "cd deno-runtime && deno task test",
2121
"gen-doc": "typedoc",
22-
"postinstall": "cd deno-runtime && deno cache main.ts && deno test --no-check --no-run"
22+
"postinstall": "node scripts/postinstall.js"
2323
},
2424
"repository": {
2525
"type": "git",
@@ -32,10 +32,11 @@
3232
],
3333
"files": [
3434
"client/**",
35-
"server/**",
3635
"definition/**",
36+
"deno-runtime/**",
3737
"lib/**",
38-
"deno-runtime/**"
38+
"scripts/**",
39+
"server/**"
3940
],
4041
"author": {
4142
"name": "Rocket.Chat",

scripts/postinstall.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
const childProcess = require('child_process');
2+
const path = require('path');
3+
4+
// Find executable installed by deno-bin
5+
const executablePath = path.join(require.resolve('deno-bin'), '..', 'bin', 'deno');
6+
7+
const rootPath = path.join(__dirname, '..');
8+
const DENO_DIR = path.join(rootPath, '.deno-cache');
9+
10+
childProcess.spawnSync(executablePath, ['cache', 'main.ts'], {
11+
cwd: path.join(rootPath, 'deno-runtime'),
12+
env: {
13+
DENO_DIR,
14+
},
15+
stdio: 'inherit',
16+
});

src/server/AppManager.ts

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,11 @@ export class AppManager {
549549
// the App instance from the source.
550550
const app = await this.getCompiler().toSandBox(this, descriptor, result);
551551

552-
undoSteps.push(() => this.getRuntime().stopRuntime(app.getDenoRuntime()));
552+
undoSteps.push(() =>
553+
this.getRuntime()
554+
.stopRuntime(app.getDenoRuntime())
555+
.catch(() => {}),
556+
);
553557

554558
// Create a user for the app
555559
try {
@@ -639,9 +643,12 @@ export class AppManager {
639643
await this.removeAppUser(app);
640644
await (this.bridges.getPersistenceBridge() as IInternalPersistenceBridge & PersistenceBridge).purge(app.getID());
641645
await this.appMetadataStorage.remove(app.getID());
642-
await this.appSourceStorage.remove(app.getStorageItem()).catch();
646+
await this.appSourceStorage.remove(app.getStorageItem()).catch(() => {});
643647

644-
await this.getRuntime().stopRuntime(app.getDenoRuntime());
648+
// Errors here don't really prevent the process from dying, so we don't really need to do anything on the catch
649+
await this.getRuntime()
650+
.stopRuntime(app.getDenoRuntime())
651+
.catch(() => {});
645652

646653
this.apps.delete(app.getID());
647654
}
@@ -687,7 +694,10 @@ export class AppManager {
687694
descriptor.signature = await this.signatureManager.signApp(descriptor);
688695
const stored = await this.appMetadataStorage.update(descriptor);
689696

690-
await this.getRuntime().stopRuntime(this.apps.get(old.id).getDenoRuntime());
697+
// Errors here don't really prevent the process from dying, so we don't really need to do anything on the catch
698+
await this.getRuntime()
699+
.stopRuntime(this.apps.get(old.id).getDenoRuntime())
700+
.catch(() => {});
691701

692702
const app = await this.getCompiler().toSandBox(this, descriptor, result);
693703

@@ -731,7 +741,10 @@ export class AppManager {
731741
if (appPackageOrInstance instanceof Buffer) {
732742
const parseResult = await this.getParser().unpackageApp(appPackageOrInstance);
733743

734-
await this.getRuntime().stopRuntime(this.apps.get(stored.id).getDenoRuntime());
744+
// Errors here don't really prevent the process from dying, so we don't really need to do anything on the catch
745+
await this.getRuntime()
746+
.stopRuntime(this.apps.get(stored.id).getDenoRuntime())
747+
.catch(() => {});
735748

736749
return this.getCompiler().toSandBox(this, stored, parseResult);
737750
}

0 commit comments

Comments
 (0)