mx-puppet-bridge
Advanced tools
Comparing version 0.0.39 to 0.0.40
@@ -112,4 +112,5 @@ "use strict"; | ||
if (!retData.success) { | ||
const print = retData.fn || retData.data ? retData.error : `ERROR: ${retData.error}`; | ||
yield this.sendMessage(roomId, print || ""); | ||
if (retData.fn) { | ||
yield this.sendMessage(roomId, `${retData.error}`); | ||
this.fnCollectListeners.set(sender, { | ||
@@ -119,6 +120,6 @@ fn: retData.fn, | ||
}); | ||
} | ||
if (!retData.data) { | ||
break; | ||
} | ||
yield this.sendMessage(roomId, `ERROR: ${retData.error}`); | ||
break; | ||
} | ||
@@ -132,5 +133,14 @@ if (!senderInfo.token) { | ||
} | ||
let data; | ||
try { | ||
data = (yield Promise.resolve(retData.data)) || {}; | ||
} | ||
catch (err) { | ||
log.warn("Failed to create/update link", err); | ||
yield this.sendMessage(roomId, `ERROR: ${err}`); | ||
break; | ||
} | ||
if (puppetId === -1) { | ||
// we need to create a new link | ||
puppetId = yield this.provisioner.new(sender, retData.data || {}, retData.userId); | ||
puppetId = yield this.provisioner.new(sender, data, retData.userId); | ||
yield this.sendMessage(roomId, `Created new link with ID ${puppetId}`); | ||
@@ -140,3 +150,3 @@ } | ||
// we need to update an existing link | ||
yield this.provisioner.update(sender, puppetId, retData.data || {}, retData.userId); | ||
yield this.provisioner.update(sender, puppetId, data, retData.userId); | ||
yield this.sendMessage(roomId, `Updated link with ID ${puppetId}`); | ||
@@ -143,0 +153,0 @@ } |
@@ -89,3 +89,3 @@ /// <reference types="node" /> | ||
error?: string; | ||
data?: IPuppetData; | ||
data?: IPuppetData | Promise<IPuppetData>; | ||
userId?: string; | ||
@@ -92,0 +92,0 @@ fn?: RetDataFn; |
{ | ||
"name": "mx-puppet-bridge", | ||
"version": "0.0.39", | ||
"version": "0.0.40", | ||
"description": "Matrix Puppeting Bridge library", | ||
@@ -5,0 +5,0 @@ "repository": { |
@@ -15,3 +15,3 @@ /* | ||
import { PuppetBridge } from "./puppetbridge"; | ||
import { RetDataFn, IRetData, IRemoteRoom } from "./interfaces"; | ||
import { RetDataFn, IRetData, IRemoteRoom, IPuppetData } from "./interfaces"; | ||
import { Provisioner } from "./provisioner"; | ||
@@ -130,4 +130,5 @@ import { PuppetType, PUPPET_TYPES } from "./db/puppetstore"; | ||
if (!retData.success) { | ||
const print = retData.fn || retData.data ? retData.error : `ERROR: ${retData.error}`; | ||
await this.sendMessage(roomId, print || ""); | ||
if (retData.fn) { | ||
await this.sendMessage(roomId, `${retData.error}`); | ||
this.fnCollectListeners.set(sender, { | ||
@@ -137,6 +138,6 @@ fn: retData.fn, | ||
}); | ||
} | ||
if (!retData.data) { | ||
break; | ||
} | ||
await this.sendMessage(roomId, `ERROR: ${retData.error}`); | ||
break; | ||
} | ||
@@ -150,9 +151,17 @@ if (!senderInfo.token) { | ||
} | ||
let data: IPuppetData; | ||
try { | ||
data = (await Promise.resolve(retData.data)) || {}; | ||
} catch (err) { | ||
log.warn("Failed to create/update link", err); | ||
await this.sendMessage(roomId, `ERROR: ${err}`); | ||
break; | ||
} | ||
if (puppetId === -1) { | ||
// we need to create a new link | ||
puppetId = await this.provisioner.new(sender, retData.data || {}, retData.userId); | ||
puppetId = await this.provisioner.new(sender, data, retData.userId); | ||
await this.sendMessage(roomId, `Created new link with ID ${puppetId}`); | ||
} else { | ||
// we need to update an existing link | ||
await this.provisioner.update(sender, puppetId, retData.data || {}, retData.userId); | ||
await this.provisioner.update(sender, puppetId, data, retData.userId); | ||
await this.sendMessage(roomId, `Updated link with ID ${puppetId}`); | ||
@@ -159,0 +168,0 @@ } |
@@ -129,3 +129,3 @@ /* | ||
error?: string; | ||
data?: IPuppetData; | ||
data?: IPuppetData | Promise<IPuppetData>; | ||
userId?: string; | ||
@@ -132,0 +132,0 @@ fn?: RetDataFn; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
778247
19884