Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion sdk/event/event.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ exports.update = async function (id, {isDelivered, user} = {}) {
return rest.patchId(resource, id, payload, user);
};

exports.parse = async function ({content, signature, user} = {}) {
exports.parse = async function (content, signature, user) {
/**
*
* Create single notification Event from a content string
Expand All @@ -189,6 +189,17 @@ exports.parse = async function ({content, signature, user} = {}) {
*
*/

if (typeof content === 'object' && content !== null && !Array.isArray(content)) {
({content, signature, user} = content);
}

if (typeof content !== 'string' || content.length === 0) {
throw new Error('content must be a non-empty JSON string');
}
if (typeof signature !== 'string' || signature.length === 0) {
throw new Error('signature must be a non-empty base-64 string');
}

let event = Object.assign(new Event(), JSON.parse(content)['event']);
try {
signature = Ellipticcurve.Signature.fromBase64(signature);
Expand Down