@cocreate/users
Advanced tools
Comparing version 1.22.27 to 1.23.0
@@ -7,4 +7,4 @@ module.exports = { | ||
{ | ||
"collection": "files", | ||
"document": { | ||
"array": "files", | ||
"object": { | ||
"_id": "6012f7af86c0ba24512cca2e", | ||
@@ -11,0 +11,0 @@ "name": "index.html", |
{ | ||
"name": "@cocreate/users", | ||
"version": "1.22.27", | ||
"version": "1.23.0", | ||
"description": "A simple users component in vanilla javascript. Easily configured using HTML5 attributes and/or JavaScript API.", | ||
@@ -28,3 +28,3 @@ "keywords": [ | ||
"start": "npx webpack --config webpack.config.js", | ||
"build": "NODE_ENV=production npx webpack --config webpack.config.js", | ||
"build": "npx webpack --mode=production --config webpack.config.js", | ||
"dev": "npx webpack --config webpack.config.js --watch", | ||
@@ -62,9 +62,9 @@ "postinstall": "node -e \"const { execSync } = require('child_process'); try { execSync('coc --version', { stdio: 'ignore' }); } catch (error) { try { execSync('npm install -g @cocreate/cli', { stdio: 'inherit' }); console.log('Installed \"@cocreate/cli\" globally.'); } catch (error) { console.error('Failed to install \"@cocreate/cli\" globally:', error); } }\"" | ||
"dependencies": { | ||
"@cocreate/actions": "^1.8.31", | ||
"@cocreate/crud-client": "^1.21.23", | ||
"@cocreate/element-prototype": "^1.8.29", | ||
"@cocreate/form": "^1.14.29", | ||
"@cocreate/local-storage": "^1.7.20", | ||
"@cocreate/render": "^1.24.31" | ||
"@cocreate/actions": "^1.8.32", | ||
"@cocreate/crud-client": "^1.21.24", | ||
"@cocreate/element-prototype": "^1.8.30", | ||
"@cocreate/elements": "^1.17.33", | ||
"@cocreate/local-storage": "^1.7.21", | ||
"@cocreate/render": "^1.24.32" | ||
} | ||
} |
/*globals CustomEvent, btoa*/ | ||
import crud from '@cocreate/crud-client'; | ||
import action from '@cocreate/actions'; | ||
import form from '@cocreate/form'; | ||
import render from '@cocreate/render'; | ||
import Crud from '@cocreate/crud-client'; | ||
import Action from '@cocreate/actions'; | ||
import Elements from '@cocreate/elements'; | ||
import Render from '@cocreate/render'; | ||
import '@cocreate/element-prototype'; | ||
@@ -18,3 +18,3 @@ import './index.css'; | ||
const self = this; | ||
crud.listen('updateUserStatus', (data) => self.updateUserStatus(data)); | ||
Crud.listen('updateUserStatus', (data) => self.updateUserStatus(data)); | ||
}, | ||
@@ -26,8 +26,8 @@ | ||
let organization_id = crud.socket.config.organization_id; | ||
let collection = form.getAttribute('collection') | ||
if (!collection) { | ||
let organization_id = Crud.socket.config.organization_id; | ||
let array = formEl.getAttribute('array') | ||
if (!array) { | ||
for (let el of formEl) { | ||
collection = el.getAttribute('collection'); | ||
if (collection) | ||
array = el.getAttribute('array'); | ||
if (array) | ||
break; | ||
@@ -37,23 +37,25 @@ } | ||
let data = form.getData(formEl, collection) | ||
data['collection'] = collection | ||
let data = Elements.getFormData(formEl, array) | ||
data.method = 'create.object' | ||
data['array'] = array | ||
data.organization_id = organization_id; | ||
if (!data.document[0]._id) | ||
data.document[0]._id = crud.ObjectId(); | ||
if (!data.object[0]._id) | ||
data.object[0]._id = Crud.ObjectId(); | ||
let user = await crud.createDocument(data) | ||
form.setDocumentId(formEl, user) | ||
let user = await Crud.send(data) | ||
Elements.setTypeValue(formEl, user) | ||
// const socket = crud.socket.getSockets() | ||
// const socket = Crud.socket.getSockets() | ||
// if (!socket[0] || !socket[0].connected || window && !window.navigator.onLine) { | ||
let key = { | ||
collection: 'keys', | ||
document: { | ||
method: 'create.object', | ||
array: 'keys', | ||
object: { | ||
type: "user", | ||
key: user.document[0]._id, | ||
key: user.object[0]._id, | ||
roles: ['user'], | ||
email: user.document.email, | ||
password: user.document.password || btoa('0000'), | ||
collection | ||
email: user.object.email, | ||
password: user.object.password || btoa('0000'), | ||
array | ||
}, | ||
@@ -63,7 +65,7 @@ organization_id | ||
let response = await crud.createDocument(key) | ||
if (response && response.document && response.document[0]) { | ||
crud.socket.send('signUp', { user, userKey }) | ||
let response = await Crud.send(key) | ||
if (response && response.object && response.object[0]) { | ||
Crud.socket.send({ method: 'signUp', user, userKey }) | ||
render.data({ | ||
Render.data({ | ||
selector: "[template='signUp']", | ||
@@ -86,17 +88,18 @@ data: { | ||
let form = btn.closest('form'); | ||
let collection = form.getAttribute('collection'); | ||
let array = form.getAttribute('array'); | ||
let query = []; | ||
const inputs = form.querySelectorAll('input[name="email"], input[name="password"], input[name="username"]'); | ||
const inputs = form.querySelectorAll('input[key="email"], input[key="password"], input[key="username"]'); | ||
inputs.forEach((input) => { | ||
const name = input.getAttribute('name'); | ||
const key = input.getAttribute('key'); | ||
const value = input.getValue(); | ||
collection = 'keys'; | ||
query.push({ name, value, operator: '$eq' }) | ||
array = 'keys'; | ||
query.push({ key, value, operator: '$eq' }) | ||
}); | ||
let request = { | ||
method: 'read.object', | ||
db: 'indexeddb', | ||
collection, | ||
array, | ||
filter: { | ||
@@ -107,11 +110,11 @@ query | ||
const socket = crud.socket.getSockets() | ||
if (!socket[0] || !socket[0].connected || window && !window.navigator.onLine || crud.socket.serverOrganization == false) { | ||
crud.readDocument(request).then((response) => { | ||
const socket = Crud.socket.getSockets() | ||
if (!socket[0] || !socket[0].connected || window && !window.navigator.onLine || Crud.socket.serverOrganization == false) { | ||
Crud.send(request).then((response) => { | ||
response['success'] = false | ||
response['status'] = "signIn failed" | ||
if (response.document && response.document[0]) { | ||
if (response.object && response.object[0]) { | ||
response['success'] = true | ||
response['status'] = "success" | ||
response['user_id'] = response.document[0].key | ||
response['user_id'] = response.object[0].key | ||
this.signInResponse(response) | ||
@@ -123,5 +126,6 @@ } else { | ||
} else { | ||
request.method = 'signIn' | ||
request.broadcastBrowser = false | ||
delete request.storage | ||
crud.socket.send('signIn', request).then((response) => { | ||
Crud.socket.send(request).then((response) => { | ||
this.signInResponse(response) | ||
@@ -136,5 +140,5 @@ }) | ||
if (success) { | ||
localStorage.setItem('organization_id', crud.socket.config.organization_id); | ||
localStorage.setItem("key", crud.socket.config.key); | ||
localStorage.setItem("host", crud.socket.config.host); | ||
localStorage.setItem('organization_id', Crud.socket.config.organization_id); | ||
localStorage.setItem("key", Crud.socket.config.key); | ||
localStorage.setItem("host", Crud.socket.config.host); | ||
localStorage.setItem('user_id', user_id); | ||
@@ -151,3 +155,3 @@ localStorage.setItem("token", token); | ||
render.data({ | ||
Render.data({ | ||
selector: "[template='signIn']", | ||
@@ -174,3 +178,3 @@ data: { | ||
render.data({ | ||
Render.data({ | ||
selector: "[template='signOut']", | ||
@@ -191,3 +195,3 @@ data: { | ||
if (data.user_id) { | ||
let statusEls = document.querySelectorAll(`[user-status][document_id='${data['user_id']}']`); | ||
let statusEls = document.querySelectorAll(`[user-status][object='${data['user_id']}']`); | ||
@@ -202,5 +206,5 @@ statusEls.forEach((el) => { | ||
redirect: (data) => { | ||
if (data.user_id && data.user_id !== crud.socket.config.user_id) | ||
if (data.user_id && data.user_id !== Crud.socket.config.user_id) | ||
return | ||
if (!data.user_id && data.clientId !== crud.socket.clientId) | ||
if (!data.user_id && data.clientId !== Crud.socket.clientId) | ||
return | ||
@@ -237,3 +241,4 @@ if (data.userStatus == 'on' || data.userStatus == 'idle') { | ||
if (redirectTag) { | ||
crud.socket.send('sendMessage', { | ||
Crud.socket.send({ | ||
method: 'sendMessage', | ||
message: 'checkSession', | ||
@@ -255,23 +260,23 @@ broadcast: false, | ||
action.init({ | ||
Action.init({ | ||
name: "signUp", | ||
endEvent: "signUp", | ||
callback: (btn, data) => { | ||
CoCreateUser.signUp(btn); | ||
callback: (data) => { | ||
CoCreateUser.signUp(data.element); | ||
}, | ||
}); | ||
action.init({ | ||
Action.init({ | ||
name: "signIn", | ||
endEvent: "signIn", | ||
callback: (btn, data) => { | ||
CoCreateUser.signIn(btn, data); | ||
callback: (data) => { | ||
CoCreateUser.signIn(data.element); | ||
}, | ||
}); | ||
action.init({ | ||
Action.init({ | ||
name: "signOut", | ||
endEvent: "signOut", | ||
callback: (btn, data) => { | ||
CoCreateUser.signOut(btn, data); | ||
callback: (data) => { | ||
CoCreateUser.signOut(data.element); | ||
}, | ||
@@ -278,0 +283,0 @@ }); |
@@ -21,15 +21,17 @@ class CoCreateUser { | ||
if (data.user) { | ||
const response = await this.crud.createDocument(data.user) | ||
this.wsManager.broadcast(socket, 'createDocument', response); | ||
data.user.method = 'create.object' | ||
const response = await this.crud.send(data.user) | ||
this.wsManager.broadcast(socket, response); | ||
} | ||
if (data.userKey) { | ||
const response = await this.crud.createDocument(data.userKey) | ||
this.wsManager.broadcast(socket, 'createDocument', response); | ||
data.userKey.method = 'create.object' | ||
const response = await this.crud.send(data.userKey) | ||
this.wsManager.broadcast(socket, response); | ||
} | ||
self.wsManager.send(socket, 'signUp', data); | ||
self.wsManager.send(socket, data); | ||
} catch (error) { | ||
console.log('createDocument error', error); | ||
console.log('create.object error', error); | ||
} | ||
@@ -42,3 +44,3 @@ } | ||
namespace: string, | ||
collection: string, | ||
array: string, | ||
data: object, | ||
@@ -53,4 +55,6 @@ eId: string, | ||
try { | ||
this.crud.readDocument(data).then(async (data) => { | ||
data.method = 'read.object' | ||
this.crud.send(data).then(async (data) => { | ||
let response = { | ||
method: 'signIn', | ||
success: false, | ||
@@ -63,4 +67,4 @@ message: "signIn failed", | ||
if (data.document[0] && data.document[0]._id && self.wsManager.authenticate) { | ||
const user_id = data.document[0].key | ||
if (data.object[0] && data.object[0]._id && self.wsManager.authenticate) { | ||
const user_id = data.object[0].key | ||
const token = await self.wsManager.authenticate.generateToken({ user_id }); | ||
@@ -81,11 +85,12 @@ | ||
// let Data = { organization_id: process.env.organization_id } | ||
// Data.document['_id'] = data.document[0]._id | ||
// Data.document['lastsignIn'] = data.document[0].lastsignIn | ||
// Data.document['organization_id'] = process.env.organization_id | ||
// crud.updateDocument(Data) | ||
// Data.object['_id'] = data.object[0]._id | ||
// Data.object['lastsignIn'] = data.object[0].lastsignIn | ||
// Data.object['organization_id'] = process.env.organization_id | ||
// crud.send(Data) | ||
// } | ||
} | ||
} | ||
self.wsManager.send(socket, 'signIn', response) | ||
self.wsManager.broadcast(socket, 'updateUserStatus', { | ||
self.wsManager.send(socket, response) | ||
self.wsManager.broadcast(socket, { | ||
method: 'updateUserStatus', | ||
user_id: response.user_id, | ||
@@ -111,4 +116,4 @@ userStatus: response.userStatus, | ||
return | ||
data.collection = 'users' | ||
data['document'] = { | ||
data.array = 'users' | ||
data['object'] = { | ||
_id: data.user_id, | ||
@@ -118,5 +123,6 @@ userStatus: data.userStatus | ||
this.crud.updateDocument(data).then((data) => { | ||
// self.wsManager.broadcast(socket, 'updateUserStatus', data) | ||
self.wsManager.broadcast(socket, 'updateUserStatus', { | ||
data.method = 'update.object' | ||
this.crud.send(data).then((data) => { | ||
self.wsManager.broadcast(socket, { | ||
method: 'updateUserStatus', | ||
user_id: data.user_id, | ||
@@ -123,0 +129,0 @@ userStatus: data.userStatus, |
const path = require("path") | ||
const TerserPlugin = require("terser-webpack-plugin") | ||
const MiniCssExtractPlugin = require("mini-css-extract-plugin") | ||
let isProduction = process.env.NODE_ENV === "production" | ||
const { CleanWebpackPlugin } = require("clean-webpack-plugin") | ||
module.exports = { | ||
entry: { | ||
"CoCreate-users": "./src/index.js", | ||
}, | ||
output: { | ||
path: path.resolve(__dirname, "dist"), | ||
filename: isProduction ? "[name].min.js" : "[name].js", | ||
libraryTarget: "umd", | ||
libraryExport: "default", | ||
library: ["CoCreate", "users"], | ||
globalObject: "this", | ||
}, | ||
module.exports = (env, argv) => { | ||
let isProduction = false | ||
if (argv.mode === 'production') | ||
isProduction = true | ||
plugins: [ | ||
new CleanWebpackPlugin(), | ||
new MiniCssExtractPlugin({ | ||
filename: "[name].css", | ||
}), | ||
], | ||
// Default mode for Webpack is production. | ||
// Depending on mode Webpack will apply different things | ||
// on final bundle. For now we don't need production's JavaScript | ||
// minifying and other thing so let's set mode to development | ||
mode: isProduction ? "production" : "development", | ||
module: { | ||
rules: [ | ||
{ | ||
test: /.js$/, | ||
exclude: /(node_modules)/, | ||
use: { | ||
loader: "babel-loader", | ||
options: { | ||
plugins: ["@babel/plugin-transform-modules-commonjs"], | ||
}, | ||
const config = { | ||
entry: { | ||
"CoCreate-users": "./src/index.js", | ||
}, | ||
}, | ||
{ | ||
test: /.css$/i, | ||
use: [ | ||
{ loader: "style-loader", options: { injectType: "linkTag" } }, | ||
"file-loader", | ||
output: { | ||
path: path.resolve(__dirname, "dist"), | ||
filename: isProduction ? "[name].min.js" : "[name].js", | ||
libraryTarget: "umd", | ||
libraryExport: "default", | ||
library: ["CoCreate", "users"], | ||
globalObject: "this", | ||
}, | ||
plugins: [ | ||
new CleanWebpackPlugin(), | ||
new MiniCssExtractPlugin({ | ||
filename: "[name].css", | ||
}), | ||
], | ||
}, | ||
], | ||
}, | ||
// Default mode for Webpack is production. | ||
// Depending on mode Webpack will apply different things | ||
// on final bundle. For now we don't need production's JavaScript | ||
// minifying and other thing so let's set mode to development | ||
mode: isProduction ? "production" : "development", | ||
module: { | ||
rules: [ | ||
{ | ||
test: /.js$/, | ||
exclude: /(node_modules)/, | ||
use: { | ||
loader: "babel-loader", | ||
options: { | ||
plugins: ["@babel/plugin-transform-modules-commonjs"], | ||
}, | ||
}, | ||
}, | ||
{ | ||
test: /.css$/i, | ||
use: [ | ||
{ loader: "style-loader", options: { injectType: "linkTag" } }, | ||
"file-loader", | ||
], | ||
}, | ||
], | ||
}, | ||
// add source map | ||
...(isProduction ? {} : { devtool: "eval-source-map" }), | ||
// add source map | ||
...(isProduction ? {} : { devtool: "eval-source-map" }), | ||
optimization: { | ||
minimize: true, | ||
minimizer: [ | ||
new TerserPlugin({ | ||
extractComments: true, | ||
// cache: true, | ||
parallel: true, | ||
// sourceMap: true, // Must be set to true if using source-maps in production | ||
terserOptions: { | ||
// https://github.com/webpack-contrib/terser-webpack-plugin#terseroptions | ||
// extractComments: 'all', | ||
compress: { | ||
drop_console: true, | ||
}, | ||
optimization: { | ||
minimize: true, | ||
minimizer: [ | ||
new TerserPlugin({ | ||
extractComments: true, | ||
// cache: true, | ||
parallel: true, | ||
// sourceMap: true, // Must be set to true if using source-maps in production | ||
terserOptions: { | ||
// https://github.com/webpack-contrib/terser-webpack-plugin#terseroptions | ||
// extractComments: 'all', | ||
compress: { | ||
drop_console: true, | ||
}, | ||
}, | ||
}), | ||
], | ||
splitChunks: { | ||
chunks: "all", | ||
minSize: 200, | ||
// maxSize: 99999, | ||
//minChunks: 1, | ||
cacheGroups: { | ||
defaultVendors: false, | ||
}, | ||
}, | ||
}, | ||
}), | ||
], | ||
splitChunks: { | ||
chunks: "all", | ||
minSize: 200, | ||
// maxSize: 99999, | ||
//minChunks: 1, | ||
cacheGroups: { | ||
defaultVendors: false, | ||
}, | ||
}, | ||
}, | ||
} | ||
} | ||
return config | ||
} |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
146621
495
0
+ Added@cocreate/elements@^1.17.33
- Removed@cocreate/form@^1.14.29
Updated@cocreate/actions@^1.8.32
Updated@cocreate/render@^1.24.32