New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@cocreate/users

Package Overview
Dependencies
Maintainers
1
Versions
322
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@cocreate/users - npm Package Compare versions

Comparing version

to
1.35.0

2

package.json
{
"name": "@cocreate/users",
"version": "1.34.2",
"version": "1.35.0",
"description": "A simple users component in vanilla javascript. Easily configured using HTML5 attributes and/or JavaScript API.",

@@ -5,0 +5,0 @@ "keywords": [

@@ -171,4 +171,8 @@ /*globals CustomEvent, btoa*/

this.redirect(data)
let statusEls
if (data.user_id) {
let statusEls = document.querySelectorAll(`[user-status][object='${data['user_id']}']`);
if (data.user_id === Crud.socket.user_id)
statusEls = document.querySelectorAll(`[user-status][object='${data['user_id']}'], [user-status][object='$user_id']`);
else
statusEls = document.querySelectorAll(`[user-status][object='${data['user_id']}']`);

@@ -230,3 +234,88 @@ statusEls.forEach((el) => {

// TODO: updatePassword()
inviteUser: async function (action) {
let email = action.form.querySelector('input[key="email"]');
if (!email)
return
else
email = await email.getValue()
let name = action.form.querySelector('input[key="name"]');
if (name)
name = await name.getValue()
let from = action.form.querySelector('input[key="from"]');
if (from)
from = await from.getValue()
let origin = action.form.querySelector('input[key="origin"]');
if (origin)
origin = await origin.getValue() || window.location.origin
let hostname = action.form.querySelector('input[key="hostname"]');
if (hostname)
hostname = await hostname.getValue() || window.location.hostname
let path = action.form.querySelector('input[key="path"]');
if (path)
path = await path.getValue()
let request = {
method: 'inviteUser',
name,
email,
from,
origin,
hostname,
path
}
Crud.socket.send(request).then((response) => {
render({
selector: "[template*='inviteUser']",
data: [{
type: 'inviteUser',
message: response.message,
success: response.success
}]
});
})
},
acceptInvite: async function (action) {
let data = {
method: 'acceptInvite',
success: false
}
let token = action.form.querySelector('input[key="token"]');
if (token)
data.token = await token.getValue()
let user_id = action.form.querySelector('input[key="_id"]');
if (user_id)
data.user_id = await user_id.getValue()
let email = action.form.querySelector('input[key="email"]');
if (email)
data.email = await email.getValue()
if (data.token && data.user_id) {
data = await Crud.socket.send(data)
} else {
data.message = 'Invitation failed'
}
if (data.success)
document.dispatchEvent(new CustomEvent('acceptInvite'));
else
render({
selector: "[template*='acceptInvite']",
data: [{
type: 'acceptInvite',
message: data.message,
success: data.success,
}]
});
},
forgotPassword: async function (action) {

@@ -336,2 +425,16 @@ let email = action.form.querySelector('input[key="email"]');

{
name: "inviteUser",
endEvent: "inviteUser",
callback: (action) => {
CoCreateUser.inviteUser(action);
}
},
{
name: "acceptInvite",
endEvent: "acceptInvite",
callback: (action) => {
CoCreateUser.acceptInvite(action);
}
},
{
name: "forgotPassword",

@@ -338,0 +441,0 @@ endEvent: "forgotPassword",

@@ -14,2 +14,4 @@ class CoCreateUser {

this.wsManager.on('checkSession', (data) => this.checkSession(data))
this.wsManager.on('inviteUser', (data) => this.inviteUser(data))
this.wsManager.on('acceptInvite', (data) => this.acceptInvite(data))
this.wsManager.on('forgotPassword', (data) => this.forgotPassword(data))

@@ -157,2 +159,124 @@ this.wsManager.on('resetPassword', (data) => this.resetPassword(data))

async inviteUser(data) {
try {
const inviteId = this.crud.ObjectId().toString()
let socket = data.socket
delete data.socket
data.method = 'object.update'
data.array = "users"
data.object = { _id: data.user_id, '$addToSet.invitations': inviteId, '$addToSet.members': data.email }
data = await this.crud.send(data)
let htmlBody = `
<html>
<head>
<title>Welcome to Yellow Oracle!</title>
</head>
<body>
<p>Hello,</p>
<p>You have been invited to join ${data.name} on Yellow Oracle.</p>
<p><a href="${data.origin}${data.path}?email=${data.email}&token=${inviteId}&user_id=${data.user_id}&name=${data.name}" style="color: #ffffff; background-color: #FFD700; padding: 10px 20px; text-decoration: none; border-radius: 5px;">Accept Your Invitation</a></p>
<p>Please note, this invitation link will expire in 48 hours. We encourage you to accept it soon to begin your journey with ${data.name} on Yellow Oracle.</p>
<p>If the button above doesn't work, you can copy and paste the following URL into your web browser:</p>
<p><a href="${data.origin}${data.path}?email=${data.email}&token=${inviteId}&user_id=${data.user_id}&name=${data.name}">${data.origin}${data.path}?email=${data.email}&token=${inviteId}&user_id=${data.user_id}&name=${data.name}</a></p>
<p>If you received this invitation by mistake or have any questions, please don't hesitate to get in touch with our support team at <a href="mailto:support@${data.hostname}">support@${data.hostname}</a>.</p>
<p>We look forward to welcoming you to ${data.name}'s Yellow Oracle account!</p>
</body>
</html>
`;
let email = {
method: 'postmark.sendEmail',
host: data.host,
postmark: {
"From": data.from,
"To": data.email,
"Subject": `${data.name} has invited you to join them on Yellow Oracle`,
"HtmlBody": htmlBody,
"TextBody": "Hello, \n\nWe received a request to reset the password for your account.If you did not make this request, please ignore this email.Otherwise, you can reset your password by copying and pasting the following link into your browser: https://example.com/reset-password\n\nThis link will expire in 24 hours for your security.\n\nNeed more help? Our support team is here for you at support@example.com.\n\nThank you for using our services!\n\nBest regards,\nThe [Your Company] Team",
"MessageStream": "outbound"
},
organization_id: data.organization_id
}
// TODO: wsManager.emit('postmark', email) needs to await response
this.wsManager.emit('postmark', email);
let response = {
socket,
host: data.host,
method: 'inviteUser',
success: true,
message: "Succesfully sent invite",
organization_id: data.organization_id,
uid: data.uid
}
this.wsManager.send(response)
} catch (error) {
data.error = error
this.wsManager.send(data)
console.log('Invite User failed', error);
}
}
async acceptInvite(data) {
const self = this;
try {
if (!data.token || !data.user_id) {
// TODO: handle error
return
}
data.method = 'object.update'
data.array = "users"
data.object = { '$pull.invitations': data.token, '$pull.members': data.email }
data.$filter = {
query: { invitations: { $in: [data.token] }, members: { $in: [data.email] } },
limit: 1
}
data = await this.crud.send(data)
let response = {
socket: data.socket,
host: data.host,
method: 'acceptInvite',
success: false,
message: "Token is invalid or has expired",
organization_id: data.organization_id,
uid: data.uid
}
for (let object of data.object) {
if (object._id) {
delete data.$filter
data.object = { _id: object._id, '$addToSet.members': data.user_id }
data = await this.crud.send(data)
response.success = true
response.message = "Invite Accepted"
break
}
}
self.wsManager.send(response)
} catch (error) {
console.log("Password reset failed", error);
}
}
async forgotPassword(data) {

@@ -238,3 +362,3 @@ const self = this;

} catch (error) {
console.log('signIn failed', error);
console.log('Forgot Password failed', error);
}

@@ -241,0 +365,0 @@ }

Sorry, the diff of this file is too big to display