Socket
Socket
Sign inDemoInstall

mx-puppet-bridge

Package Overview
Dependencies
178
Maintainers
1
Versions
112
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.0.21 to 0.0.22

2

lib/botprovisioner.js

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

const pid = parseInt(pidStr, 10);
const d = yield this.provisioner.get(pid);
const d = isNaN(pid) ? null : yield this.provisioner.get(pid);
if (!d || d.puppetMxid !== sender) {

@@ -149,0 +149,0 @@ yield this.sendMessage(roomId, "ERROR: PuppetID not found");

@@ -14,2 +14,3 @@ /// <reference types="node" />

isDirect?: boolean | null;
externalUrl?: string | null;
}

@@ -30,2 +31,3 @@ export declare class ChannelSyncroniser {

insert(mxid: string, roomData: IRemoteChan): Promise<void>;
updateBridgeInformation(data: IRemoteChan): Promise<void>;
getPartsFromMxid(mxid: string): IRemoteChan | null;

@@ -32,0 +34,0 @@ maybeLeaveGhost(chanMxid: string, userMxid: string): Promise<void>;

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

}
if (data.name !== undefined && data.name !== chan.name) {
if (data.name !== undefined && data.name !== null && data.name !== chan.name) {
doUpdate = true;

@@ -183,3 +183,4 @@ log.verbose("Updating name");

}
if ((data.avatarUrl !== undefined && data.avatarUrl !== chan.avatarUrl) || data.avatarBuffer) {
if ((data.avatarUrl !== undefined && data.avatarUrl !== null && data.avatarUrl !== chan.avatarUrl)
|| data.avatarBuffer) {
log.verbose("Updating avatar");

@@ -197,3 +198,3 @@ const { doUpdate: updateAvatar, mxcUrl, hash } = yield util_1.Util.MaybeUploadFile((buffer, mimetype, filename) => __awaiter(this, void 0, void 0, function* () {

}
if (data.topic !== undefined && data.topic !== chan.topic) {
if (data.topic !== undefined && data.topic !== null && data.topic !== chan.topic) {
doUpdate = true;

@@ -204,3 +205,3 @@ log.verbose("updating topic");

}
if (data.groupId !== undefined && data.groupId !== chan.groupId) {
if (data.groupId !== undefined && data.groupId !== null && data.groupId !== chan.groupId) {
doUpdate = true;

@@ -259,2 +260,72 @@ removeGroup = chan.groupId;

}
updateBridgeInformation(data) {
return __awaiter(this, void 0, void 0, function* () {
log.info("Updating bridge infromation state event");
const chan = yield this.maybeGet(data);
if (!chan) {
log.warn("Channel not found");
return; // nothing to do
}
const client = yield this.getChanOp(chan.mxid);
if (!client) {
log.warn("No OP in channel");
return; // no op
}
const e = (s) => encodeURIComponent(util_1.Util.str2mxid(s));
const stateKey = `de.sorunome.mx-puppet-bridge://${this.bridge.protocol.id}` +
`${chan.groupId ? "/" + e(chan.groupId) : ""}/${e(chan.roomId)}`;
const creator = yield this.bridge.provisioner.getMxid(data.puppetId);
const protocol = {
id: this.bridge.protocol.id,
displayname: this.bridge.protocol.displayname,
};
if (this.bridge.config.bridge.avatarUrl) {
protocol.avatar = this.bridge.config.bridge.avatarUrl;
}
if (this.bridge.protocol.externalUrl) {
protocol.external_url = this.bridge.protocol.externalUrl;
}
const channel = {
id: util_1.Util.str2mxid(chan.roomId),
};
if (chan.name) {
channel.displayname = chan.name;
}
if (chan.avatarMxc) {
channel.avatar = chan.avatarMxc;
}
if (chan.externalUrl) {
channel.external_url = chan.externalUrl;
}
const content = {
creator,
protocol,
channel,
};
if (chan.groupId && this.bridge.groupSyncEnabled) {
const group = yield this.bridge.groupSync.maybeGet({
groupId: chan.groupId,
puppetId: chan.puppetId,
});
if (group) {
const network = {
id: group.groupId,
};
if (group.name) {
network.displayname = group.name;
}
if (group.avatarMxc) {
network.avatar = group.avatarMxc;
}
if (group.externalUrl) {
network.external_url = group.externalUrl;
}
content.network = network;
}
}
// finally set the state event
log.verbose("sending state event", content, "with state key", stateKey);
yield client.sendStateEvent(chan.mxid, "m.bridge", stateKey, content);
});
}
getPartsFromMxid(mxid) {

@@ -353,11 +424,21 @@ const suffix = this.bridge.AS.getSuffixForAlias(mxid);

if (opClient) {
log.info("Removing old aliases from room...");
// first remove the canonical alias
yield opClient.sendStateEvent(entry.mxid, "m.room.canonical_alias", "", {});
// next fetch all aliases and remove the ones we can
const aliases = yield opClient.getRoomStateEvent(entry.mxid, "m.room.aliases", this.bridge.config.bridge.domain);
yield opClient.sendStateEvent(entry.mxid, "m.room.aliases", this.bridge.config.bridge.domain, { aliases: [] });
for (const alias of aliases.aliases) {
yield opClient.deleteRoomAlias(alias);
// we try...catch this as we *really* want to get to the DB deleting
try {
log.info("Removing old aliases from room...");
// first remove the canonical alias
yield opClient.sendStateEvent(entry.mxid, "m.room.canonical_alias", "", {});
// next fetch all aliases and remove the ones we can
try {
const aliases = yield opClient.getRoomStateEvent(entry.mxid, "m.room.aliases", this.bridge.config.bridge.domain);
for (const alias of aliases.aliases) {
yield opClient.deleteRoomAlias(alias);
}
}
catch (err) {
log.info("No aliases set");
}
}
catch (err) {
log.error("Error removing old aliases", err);
}
}

@@ -364,0 +445,0 @@ // delete from DB (also OP store), cache and trigger ghosts to quit

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

this.loginSharedSecretMap = {};
this.enableGroupSync = true;
this.enableGroupSync = false;
}

@@ -32,0 +32,0 @@ }

@@ -12,2 +12,3 @@ import { IDatabaseConnector } from "./connector";

groupId?: string | null;
externalUrl?: string | null;
}

@@ -14,0 +15,0 @@ export declare class DbChanStore {

@@ -13,2 +13,3 @@ import { IDatabaseConnector } from "./connector";

roomIds: string[];
externalUrl?: string | null;
}

@@ -15,0 +16,0 @@ export declare class DbGroupStore {

@@ -9,2 +9,3 @@ import { IDatabaseConnector } from "./connector";

avatarHash?: string | null;
externalUrl?: string | null;
}

@@ -11,0 +12,0 @@ export declare class DbUserStore {

@@ -13,2 +13,3 @@ /// <reference types="node" />

roomIds?: string[] | null;
externalUrl?: string | null;
}

@@ -15,0 +16,0 @@ export declare class GroupSyncroniser {

@@ -110,6 +110,8 @@ "use strict";

else {
update.name = data.name !== undefined && data.name !== group.name;
update.avatar = data.avatarUrl !== undefined && data.avatarUrl !== group.avatarUrl;
update.shortDescription = data.shortDescription !== undefined && data.shortDescription !== group.shortDescription;
update.longDescription = data.longDescription !== undefined && data.longDescription !== group.longDescription;
update.name = data.name !== undefined && data.name !== null && data.name !== group.name;
update.avatar = data.avatarUrl !== undefined && data.avatarUrl !== null && data.avatarUrl !== group.avatarUrl;
update.shortDescription = data.shortDescription !== undefined && data.shortDescription !== null
&& data.shortDescription !== group.shortDescription;
update.longDescription = data.longDescription !== undefined && data.longDescription !== null
&& data.longDescription !== group.longDescription;
if (data.roomIds) {

@@ -116,0 +118,0 @@ for (const r of data.roomIds) {

@@ -77,2 +77,7 @@ /// <reference types="node" />

}
export interface IProtocolInformation {
id?: string;
displayname?: string;
externalUrl?: string;
}
export declare type CreateChanHook = (chan: IRemoteChan) => Promise<IRemoteChan | null>;

@@ -109,2 +114,3 @@ export declare type CreateUserHook = (user: IRemoteUser) => Promise<IRemoteUser | null>;

store: Store;
protocol: IProtocolInformation;
private appservice;

@@ -117,3 +123,3 @@ private ghostInviteCache;

private delayedFunction;
constructor(registrationPath: string, configPath: string, features: IPuppetBridgeFeatures);
constructor(registrationPath: string, configPath: string, features: IPuppetBridgeFeatures, prot?: IProtocolInformation);
readConfig(): void;

@@ -120,0 +126,0 @@ init(): Promise<void>;

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

class PuppetBridge extends events_1.EventEmitter {
constructor(registrationPath, configPath, features) {
constructor(registrationPath, configPath, features, prot) {
super();

@@ -44,2 +44,15 @@ this.registrationPath = registrationPath;

this.features = features;
if (!prot) {
this.protocol = {
id: "unknown-protocol",
displayname: "Unknown Protocol",
};
}
else {
this.protocol = {
id: prot.id || "unknown-protocol",
displayname: prot.displayname || "Unknown Protocol",
externalUrl: prot.externalUrl,
};
}
this.ghostInviteCache = new timedcache_1.TimedCache(PUPPET_INVITE_CACHE_LIFETIME);

@@ -1164,2 +1177,3 @@ this.hooks = {};

yield intent.joinRoom(roomId);
yield this.userSync.getClient(parts); // create user, if it doesn't exist
});

@@ -1166,0 +1180,0 @@ }

@@ -26,3 +26,3 @@ /// <reference types="node" />

get eventStore(): DbEventStore;
init(overrideSchema?: number, table?: string, getSchemaClass?: GetSchemaClass): Promise<void>;
init(overrideSchema?: number, table?: string, getSchemaClass?: GetSchemaClass, openDatabase?: boolean): Promise<void>;
close(): Promise<void>;

@@ -29,0 +29,0 @@ getFileMxc(thing: string | Buffer): Promise<string | null>;

@@ -42,6 +42,8 @@ "use strict";

}
init(overrideSchema = 0, table = "schema", getSchemaClass) {
init(overrideSchema = 0, table = "schema", getSchemaClass, openDatabase = true) {
return __awaiter(this, void 0, void 0, function* () {
log.info("Starting DB Init");
yield this.openDatabase();
if (openDatabase) {
yield this.openDatabase();
}
let version = yield this.getSchemaVersion(table);

@@ -48,0 +50,0 @@ const targetSchema = overrideSchema || exports.CURRENT_SCHEMA;

@@ -11,2 +11,3 @@ /// <reference types="node" />

name?: string | null;
externalUrl?: string | null;
}

@@ -13,0 +14,0 @@ export declare class UserSyncroniser {

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

else {
update.name = data.name !== undefined && data.name !== user.name;
update.avatar = data.avatarUrl !== undefined && data.avatarUrl !== user.avatarUrl;
update.name = data.name !== undefined && data.name !== null && data.name !== user.name;
update.avatar = data.avatarUrl !== undefined && data.avatarUrl !== null && data.avatarUrl !== user.avatarUrl;
}

@@ -115,0 +115,0 @@ const intent = this.bridge.AS.getIntentForSuffix(`${data.puppetId}_${util_1.Util.str2mxid(data.userId)}`);

{
"name": "mx-puppet-bridge",
"version": "0.0.21",
"version": "0.0.22",
"description": "Matrix Puppeting Bridge library",

@@ -5,0 +5,0 @@ "repository": {

@@ -158,3 +158,3 @@ import { PuppetBridge, RetDataFn, IRetData } from "./puppetbridge";

const pid = parseInt(pidStr, 10);
const d = await this.provisioner.get(pid);
const d = isNaN(pid) ? null : await this.provisioner.get(pid);
if (!d || d.puppetMxid !== sender) {

@@ -161,0 +161,0 @@ await this.sendMessage(roomId, "ERROR: PuppetID not found");

@@ -24,4 +24,19 @@ import { PuppetBridge } from "./puppetbridge";

isDirect?: boolean | null;
externalUrl?: string | null;
}
interface ISingleBridgeInformation {
id: string;
displayname?: string;
avatar?: string;
external_url?: string;
}
interface IBridgeInformation {
creator?: string;
protocol: ISingleBridgeInformation;
network?: ISingleBridgeInformation;
channel: ISingleBridgeInformation;
}
export class ChannelSyncroniser {

@@ -190,3 +205,3 @@ private chanStore: DbChanStore;

}
if (data.name !== undefined && data.name !== chan.name) {
if (data.name !== undefined && data.name !== null && data.name !== chan.name) {
doUpdate = true;

@@ -202,3 +217,4 @@ log.verbose("Updating name");

}
if ((data.avatarUrl !== undefined && data.avatarUrl !== chan.avatarUrl) || data.avatarBuffer) {
if ((data.avatarUrl !== undefined && data.avatarUrl !== null && data.avatarUrl !== chan.avatarUrl)
|| data.avatarBuffer) {
log.verbose("Updating avatar");

@@ -222,3 +238,3 @@ const { doUpdate: updateAvatar, mxcUrl, hash } = await Util.MaybeUploadFile(

}
if (data.topic !== undefined && data.topic !== chan.topic) {
if (data.topic !== undefined && data.topic !== null && data.topic !== chan.topic) {
doUpdate = true;

@@ -234,3 +250,3 @@ log.verbose("updating topic");

}
if (data.groupId !== undefined && data.groupId !== chan.groupId) {
if (data.groupId !== undefined && data.groupId !== null && data.groupId !== chan.groupId) {
doUpdate = true;

@@ -290,2 +306,76 @@ removeGroup = chan.groupId;

public async updateBridgeInformation(data: IRemoteChan) {
log.info("Updating bridge infromation state event");
const chan = await this.maybeGet(data);
if (!chan) {
log.warn("Channel not found");
return; // nothing to do
}
const client = await this.getChanOp(chan.mxid);
if (!client) {
log.warn("No OP in channel");
return; // no op
}
const e = (s: string) => encodeURIComponent(Util.str2mxid(s));
const stateKey = `de.sorunome.mx-puppet-bridge://${this.bridge.protocol.id}` +
`${chan.groupId ? "/" + e(chan.groupId) : ""}/${e(chan.roomId)}`;
const creator = await this.bridge.provisioner.getMxid(data.puppetId);
const protocol: ISingleBridgeInformation = {
id: this.bridge.protocol.id!,
displayname: this.bridge.protocol.displayname,
};
if (this.bridge.config.bridge.avatarUrl) {
protocol.avatar = this.bridge.config.bridge.avatarUrl;
}
if (this.bridge.protocol.externalUrl) {
protocol.external_url = this.bridge.protocol.externalUrl;
}
const channel: ISingleBridgeInformation = {
id: Util.str2mxid(chan.roomId),
};
if (chan.name) {
channel.displayname = chan.name;
}
if (chan.avatarMxc) {
channel.avatar = chan.avatarMxc;
}
if (chan.externalUrl) {
channel.external_url = chan.externalUrl;
}
const content: IBridgeInformation = {
creator,
protocol,
channel,
};
if (chan.groupId && this.bridge.groupSyncEnabled) {
const group = await this.bridge.groupSync.maybeGet({
groupId: chan.groupId,
puppetId: chan.puppetId,
});
if (group) {
const network: ISingleBridgeInformation = {
id: group.groupId,
};
if (group.name) {
network.displayname = group.name;
}
if (group.avatarMxc) {
network.avatar = group.avatarMxc;
}
if (group.externalUrl) {
network.external_url = group.externalUrl;
}
content.network = network;
}
}
// finally set the state event
log.verbose("sending state event", content, "with state key", stateKey);
await client.sendStateEvent(
chan.mxid,
"m.bridge",
stateKey,
content,
);
}
public getPartsFromMxid(mxid: string): IRemoteChan | null {

@@ -383,10 +473,18 @@ const suffix = this.bridge.AS.getSuffixForAlias(mxid);

if (opClient) {
log.info("Removing old aliases from room...");
// first remove the canonical alias
await opClient.sendStateEvent(entry.mxid, "m.room.canonical_alias", "", {});
// next fetch all aliases and remove the ones we can
const aliases = await opClient.getRoomStateEvent(entry.mxid, "m.room.aliases", this.bridge.config.bridge.domain);
await opClient.sendStateEvent(entry.mxid, "m.room.aliases", this.bridge.config.bridge.domain, { aliases: [] });
for (const alias of aliases.aliases) {
await opClient.deleteRoomAlias(alias);
// we try...catch this as we *really* want to get to the DB deleting
try {
log.info("Removing old aliases from room...");
// first remove the canonical alias
await opClient.sendStateEvent(entry.mxid, "m.room.canonical_alias", "", {});
// next fetch all aliases and remove the ones we can
try {
const aliases = await opClient.getRoomStateEvent(entry.mxid, "m.room.aliases", this.bridge.config.bridge.domain);
for (const alias of aliases.aliases) {
await opClient.deleteRoomAlias(alias);
}
} catch (err) {
log.info("No aliases set");
}
} catch (err) {
log.error("Error removing old aliases", err);
}

@@ -393,0 +491,0 @@ }

@@ -29,3 +29,3 @@ export class MxBridgeConfig {

public avatarUrl?: string;
public enableGroupSync: boolean = true;
public enableGroupSync: boolean = false;
}

@@ -32,0 +32,0 @@

@@ -20,2 +20,3 @@ import { IDatabaseConnector, ISqlRow } from "./connector";

groupId?: string | null;
externalUrl?: string | null;
}

@@ -22,0 +23,0 @@

@@ -21,2 +21,3 @@ import { IDatabaseConnector, ISqlRow } from "./connector";

roomIds: string[];
externalUrl?: string | null;
}

@@ -23,0 +24,0 @@

@@ -17,2 +17,3 @@ import { IDatabaseConnector } from "./connector";

avatarHash?: string | null;
externalUrl?: string | null;
}

@@ -19,0 +20,0 @@

@@ -23,2 +23,3 @@ import { PuppetBridge } from "./puppetbridge";

roomIds?: string[] | null;
externalUrl?: string | null;
}

@@ -116,6 +117,8 @@

} else {
update.name = data.name !== undefined && data.name !== group.name;
update.avatar = data.avatarUrl !== undefined && data.avatarUrl !== group.avatarUrl;
update.shortDescription = data.shortDescription !== undefined && data.shortDescription !== group.shortDescription;
update.longDescription = data.longDescription !== undefined && data.longDescription !== group.longDescription;
update.name = data.name !== undefined && data.name !== null && data.name !== group.name;
update.avatar = data.avatarUrl !== undefined && data.avatarUrl !== null && data.avatarUrl !== group.avatarUrl;
update.shortDescription = data.shortDescription !== undefined && data.shortDescription !== null
&& data.shortDescription !== group.shortDescription;
update.longDescription = data.longDescription !== undefined && data.longDescription !== null
&& data.longDescription !== group.longDescription;
if (data.roomIds) {

@@ -122,0 +125,0 @@ for (const r of data.roomIds) {

@@ -124,2 +124,8 @@ import * as fs from "fs";

export interface IProtocolInformation {
id?: string;
displayname?: string;
externalUrl?: string;
}
export type CreateChanHook = (chan: IRemoteChan) => Promise<IRemoteChan | null>;

@@ -155,2 +161,3 @@ export type CreateUserHook = (user: IRemoteUser) => Promise<IRemoteUser | null>;

public store: Store;
public protocol: IProtocolInformation;
private appservice: Appservice;

@@ -168,4 +175,17 @@ private ghostInviteCache: TimedCache<string, boolean>;

private features: IPuppetBridgeFeatures,
prot?: IProtocolInformation,
) {
super();
if (!prot) {
this.protocol = {
id: "unknown-protocol",
displayname: "Unknown Protocol",
};
} else {
this.protocol = {
id: prot.id || "unknown-protocol",
displayname: prot.displayname || "Unknown Protocol",
externalUrl: prot.externalUrl,
};
}
this.ghostInviteCache = new TimedCache(PUPPET_INVITE_CACHE_LIFETIME);

@@ -1284,2 +1304,3 @@ this.hooks = {} as IPuppetBridgeHooks;

await intent.joinRoom(roomId);
await this.userSync.getClient(parts); // create user, if it doesn't exist
}

@@ -1286,0 +1307,0 @@

@@ -53,5 +53,8 @@ import { IDbSchema } from "./db/schema/dbschema";

getSchemaClass?: GetSchemaClass,
openDatabase: boolean = true,
): Promise<void> {
log.info("Starting DB Init");
await this.openDatabase();
if (openDatabase) {
await this.openDatabase();
}
let version = await this.getSchemaVersion(table);

@@ -58,0 +61,0 @@ const targetSchema = overrideSchema || CURRENT_SCHEMA;

@@ -21,2 +21,3 @@ import { PuppetBridge } from "./puppetbridge";

name?: string | null;
externalUrl?: string | null;
}

@@ -114,4 +115,4 @@

} else {
update.name = data.name !== undefined && data.name !== user.name;
update.avatar = data.avatarUrl !== undefined && data.avatarUrl !== user.avatarUrl;
update.name = data.name !== undefined && data.name !== null && data.name !== user.name;
update.avatar = data.avatarUrl !== undefined && data.avatarUrl !== null && data.avatarUrl !== user.avatarUrl;
}

@@ -118,0 +119,0 @@ const intent = this.bridge.AS.getIntentForSuffix(`${data.puppetId}_${Util.str2mxid(data.userId)}`);

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc